I am trying to build a Logistic Regression model that is able to run regardless of the nature of the predictor variables as long as the response variable stays the same. Here's a sample of what I have in mind:
#Take in the data
newdata = read.csv("book1.csv", head = TRUE)
#Store the response variable whose column heading you know beforehand
y = "response.variable"
#Identify the predictor variables (this is where I am stuck)
#Below is the algorithm of what I have in mind though
1) Take remaining column headings except "response.variable"
2) Store them as x = c(other headings)
#Form of model
model.form = reformulate(x, response = y)
#Build model
logit = glm(model.form, family = "binomial", data = newdata)
Any ideas are welcome.
Edit: When I use the code glm(y ~., data = newdata) as suggested by @laterow, it gives an error statement:
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]:
contrasts can be applied only to factors with 2 or more levels