【发布时间】:2018-04-14 12:55:02
【问题描述】:
我无法估计一个因子变量为因变量的 logit 模型。我创建了一个可重现的示例来更好地解释并显示错误消息。
## create a reproducible example that replicates the problem
set.seed(12) # reproducibility of the "randomly" generated data.
df<-data.frame(dummy=as.factor(rep(c("yes","no"),100)), # factor encoding
x=rnorm(n = 200,mean = 5,sd = 1)) # some predictor variable
# calculate regression with different encodings
summary(glm(formula = dummy~x,data = df)) # does not work
这种方法的错误信息是
Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
NA/NaN/Inf in 'y'
In addition: Warning messages:
1: In Ops.factor(y, mu) : ‘-’ not meaningful for factors
2: In Ops.factor(eta, offset) : ‘-’ not meaningful for factors
3: In Ops.factor(y, mu) : ‘-’ not meaningful for factors
我不太明白这条消息。数据规模(因子)有什么问题,还是我如何应用该函数的问题?任何帮助将非常感激。
【问题讨论】:
标签: r char logistic-regression