[R] Question on function "glm.fit"

Thomas Lumley thomas at biostat.washington.edu
Tue Nov 9 20:06:01 CET 1999


On Tue, 9 Nov 1999, DEVAS, Vipul wrote:

> I have a code that contains function "glm.fit" and it works in S-PLUS.  But
> this same code (with some minor changes) does not work in R.  I am supplying
> the part of the code.  Can somebody help with this problem?
> The code
> ***************************************************
> x1 <- seq(from=-1,to=2, length=20)
> x2 <- (rep(1:5,4))/4
> x <- cbind(1,x1,x2)
> y <- c(0,1,1,1,1,1,0,0,1,1,1,0,1,0,1,1,1,1,1,1)
> glm.fit(x,y,fam=binomial(link=logit))$coeff
> *********************************************************

The problem seems to be that glm.fit() assumes its x matrix has non-null
column names.  This will always be true when x is generated by the
model.matrix() function, as it is when glm.fit() is called from glm()

R>glm.fit(model.matrix(~x1+x2,model.frame(~x1+x2)),y,family=binomial())$coeff
(Intercept)          x1          x2 
-0.08959875  0.44189065  1.45697672 
R> xxx<-x
R> colnames(xxx)
NULL
R> colnames(xxx)<-c("1","x1","x2")
R> glm.fit(xxx,y,fam=binomial())$coeff
          1          x1          x2 
-0.08959875  0.44189065  1.45697672 


The column names are used to label the estimated effects in the line
    names(fit$effects) <- c(xxnames[seq(fit$rank)], rep("", nobs - 
        fit$rank))
near the end of the function.


Presumably this should be fixed -- perhaps label the columns "1" "2" "3"
and so on?


	-thomas

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list