Warning: package 'tidyverse' was built under R version 4.4.3
Warning: package 'ggplot2' was built under R version 4.4.3
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(mediation)
Warning: package 'mediation' was built under R version 4.4.3
Loading required package: MASS
Attaching package: 'MASS'
The following object is masked from 'package:dplyr':
select
Loading required package: Matrix
Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':
expand, pack, unpack
Loading required package: mvtnorm
Loading required package: sandwich
Warning: package 'sandwich' was built under R version 4.4.3
Please cite as:
Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
library(skimr)library(jtools)
Warning: package 'jtools' was built under R version 4.4.3
Attaching package: 'jtools'
The following object is masked from 'package:mvtnorm':
standardize
data<- mediation::framing
complete_data <- data %>%filter(if_all(c(emo, treat), ~!is.na(.))) %>%mutate(english=as.numeric(english))skim(complete_data)
Data summary
Name
complete_data
Number of rows
265
Number of columns
15
_______________________
Column type frequency:
factor
4
numeric
11
________________________
Group variables
None
Variable type: factor
skim_variable
n_missing
complete_rate
ordered
n_unique
top_counts
cond
0
1
FALSE
4
1: 68, 2: 67, 3: 67, 4: 63
anx
0
1
FALSE
4
som: 86, a l: 74, ver: 60, not: 45
educ
0
1
FALSE
4
hig: 92, bac: 83, som: 70, les: 20
gender
0
1
FALSE
2
fem: 139, mal: 126, not: 0, ref: 0
Variable type: numeric
skim_variable
n_missing
complete_rate
mean
sd
p0
p25
p50
p75
p100
hist
age
0
1
47.77
15.97
18
35
47
60
85
▆▇▇▆▂
income
0
1
10.80
3.92
1
8
11
13
19
▂▅▆▇▂
emo
0
1
6.97
2.77
3
5
7
9
12
▇▇▇▅▅
p_harm
0
1
5.89
1.76
2
4
6
8
8
▂▃▂▅▇
tone
0
1
0.51
0.50
0
0
1
1
1
▇▁▁▁▇
eth
0
1
0.51
0.50
0
0
1
1
1
▇▁▁▁▇
treat
0
1
0.26
0.44
0
0
0
1
1
▇▁▁▁▃
english
0
1
3.42
0.77
1
3
4
4
4
▁▁▁▅▇
immigr
0
1
3.03
0.97
1
2
3
4
4
▂▅▁▆▇
anti_info
0
1
0.11
0.31
0
0
0
0
1
▇▁▁▁▁
cong_mesg
0
1
0.33
0.47
0
0
0
1
1
▇▁▁▁▃
#Model 0: Predict your DV with IV and Other Controlsmodel_0 <-lm(immigr~treat, complete_data)#Model 1: Predict your Mediator with IV and Other Controlsmodel_m <-lm(emo ~treat, complete_data)#Model 2: Predict your DV with IV, Mediator and Other Controlsmodel_y <-lm(immigr~treat+emo, complete_data)export_summs(model_0, model_m, model_y, digits=3, model.names =c("immigration w/o \ntreat", "Mediator Model", "immigration w/ \ntreat"))
immigration w/o treat
Mediator Model
immigration w/ treat
(Intercept)
2.914 ***
6.594 ***
1.674 ***
(0.068)
(0.193)
(0.134)
treat
0.439 **
1.480 ***
0.161
(0.134)
(0.380)
(0.116)
emo
0.188 ***
(0.018)
N
265
265
265
R2
0.040
0.054
0.315
*** p < 0.001; ** p < 0.01; * p < 0.05.
#Run the mediation analysis with bootstrapping for CIs#Assign specific variables to be Mediator and Treatment (Treatment has to be numeric or binary)results <-mediate(model_m, model_y, treat='treat', mediator='emo',boot=TRUE, sims=100)
Running nonparametric bootstrap
#Has to have exact same number of cases in each modelcomplete_data_1 <- data %>%filter(if_all(c(treat, emo), ~!is.na(.)))#Model 1: Predict your Mediator with IV and Other Controlsmodel_m_m <-lm(emo ~ treat, complete_data_1)#Model 2: Predict your DV with IV, Mediator and Other Controlsmodel_y_y <-lm(immigr~treat+emo, complete_data_1)export_summs(model_0, model_m_m, model_y_y, digits=3, model.names =c("Immigration w/o \nTreat", "Mediator Model", "Immigration w/ \nTreat"))
Immigration w/o Treat
Mediator Model
Immigration w/ Treat
(Intercept)
2.914 ***
6.594 ***
1.674 ***
(0.068)
(0.193)
(0.134)
treat
0.439 **
1.480 ***
0.161
(0.134)
(0.380)
(0.116)
emo
0.188 ***
(0.018)
N
265
265
265
R2
0.040
0.054
0.315
*** p < 0.001; ** p < 0.01; * p < 0.05.
#Run the mediation analysis with bootstrapping for CIsresults_1 <-mediate(model_m_m, model_y_y, treat='treat', mediator='emo',boot=TRUE, sims=100)
#Model 0: Predict your DV with IV and Other Controlsmodel_0_1 <-lm(english ~ treat, complete_data)#Model 1: Predict your Mediator with IV and Other Controlsmodel_m_1 <-lm(emo ~ treat, complete_data)#Model 2: Predict your DV with IV, Mediator and Other Controlsmodel_y_1 <-lm(english ~ treat+emo, complete_data)export_summs(model_0_1, model_m_1, model_y_1, digits=3, model.names =c("english w/o \ntreat", "Mediator Model", "english w/ \ntreat"))
english w/o treat
Mediator Model
english w/ treat
(Intercept)
3.396 ***
6.594 ***
2.836 ***
(0.055)
(0.193)
(0.123)
treat
0.104
1.480 ***
-0.022
(0.108)
(0.380)
(0.107)
emo
0.085 ***
(0.017)
N
265
265
265
R2
0.003
0.054
0.092
*** p < 0.001; ** p < 0.01; * p < 0.05.
#Run the mediation analysis with bootstrapping for CIs#Assign specific variables to be Mediator and Treatment (Treatment has to be numeric or binary)results <-mediate(model_m_1, model_y_1, treat='treat', mediator='emo',boot=TRUE, sims=100)
Running nonparametric bootstrap
#Has to have exact same number of cases in each modelcomplete_data_2 <- data %>%filter(if_all(c(treat, emo), ~!is.na(.)))%>%mutate(english=as.numeric(english))#Model 1: Predict your Mediator with IV and Other Controlsmodel_m_m_1 <-lm(emo ~ treat, complete_data_2)#Model 2: Predict your DV with IV, Mediator and Other Controlsmodel_y_y_1 <-lm(english ~ treat+emo, complete_data_2)export_summs(model_0_1, model_m_m_1, model_y_y_1, digits=3, model.names =c("Immigration w/o \nTreat", "Mediator Model", "Immigration w/ \nTreat"))
Immigration w/o Treat
Mediator Model
Immigration w/ Treat
(Intercept)
3.396 ***
6.594 ***
2.836 ***
(0.055)
(0.193)
(0.123)
treat
0.104
1.480 ***
-0.022
(0.108)
(0.380)
(0.107)
emo
0.085 ***
(0.017)
N
265
265
265
R2
0.003
0.054
0.092
*** p < 0.001; ** p < 0.01; * p < 0.05.
#Run the mediation analysis with bootstrapping for CIsresults_2 <-mediate(model_m_m_1, model_y_y_1, treat='treat', mediator='emo',boot=TRUE, sims=100)