Hi all,
I'm interested in updating glm using glm.fit() (of course my final output is
different, but the problem is in glm.fit()). Then my function is, say:
fn<-function(obj,z){
X<-update(obj,x=T)$x
X<-cbind(X,z)
y<-obj$y
fam<-family(obj)
o<-obj$offset
contr<-obj$control
w<-obj$weights
o<-glm.fit(x=X,y=y,offset=o,weights=w,family=fam,control=contr)
o$coef}
Such function works with gaussian family, but I have some problems with
binomial one. To test it let use the Down-syndrome data in the boot library:
library(boot)
data(downs.bc)
o<-glm(r/m~age ,family=binomial,weight=m,data=downs.bc)
> fn(o,z=I(downs.bc$age^2))
(Intercept) age z
-4.940844023 -0.250360022 0.006250743
Warning message:
non-integer #successes in a binomial glm! in: eval(expr, envir, enclos)
but
> update(o,.~.+I(downs.bc$age^2))$coef
(Intercept) age I(downs.bc$age^2)
-2.243578933 -0.414359607 0.008624326
Of course there is some problems, probably I'm missing something in
extracting the response, but I'm stuck and not able to solve my problem.
I would like use my function with *any* glm() (with any
family,link,offset,....).
Where have I to modify my code in order to use glm.fit()?
Also I would like to use "fn(o,z=I(age^2))" without specifying the
dataframe
(i.e. "fn(o,z=I(downs.bc$age^2))"). That is fn() should search its
argument
z in the environment of obj and then in the global environment. Where is the
trick?
Many thanks for your help!
best,
vito
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._