首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用模型总结法计算扫帚后的边际效应

用模型总结法计算扫帚后的边际效应
EN

Stack Overflow用户
提问于 2021-12-09 11:10:39
回答 1查看 62关注 0票数 0

我试图1.在broom中运行嵌套回归后计算边际效果,然后将输出转换为模型摘要可读的格式,以便使用readable将输出编成Word。

代码语言:javascript
复制
library(tidyverse)
library(broom)
library(mfx)
library(modelsummary)


year <- rep(2014:2015, length.out=10000)
group <- sample(c(0,1,2,3,4,5,6), replace=TRUE, size=10000)
female <- sample(c(0,1), replace=TRUE, size=10000)
smoker <- sample(c(0,1), replace=TRUE, size=10000)
dta <- tibble(year = year, group = group, female = female, smoker = smoker)

mods <- dta %>%
  nest(data = c(-year)) %>%
  mutate(model = map(data, ~ glm(smoker ~ female*group, data = .,
                                 family = binomial(link = "probit"))),  # this is the model itself
         mfx=probitmfx(model, data=data))%>%                             # trying to convert to marginal effects 
  tidy()                                                                 # convert to readable format

modelsummary(mods)

我每走一步都会收到各种各样的错误信息。

EN

回答 1

Stack Overflow用户

发布于 2021-12-09 12:23:12

我想出来了:

代码语言:javascript
复制
mods <- dta %>%
  nest(data = c(-year)) %>%
  mutate(model = map(data, ~ glm(smoker ~ female*group, data = .,
                                 family = binomial(link = "probit"))),
         mfx=map(data, ~ probitmfx(smoker ~ female*group, data = .,
                             )))
mfx <-mods[[4]]

modelsummary(mfx)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70288865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档