Dear R-users: How does one calculate in R the odds ratios for a CATEGORICAL predictor variable that has 4 levels. I see r-help inquiries regarding odds ratios for what looked like a continuous predictor variable. I was wondering how to get the pairwise odds ratios for comparisons of levels of a categorical predictor variable. I can't seem to get the correct output using: > sp.glm=glm(cohort$logreg~cohort$hab, family=binomial) > summary(sp.glm) This gives me the coefficient for the effect of hab overall, but not the coefficients for the comparisons of each of the levels. I suspect this has something to do with the contrasts statement, but I can't figure it out, and would be very appreciative of any help you can provide. Thank you, Sabrina ______________________________________________________________ Sabrina E. Russo Postdoctoral Fellow Center for Tropical Forest Science - Arnold Arboretum Asia Program Harvard University 22 Divinity Avenue Cambridge, MA 02138 USA 617-496-2380 phone 617-495-9484 FAX srusso@oeb.harvard.edu [[alternative HTML version deleted]]
Is hab coded as a factor or a numeric variable? -roger Sabrina Russo wrote:> Dear R-users: > How does one calculate in R the odds ratios for a CATEGORICAL predictor > variable that has 4 levels. I see r-help inquiries regarding odds ratios > for what looked like a continuous predictor variable. I was wondering how > to get the pairwise odds ratios for comparisons of levels of a categorical > predictor variable. I can't seem to get the correct output using: > > sp.glm=glm(cohort$logreg~cohort$hab, family=binomial) > > summary(sp.glm) > > This gives me the coefficient for the effect of hab overall, but not the > coefficients for the comparisons of each of the levels. I suspect this has > something to do with the contrasts statement, but I can't figure it out, > and would be very appreciative of any help you can provide. > Thank you, > Sabrina > > ______________________________________________________________ > Sabrina E. Russo > Postdoctoral Fellow > Center for Tropical Forest Science - Arnold Arboretum Asia Program > Harvard University > 22 Divinity Avenue > Cambridge, MA 02138 USA > > 617-496-2380 phone > 617-495-9484 FAX > srusso at oeb.harvard.edu > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
On Fri, 05 Dec 2003 14:00:05 -0500 Sabrina Russo <srusso at oeb.harvard.edu> wrote:> Dear R-users: > How does one calculate in R the odds ratios for a CATEGORICAL predictor > > variable that has 4 levels. I see r-help inquiries regarding odds > ratios for what looked like a continuous predictor variable. I was > wondering how to get the pairwise odds ratios for comparisons of levels > of a categorical predictor variable. I can't seem to get the correct > output using: > > sp.glm=glm(cohort$logreg~cohort$hab, family=binomial) > > summary(sp.glm) > > This gives me the coefficient for the effect of hab overall, but not the > > coefficients for the comparisons of each of the levels. I suspect this > has something to do with the contrasts statement, but I can't figure it > out, and would be very appreciative of any help you can provide. > Thank you, > Sabrina > > ______________________________________________________________ > Sabrina E. Russo > Postdoctoral Fellow > Center for Tropical Forest Science - Arnold Arboretum Asia Program > Harvard University > 22 Divinity Avenue > Cambridge, MA 02138 USA > > 617-496-2380 phone > 617-495-9484 FAX > srusso at oeb.harvard.edu >library(Design) f <- lrm(. . .) summary(f) --- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University
On Fri, 5 Dec 2003, Sabrina Russo wrote:> Dear R-users: > How does one calculate in R the odds ratios for a CATEGORICAL predictor > variable that has 4 levels. I see r-help inquiries regarding odds ratios > for what looked like a continuous predictor variable. I was wondering how > to get the pairwise odds ratios for comparisons of levels of a categorical > predictor variable. I can't seem to get the correct output using: > > sp.glm=glm(cohort$logreg~cohort$hab, family=binomial) > > summary(sp.glm) >If the predictor isn't already coded as a factor, use sp.glm=glm(cohort$logreg~factor(cohort$hab), family=binomial) This will give contrasts with the first level of the factor. A tidier way to specify the same thing is sp.glm <- glm(logreg~factor(hab), data=cohort, family=binomial) -thomas