我一直在关注数据科学 R 中的“许多模型”一章。我已经能够适应我的模型并将它们作为列表列存储在 tibble 中。这很棒,并且使存储更简单。问题似乎是处理每个模型条目有点笨拙,因为我有这种格式的它们。例如:
model_table %>%
dplyr::filter(! unlist(map(model_fit, is.null))) %>%
dplyr::mutate("GAIC" = unlist(purrr::map(model_fit, gamlss::GAIC)),
"BIC" = unlist(purrr::map(model_fit, BIC)),
"AIC" = unlist(purrr::map(model_fit, AIC)),
"deviance" = unlist(purrr::map(model_fit, deviance)),
"df.residual" = unlist(purrr::map(model_fit, df.residual)),
"log. Likelihood" = unlist(purrr::map(model_fit, logLik)),
"converged" = unlist(purrr::map(model_fit, function(x) x$converged))) %>%
dplyr::ungroup() %>%
dplyr::mutate("dBIC" = round(BIC - min(BIC), 2),
"dAIC" = round(AIC - min(AIC), 2)) %>%
dplyr::arrange(dBIC)
我反复使用这个功能unlist(purrr::map(..., ...))
,这让我觉得我做的不对。
有没有更标准或更明智的方法来做到这一点?