I was searching for GLM content, then I found this forum, so I thought you could help me .

I'm

**starting**to study GLMs and I know the glm R function but I would like to try to create an algorithm in R to estimate the parameters of a Binomial GLM.

I have found this article (in portuguese)

http://www2.dbd.puc-rio.br/pergamum/tesesabertas/9924892_04_cap_03.pdf

And on pages 10 and 11 shows the algorithm procedure.

I tried to put in R, using the fact that my response Y is only 0 or 1 and my sample is composed of 128 people.

a)Since I need some start value for mu (mi) a choose 0.5 but what's a good choice for it? Since it's logistic link function I think mu=mi=y wouldn't be possible.

b)The algorithm is incorrect since R answers is not the same.

Can anyone help me? Thanks in advance .

y is the response, mi is the mean mu, w is the diagonal weight matrix, z results from eta+(y-mi)dn/dmi, B is the estimative of Beta parameters.

#1st iteration

for (i in 1:128)

mi

*=0.5*

y=hiper.f

eta=logit(mi)

z=eta+(y-mi)/(mi*(1-mi))

w<-matrix(0,128,128)

for(j in 1:128)

w[j,j]<-128*mi[j]*(1-mi[j])

B<-solve(t(X)%*%w%*%X)%*%t(X)%*%w%*%z

#other iterations

for(i in 1:4) {

eta=X%*%B

mi=exp(eta)/(1+exp(eta))

z=eta+(y-mi)/(mi*(1-mi))

for(j in 1:128)

w[j,j]<-128*mi[j]*(1-mi[j])

B<-solve(t(X)%*%w%*%X)%*%t(X)%*%w%*%z

}

Sorry if I said anything wrong or if the algorithm is very very incorrect. Thanks!

y=hiper.f

eta=logit(mi)

z=eta+(y-mi)/(mi*(1-mi))

w<-matrix(0,128,128)

for(j in 1:128)

w[j,j]<-128*mi[j]*(1-mi[j])

B<-solve(t(X)%*%w%*%X)%*%t(X)%*%w%*%z

#other iterations

for(i in 1:4) {

eta=X%*%B

mi=exp(eta)/(1+exp(eta))

z=eta+(y-mi)/(mi*(1-mi))

for(j in 1:128)

w[j,j]<-128*mi[j]*(1-mi[j])

B<-solve(t(X)%*%w%*%X)%*%t(X)%*%w%*%z

}

Sorry if I said anything wrong or if the algorithm is very very incorrect. Thanks!