将每个模型的样本大小列添加到结果数据框中

时间:2018-05-18 15:18:33

标签: r regression linear-regression data-manipulation

我在mtcars数据集中运行回归模型并将结果导出到数据框

library(tidyverse)
library(broom)

outcomes <- c("wt", "mpg", "hp", "disp")
exposures <- c("gear", "vs", "am")
covariates <- c("drat", "qsec")

expand.grid(outcomes, exposures, covariates) %>%
group_by(Var1, Var2) %>%
summarise(Var3 = paste0(Var3, collapse = "+")) %>%
rowwise() %>%
summarise(frm = paste0(Var1, "~factor(", Var2, ")+", Var3)) %>%
group_by(model_id = row_number(),
       frm, samplesize=nrow(mtcars)) %>%
do(tidy(lm(.$frm, data = mtcars))) %>%
ungroup()

我知道mtcars没有丢失的数据,但如果我的数据框包含缺失值,那么列samplesize是否会显示每个模型的样本大小,即frm的每个组合?

0 个答案:

没有答案