Here's my solution, with bbmle
.
Data:
dframe1 <- structure(list(independent_variable = c(0.3, 0.24, 0.23, 0.16,
0.14, 0.05, 0.01, -0.1, -0.2), dependent_variable = c(1, 1,
1, 0.95, 0.93, 0.65, 0.55, 0.5, 0.5)), .Names = c("independent_variable",
"dependent_variable"), class = "data.frame", row.names = c(NA,
-9L))
Construct a cumulative Weibull that goes from 0.5 to 1.0 by definition:
wfun <- function(x,shape,scale) {
(1+pweibull(x,shape,scale))/2.0
}
dframe2 <- transform(dframe1,y=round(40*dependent_variable),x=independent_variable)
Fit a Weibull (log-scale relevant parameters), with binomial variation:
library(bbmle)
m1 <- mle2(y~dbinom(prob=wfun(exp(a+b*x),shape=exp(logshape),scale=1),size=40),
data=dframe2,start=list(a=0,b=0,logshape=0))
Generate predictions:
pframe <- data.frame(x=seq(-0.2,0.3,length=101))
pframe$y <- predict(m1,pframe)
png("wplot.png")
with(dframe2,plot(y/40~x))
with(pframe,lines(y/40~x,col=2))
dev.off()