I have a glm
model and a summarized dataset that requires I bind the coefficients
, standard error
and p.value
from the summary of the model to the summarized dataset. For an example, I used the mtcars
data set. I added columns
to the final unioned data set to mimic where I would like coefficients, standard errors, and p-values
to be placed. In terms of the base values that aren't shown in the model, I would like to add a "1
" to coefficients
and use the intercept, standard errors and p-value
. How could I do all of this?
library(tidyverse)
mtcars <- as_tibble(mtcars)
mtcars$cyl <- as.factor(mtcars$cyl)
mtcars$gear <- as.factor(mtcars$gear)
#run model
model1 <- glm(mpg ~ cyl + gear, data = mtcars)
summary(model1)
#start developing summarized data set
mtcars_wght <- mtcars %>%
group_by(cyl) %>%
rename(level = cyl) %>%
summarise("sum_weight" = sum(wt)) %>%
mutate("variable" = "cyl")
mtcars_gear <- mtcars %>%
group_by(gear) %>%
summarise("sum_weight" = sum(wt)) %>%
mutate("variable" = "gear") %>%
rename(level = gear)
#make summarized data set example
mtcars_sum <- mtcars_wght %>%
bind_rows(mtcars_gear) %>%
mutate("coefficient" = "x", "std.error" = "y", "p_value" = "z")