From angel.rodriguez at matiainstituto.net Tue Sep 16 12:46:30 2014 From: angel.rodriguez at matiainstituto.net (Angel Rodriguez) Date: Tue, 16 Sep 2014 12:46:30 +0200 Subject: [Mediation-information] Mediation analysis multilevel data ordered mediator Message-ID: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local> Dear subscribers, I've read that for causal mediation analysis of multilevel data, lmer or glmer have to be used. Isn't possible therefore to use an ordered categorical mediator in the analysis? Thank you very much. Angel Rodriguez-Laso -------------- next part -------------- An HTML attachment was scrubbed... URL: From kimai at princeton.edu Tue Sep 16 14:48:21 2014 From: kimai at princeton.edu (Kosuke Imai) Date: Tue, 16 Sep 2014 08:48:21 -0400 Subject: [Mediation-information] Mediation analysis multilevel data ordered mediator In-Reply-To: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local> References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local> Message-ID: As far as I know, there is no reliable frequentist implementation of ordered multi-level in most packages such as R or Stata. My suggestion would be to dichotomize the outcome variable (or use a linear model approximation if you have a large number of categories) or use a Bayesian MCMC approach. Best, Kosuke Kosuke Imai Department of Politics Princeton University http://imai.princeton.edu On Tue, Sep 16, 2014 at 6:46 AM, Angel Rodriguez < angel.rodriguez at matiainstituto.net> wrote: > > Dear subscribers, > > I've read that for causal mediation analysis of multilevel data, lmer or > glmer have to be used. Isn't possible therefore to use an ordered > categorical mediator in the analysis? > > Thank you very much. > > Angel Rodriguez-Laso > > _______________________________________________ > Mediation-information mailing list > Mediation-information at lists.r-forge.r-project.org > > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/mediation-information > -------------- next part -------------- An HTML attachment was scrubbed... URL: From angel.rodriguez at matiainstituto.net Tue Sep 16 14:49:14 2014 From: angel.rodriguez at matiainstituto.net (Angel Rodriguez) Date: Tue, 16 Sep 2014 14:49:14 +0200 Subject: [Mediation-information] Mediation analysis multilevel data ordered mediator References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local> Message-ID: <8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> Thank you, Kosuke. You mean also that the mediator has to be dichotomized (it is the dependent variable in one of the equations). Right? Angel Rodriguez-Laso -----Mensaje original----- De: Kosuke Imai [mailto:kimai at princeton.edu] Enviado el: mar 16/09/2014 14:48 Para: Angel Rodriguez CC: mediation-information at r-forge.wu-wien.ac.at Asunto: Re: [Mediation-information] Mediation analysis multilevel data ordered mediator As far as I know, there is no reliable frequentist implementation of ordered multi-level in most packages such as R or Stata. My suggestion would be to dichotomize the outcome variable (or use a linear model approximation if you have a large number of categories) or use a Bayesian MCMC approach. Best, Kosuke Kosuke Imai Department of Politics Princeton University http://imai.princeton.edu On Tue, Sep 16, 2014 at 6:46 AM, Angel Rodriguez < angel.rodriguez at matiainstituto.net> wrote: > > Dear subscribers, > > I've read that for causal mediation analysis of multilevel data, lmer or > glmer have to be used. Isn't possible therefore to use an ordered > categorical mediator in the analysis? > > Thank you very much. > > Angel Rodriguez-Laso > > _______________________________________________ > Mediation-information mailing list > Mediation-information at lists.r-forge.r-project.org > > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/mediation-information > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kimai at princeton.edu Tue Sep 16 14:53:02 2014 From: kimai at princeton.edu (Kosuke Imai) Date: Tue, 16 Sep 2014 08:53:02 -0400 Subject: [Mediation-information] Mediation analysis multilevel data ordered mediator In-Reply-To: <8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local> <8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> Message-ID: yes, that's right. Kosuke Imai Department of Politics Princeton University http://imai.princeton.edu On Tue, Sep 16, 2014 at 8:49 AM, Angel Rodriguez < angel.rodriguez at matiainstituto.net> wrote: > Thank you, Kosuke. You mean also that the mediator has to be > dichotomized (it is the dependent variable in one of the equations). Right? > > Angel Rodriguez-Laso > > > -----Mensaje original----- > De: Kosuke Imai [mailto:kimai at princeton.edu ] > Enviado el: mar 16/09/2014 14:48 > Para: Angel Rodriguez > CC: mediation-information at r-forge.wu-wien.ac.at > Asunto: Re: [Mediation-information] Mediation analysis multilevel data > ordered mediator > > As far as I know, there is no reliable frequentist implementation of > ordered multi-level in most packages such as R or Stata. My suggestion > would be to dichotomize the outcome variable (or use a linear model > approximation if you have a large number of categories) or use a Bayesian > MCMC approach. > > Best, > Kosuke > > Kosuke Imai > Department of Politics > Princeton University > http://imai.princeton.edu > > On Tue, Sep 16, 2014 at 6:46 AM, Angel Rodriguez < > angel.rodriguez at matiainstituto.net> wrote: > > > > > Dear subscribers, > > > > I've read that for causal mediation analysis of multilevel data, lmer or > > glmer have to be used. Isn't possible therefore to use an ordered > > categorical mediator in the analysis? > > > > Thank you very much. > > > > Angel Rodriguez-Laso > > > > _______________________________________________ > > Mediation-information mailing list > > Mediation-information at lists.r-forge.r-project.org > > > > > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/mediation-information > > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From angel.rodriguez at matiainstituto.net Fri Sep 19 13:15:47 2014 From: angel.rodriguez at matiainstituto.net (Angel Rodriguez) Date: Fri, 19 Sep 2014 13:15:47 +0200 Subject: [Mediation-information] (no subject) References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local><8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> Message-ID: <8564BCD7D26E0D40872F1A132C8BBB250258B2A9@MATIAEXCH.matiaf.local> Dear Subscribers, I've encountered the following error message. Edad_c is numeric. Estudic, sexo, deprinf and benvii are dichotomic. Regalf has three categories. Any help would be very valuable. Best regards, Angel Rodriguez-Laso > med.fit <- glm(estudic ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65) > out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estudic, family="binomial" ,data=child65) > library("mediation") Loading required package: MASS Loading required package: Matrix Loading required package: lpSolve Loading required package: mvtnorm mediation: Causal Mediation Analysis Version: 4.4.2 > library("sandwich") > set.seed(2014) > med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100) Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed In addition: Warning message: In mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", : treatment and control values do not match factor levels; using no and s? as control and treatment, respectively ________________________________ -------------- next part -------------- An HTML attachment was scrubbed... URL: From hirose at Princeton.EDU Fri Sep 19 14:17:07 2014 From: hirose at Princeton.EDU (Kentaro Hirose) Date: Fri, 19 Sep 2014 12:17:07 +0000 Subject: [Mediation-information] (no subject) In-Reply-To: <8564BCD7D26E0D40872F1A132C8BBB250258B2A9@MATIAEXCH.matiaf.local> References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local><8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> , <8564BCD7D26E0D40872F1A132C8BBB250258B2A9@MATIAEXCH.matiaf.local> Message-ID: <7F71CA3EDBFDB742900C47C9596B9023390A77E2@CSGMBX201W.pu.win.princeton.edu> Hi Angel, The warning message "treatment and control values do not match factor levels" pops up when your treatment has more than two values but you don't specify the specific values of the treatment that you're interested when deriving the treatment effect. So, for example, if you're interested in the treatment effect when the value of the treatment changes from no to si, then you should use the following command: med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100, control.value = "no", treat.value = "si") Best, Kentaro ________________________________________ From: mediation-information-bounces at r-forge.wu-wien.ac.at [mediation-information-bounces at r-forge.wu-wien.ac.at] on behalf of Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Friday, September 19, 2014 7:15 AM To: mediation-information at r-forge.wu-wien.ac.at Subject: Re: [Mediation-information] (no subject) Dear Subscribers, I've encountered the following error message. Edad_c is numeric. Estudic, sexo, deprinf and benvii are dichotomic. Regalf has three categories. Any help would be very valuable. Best regards, Angel Rodriguez-Laso > med.fit <- glm(estudic ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65) > out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estudic, family="binomial" ,data=child65) > library("mediation") Loading required package: MASS Loading required package: Matrix Loading required package: lpSolve Loading required package: mvtnorm mediation: Causal Mediation Analysis Version: 4.4.2 > library("sandwich") > set.seed(2014) > med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100) Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed In addition: Warning message: In mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", : treatment and control values do not match factor levels; using no and s? as control and treatment, respectively ________________________________ From angel.rodriguez at matiainstituto.net Fri Sep 19 14:22:43 2014 From: angel.rodriguez at matiainstituto.net (Angel Rodriguez) Date: Fri, 19 Sep 2014 14:22:43 +0200 Subject: [Mediation-information] (no subject) References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local><8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> , <8564BCD7D26E0D40872F1A132C8BBB250258B2A9@MATIAEXCH.matiaf.local> <7F71CA3EDBFDB742900C47C9596B9023390A77E2@CSGMBX201W.pu.win.princeton.edu> Message-ID: <8564BCD7D26E0D40872F1A132C8BBB250258B2AB@MATIAEXCH.matiaf.local> Thank you, Kentaro. The treatment variable has two values only. With your command that warning disappears but, what about the error: Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed ? Angel ________________________________ De: mediation-information-bounces at lists.r-forge.r-project.org en nombre de Kentaro Hirose Enviado el: vie 19/09/2014 14:17 Para: mediation-information at r-forge.wu-wien.ac.at Asunto: Re: [Mediation-information] (no subject) Hi Angel, The warning message "treatment and control values do not match factor levels" pops up when your treatment has more than two values but you don't specify the specific values of the treatment that you're interested when deriving the treatment effect. So, for example, if you're interested in the treatment effect when the value of the treatment changes from no to si, then you should use the following command: med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100, control.value = "no", treat.value = "si") Best, Kentaro ________________________________________ From: mediation-information-bounces at r-forge.wu-wien.ac.at [mediation-information-bounces at r-forge.wu-wien.ac.at] on behalf of Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Friday, September 19, 2014 7:15 AM To: mediation-information at r-forge.wu-wien.ac.at Subject: Re: [Mediation-information] (no subject) Dear Subscribers, I've encountered the following error message. Edad_c is numeric. Estudic, sexo, deprinf and benvii are dichotomic. Regalf has three categories. Any help would be very valuable. Best regards, Angel Rodriguez-Laso > med.fit <- glm(estudic ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65) > out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estudic, family="binomial" ,data=child65) > library("mediation") Loading required package: MASS Loading required package: Matrix Loading required package: lpSolve Loading required package: mvtnorm mediation: Causal Mediation Analysis Version: 4.4.2 > library("sandwich") > set.seed(2014) > med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100) Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed In addition: Warning message: In mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", : treatment and control values do not match factor levels; using no and s? as control and treatment, respectively ________________________________ _______________________________________________ Mediation-information mailing list Mediation-information at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/mediation-information -------------- next part -------------- An HTML attachment was scrubbed... URL: From hirose at Princeton.EDU Fri Sep 19 14:33:21 2014 From: hirose at Princeton.EDU (Kentaro Hirose) Date: Fri, 19 Sep 2014 12:33:21 +0000 Subject: [Mediation-information] (no subject) In-Reply-To: <8564BCD7D26E0D40872F1A132C8BBB250258B2AB@MATIAEXCH.matiaf.local> References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local><8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> , <8564BCD7D26E0D40872F1A132C8BBB250258B2A9@MATIAEXCH.matiaf.local> <7F71CA3EDBFDB742900C47C9596B9023390A77E2@CSGMBX201W.pu.win.princeton.edu>, <8564BCD7D26E0D40872F1A132C8BBB250258B2AB@MATIAEXCH.matiaf.local> Message-ID: <7F71CA3EDBFDB742900C47C9596B9023390A97F7@CSGMBX201W.pu.win.princeton.edu> I guess it's somehow related to the data you're using. I'll figure out the problem if you send me a small subset of your data and code. Best, Kentaro ________________________________________ From: Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Friday, September 19, 2014 8:22 AM To: Kentaro Hirose; mediation-information at r-forge.wu-wien.ac.at Subject: RE: [Mediation-information] (no subject) Thank you, Kentaro. The treatment variable has two values only. With your command that warning disappears but, what about the error: Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed ? Angel ________________________________ De: mediation-information-bounces at lists.r-forge.r-project.org en nombre de Kentaro Hirose Enviado el: vie 19/09/2014 14:17 Para: mediation-information at r-forge.wu-wien.ac.at Asunto: Re: [Mediation-information] (no subject) Hi Angel, The warning message "treatment and control values do not match factor levels" pops up when your treatment has more than two values but you don't specify the specific values of the treatment that you're interested when deriving the treatment effect. So, for example, if you're interested in the treatment effect when the value of the treatment changes from no to si, then you should use the following command: med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100, control.value = "no", treat.value = "si") Best, Kentaro ________________________________________ From: mediation-information-bounces at r-forge.wu-wien.ac.at [mediation-information-bounces at r-forge.wu-wien.ac.at] on behalf of Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Friday, September 19, 2014 7:15 AM To: mediation-information at r-forge.wu-wien.ac.at Subject: Re: [Mediation-information] (no subject) Dear Subscribers, I've encountered the following error message. Edad_c is numeric. Estudic, sexo, deprinf and benvii are dichotomic. Regalf has three categories. Any help would be very valuable. Best regards, Angel Rodriguez-Laso > med.fit <- glm(estudic ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65) > out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estudic, family="binomial" ,data=child65) > library("mediation") Loading required package: MASS Loading required package: Matrix Loading required package: lpSolve Loading required package: mvtnorm mediation: Causal Mediation Analysis Version: 4.4.2 > library("sandwich") > set.seed(2014) > med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100) Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed In addition: Warning message: In mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", : treatment and control values do not match factor levels; using no and s? as control and treatment, respectively ________________________________ _______________________________________________ Mediation-information mailing list Mediation-information at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/mediation-information From angel.rodriguez at matiainstituto.net Fri Sep 19 14:35:34 2014 From: angel.rodriguez at matiainstituto.net (Angel Rodriguez) Date: Fri, 19 Sep 2014 14:35:34 +0200 Subject: [Mediation-information] (no subject) References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local><8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> , <8564BCD7D26E0D40872F1A132C8BBB250258B2A9@MATIAEXCH.matiaf.local> <7F71CA3EDBFDB742900C47C9596B9023390A77E2@CSGMBX201W.pu.win.princeton.edu>, <8564BCD7D26E0D40872F1A132C8BBB250258B2AB@MATIAEXCH.matiaf.local> <7F71CA3EDBFDB742900C47C9596B9023390A97F7@CSGMBX201W.pu.win.princeton.edu> Message-ID: <8564BCD7D26E0D40872F1A132C8BBB250258B2AC@MATIAEXCH.matiaf.local> Thank you very much. Should I attach them to a message? Angel ________________________________ De: Kentaro Hirose [mailto:hirose at Princeton.EDU] Enviado el: vie 19/09/2014 14:33 Para: Angel Rodriguez; mediation-information at r-forge.wu-wien.ac.at Asunto: RE: [Mediation-information] (no subject) I guess it's somehow related to the data you're using. I'll figure out the problem if you send me a small subset of your data and code. Best, Kentaro ________________________________________ From: Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Friday, September 19, 2014 8:22 AM To: Kentaro Hirose; mediation-information at r-forge.wu-wien.ac.at Subject: RE: [Mediation-information] (no subject) Thank you, Kentaro. The treatment variable has two values only. With your command that warning disappears but, what about the error: Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed ? Angel ________________________________ De: mediation-information-bounces at lists.r-forge.r-project.org en nombre de Kentaro Hirose Enviado el: vie 19/09/2014 14:17 Para: mediation-information at r-forge.wu-wien.ac.at Asunto: Re: [Mediation-information] (no subject) Hi Angel, The warning message "treatment and control values do not match factor levels" pops up when your treatment has more than two values but you don't specify the specific values of the treatment that you're interested when deriving the treatment effect. So, for example, if you're interested in the treatment effect when the value of the treatment changes from no to si, then you should use the following command: med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100, control.value = "no", treat.value = "si") Best, Kentaro ________________________________________ From: mediation-information-bounces at r-forge.wu-wien.ac.at [mediation-information-bounces at r-forge.wu-wien.ac.at] on behalf of Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Friday, September 19, 2014 7:15 AM To: mediation-information at r-forge.wu-wien.ac.at Subject: Re: [Mediation-information] (no subject) Dear Subscribers, I've encountered the following error message. Edad_c is numeric. Estudic, sexo, deprinf and benvii are dichotomic. Regalf has three categories. Any help would be very valuable. Best regards, Angel Rodriguez-Laso > med.fit <- glm(estudic ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65) > out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estudic, family="binomial" ,data=child65) > library("mediation") Loading required package: MASS Loading required package: Matrix Loading required package: lpSolve Loading required package: mvtnorm mediation: Causal Mediation Analysis Version: 4.4.2 > library("sandwich") > set.seed(2014) > med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100) Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed In addition: Warning message: In mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", : treatment and control values do not match factor levels; using no and s? as control and treatment, respectively ________________________________ _______________________________________________ Mediation-information mailing list Mediation-information at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/mediation-information -------------- next part -------------- An HTML attachment was scrubbed... URL: From angel.rodriguez at matiainstituto.net Wed Sep 24 13:18:39 2014 From: angel.rodriguez at matiainstituto.net (Angel Rodriguez) Date: Wed, 24 Sep 2014 13:18:39 +0200 Subject: [Mediation-information] Mediator must be a number References: <8564BCD7D26E0D40872F1A132C8BBB250258B28D@MATIAEXCH.matiaf.local><8564BCD7D26E0D40872F1A132C8BBB250258B290@MATIAEXCH.matiaf.local> , <8564BCD7D26E0D40872F1A132C8BBB250258B2A9@MATIAEXCH.matiaf.local> <7F71CA3EDBFDB742900C47C9596B9023390A77E2@CSGMBX201W.pu.win.princeton.edu>, <8564BCD7D26E0D40872F1A132C8BBB250258B2AB@MATIAEXCH.matiaf.local> <7F71CA3EDBFDB742900C47C9596B9023390A97F7@CSGMBX201W.pu.win.princeton.edu> Message-ID: <8564BCD7D26E0D40872F1A132C8BBB250258B2C1@MATIAEXCH.matiaf.local> Dear Subscribers, I copy the solution that Kentaro very kindly found for the problem I posted on the 19th of September: Hi Angel, You have to change the mediator into number like 0 and 1. --------------------------------------------------------------------------- library("mediation") library("sandwich") set.seed(2014) load("~/Desktop/kentaro.rda") kentaro$estudic.new <- 0 kentaro$estudic.new[kentaro$estudic == "Menos que primarios"] <- 1 kentaro$estudic <- kentaro$estudic.new med.fit <- glm(estudic ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=kentaro) out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estudic, family="binomial" ,data=kentaro) med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100, control.value = "no", treat.value = "s\xed") summary(med.out) --------------------------------------------------------------------------- Best, Kentaro Now, with the same database but this time using a multimed procedure, I encounter this problem: > Xnames <- c("edad_c", "sexo", "regalf") > m.med <- multimed(outcome = "benvii", med.main = "p207dic", med.alt = "estuprimas", treat = "deprinf", covariates = Xnames, data = child65, sims = 1000) Error: variable 'deprinf' was fitted with type "factor" but type "numeric" was supplied In addition: Warning messages: 1: In Ops.factor(data.1[, med.main], 2) : ^ not meaningful for factors 2: In Ops.factor(data.1[, treat], data.1[, med.main]^2) : * not meaningful for factors 3: In model.response(mf, "numeric") : using type = "numeric" with a factor response will be ignored 4: In Ops.factor(y, z$residuals) : - not meaningful for factors 5: In model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : variable 'deprinf' is not a factor > str(child65$deprinf) Factor w/ 2 levels "no","s?": 1 2 2 2 1 2 2 1 1 1 ... So, deprinf is a factor but is considered numeric by multimed. Any clue? Thank you very much. Angel Rodr?guez Laso -----Mensaje original----- De: Kentaro Hirose [mailto:hirose at Princeton.EDU] Enviado el: vie 19/09/2014 14:33 Para: Angel Rodriguez; mediation-information at r-forge.wu-wien.ac.at Asunto: RE: [Mediation-information] (no subject) I guess it's somehow related to the data you're using. I'll figure out the problem if you send me a small subset of your data and code. Best, Kentaro ________________________________________ From: Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Friday, September 19, 2014 8:22 AM To: Kentaro Hirose; mediation-information at r-forge.wu-wien.ac.at Subject: RE: [Mediation-information] (no subject) Thank you, Kentaro. The treatment variable has two values only. With your command that warning disappears but, what about the error: Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed ? Angel ________________________________ De: mediation-information-bounces at lists.r-forge.r-project.org en nombre de Kentaro Hirose Enviado el: vie 19/09/2014 14:17 Para: mediation-information at r-forge.wu-wien.ac.at Asunto: Re: [Mediation-information] (no subject) Hi Angel, The warning message "treatment and control values do not match factor levels" pops up when your treatment has more than two values but you don't specify the specific values of the treatment that you're interested when deriving the treatment effect. So, for example, if you're interested in the treatment effect when the value of the treatment changes from no to si, then you should use the following command: med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100, control.value = "no", treat.value = "si") Best, Kentaro ________________________________________ From: mediation-information-bounces at r-forge.wu-wien.ac.at [mediation-information-bounces at r-forge.wu-wien.ac.at] on behalf of Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Friday, September 19, 2014 7:15 AM To: mediation-information at r-forge.wu-wien.ac.at Subject: Re: [Mediation-information] (no subject) Dear Subscribers, I've encountered the following error message. Edad_c is numeric. Estudic, sexo, deprinf and benvii are dichotomic. Regalf has three categories. Any help would be very valuable. Best regards, Angel Rodriguez-Laso > med.fit <- glm(estudic ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65) > out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estudic, family="binomial" ,data=child65) > library("mediation") Loading required package: MASS Loading required package: Matrix Loading required package: lpSolve Loading required package: mvtnorm mediation: Causal Mediation Analysis Version: 4.4.2 > library("sandwich") > set.seed(2014) > med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", robustSE = TRUE, sims = 100) Error in if (xhat == 0) out <- 1 else { : missing value where TRUE/FALSE needed In addition: Warning message: In mediate(med.fit, out.fit, treat = "deprinf", mediator = "estudic", : treatment and control values do not match factor levels; using no and s? as control and treatment, respectively ________________________________ _______________________________________________ Mediation-information mailing list Mediation-information at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/mediation-information -------------- next part -------------- An HTML attachment was scrubbed... URL: From angel.rodriguez at matiainstituto.net Wed Sep 24 13:27:49 2014 From: angel.rodriguez at matiainstituto.net (Angel Rodriguez) Date: Wed, 24 Sep 2014 13:27:49 +0200 Subject: [Mediation-information] Counterintuitive results Message-ID: <8564BCD7D26E0D40872F1A132C8BBB250258B2C2@MATIAEXCH.matiaf.local> Dear Subscribers, I've carried out the following model: > library("sandwich") > set.seed(2014) > med.fit <- glm(estuprimas ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65) > out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estuprimas, family="binomial" ,data=child65) > med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estuprimas", robustSE = TRUE, sims=1000, control.value = "no", treat.value = "s\xed") > summary(med.out) Causal Mediation Analysis Quasi-Bayesian Confidence Intervals Estimate 95% CI Lower 95% CI Upper p-value ACME (control) -0.012543 -0.029801 0.000732 0.07 ACME (treated) -0.011498 -0.027808 0.000723 0.07 ADE (control) -0.049137 -0.125894 0.031768 0.27 ADE (treated) -0.048092 -0.121987 0.031410 0.27 Total Effect -0.060635 -0.137208 0.021339 0.15 Prop. Mediated (control) 0.169334 -0.848191 1.686179 0.21 Prop. Mediated (treated) 0.147997 -0.854962 1.689611 0.21 ACME (average) -0.012021 -0.028888 0.000728 0.07 ADE (average) -0.048615 -0.124610 0.031589 0.27 Prop. Mediated (average) 0.158665 -0.851577 1.687895 0.21 Sample Size Used: 657 Simulations: 1000 If I understand well, this means that, of the total association of having experienced infant deprivation vs not having experienced it (variable deprinf) on having aged well (-0.06 (OR=0.94; CI95%= 0.87-1.02)) , 15.9% is via the mediator having primary education or more vs less than primary education (estuprimas). This does not make sense to me, because having primary education or more is a protective factor for aging well, as you can see in this model: Call: glm(formula = benvii ~ edad_c + sexo + regalf + deprinf + estuprimas, family = "binomial", data = child65) Deviance Residuals: Min 1Q Median 3Q Max -1.6054 -0.8433 -0.5597 1.0327 2.6291 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 7.29876 1.20323 6.066 1.31e-09 *** edad_c -0.10262 0.01619 -6.339 2.31e-10 *** sexomujer -0.89359 0.18639 -4.794 1.63e-06 *** regalfMedia -0.63054 0.27055 -2.331 0.01977 * regalfBaja -0.71116 0.23645 -3.008 0.00263 ** deprinfs? -0.29268 0.23603 -1.240 0.21497 estuprimas 0.33773 0.18910 1.786 0.07411 . I'd appreciate some insight into this result. Thank you very much. Angel Rodr?guez-Laso -------------- next part -------------- An HTML attachment was scrubbed... URL: From hirose at Princeton.EDU Wed Sep 24 16:05:38 2014 From: hirose at Princeton.EDU (Kentaro Hirose) Date: Wed, 24 Sep 2014 14:05:38 +0000 Subject: [Mediation-information] Counterintuitive results In-Reply-To: <8564BCD7D26E0D40872F1A132C8BBB250258B2C2@MATIAEXCH.matiaf.local> References: <8564BCD7D26E0D40872F1A132C8BBB250258B2C2@MATIAEXCH.matiaf.local> Message-ID: <7F71CA3EDBFDB742900C47C9596B9023390AB2DE@CSGMBX201W.pu.win.princeton.edu> Hi Angel, To rephrase your question, "why do I get a negative total effect of the treatment on the outcome even though the mediator has a positive effect in the outcome regression model?" If this is your question, we also need to know the effect of the treatment on the mediator. If this is negative, then everything makes sense: [1] T has a negative effect on M, [2] M has a positive effect on Y, and [3] T has a negative direct effect on Y as shown in the second table; If so, T would have a negative total effect on Y. Best, Kentaro ________________________________________ From: mediation-information-bounces at r-forge.wu-wien.ac.at [mediation-information-bounces at r-forge.wu-wien.ac.at] on behalf of Angel Rodriguez [angel.rodriguez at matiainstituto.net] Sent: Wednesday, September 24, 2014 7:27 AM To: mediation-information at r-forge.wu-wien.ac.at Subject: [Mediation-information] Counterintuitive results Dear Subscribers, I've carried out the following model: > library("sandwich") > set.seed(2014) > med.fit <- glm(estuprimas ~ edad_c + sexo + regalf + deprinf, family="binomial" ,data=child65) > out.fit <- glm(benvii ~ edad_c + sexo + regalf + deprinf + estuprimas, family="binomial" ,data=child65) > med.out <- mediate(med.fit, out.fit, treat = "deprinf", mediator = "estuprimas", robustSE = TRUE, sims=1000, control.value = "no", treat.value = "s\xed") > summary(med.out) Causal Mediation Analysis Quasi-Bayesian Confidence Intervals Estimate 95% CI Lower 95% CI Upper p-value ACME (control) -0.012543 -0.029801 0.000732 0.07 ACME (treated) -0.011498 -0.027808 0.000723 0.07 ADE (control) -0.049137 -0.125894 0.031768 0.27 ADE (treated) -0.048092 -0.121987 0.031410 0.27 Total Effect -0.060635 -0.137208 0.021339 0.15 Prop. Mediated (control) 0.169334 -0.848191 1.686179 0.21 Prop. Mediated (treated) 0.147997 -0.854962 1.689611 0.21 ACME (average) -0.012021 -0.028888 0.000728 0.07 ADE (average) -0.048615 -0.124610 0.031589 0.27 Prop. Mediated (average) 0.158665 -0.851577 1.687895 0.21 Sample Size Used: 657 Simulations: 1000 If I understand well, this means that, of the total association of having experienced infant deprivation vs not having experienced it (variable deprinf) on having aged well (-0.06 (OR=0.94; CI95%= 0.87-1.02)) , 15.9% is via the mediator having primary education or more vs less than primary education (estuprimas). This does not make sense to me, because having primary education or more is a protective factor for aging well, as you can see in this model: Call: glm(formula = benvii ~ edad_c + sexo + regalf + deprinf + estuprimas, family = "binomial", data = child65) Deviance Residuals: Min 1Q Median 3Q Max -1.6054 -0.8433 -0.5597 1.0327 2.6291 Coefficients: Estimate Std. Error z value Pr(>|z|) (Intercept) 7.29876 1.20323 6.066 1.31e-09 *** edad_c -0.10262 0.01619 -6.339 2.31e-10 *** sexomujer -0.89359 0.18639 -4.794 1.63e-06 *** regalfMedia -0.63054 0.27055 -2.331 0.01977 * regalfBaja -0.71116 0.23645 -3.008 0.00263 ** deprinfs? -0.29268 0.23603 -1.240 0.21497 estuprimas 0.33773 0.18910 1.786 0.07411 . I'd appreciate some insight into this result. Thank you very much. Angel Rodr?guez-Laso