首页 > 解决方案 > boxCox() 不接受 map() 创建的线性模型,尽管是同一类?

问题描述

我有几个模型,我试图一次生成,然后运行单独的boxCox()转换。但是每次我尝试运行boxCox()时,我都会遇到一个奇怪的错误。

我认为这与.x使用map(). 这是一个小代表来证明我的错误:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(purrr)
library(broom)
library(car)
#> Loading required package: carData
#> 
#> Attaching package: 'car'
#> The following object is masked from 'package:purrr':
#> 
#>     some
#> The following object is masked from 'package:dplyr':
#> 
#>     recode

formulas <- c(mpg ~ wt,
              sqrt(mpg) ~ wt, 
              sqrt(mpg) ~ sqrt(wt))

proj_lm <- tibble(formulas) %>% 
  mutate(lm_models = map(formulas, ~lm(formula = .x, data = mtcars)))

boxCox(proj_lm$lm_models[[1]])
#> Error in stats::model.frame(formula = .x, data = mtcars, drop.unused.levels = TRUE): object '.x' not found

reprex 包(v0.2.1)于 2019 年 1 月 11 日创建

标签: rpurrrbroom

解决方案


推荐阅读