Re: [R] a question about glm( )

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Fri 07 Jul 2006 - 07:53:09 EST

qli@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@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@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@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
Received on Fri Jul 07 07:57:12 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 07 Jul 2006 - 08:15:47 EST.

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