Logit模型的预测值问题

时间:2018-12-23 04:00:37

标签: logistic-regression glm predict

我正在尝试找到ECG = 2时的预测概率,但是我不断收到错误消息。我的数据集有4列78行。

> head(coronaryheart)

  sex ecg age ca
1   0   0  28  0
2   1   0  42  1
3   0   1  46  0
4   1   1  45  0
5   0   0  34  0
6   1   0  44  1

这是我的模特:

ca.logit <- glm(ca ~ age + ecg + sex, data=coronaryheart, 
               binomial(link="logit"), 
               na.action="na.exclude")

我的问题是下面的代码。我对R相当陌生,并且已经使用了一段时间。

ageof30 <- with(coronaryheart, data.frame(age=30))
predict(object=ca.logit, newdata=ageof30, type="response")

错误消息:

Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : 
  variable lengths differ (found for 'ecg')
In addition: Warning message:
'newdata' had 1 row but variables found have 78 rows 

这是怎么回事?

0 个答案:

没有答案
相关问题