[R] Fitting a modified logistic with glm?
Ken Knoblauch
ken.knoblauch at inserm.fr
Sun Nov 9 15:09:04 CET 2008
Mike Lawrence <mike <at> thatmike.com> writes:
> Where f(x) is a logistic function, I have data that follow:
> g(x) = f(x)*.5 + .5
> How would you suggest I modify the standard glm(..., family='binomial')
> function to fit this? Here's an example of a clearly ill-advised attempt to
> simply use the standard glm(..., family='binomial') approach:
> #define the scale and location of the modified logistic to be fit
> location = 20
> scale = 30
> x = runif(200,-200,200)
> x.noise = runif(length(x),-10,10)
> prob.success = plogis(x+x.noise,location,scale)*.5 + .5
> y = rep(NA,length(x))
> for(i in 1:length(x)){
> y[i] = sample(
> x = c(1,0)
> , size = 1
> , prob = c(prob.success[i], 1-prob.success[i])
> )
> }
> plot(x,y)
> curve(plogis(x,location,scale)*.5 + .5,add=T)
Hi,
You might try the link mafc.logit(m = 2) defined in the
psyphy package. Continuing with your example,
library(psyphy)
fit <- glm(y ~ x, binomial(mafc.logit(2)),
control = glm.control(maxit = 100)) # default didn't converge
x.ord <- order(x)
lines(x[x.ord], fitted(fit)[x.ord], col = "red", lwd = 3)
HTH,
Ken
--
Ken Knoblauch
Inserm U846
Institut Cellule Souche et Cerveau
Département Neurosciences Intégratives
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr
More information about the R-help
mailing list