如何将glm()整理成类似lmList的结构?

问题描述 投票:0回答:1

为了再现,我对虹膜数据做了一些处理:

data(iris)
View(iris)
library("dplyr")
library("magrittr")
library("tidyverse")
iris <- filter(iris, Petal.Width<1)
iris <- mutate(iris,
               Species2 = case_when(
                 Petal.Width == 0.1 ~ "setosa",
                 Petal.Width != 0.1 ~ "versicolor"))

我能够为lm()做这样的事情:

iris %>% group_by(Species2) %>% 
do(tidy(lm(Petal.Width ~ Sepal.Width*Sepal.Length, data = .)))

fit1 <- nlme::lmList((Petal.Width) ~ Sepal.Width*Sepal.Length 
| Species2, data = iris)
do.call(stargazer, c(fit1, type = "text"))

我希望能够对glm()执行相同的操作:

iris %>% group_by(Species2) %>%
  do(tidy(glm(Petal.Width ~ Sepal.Width*Sepal.Length, data = ., 
family=quasibinomial)))

fit1 <- nlme::lmList((Petal.Width) ~ Sepal.Width*Sepal.Length | 
Species2, data = iris)
# this needs to be a lmList for glm and glmlist() does not seem to work

do.call(stargazer, c(fit1, type = "text"))

当前,当我使用nlme :: lmList时,会显示lm结果。我希望glm结果在表中。

r glm tidy
1个回答
0
投票
对此的一种可能的解决方案将是取代GLM:

model = glm(Petal.Width ~ Sepal.Width*Sepal.Length, data = iris, family=quasibinomial, subset = type == "setosa") model1 = glm(Petal.Width ~ Sepal.Width*Sepal.Length, data = iris, family=quasibinomial, subset = type == "veriscolor") stargazer(model, model1)

© www.soinside.com 2019 - 2024. All rights reserved.