[R] a question about glm( )

Peter Dalgaard p.dalgaard at biostat.ku.dk
Thu Jul 6 23:53:09 CEST 2006


qli at math.wustl.edu writes:

> Hi,
> 
> I am working on an example about generalized linear model in a paper using
> glm( ). The code is quite simple and straightforward, but the result is
> rediculous. The true parameter is c(4, -6), but the result is c(2.264774,
> -3.457114) Can anybody tell me the reason for this? Thanks a lot!!!

What's ridiculous about that? With a sample size of 100, the
estimation variation is going to be substantial. I get

> beta.old
(Intercept)      x[, 2]
   3.096393   -4.845186
> confint(glm (y~x[,2],family=binomial()))
Waiting for profiling to be done...
                2.5 %    97.5 %
(Intercept)  1.251333  5.574944
x[, 2]      -8.093080 -2.370165

and c(4, -6) is well within the confidence limits.

 
> Here is the code:
> 
> 
> g=function(t){exp(t)/(1+exp(t))}	#the given link function
> 
> 
> n = 100	 # sample size
> beta.true = c(4,-6)	#the true parameter
> 
> #----------------------------------------- the given x
> x = rep(0,n)
> 
> for(i in 1:n)
> 
> 	{if (i<=80)
> 
> 		x[i]=0.90-0.0025*i
> 
> 	 else
> 
> 		x[i]=0.70-0.035*(i-80)
> 
> 	}
> 
> x = cbind(1,x)
> 
> #----------------------------------------- to generate y
> 
> meany = g(x%*%beta.true)
> 
> 
> y = rep(0,100)
> for(i in 1:n)
> 
> 	{ # simulate the data from a binomial distribution
> 
> 		y[i] = rbinom(1,1,meany[i])
> 	}
> 
> 
> #------------------------------------------ to do the Quasi-likelihood
> beta.old = glm (y~x[,2],family=binomial())$coef
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list