Dear R-help list members, I am currently trying to fit a generalized linear model using a binomial with the canonical link. The usual solution is to use the R function glm() in the package "stats". However, I run into problem when I want to fit a glm without an intercept. It is indicated that the solution is in changing the function glm.fit (also in "stats"), by specifying intercept=FALSE. I have not been successful in getting any output though. Any suggestion on how to fit a glm with no intercept? Regards, Gudrun -- Gudrun Jonasdottir, M.Sc. Matematiska institutionen Stockholms Universitet SE- 106 91 Stockholm Work: +46 (0)8 16 45 56 Mobile: +46 (0)709 779 800 -------------------------------------------- "N?r inget annat hj?lper, l?s instruktionsboken." - Canns axiom
Hi Gudrun, try the following: y <- rbinom(100, 1, 0.5) x <- rnorm(100) ############## glm(y~x, family=binomial) glm(y~x-1, family=binomial) I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/336899 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Gudrun Jonasdottir" <gudrunj at math.su.se> To: <r-help at stat.math.ethz.ch> Sent: Friday, January 07, 2005 3:40 PM Subject: [R] glm fit with no intercept> Dear R-help list members, > > I am currently trying to fit a generalized linear model using a > binomial > with the canonical link. The usual solution is to use the R function > glm() > in the package "stats". However, I run into problem when I want to > fit a > glm without an intercept. It is indicated that the solution is in > changing > the function glm.fit (also in "stats"), by specifying > intercept=FALSE. I > have not been successful in getting any output though. > > Any suggestion on how to fit a glm with no intercept? > > Regards, > Gudrun > > -- > Gudrun Jonasdottir, M.Sc. > Matematiska institutionen > Stockholms Universitet > SE- 106 91 Stockholm > > Work: +46 (0)8 16 45 56 > Mobile: +46 (0)709 779 800 > -------------------------------------------- > "N?r inget annat hj?lper, l?s instruktionsboken." > - Canns axiom > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >
"Gudrun Jonasdottir" <gudrunj at math.su.se> writes:> Dear R-help list members, > > I am currently trying to fit a generalized linear model using a binomial > with the canonical link. The usual solution is to use the R function glm() > in the package "stats". However, I run into problem when I want to fit a > glm without an intercept. It is indicated that the solution is in changing > the function glm.fit (also in "stats"), by specifying intercept=FALSE. I > have not been successful in getting any output though. > > Any suggestion on how to fit a glm with no intercept?Use -1 in the model formula. x <- sample(0:1,10,rep=T) d <- runif(10) summary(glm(x~d-1,family=binomial))> "N?r inget annat hj?lper, l?s instruktionsboken." > - Canns axiom.. i n?rvarande fall: "An Introduction to R", Ch.11. -- 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
As in any modelling situation in R or S, to suppress the intercept you simply put a ``-1'' in the formula. E.g.: fit <- glm(y~x-1,family=binomial) cheers, Rolf Turner rolf at math.unb.ca
On Fri, 7 Jan 2005, Gudrun Jonasdottir wrote:> I am currently trying to fit a generalized linear model using a binomial > with the canonical link. The usual solution is to use the R function glm() > in the package "stats". However, I run into problem when I want to fit a > glm without an intercept. It is indicated that the solution is in changingWhere is it so indicated?> the function glm.fit (also in "stats"), by specifying intercept=FALSE. I > have not been successful in getting any output though. > > Any suggestion on how to fit a glm with no intercept?>From MASS4:ldose <- rep(0:5, 2) numdead <- c(1, 4, 9, 13, 18, 20, 0, 2, 6, 10, 12, 16) sex <- factor(rep(c("M", "F"), c(6, 6))) SF <- cbind(numdead, numalive = 20 - numdead) glm(SF ~ sex+ ldose, family = binomial) glm(SF ~ sex + ldose - 1, family = binomial) # no intercept glm(SF ~ ldose - 1, family = binomial) # and not even a factor Please tell us more of what you have tried. -- 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 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Apparently Analagous Threads
- Finding LD50 from an interaction Generalised Linear model
- paradox about the degree of freedom in a logistic regression model
- Finney's fiducial confidence intervals of LD50
- creating bins for a plot
- how to obtain the OR and 95%CI with 1 SD change of a continue variable