【发布时间】:2016-04-11 22:23:46
【问题描述】:
我正在尝试构建一个逻辑回归模型,只要响应变量保持不变,该模型就能够运行而不管预测变量的性质如何。这是我的想法的一个示例:
#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)
欢迎提出任何想法。
编辑: 当我使用代码时 glm(y ~., data = newdata) 正如@laterow 所建议的,它给出了一个错误声明:
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]:
contrasts can be applied only to factors with 2 or more levels
【问题讨论】:
-
glm(y ~ ., data = newdata)
标签: r data-modeling logistic-regression