Java Mailing List Archive

http://www.r-help.com/

Home » Home (12/2007) » R Help for Statistical Computing »

[R] glm(family=binomial(link=logit))

Robin Hankin

2005-07-15

Replies:

Hi

I am trying to make glm() work to analyze a toy logit system.

I have a dataframe with x and y independent variables. I have

L=1+x-y       (ie coefficients 1,1,-1)

then if I have a logit relation with L=log(p/(1-p)),
p=1/(1+exp(L)).

If I interpret "p" as the probability of success in a Bernouilli
trial, and I can observe the result (0 for "no", 1 for "yes")
how do I retrieve the coefficients c(1,1,-1)
from the data?

n <- 300
des <- data.frame(x=(1:n)/n,y=sample(n)/n)  # experimental design
des <- cbind(des,L=1+des$x-des$y)        # L=1+x-y
des <- cbind(des,p=1/(1+exp(des$L)))      # p=1/(1+e^L)
des <- cbind(des,obs=rbinom(n,1,des$p))    # observation: prob of
success = p.


My attempt is:

glm(obs~x+y,data=des,family=binomial(link="logit"))

But it does not retrieve the correct coefficients of c(1,1,-1) ;
I would expect a reasonably close answer with so much data.

What is the correct glm() call to perform my logit analysis?





--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743

______________________________________________
R-help@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
©2008 r-help.com - Jax Systems, LLC, U.S.A.