【发布时间】:2014-07-06 06:00:17
【问题描述】:
我正在 R 中构建一个带有分类预测变量和二元响应的 glm。我的数据是这样的(但要大得多并且有多个预测变量):
y <- c(1,1,1,0,0) #response
x <- c(0,0,0,1,2) #predictor
由于这些数据是分类的(但它是用数字表示的),我这样做了:
y <- as.factor(y)
x <- as.factor(x)
然后我建立了我的模型:
g1 <- glm(y~x, family=binomial(link="logit"))
但是模型的细节如下:
g1
Call: glm(formula = y ~ x, family = binomial(link = "logit"))
Coefficients:
(Intercept) x1 x2
24.57 -49.13 -49.13
Degrees of Freedom: 4 Total (i.e. Null); 2 Residual
Null Deviance: 6.73
Residual Deviance: 2.143e-10 AIC: 6
总结是:
summary(g1)
Call:
glm(formula = y ~ x, family = binomial(link = "logit"))
Deviance Residuals:
1 2 3 4 5
6.547e-06 6.547e-06 6.547e-06 -6.547e-06 -6.547e-06
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 24.57 75639.11 0 1
x1 -49.13 151278.15 0 1
x2 -49.13 151278.15 0 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 6.7301e+00 on 4 degrees of freedom
Residual deviance: 2.1434e-10 on 2 degrees of freedom
AIC: 6
Number of Fisher Scoring iterations: 23
我不明白为什么 R 在 x1 和 x2 中复制了 x 预测器? x1 和 x2 是什么意思?
我还需要用估计值明确写下模型,格式如下:y ~ B0 + B1*x 所以我现在卡住了,因为 x 已被一分为二,并且没有称为 x1 和 x2 的初始变量...
感谢您的帮助!
【问题讨论】: