Ravi Kulkarni
2010-Mar-28 17:15 UTC
[R] Coding of categorical variables for logistic regression?
Hello, I am trying to do a logistic regression and have one predictor variable (x) that is ratio and two predictor variables (y and z) that are categorical. These have three levels each which I have called "High", "Medium" and "Low". My question: do I need to use a numerical coding scheme for the categorical variables as required by some statistical software packages, with some sort of numeric dummy-variable coding? I am using: glm(binvar~x+y+z, family=binomial(link="logit")) Thanks, Ravi Kulkarni -- View this message in context: http://n4.nabble.com/Coding-of-categorical-variables-for-logistic-regression-tp1694250p1694250.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2010-Mar-28 17:30 UTC
[R] Coding of categorical variables for logistic regression?
On Mar 28, 2010, at 1:15 PM, Ravi Kulkarni wrote:> > Hello, > I am trying to do a logistic regression and have one predictor > variable > (x) that is ratio and two predictor variables (y and z) that are > categorical. These have three levels each which I have called "High", > "Medium" and "Low". > My question: do I need to use a numerical coding scheme for the > categorical variables as required by some statistical software > packages, > with some sort of numeric dummy-variable coding?No. If you have constructed those variables as factors, the regression functions in R will interpret them correctly, i.e. as though the dummies were in there. If you have not constructed them as factors, you should do so now. ?factor ?levels> > I am using: > glm(binvar~x+y+z, family=binomial(link="logit")) > > Thanks, > > Ravi Kulkarni > --David Winsemius, MD West Hartford, CT
Johannes Huesing
2010-Mar-28 18:20 UTC
[R] Coding of categorical variables for logistic regression?
Ravi Kulkarni <ravi.kulk at gmail.com> [Sun, Mar 28, 2010 at 07:15:52PM CEST]: [...]> I am trying to do a logistic regression and have one predictor variable > (x) that is ratio and two predictor variables (y and z) that are > categorical. These have three levels each which I have called "High", > "Medium" and "Low".You don't plan to use the information that y and z are apparently ordinal? -- Johannes H?sing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johannes at huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")
Ravi Kulkarni
2010-Mar-29 02:39 UTC
[R] Coding of categorical variables for logistic regression?
How do I use the "extra" information that two of my predictors are ordinal? (I did not know I could do that.) Thanks, Ravi -- View this message in context: http://n4.nabble.com/Coding-of-categorical-variables-for-logistic-regression-tp1694250p1694644.html Sent from the R help mailing list archive at Nabble.com.
?polr of the MASS package. On Mon, Mar 29, 2010 at 10:39 AM, Ravi Kulkarni <ravi.kulk at gmail.com> wrote:> > How do I use the "extra" information that two of my predictors are ordinal? > (I did not know I could do that.) > > Thanks, > ?Ravi > -- > View this message in context: http://n4.nabble.com/Coding-of-categorical-variables-for-logistic-regression-tp1694250p1694644.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- CH Chan Research Assistant - KWH http://www.macgrass.com
David Winsemius
2010-Mar-29 05:42 UTC
[R] Coding of categorical variables for logistic regression?
Just because a covariate is ordered does not ensure that the relationship will be monotonic. -- David. On Mar 28, 2010, at 11:09 PM, C.H. wrote:> ?polr of the MASS package. > > > On Mon, Mar 29, 2010 at 10:39 AM, Ravi Kulkarni > <ravi.kulk at gmail.com> wrote: >> >> How do I use the "extra" information that two of my predictors are >> ordinal? >> (I did not know I could do that.) >> >> Thanks, >> Ravi >> -- >> View this message in context: http://n4.nabble.com/Coding-of-categorical-variables-for-logistic-regression-tp1694250p1694644.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > CH Chan > Research Assistant - KWH > http://www.macgrass.com > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT
Daniel Malter
2010-Mar-29 06:13 UTC
[R] Coding of categorical variables for logistic regression?
This is about the covariates, not the dependent variable. So a polynomial logistic regression seems hardly appropriate. David is right with his latest statement, just because they are ordered does not assure that the effect is monotonic. If the "low", "medium", and "high" groups had even spacing (e.g., 10, 20, 30 (on whatever scale)), you could use an alternative way of factor coding. Orthogonal polynomial contrasts tests for curvilinear effects by while keeping the factor nature of the variable intact. That is, it is not the same as including the numeric variable and its higher order polynomials (e.g., Rosenthal and Rosnow 1985). Daniel ------------------------- cuncta stricte discussurus ------------------------- -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of C.H. Sent: Sunday, March 28, 2010 11:10 PM To: Ravi Kulkarni Cc: r-help at r-project.org Subject: Re: [R] Coding of categorical variables for logistic regression? ?polr of the MASS package. On Mon, Mar 29, 2010 at 10:39 AM, Ravi Kulkarni <ravi.kulk at gmail.com> wrote:> > How do I use the "extra" information that two of my predictors are ordinal? > (I did not know I could do that.) > > Thanks, > Ravi > -- > View this message in context: http://n4.nabble.com/Coding-of-categorical-variables-for-logistic-regression-tp1694250p1694644.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- CH Chan Research Assistant - KWH http://www.macgrass.com ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.