0
我試圖在嵌套數據框as described here內運行迴歸。爲了達到我的目的,我使用lfe
包中的felm
,因爲我有很多級別的固定效果。felm不適用掃帚::增強/咕嚕聲,但與整齊
如果我使用felm
而不是lm
重新進行上述鏈接中的示例,它在大多數情況下都可以使用,直到我嘗試使用broom::augment
。
library(tidyverse)
library(broom)
library(gapminder)
library(lfe)
by_country <- gapminder %>%
group_by(continent, country) %>%
nest()
country_felm <- function(data){
felm(lifeExp ~ year, data = data)
}
by_country <- by_country %>%
mutate(model = purrr::map(data, country_felm)
)
一切正常了這一點,除了我不得不在purrr::map
在代碼的最後一行,可能是另一個felm
怪癖使用的功能,而不是一個公式。
現在,如果我嘗試使用broom
來提取模型輸出,它適用於glance
和tidy
,但不適用於augment
。
by_country %>% unnest(model %>% purrr::map(broom::glance))
by_country %>% unnest(model %>% purrr::map(broom::tidy))
by_country %>% unnest(model %>% purrr::map(broom::augment))
試圖在以下錯誤消息以使用augment
結果:
Error in mutate_impl(.data, dots) :
argument must be coercible to non-negative integer
In addition: Warning message:
In seq_len(nrow(x)) : first element used of 'length.out' argument