r - eval 中的错误(object$call$data):对象“。” 在 gls 模型对象上运行 Anova 时找不到
问题描述
我已成功在amelia
使用以下代码 生成的估算数据集上运行 gls
mod <- impute_data %>% mutate(gls_mod = data %>% purrr::map(~nlme::gls(resp_var ~ pred_var1 + pred_var2 + pred_var2), data = .)))
现在,我想运行car::Anova
以测试每个预测变量的重要性。为此,我使用了:
Anova_mod <- mod %>% mutate(gls.Anova = mod_gls %>% purrr::map(print(~car::Anova(.))))
并收到以下错误消息:Error in eval(object$call$data) : object '.' not found
但是,如果我通过 单独运行每个估算数据集car::Anova
,则效果很好(但我不想单独运行每个数据集)。如果我将以前的代码更改为该代码mod %>% mutate(gls.Anova = mod_gls %>% purrr::map(print(~anova(.))))
也可以正常工作。但是,我需要car::Anova
获得 II 型 SS。我无法解释此错误消息。任何有关解释错误消息的帮助都会很棒。
解决方案
我得到了同样的错误(使用mtcars
,见下文)。与模型的Error in eval(object$call$data) : object '.' not found
估计有关,map
并且源自data = .
。例如,从 切换.
到.x
,即运行mod <- impute_data %>% mutate(gls_mod = data %>% purrr::map(~nlme::gls(resp_var ~ pred_var1 + pred_var2 + pred_var2), data = .x)))
将错误消息更改为Error in eval(object$call$data) : object '.x' not found
。换句话说car::Anova
,就是寻找一个它找不到的data
对象。.
我很确定几个月前我遇到了这个问题,但我不记得我是如何解决的。):
一个简单的解决方案是使用“老式”for 循环来估计模型。使用作为示例数据,按公式mtcars
拆分和使用。不如优雅,但它有效:cyl
mpg ~ hp
map
library(dplyr)
df_list <- mtcars %>%
split(.$cyl)
mod_gls_loop <- list()
for (i in seq_along(df_list)) {
mod_gls_loop[[i]] <- nlme::gls(mpg ~ hp, data = df_list[[i]])
}
Anova_gls <- mod_gls_loop %>% purrr::map(~ print(car::Anova(.)))
#> Analysis of Deviance Table (Type II tests)
#>
#> Response: mpg
#> Df Chisq Pr(>Chisq)
#> hp 1 3.3976 0.06529 .
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Analysis of Deviance Table (Type II tests)
#>
#> Response: mpg
#> Df Chisq Pr(>Chisq)
#> hp 1 0.0821 0.7745
#> Analysis of Deviance Table (Type II tests)
#>
#> Response: mpg
#> Df Chisq Pr(>Chisq)
#> hp 1 1.0498 0.3055
由reprex 包于 2020-03-11 创建(v0.3.0)
推荐阅读
- bash - 如何将递增的数字添加到与带有 Bash(awk)的模式匹配的行
- angular - 如何在角度6中组合两个相同类型的可观察数组?
- php - 内连接mysql php
- python - python setup.py 找不到所需的包
- tensorflow - TensorFlow GPU编译标志?
- python - Python - 检查值是否存在于两个单独的列表中
- c++ - 不能将方法返回值用于另一个方法
- python - 将数据框行值应用于 Python 中的列
- amazon-sns - SNS过滤器可以与订阅同时应用吗?
- python - 安装 xbpch 后出现 Jupyter 内核错误