Hi Bert, Thank you for the kind reply. But what if I don't turn the variable into a factor. Let's say that in excel I just coded the variable as 1s and 0s and just imported the dataset into R and fitted the logistic regression without turning any categorical variable or dummy variable into a factor? Does R requires every dummy variable to be treated as a factor? Best regards, Paul El s?b., 1 de agosto de 2020 12:59 p. m., Bert Gunter < bgunter.4567 at gmail.com> escribi?:> x <- factor(0:1) > x <- factor("yes","no") > > will produce identical results up to labeling. > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sat, Aug 1, 2020 at 10:40 AM Paul Bernal <paulbernal07 at gmail.com> > wrote: > >> Dear friends, >> >> Hope you are doing great. I want to fit a logistic regression in R, where >> the dependent variable is the covid status (I used 1 for covid positives, >> and 0 for covid negatives), but when I ran the glm, R complains that I >> should make the dependent variable a factor. >> >> What would be more advisable, to keep the dependent variable with 1s and >> 0s, or code it as yes/no and then make it a factor? >> >> Any guidance will be greatly appreciated, >> >> Best regards, >> >> Paul >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> >[[alternative HTML version deleted]]
You appear to be confusing a binomial **response** with categorical "dependent variables." glm() of course fits continuous or categorical dependent variables. If a continuous dependent variable has only 2 values, the results for glm() will be the same whether or not it is considered to be continuous or categorical, though you may not recognize it as such. This discussion has already wandered off topic to statistical issues. I will not comment further on or off list. I suggest you consult a good reference on linear/generalized linear models or talk with a local statistician. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Aug 1, 2020 at 11:04 AM Paul Bernal <paulbernal07 at gmail.com> wrote:> Hi Bert, > > Thank you for the kind reply. > > But what if I don't turn the variable into a factor. Let's say that in > excel I just coded the variable as 1s and 0s and just imported the dataset > into R and fitted the logistic regression without turning any categorical > variable or dummy variable into a factor? > > Does R requires every dummy variable to be treated as a factor? > > Best regards, > > Paul > > El s?b., 1 de agosto de 2020 12:59 p. m., Bert Gunter < > bgunter.4567 at gmail.com> escribi?: > >> x <- factor(0:1) >> x <- factor("yes","no") >> >> will produce identical results up to labeling. >> >> >> Bert Gunter >> >> "The trouble with having an open mind is that people keep coming along >> and sticking things into it." >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >> >> >> On Sat, Aug 1, 2020 at 10:40 AM Paul Bernal <paulbernal07 at gmail.com> >> wrote: >> >>> Dear friends, >>> >>> Hope you are doing great. I want to fit a logistic regression in R, where >>> the dependent variable is the covid status (I used 1 for covid positives, >>> and 0 for covid negatives), but when I ran the glm, R complains that I >>> should make the dependent variable a factor. >>> >>> What would be more advisable, to keep the dependent variable with 1s and >>> 0s, or code it as yes/no and then make it a factor? >>> >>> Any guidance will be greatly appreciated, >>> >>> Best regards, >>> >>> Paul >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> 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. >>> >>[[alternative HTML version deleted]]
Sorry, typo.My first sentences should read: "You appear to be confusing a binomial **response** with categorical "independent variables." glm() of course fits continuous or categorical independent variables." Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Aug 1, 2020 at 11:11 AM Bert Gunter <bgunter.4567 at gmail.com> wrote:> You appear to be confusing a binomial **response** with categorical > "dependent variables." glm() of course fits continuous or categorical > dependent variables. If a continuous dependent variable has only 2 values, > the results for glm() will be the same whether or not it is considered to > be continuous or categorical, though you may not recognize it as such. > > This discussion has already wandered off topic to statistical issues. I > will not comment further on or off list. I suggest you consult a good > reference on linear/generalized linear models or talk with a local > statistician. > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sat, Aug 1, 2020 at 11:04 AM Paul Bernal <paulbernal07 at gmail.com> > wrote: > >> Hi Bert, >> >> Thank you for the kind reply. >> >> But what if I don't turn the variable into a factor. Let's say that in >> excel I just coded the variable as 1s and 0s and just imported the dataset >> into R and fitted the logistic regression without turning any categorical >> variable or dummy variable into a factor? >> >> Does R requires every dummy variable to be treated as a factor? >> >> Best regards, >> >> Paul >> >> El s?b., 1 de agosto de 2020 12:59 p. m., Bert Gunter < >> bgunter.4567 at gmail.com> escribi?: >> >>> x <- factor(0:1) >>> x <- factor("yes","no") >>> >>> will produce identical results up to labeling. >>> >>> >>> Bert Gunter >>> >>> "The trouble with having an open mind is that people keep coming along >>> and sticking things into it." >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>> >>> >>> On Sat, Aug 1, 2020 at 10:40 AM Paul Bernal <paulbernal07 at gmail.com> >>> wrote: >>> >>>> Dear friends, >>>> >>>> Hope you are doing great. I want to fit a logistic regression in R, >>>> where >>>> the dependent variable is the covid status (I used 1 for covid >>>> positives, >>>> and 0 for covid negatives), but when I ran the glm, R complains that I >>>> should make the dependent variable a factor. >>>> >>>> What would be more advisable, to keep the dependent variable with 1s and >>>> 0s, or code it as yes/no and then make it a factor? >>>> >>>> Any guidance will be greatly appreciated, >>>> >>>> Best regards, >>>> >>>> Paul >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> 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. >>>> >>>[[alternative HTML version deleted]]
... and further: " If a continuous independent variable has only 2 values,..." Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Aug 1, 2020 at 11:11 AM Bert Gunter <bgunter.4567 at gmail.com> wrote:> You appear to be confusing a binomial **response** with categorical > "dependent variables." glm() of course fits continuous or categorical > dependent variables. If a continuous dependent variable has only 2 values, > the results for glm() will be the same whether or not it is considered to > be continuous or categorical, though you may not recognize it as such. > > This discussion has already wandered off topic to statistical issues. I > will not comment further on or off list. I suggest you consult a good > reference on linear/generalized linear models or talk with a local > statistician. > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sat, Aug 1, 2020 at 11:04 AM Paul Bernal <paulbernal07 at gmail.com> > wrote: > >> Hi Bert, >> >> Thank you for the kind reply. >> >> But what if I don't turn the variable into a factor. Let's say that in >> excel I just coded the variable as 1s and 0s and just imported the dataset >> into R and fitted the logistic regression without turning any categorical >> variable or dummy variable into a factor? >> >> Does R requires every dummy variable to be treated as a factor? >> >> Best regards, >> >> Paul >> >> El s?b., 1 de agosto de 2020 12:59 p. m., Bert Gunter < >> bgunter.4567 at gmail.com> escribi?: >> >>> x <- factor(0:1) >>> x <- factor("yes","no") >>> >>> will produce identical results up to labeling. >>> >>> >>> Bert Gunter >>> >>> "The trouble with having an open mind is that people keep coming along >>> and sticking things into it." >>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >>> >>> >>> On Sat, Aug 1, 2020 at 10:40 AM Paul Bernal <paulbernal07 at gmail.com> >>> wrote: >>> >>>> Dear friends, >>>> >>>> Hope you are doing great. I want to fit a logistic regression in R, >>>> where >>>> the dependent variable is the covid status (I used 1 for covid >>>> positives, >>>> and 0 for covid negatives), but when I ran the glm, R complains that I >>>> should make the dependent variable a factor. >>>> >>>> What would be more advisable, to keep the dependent variable with 1s and >>>> 0s, or code it as yes/no and then make it a factor? >>>> >>>> Any guidance will be greatly appreciated, >>>> >>>> Best regards, >>>> >>>> Paul >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >>>> 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. >>>> >>>[[alternative HTML version deleted]]
Patrick (Malone Quantitative)
2020-Aug-01 18:15 UTC
[R] Dependent Variable in Logistic Regression
No, R does not. glm() does in order to do logistic regression. On Sat, Aug 1, 2020 at 2:11 PM Paul Bernal <paulbernal07 at gmail.com> wrote:> Hi Bert, > > Thank you for the kind reply. > > But what if I don't turn the variable into a factor. Let's say that in > excel I just coded the variable as 1s and 0s and just imported the dataset > into R and fitted the logistic regression without turning any categorical > variable or dummy variable into a factor? > > Does R requires every dummy variable to be treated as a factor? > > Best regards, > > Paul > > El s?b., 1 de agosto de 2020 12:59 p. m., Bert Gunter < > bgunter.4567 at gmail.com> escribi?: > > > x <- factor(0:1) > > x <- factor("yes","no") > > > > will produce identical results up to labeling. > > > > > > Bert Gunter > > > > "The trouble with having an open mind is that people keep coming along > and > > sticking things into it." > > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > > > > On Sat, Aug 1, 2020 at 10:40 AM Paul Bernal <paulbernal07 at gmail.com> > > wrote: > > > >> Dear friends, > >> > >> Hope you are doing great. I want to fit a logistic regression in R, > where > >> the dependent variable is the covid status (I used 1 for covid > positives, > >> and 0 for covid negatives), but when I ran the glm, R complains that I > >> should make the dependent variable a factor. > >> > >> What would be more advisable, to keep the dependent variable with 1s and > >> 0s, or code it as yes/no and then make it a factor? > >> > >> Any guidance will be greatly appreciated, > >> > >> Best regards, > >> > >> Paul > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> 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. > >> > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >-- Patrick S. Malone, Ph.D., Malone Quantitative NEW Service Models: http://malonequantitative.com He/Him/His [[alternative HTML version deleted]]
... yes, but so does lm() for a categorical **INdependent** variable with more than 2 numerically labeled levels. n levels = (n-1) df for a categorical covariate, but 1 for a continuous one (unless more complex models are explicitly specified of course). As I said, the OP seems confused about whether he is referring to the response or covariates. Or maybe he just made the same typo I did. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sat, Aug 1, 2020 at 11:15 AM Patrick (Malone Quantitative) < malone at malonequantitative.com> wrote:> No, R does not. glm() does in order to do logistic regression. > > On Sat, Aug 1, 2020 at 2:11 PM Paul Bernal <paulbernal07 at gmail.com> wrote: > >> Hi Bert, >> >> Thank you for the kind reply. >> >> But what if I don't turn the variable into a factor. Let's say that in >> excel I just coded the variable as 1s and 0s and just imported the dataset >> into R and fitted the logistic regression without turning any categorical >> variable or dummy variable into a factor? >> >> Does R requires every dummy variable to be treated as a factor? >> >> Best regards, >> >> Paul >> >> El s?b., 1 de agosto de 2020 12:59 p. m., Bert Gunter < >> bgunter.4567 at gmail.com> escribi?: >> >> > x <- factor(0:1) >> > x <- factor("yes","no") >> > >> > will produce identical results up to labeling. >> > >> > >> > Bert Gunter >> > >> > "The trouble with having an open mind is that people keep coming along >> and >> > sticking things into it." >> > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) >> > >> > >> > On Sat, Aug 1, 2020 at 10:40 AM Paul Bernal <paulbernal07 at gmail.com> >> > wrote: >> > >> >> Dear friends, >> >> >> >> Hope you are doing great. I want to fit a logistic regression in R, >> where >> >> the dependent variable is the covid status (I used 1 for covid >> positives, >> >> and 0 for covid negatives), but when I ran the glm, R complains that I >> >> should make the dependent variable a factor. >> >> >> >> What would be more advisable, to keep the dependent variable with 1s >> and >> >> 0s, or code it as yes/no and then make it a factor? >> >> >> >> Any guidance will be greatly appreciated, >> >> >> >> Best regards, >> >> >> >> Paul >> >> >> >> [[alternative HTML version deleted]] >> >> >> >> ______________________________________________ >> >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> >> 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. >> >> >> > >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> > > > -- > Patrick S. Malone, Ph.D., Malone Quantitative > NEW Service Models: http://malonequantitative.com > > He/Him/His >[[alternative HTML version deleted]]