Whenever I am building the first model in Logistic regression there is an error

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












Whenever I am building the first model in logistic regression, it is throwing the error shown below. My code is:



mo2 <- glm(train3$Medal ~ ., data = train3[, -15], family = "binomial")

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels


That is what it is showing, please help me with it.










share|cite|improve this question









New contributor




Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    Hi Shobs, questions focused on coding and debugging are off-topic on CrossValidated (but on topic at Stack Overflow). Also, check out formatting guide to see how properly format the text of your questions.
    – Jan Kukacka
    4 hours ago
















up vote
1
down vote

favorite












Whenever I am building the first model in logistic regression, it is throwing the error shown below. My code is:



mo2 <- glm(train3$Medal ~ ., data = train3[, -15], family = "binomial")

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels


That is what it is showing, please help me with it.










share|cite|improve this question









New contributor




Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    Hi Shobs, questions focused on coding and debugging are off-topic on CrossValidated (but on topic at Stack Overflow). Also, check out formatting guide to see how properly format the text of your questions.
    – Jan Kukacka
    4 hours ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Whenever I am building the first model in logistic regression, it is throwing the error shown below. My code is:



mo2 <- glm(train3$Medal ~ ., data = train3[, -15], family = "binomial")

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels


That is what it is showing, please help me with it.










share|cite|improve this question









New contributor




Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Whenever I am building the first model in logistic regression, it is throwing the error shown below. My code is:



mo2 <- glm(train3$Medal ~ ., data = train3[, -15], family = "binomial")

Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels


That is what it is showing, please help me with it.







regression logistic






share|cite|improve this question









New contributor




Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|cite|improve this question









New contributor




Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|cite|improve this question




share|cite|improve this question








edited 4 hours ago









Jan Kukacka

4,73111334




4,73111334






New contributor




Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









Shobs

61




61




New contributor




Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Shobs is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1




    Hi Shobs, questions focused on coding and debugging are off-topic on CrossValidated (but on topic at Stack Overflow). Also, check out formatting guide to see how properly format the text of your questions.
    – Jan Kukacka
    4 hours ago












  • 1




    Hi Shobs, questions focused on coding and debugging are off-topic on CrossValidated (but on topic at Stack Overflow). Also, check out formatting guide to see how properly format the text of your questions.
    – Jan Kukacka
    4 hours ago







1




1




Hi Shobs, questions focused on coding and debugging are off-topic on CrossValidated (but on topic at Stack Overflow). Also, check out formatting guide to see how properly format the text of your questions.
– Jan Kukacka
4 hours ago




Hi Shobs, questions focused on coding and debugging are off-topic on CrossValidated (but on topic at Stack Overflow). Also, check out formatting guide to see how properly format the text of your questions.
– Jan Kukacka
4 hours ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote













The error message indicates that you include in your model categorical variables (i.e., factors in R) that only have one category/level. You could exclude those with the following code:



keep <- function (x) 
if (is.factor(x)

train3. <- train3[sapply(train3, keep)]


Then you will need to use train3. in the call to glm(), i.e.,



mo2 <- glm(Medal ~ ., data = train3., family = binomial())


I have not excluded the 15th column in train3. as you did in your original code; you will need to do it yourself.






share|cite|improve this answer




















    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: "65"
    ;
    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: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    Shobs is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstats.stackexchange.com%2fquestions%2f368739%2fwhenever-i-am-building-the-first-model-in-logistic-regression-there-is-an-error%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    The error message indicates that you include in your model categorical variables (i.e., factors in R) that only have one category/level. You could exclude those with the following code:



    keep <- function (x) 
    if (is.factor(x)

    train3. <- train3[sapply(train3, keep)]


    Then you will need to use train3. in the call to glm(), i.e.,



    mo2 <- glm(Medal ~ ., data = train3., family = binomial())


    I have not excluded the 15th column in train3. as you did in your original code; you will need to do it yourself.






    share|cite|improve this answer
























      up vote
      3
      down vote













      The error message indicates that you include in your model categorical variables (i.e., factors in R) that only have one category/level. You could exclude those with the following code:



      keep <- function (x) 
      if (is.factor(x)

      train3. <- train3[sapply(train3, keep)]


      Then you will need to use train3. in the call to glm(), i.e.,



      mo2 <- glm(Medal ~ ., data = train3., family = binomial())


      I have not excluded the 15th column in train3. as you did in your original code; you will need to do it yourself.






      share|cite|improve this answer






















        up vote
        3
        down vote










        up vote
        3
        down vote









        The error message indicates that you include in your model categorical variables (i.e., factors in R) that only have one category/level. You could exclude those with the following code:



        keep <- function (x) 
        if (is.factor(x)

        train3. <- train3[sapply(train3, keep)]


        Then you will need to use train3. in the call to glm(), i.e.,



        mo2 <- glm(Medal ~ ., data = train3., family = binomial())


        I have not excluded the 15th column in train3. as you did in your original code; you will need to do it yourself.






        share|cite|improve this answer












        The error message indicates that you include in your model categorical variables (i.e., factors in R) that only have one category/level. You could exclude those with the following code:



        keep <- function (x) 
        if (is.factor(x)

        train3. <- train3[sapply(train3, keep)]


        Then you will need to use train3. in the call to glm(), i.e.,



        mo2 <- glm(Medal ~ ., data = train3., family = binomial())


        I have not excluded the 15th column in train3. as you did in your original code; you will need to do it yourself.







        share|cite|improve this answer












        share|cite|improve this answer



        share|cite|improve this answer










        answered 4 hours ago









        Dimitris Rizopoulos

        1,08318




        1,08318




















            Shobs is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            Shobs is a new contributor. Be nice, and check out our Code of Conduct.












            Shobs is a new contributor. Be nice, and check out our Code of Conduct.











            Shobs is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstats.stackexchange.com%2fquestions%2f368739%2fwhenever-i-am-building-the-first-model-in-logistic-regression-there-is-an-error%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            One-line joke