boxCox()不会接受由map()创建的线性模型,尽管它们是同一类?

时间:2019-01-11 18:01:10

标签: r purrr broom

我尝试一次生成多个模型,然后运行单独的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 package(v0.2.1)于2019-01-11创建

0 个答案:

没有答案