啊,我明白了!看来您只需要将原始df传递给
newdata
的论点
predictions
。例如。
mod <- lm(mpg ~ hp + factor(cyl), data = mtcars)
pred <- predictions(mod, newdata = mtcars)
pred %>% head()
Estimate Std. Error z Pr(>|z|) 2.5 % 97.5 % cyl disp hp drat wt qsec vs am gear
20.0 1.204 16.6 <0.001 17.7 22.4 6 160 110 3.90 2.62 16.5 0 1 4
20.0 1.204 16.6 <0.001 17.7 22.4 6 160 110 3.90 2.88 17.0 0 1 4
26.4 0.962 27.5 <0.001 24.5 28.3 4 108 93 3.85 2.32 18.6 1 1 4
20.0 1.204 16.6 <0.001 17.7 22.4 6 258 110 3.08 3.21 19.4 1 0 3
15.9 0.992 16.0 <0.001 14.0 17.9 8 360 175 3.15 3.44 17.0 0 0 3
20.2 1.219 16.5 <0.001 17.8 22.5 6 225 105 2.76 3.46 20.2 1 0 3
carb
4
4
1
1
2
1
Columns: rowid, estimate, std.error, statistic, p.value, conf.low, conf.high, mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb