简体   繁体   English

多个模型的系数图

[英]Coefficient plot over multiple models

I have a series of 33 fixed effects regressions.我有一系列 33 个固定效应回归。 Each regression has its own unique dependent variable: the cost of different trade product types.每个回归都有自己独特的因变量:不同贸易产品类型的成本。 Each trade product type has two regressions for two different key independent variables, STC_exp and STC_import.对于两个不同的关键自变量,STC_exp 和 STC_import,每种贸易产品类型都有两个回归。

lval28_exports_tradeonly <- felm(lval28 ~ STC_exp | pair + year | 0 | pair, subset(STC_Data, NoTrade28 == 1))
lval28_imports_tradeonly <- felm(lval28 ~ STC_imp | pair + year | 0 | pair, subset(STC_Data, NoTrade28 == 1))

lval29_exports_tradeonly <- felm(lval29 ~ STC_exp | pair + year | 0 | pair, subset(STC_Data, NoTrade29 == 1))
lval29_imports_tradeonly <- felm(lval29 ~ STC_imp | pair + year | 0 | pair, subset(STC_Data, NoTrade29 == 1))

What I want to do is create a coefficient plot so that the two independent variables for each of the dependent variables either share the same line on the coefficient plot or can be grouped together.我想要做的是创建一个系数图,以便每个因变量的两个自变量在系数图上共享同一条线或可以组合在一起。 I tried doing this with plot_summs in jtools package and some other packages, but I'm not having much success.我尝试用plot_summs包和其他一些包中的jtools来做这个,但我没有取得太大的成功。

I can make each figure individually:我可以单独制作每个数字:

ore <- plot_summs(lval26_imports_tradeonly, lval26_exports_tradeonly, coefs = c("Ore" = "STC_exp", "Ore" = "STC_imp"), model.names = c("STC on importer", "STC on exporter"))

inorganic.chemicals <- plot_summs(lval28_imports_tradeonly, lval28_exports_tradeonly, coefs = c("Inorganic Chemicals" = "STC_exp", "Inorganic Chemicals" = "STC_imp"), model.names = c("STC on importer", "STC on exporter"))

But I would like to be able to combine them in some way.但我希望能够以某种方式将它们结合起来。 Perhaps the jtools package isn't the right away to go?也许 jtools 包不是马上就可以使用的?

在此处输入图片说明 在此处输入图片说明

You could just make it with ggplot directly.你可以直接用ggplot制作它。

Below, I make some example data that looks to have similar properties to yours.下面,我制作了一些示例数据,它们看起来与您的属性相似。 Without your data, I can't replicate your example directly.没有您的数据,我无法直接复制您的示例。

library(tibble)
library(dplyr)
library(tidyr)

set.seed(25443)
dat <- tibble(STC_exp  = runif(500, -3, 3), 
              STC_imp = runif(500, -3, 3))

b1 <- runif(33, .1, .5)
b2 <- runif(33, .1, .5)
for(i in 1:33){
  dat[[paste0("lval", i)]] <- b1[i] * dat$STC_exp + b2[i] * dat$STC_imp + rnorm(500, 0, .25)
}

reshape the data to long-format on both STC_ variables and all of the lval variables.STC_变量和所有lval变量STC_数据重塑为长格式。

library(tidyr)
dat <- dat %>% pivot_longer(cols=c("STC_exp", "STC_imp"), names_to= "ie", values_to = "stc")
dat <- dat %>% pivot_longer(cols=starts_with("lval"), names_to="var", values_to = "lval")

Run the models and collect the output.运行模型并收集输出。

library(purrr)
library(broom)

mods <- dat %>%
  group_by(ie, var) %>% 
  summarise(lm_mod= list(lm(lval ~ stc))) %>%
  mutate(tidied = map(lm_mod,tidy,conf.int = TRUE)) %>%
  unnest(tidied)
mods <- select(mods, -lm_mod) %>% 
  filter(term == "stc")

Make the plot制作情节

library(ggplot2)
mods %>% 
  mutate(ie = factor(ie, levels=c("STC_exp", "STC_imp"), 
                     labels=c("STC on Exporter", "STC on Importer"))) %>% 
ggplot(aes(x=estimate, y=var, colour=ie)) + 
  geom_point(position = position_dodge(width=.75)) + 
  geom_errorbarh(aes(xmin=conf.low, xmax=conf.high), position=position_dodge(width=.75), height=0) + 
  labs(x="Estimate", y="", colour="Model") + 
  theme_bw()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM