[R] Question on function "glm.fit"

Prof Brian D Ripley ripley at stats.ox.ac.uk
Tue Nov 9 20:09:56 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?

First, please do not use internal functions like this. There is no reason
not to use the advertised interface for glm.

glm(y ~ x1+x2, family=binomial(link=logit))$coeff
(Intercept)          x1          x2 
-0.08959875  0.44189065  1.45697672 

works in R as it would in S.

However, if you really want to know, you need to set x up correctly.

x <- cbind(intercept=1, x1=x1, x2=x2)
glm.fit(x,y,fam=binomial(link=logit))$coeff
  intercept          x1          x2 
-0.08959875  0.44189065  1.45697672 

The x matrix _must_ have colnames (and it would have in S-PLUS). As it is
an internal function, it does not check these things.

Whoever wrote the help page for glm.fit might note that

     x,y: logical values indicating whether the response
          vector and design matrix used in the fitting pro-
          cess should be returned as components of the
          returned value.

is none too helpful for glm.fit!  I believe it should have a help page
saying *Internal function, not for use directly*, but I tend to lose
such arguments! The S-PLUS one says

x:     a model matrix (design matrix).

so your example is incorrect in S, too. (Your x is not a model matrix.)

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

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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