I am running a mediation model using the R mediation package, but I am not getting the correct output for my variable types. I have a continuous predictor, but the output is treating my predictor as a categorical variable.
In short:
Predictor = cognitive test score [Composite_Z] (continuous)
Mediator = self-awareness [Awareness] (dichotomous; variable type = numerical in order to run mediation)
Outcome = driving frequency [DRFRQ] (dichotomous)
10 Covariates = Age (continuous), Sex (dichotomous), Race (dichotomous), Education (dichotomous), Severity (continuous), Time (continuous), Seizures (dichotomous), Income (ordinal), Motor (continuous), UrbanRural (ordinal)
I have two models that are going into my mediation analysis (both of these run fine without issues)--
Model #1 : binary logistic regression examining the relationship between cognition (predictor) and self-awareness, while accounting for the covariates.
R code:
fit.a.A3H1 <- glm(Awareness ~ Composite_Z + Age + Sex + Race +
Education + Severity + Time + Seizures + Income + Motor
+ UrbanRural, family=binomial(link="logit"), data=A3H1.df)
Model #2 : binary logistic regression examining the relationship between cognition (predictor) and driving frequency (outcome), while accounting for self-awareness (mediator) and the covariates.
R code:
fit.total.A3H1 <- glm(DRFRQ ~ Composite_Z + Awareness + Age + Sex
+ Race + Education + Severity + Time + Seizures + Income
+ Motor + UrbanRural, family=binomial(link="logit"), data = A3H1.df)
Mediation model : Then, I put those models (outlined above) into my mediation analysis. I am using the R mediation package to run the analysis.
R code:
fitMed.A3H1 <- mediate(fit.a.A3H1, fit.total.A3H1, sims=1000, boot=FALSE,
treat="Composite_Z", mediator="Awareness",
covariates = NULL, use_speed = FALSE)
Output:
Causal Mediation Analysis
Quasi-Bayesian Confidence Intervals
Estimate 95% CI Lower 95% CI Upper p-value
ACME (control) -0.001007 -0.004191 0.00 0.27
ACME (treated) -0.000686 -0.002933 0.00 0.27
ADE (control) 0.031882 0.003696 0.06 0.03 *
ADE (treated) 0.032203 0.003727 0.06 0.03 *
Total Effect 0.031196 0.004744 0.05 0.03 *
Prop. Mediated (control) -0.024010 -0.134304 0.08 0.25
Prop. Mediated (treated) -0.016399 -0.113058 0.07 0.25
ACME (average) -0.000846 -0.003507 0.00 0.27
ADE (average) 0.032042 0.003711 0.06 0.03 *
Prop. Mediated (average) -0.020204 -0.124782 0.08 0.25
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Sample Size Used: 350
Simulations: 1000
The output gives the results in groups, even though my predictor is a continuous variable. Does anyone know why I'm running into this problem and ways I could fix it? Any suggestions would be greatly appreciated!
What's also strange is that I do not have this problem when I run a separate mediation analysis with the same predictor/mediator/covariates (but a different outcome variable that is continuous instead of dichotomous). This separate mediation analysis is made up of a (1) binary logistic regression model and (2) linear regression model, and the output shows only the overall ACME/ADE/etc (ie, there are not groups).
It looks like the output from the mediate()
function takes the form of whatever the final DV is: ie, if you have a binary DV, the outcome will be seperated into control and treated, whereas if you have a continuous DV, the output will not (as the output is on a numeric not a nominal scale, thus representing the β).
Using code from the mediate package vignette , please see the following example:
library(mediation)
data("framing", package = "mediation")
set.seed(2014)
#1: models exactly from mediation vignette: continuous m, binary DV
med.fit <- lm(emo ~ treat + age + educ + gender + income, data = framing)
out.fit <- glm(cong_mesg ~ emo + treat + age + educ + gender + income, data = framing, family = binomial("probit"))
med.out <- mediate(med.fit, out.fit, treat = "treat", mediator = "emo", robustSE = TRUE, sims = 100)
summary(med.out)
#2: models swapped: binary DV, continuous m
med.fit <- glm(cong_mesg ~ treat + age + educ + gender + income, data = framing, family = binomial("probit"))
out.fit <- lm(emo ~ cong_mesg + treat + age + educ + gender + income, data = framing)
med.out <- mediate(med.fit, out.fit, treat = "treat", mediator = "emo", robustSE = TRUE, sims = 100)
summary(med.out)
As you can see #1
has a binary DV and continuous M, and output from mediate()
is seperated into control and treated, whereas output from 2
has continuous DV and binary M, and output is not.
In case of a continuous treatment variable you will have to define the control group and the treatment group when calling mediate
(here x
and y
):
fitMed.A3H1 <- mediate(fit.a.A3H1, fit.total.A3H1, sims=1000, boot=FALSE,
treat="Composite_Z", mediator="Awareness",
control.value = x, treat.value = y,
covariates = NULL, use_speed = FALSE)
I know it might not result with the effect you might be expecting but the package was built thinking of an experiment with a limited number of treatment options. (See section 3.3 in the vignette )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.