r - 缺少 newdata 参数时 predict() 如何工作?
问题描述
我最近在学习跨栏模型。我找到了一个包含这些代码的博客。
library(AER)
data("NMES1988")
nmes <- NMES1988[, c(1, 6:8, 13, 15, 18)]
plot(table(nmes$visits))
mod1 <- glm(visits ~. , data = nmes, family = "poisson")
mu <- predict(mod1, type = "response")
exp <- sum(dpois(x=0, lambda = mu))
predict() 函数中缺少 newdata 参数。这个函数会根据旧数据 nmes 进行预测吗?
解决方案
是的,它使用原始数据,即产生fitted.values
(yhat)。查看:
mu <- predict(mod1, type = "response")
mu2 <- predict(mod1, type = "response", newdata=nmes)
mu3 <- mod1$fitted.values
identical(mu, mu2)
# [1] TRUE
identical(mu, mu3)
# [1] TRUE
推荐阅读
- android - 如何获得像优步这样的浮动按钮
- c# - 按类型名称进行依赖注入
- json - powershell "ConvertTo-Json" 的 json 格式输出混乱
- shopify - 当用户点击它时更改图像变体 url
- python - 不产生的协程和正常的同步功能之间有什么区别吗?
- apache - 如何在 AWS 负载均衡器响应中禁用 Apache HTTP 标头信息?
- javascript - JS中的循环时间
- vuetify.js - Vuetify 输入掩码
- c# - 如何编译 .NET Core 2.1 API 项目以面向 .NET Framework 4.7
- javascript - Python Flask,后台进程的自定义状态作为响应