[R] Fitting a modified logistic with glm?

From: Mike Lawrence <mike_at_thatmike.com>
Date: Sat, 08 Nov 2008 12:51:24 -0400


Hi all,

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:

########
# First generate some data
########
#define the scale and location of the modified logistic to be fit
location = 20
scale = 30

# choose some x values

x = runif(200,-200,200)

# generate some random noise to add to x in order to
# simulate real-word measurement and avoid perfect fits
x.noise = runif(length(x),-10,10)

# define the probability of success for each x given the modified logistic
prob.success = plogis(x+x.noise,location,scale)*.5 + .5

# obtain y, the observed success/failure at each x

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])
    )
}

#show the data and the source modified logistic
plot(x,y)
curve(plogis(x,location,scale)*.5 + .5,add=T)

########
# Now try to fit the data
########

#fit using standard glm and plot the result
fit = glm(y~x,family='binomial')
curve(plogis(fit$coefficients[1]+x*fit$coefficients[2])*.5+.5,add=T,col='red',lty=2)

# It's clear that it's inappropriate to use the standard
"glm(y~x,family='binomial')"
# method to fit the modified logistic data, but what is the alternative?

-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University
www.thatmike.com

Looking to arrange a meeting? Check my public calendar and find a time that
is mutually free:
http://tinyurl.com/mikescalendar
(tiny url redirects to google calendar)

~ Certainty is folly... I think. ~

	[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 08 Nov 2008 - 19:37:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 09 Nov 2008 - 18:30:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive