R programming: glm() function

0 votes

I'm trying to run a regression model. When I create it using the glm function like this:

lm.fit <- glm(res~., data=train) #res is class of my dataset

I get an error like this:

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

my data set has15 variable, 10 of them are integer and 5 of them are factor.

Jan 23 in Data Analytics by Sophie may
• 9,050 points
25 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Since you mentioned you have factorized variables, check which one of your factors has less than 2 levels.

sapply(train, function(x) if (is.factor(x)) length(levels(x)) else NA)

This should do it.

answered Jan 23 by Tyrion anex
• 8,280 points

Related Questions In Data Analytics

0 votes
1 answer

Error: could not find function - R Programming

This error usually occurs when a package ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,000 points
115 views
0 votes
1 answer

Report function outputs in R programming

In your case, you've stored the output ...READ MORE

answered Jan 14 in Data Analytics by Sophie may
• 9,050 points
22 views
0 votes
1 answer

R function for finding the index of an element in a vector?

Yes, we can find the index of ...READ MORE

answered Apr 13, 2018 in Data Analytics by zombie
• 3,690 points
71 views
0 votes
1 answer

Which function can I use to clear the console in R and RStudio ?

Description                   Windows & Linux           Mac Clear console                      Ctrl+L ...READ MORE

answered Apr 17, 2018 in Data Analytics by anonymous
662 views
+1 vote
2 answers
0 votes
1 answer

R programming logic

Use gsub to match the substring that we want ...READ MORE

answered Nov 16, 2018 in Data Analytics by Maverick
• 10,000 points
13 views
0 votes
1 answer
+4 votes
2 answers
0 votes
1 answer

R programming: How to pass variables from a r program to mysql function?

To include the R variables called start.date and end.date, you can use paste to ...READ MORE

answered Dec 28, 2018 in Data Analytics by Tyrion anex
• 8,280 points
52 views
0 votes
1 answer

R programming: sapply() function

There are 2 ways to do it, ...READ MORE

answered Jan 23 in Data Analytics by Tyrion anex
• 8,280 points
22 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.