[R] a question about glm( )

qli at math.wustl.edu qli at math.wustl.edu
Thu Jul 6 23:41:03 CEST 2006


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!!!

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 = 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

More information about the R-help mailing list