R 如何绘制变量';基于glm模型的s预测概率

R 如何绘制变量';基于glm模型的s预测概率,r,loops,plot,glm,R,Loops,Plot,Glm,我想画出glm模型中的每个变量,其中y轴是预测概率,x轴是变量水平或值。 以下是我的代码,我尝试过这样做: 数据: dat <- read.table(text = "target apcalc admit num 0 0 0 21 0 0 1 24 0 1 0 55 0 1 1

我想画出glm模型中的每个变量,其中y轴是预测概率,x轴是变量水平或值。 以下是我的代码,我尝试过这样做:

数据:

dat <- read.table(text = "target apcalc    admit   num
     0        0        0         21
     0        0        1         24
     0        1        0         55
     0        1        1         72
     1        0        0         5
     1        0        1         31
     1        1        0         11
     1        1        1         3",  header = TRUE)
我得到了一个奇怪的图作为输出(“索引”在x轴上,而“预测(f,I.var.names=I,newdata=dat,type='response')”在y轴上。我如何修复代码以获得期望的结果?
(为了在这里展示,我还不知道声誉)

在运行f时,这里用预测概率绘制所有变量

f<-glm(target ~ apcalc + admit +num, data=dat,family=binomial(link="logit"))

PredProb=predict(f,type='response') #predicting probabilities

par(mfrow=c(2,2))
for(i in names(dat)){
  plot(dat[,i],PredProb,xlab=i)
}

fAm我正在使用$var.names调用作为模型一部分的变量?我不确定,因此提出了我的问题。非常感谢…510947
for(i in 1:length(f$var.names)){
          plot(predict(f,i.var.names=i,newdata=dat,type='response'))
      }
f<-glm(target ~ apcalc + admit +num, data=dat,family=binomial("logit"))

f

Call:  glm(formula = target ~ apcalc + admit + num, family = binomial("logit"), 
    data = dat)

Coefficients:
(Intercept)       apcalc        admit          num  
     2.2690       3.1742       2.4406      -0.1721  

Degrees of Freedom: 7 Total (i.e. Null);  4 Residual
Null Deviance:      11.09 
Residual Deviance: 5.172        AIC: 13.17

f$var.names
NULL
f<-glm(target ~ apcalc + admit +num, data=dat,family=binomial(link="logit"))

PredProb=predict(f,type='response') #predicting probabilities

par(mfrow=c(2,2))
for(i in names(dat)){
  plot(dat[,i],PredProb,xlab=i)
}