Whenever I am building the first model in Logistic regression there is an error
Clash 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.
regression logistic
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.
add a comment |Â
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.
regression logistic
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
add a comment |Â
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.
regression logistic
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
regression logistic
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.
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
add a comment |Â
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
add a comment |Â
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., factor
s 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.
add a comment |Â
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., factor
s 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.
add a comment |Â
up vote
3
down vote
The error message indicates that you include in your model categorical variables (i.e., factor
s 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.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
The error message indicates that you include in your model categorical variables (i.e., factor
s 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.
The error message indicates that you include in your model categorical variables (i.e., factor
s 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.
answered 4 hours ago


Dimitris Rizopoulos
1,08318
1,08318
add a comment |Â
add a comment |Â
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.
Shobs is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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