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 ********************************************************* My email address is "vipul.devas at rp-rorer.com" Thank you. Vipul -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"DEVAS, Vipul" <Vipul.Devas at rp-rorer.com> writes:> 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 > *********************************************************Aha! We've had a similar report but with no reproduction instructions. Thank you very much for the clear example. The thing that happens is that your x has no dimnames, but is a matrix, so xnames and xxnames inside glm.fit are NULL and when you get to names(fit$effects) <- c(xxnames[seq(fit$rank)], rep("", nobs - fit$rank)) everything comes to a screeching halt. If you add column names, things are OK:> colnames(x)<-1:3 > glm.fit(x,y,fam=binomial(link=logit))$coeff1 2 3 -0.08959875 0.44189065 1.45697672 I'm not really sure whether there's a bug in cbind, glm.fit, or both... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._