Using linear regression with binary and categorical variables.











up vote
1
down vote

favorite












I have a dataset with a binary variable: "Religious" with $0$ being "no" and $1$ being "yes". And a categorical variable "Contraceptive" having the values $1,2$ and $3$. Where $1$ = no use, $2$ = short term use and $3$ = long term use. The original dataset is something like this:



begin{align}
&text{Religious}::: text{Contraceptive}\
&1 hspace{42pt} 1 \
&1 hspace{42pt} 1 \
&0 hspace{42pt} 2 \
&0 hspace{42pt} 3 \
&vdots
end{align}



then I created three other columns and changed the contraceptive column to:



begin{align}
&text{no use} ::: text{short} ::: text{long}\
&1 hspace{28pt} 0 hspace{28pt} 0 \
&1 hspace{28pt} 0 hspace{28pt} 0 \
&0 hspace{28pt} 1 hspace{28pt} 0\
&0 hspace{28pt} 0 hspace{28pt} 1\
&vdots
end{align}



Is now possible to use a simple linear regression with these variables? How does one do that? I'm using R.










share|cite|improve this question


























    up vote
    1
    down vote

    favorite












    I have a dataset with a binary variable: "Religious" with $0$ being "no" and $1$ being "yes". And a categorical variable "Contraceptive" having the values $1,2$ and $3$. Where $1$ = no use, $2$ = short term use and $3$ = long term use. The original dataset is something like this:



    begin{align}
    &text{Religious}::: text{Contraceptive}\
    &1 hspace{42pt} 1 \
    &1 hspace{42pt} 1 \
    &0 hspace{42pt} 2 \
    &0 hspace{42pt} 3 \
    &vdots
    end{align}



    then I created three other columns and changed the contraceptive column to:



    begin{align}
    &text{no use} ::: text{short} ::: text{long}\
    &1 hspace{28pt} 0 hspace{28pt} 0 \
    &1 hspace{28pt} 0 hspace{28pt} 0 \
    &0 hspace{28pt} 1 hspace{28pt} 0\
    &0 hspace{28pt} 0 hspace{28pt} 1\
    &vdots
    end{align}



    Is now possible to use a simple linear regression with these variables? How does one do that? I'm using R.










    share|cite|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a dataset with a binary variable: "Religious" with $0$ being "no" and $1$ being "yes". And a categorical variable "Contraceptive" having the values $1,2$ and $3$. Where $1$ = no use, $2$ = short term use and $3$ = long term use. The original dataset is something like this:



      begin{align}
      &text{Religious}::: text{Contraceptive}\
      &1 hspace{42pt} 1 \
      &1 hspace{42pt} 1 \
      &0 hspace{42pt} 2 \
      &0 hspace{42pt} 3 \
      &vdots
      end{align}



      then I created three other columns and changed the contraceptive column to:



      begin{align}
      &text{no use} ::: text{short} ::: text{long}\
      &1 hspace{28pt} 0 hspace{28pt} 0 \
      &1 hspace{28pt} 0 hspace{28pt} 0 \
      &0 hspace{28pt} 1 hspace{28pt} 0\
      &0 hspace{28pt} 0 hspace{28pt} 1\
      &vdots
      end{align}



      Is now possible to use a simple linear regression with these variables? How does one do that? I'm using R.










      share|cite|improve this question













      I have a dataset with a binary variable: "Religious" with $0$ being "no" and $1$ being "yes". And a categorical variable "Contraceptive" having the values $1,2$ and $3$. Where $1$ = no use, $2$ = short term use and $3$ = long term use. The original dataset is something like this:



      begin{align}
      &text{Religious}::: text{Contraceptive}\
      &1 hspace{42pt} 1 \
      &1 hspace{42pt} 1 \
      &0 hspace{42pt} 2 \
      &0 hspace{42pt} 3 \
      &vdots
      end{align}



      then I created three other columns and changed the contraceptive column to:



      begin{align}
      &text{no use} ::: text{short} ::: text{long}\
      &1 hspace{28pt} 0 hspace{28pt} 0 \
      &1 hspace{28pt} 0 hspace{28pt} 0 \
      &0 hspace{28pt} 1 hspace{28pt} 0\
      &0 hspace{28pt} 0 hspace{28pt} 1\
      &vdots
      end{align}



      Is now possible to use a simple linear regression with these variables? How does one do that? I'm using R.







      linear-algebra statistics regression






      share|cite|improve this question













      share|cite|improve this question











      share|cite|improve this question




      share|cite|improve this question










      asked Nov 18 at 19:08









      Pinteco

      629212




      629212






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          No. Your dependent variable is binary, i.e., ${0,1}$, hence a possible model is a logistic regression, i.e.,
          $$
          widehat{ mathbb{P}( Y_i = 1) } = frac{1}
          { 1 + exp{ -(beta_0 + beta_1text{short}
          +
          beta_1 text{short} )
          }},
          $$

          in R



          glm( formula = Religious ~ short + long,
          family = binomial(link = "logit") )






          share|cite|improve this answer





















          • What if the dependent variable is Contraceptive. I want to check how the religion impacts on the method of use in the contraceptive.
            – Pinteco
            Nov 18 at 19:57










          • Then multinomial logistic regression en.wikipedia.org/wiki/Multinomial_logistic_regression
            – V. Vancak
            Nov 18 at 19:58










          • If I had a categorical (contraceptive) with a numerical (age) then can I use a linear regression? What type of variables can I use linear regression, when the dependent variable is a categorical one (contraceptive) ? Maybe something like this exists in multiple linear regression, lm(short+long+noUse ~ age)
            – Pinteco
            Nov 18 at 20:10












          • Then you can use a multivariate regression. E.g., users.stat.umn.edu/~helwig/notes/mvlr-Notes.pdf slide 43 and on
            – V. Vancak
            Nov 18 at 20:13











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "69"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3003988%2fusing-linear-regression-with-binary-and-categorical-variables%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          No. Your dependent variable is binary, i.e., ${0,1}$, hence a possible model is a logistic regression, i.e.,
          $$
          widehat{ mathbb{P}( Y_i = 1) } = frac{1}
          { 1 + exp{ -(beta_0 + beta_1text{short}
          +
          beta_1 text{short} )
          }},
          $$

          in R



          glm( formula = Religious ~ short + long,
          family = binomial(link = "logit") )






          share|cite|improve this answer





















          • What if the dependent variable is Contraceptive. I want to check how the religion impacts on the method of use in the contraceptive.
            – Pinteco
            Nov 18 at 19:57










          • Then multinomial logistic regression en.wikipedia.org/wiki/Multinomial_logistic_regression
            – V. Vancak
            Nov 18 at 19:58










          • If I had a categorical (contraceptive) with a numerical (age) then can I use a linear regression? What type of variables can I use linear regression, when the dependent variable is a categorical one (contraceptive) ? Maybe something like this exists in multiple linear regression, lm(short+long+noUse ~ age)
            – Pinteco
            Nov 18 at 20:10












          • Then you can use a multivariate regression. E.g., users.stat.umn.edu/~helwig/notes/mvlr-Notes.pdf slide 43 and on
            – V. Vancak
            Nov 18 at 20:13















          up vote
          2
          down vote



          accepted










          No. Your dependent variable is binary, i.e., ${0,1}$, hence a possible model is a logistic regression, i.e.,
          $$
          widehat{ mathbb{P}( Y_i = 1) } = frac{1}
          { 1 + exp{ -(beta_0 + beta_1text{short}
          +
          beta_1 text{short} )
          }},
          $$

          in R



          glm( formula = Religious ~ short + long,
          family = binomial(link = "logit") )






          share|cite|improve this answer





















          • What if the dependent variable is Contraceptive. I want to check how the religion impacts on the method of use in the contraceptive.
            – Pinteco
            Nov 18 at 19:57










          • Then multinomial logistic regression en.wikipedia.org/wiki/Multinomial_logistic_regression
            – V. Vancak
            Nov 18 at 19:58










          • If I had a categorical (contraceptive) with a numerical (age) then can I use a linear regression? What type of variables can I use linear regression, when the dependent variable is a categorical one (contraceptive) ? Maybe something like this exists in multiple linear regression, lm(short+long+noUse ~ age)
            – Pinteco
            Nov 18 at 20:10












          • Then you can use a multivariate regression. E.g., users.stat.umn.edu/~helwig/notes/mvlr-Notes.pdf slide 43 and on
            – V. Vancak
            Nov 18 at 20:13













          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          No. Your dependent variable is binary, i.e., ${0,1}$, hence a possible model is a logistic regression, i.e.,
          $$
          widehat{ mathbb{P}( Y_i = 1) } = frac{1}
          { 1 + exp{ -(beta_0 + beta_1text{short}
          +
          beta_1 text{short} )
          }},
          $$

          in R



          glm( formula = Religious ~ short + long,
          family = binomial(link = "logit") )






          share|cite|improve this answer












          No. Your dependent variable is binary, i.e., ${0,1}$, hence a possible model is a logistic regression, i.e.,
          $$
          widehat{ mathbb{P}( Y_i = 1) } = frac{1}
          { 1 + exp{ -(beta_0 + beta_1text{short}
          +
          beta_1 text{short} )
          }},
          $$

          in R



          glm( formula = Religious ~ short + long,
          family = binomial(link = "logit") )







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Nov 18 at 19:54









          V. Vancak

          10.5k2926




          10.5k2926












          • What if the dependent variable is Contraceptive. I want to check how the religion impacts on the method of use in the contraceptive.
            – Pinteco
            Nov 18 at 19:57










          • Then multinomial logistic regression en.wikipedia.org/wiki/Multinomial_logistic_regression
            – V. Vancak
            Nov 18 at 19:58










          • If I had a categorical (contraceptive) with a numerical (age) then can I use a linear regression? What type of variables can I use linear regression, when the dependent variable is a categorical one (contraceptive) ? Maybe something like this exists in multiple linear regression, lm(short+long+noUse ~ age)
            – Pinteco
            Nov 18 at 20:10












          • Then you can use a multivariate regression. E.g., users.stat.umn.edu/~helwig/notes/mvlr-Notes.pdf slide 43 and on
            – V. Vancak
            Nov 18 at 20:13


















          • What if the dependent variable is Contraceptive. I want to check how the religion impacts on the method of use in the contraceptive.
            – Pinteco
            Nov 18 at 19:57










          • Then multinomial logistic regression en.wikipedia.org/wiki/Multinomial_logistic_regression
            – V. Vancak
            Nov 18 at 19:58










          • If I had a categorical (contraceptive) with a numerical (age) then can I use a linear regression? What type of variables can I use linear regression, when the dependent variable is a categorical one (contraceptive) ? Maybe something like this exists in multiple linear regression, lm(short+long+noUse ~ age)
            – Pinteco
            Nov 18 at 20:10












          • Then you can use a multivariate regression. E.g., users.stat.umn.edu/~helwig/notes/mvlr-Notes.pdf slide 43 and on
            – V. Vancak
            Nov 18 at 20:13
















          What if the dependent variable is Contraceptive. I want to check how the religion impacts on the method of use in the contraceptive.
          – Pinteco
          Nov 18 at 19:57




          What if the dependent variable is Contraceptive. I want to check how the religion impacts on the method of use in the contraceptive.
          – Pinteco
          Nov 18 at 19:57












          Then multinomial logistic regression en.wikipedia.org/wiki/Multinomial_logistic_regression
          – V. Vancak
          Nov 18 at 19:58




          Then multinomial logistic regression en.wikipedia.org/wiki/Multinomial_logistic_regression
          – V. Vancak
          Nov 18 at 19:58












          If I had a categorical (contraceptive) with a numerical (age) then can I use a linear regression? What type of variables can I use linear regression, when the dependent variable is a categorical one (contraceptive) ? Maybe something like this exists in multiple linear regression, lm(short+long+noUse ~ age)
          – Pinteco
          Nov 18 at 20:10






          If I had a categorical (contraceptive) with a numerical (age) then can I use a linear regression? What type of variables can I use linear regression, when the dependent variable is a categorical one (contraceptive) ? Maybe something like this exists in multiple linear regression, lm(short+long+noUse ~ age)
          – Pinteco
          Nov 18 at 20:10














          Then you can use a multivariate regression. E.g., users.stat.umn.edu/~helwig/notes/mvlr-Notes.pdf slide 43 and on
          – V. Vancak
          Nov 18 at 20:13




          Then you can use a multivariate regression. E.g., users.stat.umn.edu/~helwig/notes/mvlr-Notes.pdf slide 43 and on
          – V. Vancak
          Nov 18 at 20:13


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3003988%2fusing-linear-regression-with-binary-and-categorical-variables%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Willebadessen

          Ida-Boy-Ed-Garten

          Residenzschloss Arolsen