Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

createModels function runs but nothing happens

15 views
Skip to first unread message

Bradley

unread,
Jun 23, 2024, 4:01:20 PM6/23/24
to MplusAutomation
I'm attempting to create new models that iterate through my outcomes, moderators, and a few different model specification options. When I first started writing this script, when I ran the code it would launch xQuartz and not do anything so I removed that app. Now when I run the script R runs, but nothing happens. I let it run for hours and it didn't write a single input file.

Here is my code

library(MplusAutomation)
library(readxl)
library(writexl)
library(tidyverse)

options(scipen = 999)

setwd("/Users/private/Desktop/test")

template <- '
[[init]]
iterators = mod dv option withx;
mod = 1:6;
dv = 1:2;
option = 2:3;
withx = 0:1;

mname#mod = reaff remea remas recon redet rerel;
dvname#dv = jsb ww;

filename = "CRfinal_[[mname#mod]]_[[dvname#dv]]_opt[[option]][[withx]].inp";
outputDirectory = "/Users/private/Desktop/test";
[[/init]]
TITLE: Moderated mediation model with 3 DVs for Supplemental Compensation Project;
DATA: FILE = "SC project-all data mplus ready2.csv";
VARIABLE:
NAMES =
id time jsb0 ww0 ind remote remday whrs age gend
gend_r race_r educ rel income child hpha0 hpla0
lpha0 lpla0 redet0 rerel0 remas0 recon0 remea0 reaff0
ra0 aut wm tv lplaf lphaf hphaf hplaf
remas recon redet rerel remea reaff ra ww
jsb lplas lphas hphas hplas;

USEVAR = x1 x2 x3 m w mw y meanx1 meanx2 meanx3 meanm meanw meanmw;

MISSING = all (-999);

CLUSTER = id;

WITHIN = x1 x2 x3 m w mw;

BETWEEN = meanx1 meanx2 meanx3 meanm meanw meanmw;

DEFINE:

x1 = aut;
x2 = wm;
x3 = tv;
m = lplaf;
w = [[mname#mod]];
mw = m * w;
y = [[dvname#dv]];
CENTER x1 x2 x3 m w (GROUPMEAN);
meanx1 = CLUSTER_MEAN(x1);
meanx2 = CLUSTER_MEAN(x2);
meanx3 = CLUSTER_MEAN(x3);
meanm = CLUSTER_MEAN(m);
meanw = CLUSTER_MEAN(w);
meanmw = meanm*meanw;

ANALYSIS:

TYPE = TWOLEVEL RANDOM;

MODEL:

%WITHIN%

y ON m (b1);
y ON w (c1);
y ON mw (c2);

y ON x1 (cdash1);
y ON x2 (cdash2);
y ON x3 (cdash3);

m ON x1 (a1);
m ON x2 (a2);
m ON x3 (a3);

[[withx = 1]]
x1 x2 x3 WITH x1 x2 x3;
[[/withx = 1]]

!Option 1:
!MW WITH m;

[[option = 2]]
!Option 2:
mw WITH m w;
meanmw WITH meanm meanw;
[[/option = 2]]

[[option = 3]]
!Option 3 - Fully saturated model:
m w mw WITH m w mw;
meanm meanw meanmw WITH meanm meanw meanmw;
[[/option = 3]]

%BETWEEN%

y;
meanm;
Y ON meanm (mb1);
y ON meanw (mc1);
y ON meanmw (mc2);

y ON meanx1 (mcdash1);
y ON meanx2 (mcdash2);
y ON meanx3 (mcdash3);

meanm ON meanx1 (ma1);
meanm ON meanx2 (ma2);
meanm ON meanx3 (ma3);

!Option 1:
!meanmw WITH meanm;

!Option 2:
!meanmw WITH meanm meanw;

!Option 3 - Fully saturated model:
!meanm meanw meanmw WITH meanm meanw meanmw;

MODEL CONSTRAINT:
NEW(
LW MW HW
SSLW SSMW SSHW
INDW1 INDW2 INDW3
INDW1L INDW1M INDW1H
INDW2L INDW2M INDW2H
INDW3L INDW3M INDW3H
IMMW1 IMMW2 IMMW3
DFW1 DFW2 DFW3
LB MB HB
SSLB SSMB SSHB
INDB1 INDB2 INDB3
INDB1L INDB1M INDB1H
INDB2L INDB2M INDB2H
INDB3L INDB3M INDB3H
IMMB1 IMMB2 IMMB3
DFB1 DFB2 DFB3);

!Within Level
[[mname#mod = reaff]]
LW = -0.541489;
MW = 0;
HW = 0.541489;
LB = 3.009768;
MB = 3.804944;
HB = 4.600119;
[[/mname#mod = reaff]]

[[mname#mod = remea]]
LW = -0.66347;
MW = 0;
HW = 0.66347;
LB = 2.809738;
MB = 3.611601;
HB = 4.413464;
[[/mname#mod = remea]]

[[mname#mod = remas]]
LW = -0.620487;
MW = 0;
HW = 0.620487;
LB = 1.686292;
MB = 2.551028;
HB = 3.415764;
[[/mname#mod = remas]]

[[mname#mod = recon]]
LW = -0.5381373;
MW = 0;
HW = 0.5381373;
LB = 3.19368;
MB = 3.895925;
HB = 4.598171;
[[/mname#mod = recon]]

[[mname#mod = redet]]
LW = -0.6385424;
MW = 0;
HW = 0.6385424;
LB = 2.951734;
MB = 3.788363;
HB = 4.624992;
[[/mname#mod = redet]]

[[mname#mod = rerel]]
LW = -0.621907;
MW = 0;
HW = 0.621907;
LB = 3.046488;
MB = 3.832232;
HB = 4.617976;
[[/mname#mod = rerel]]

!Simple slopes for each value of moderator at within level

SSLW = b1 + c2*LW;
SSMW = b1 + c2*MW;
SSHW = b1 + c2*HW;

!Indirect effects at within level

INDW1 = a1*b1;
INDW2 = a2*b1;
INDW3 = a3*b1;

!Conditional indirect effects at within level

INDW1L = a1*b1 + a1*c2*LW;
INDW1M = a1*b1 + a1*c2*MW;
INDW1H = a1*b1 + a1*c2*HW;

INDW2L = a2*b1 + a2*c2*LW;
INDW2M = a2*b1 + a2*c2*MW;
INDW2H = a2*b1 + a2*c2*HW;

INDW3L = a3*b1 + a3*c2*LW;
INDW3M = a3*b1 + a3*c2*MW;
INDW3H = a3*b1 + a3*c2*HW;

!IMM at within level

IMMW1 = a1*c2;
IMMW2 = a2*c2;
IMMW3 = a3*c2;

!Differences at within level

DFW1 = INDW1H - INDW1L;
DFW2 = INDW2H - INDW2L;
DFW3 = INDW3H - INDW3L;

!Between Level

!Simple slopes for each value of moderator at between level

SSLB = mb1 + mc2*LB;
SSMB = mb1 + mc2*MB;
SSHB = mb1 + mc2*HB;

!Indirect effects at between level

INDB1 = ma1*mb1;
INDB2 = ma2*mb1;
INDB3 = ma3*mb1;

!Conditional indirect effects at between level

INDB1L = ma1*mb1 + ma1*mc2*LB;
INDB1M = ma1*mb1 + ma1*mc2*MB;
INDB1H = ma1*mb1 + ma1*mc2*HB;

INDB2L = ma2*mb1 + ma2*mc2*LB;
INDB2M = ma2*mb1 + ma2*mc2*MB;
INDB2H = ma2*mb1 + ma2*mc2*HB;

INDB3L = ma3*mb1 + ma3*mc2*LB;
INDB3M = ma3*mb1 + ma3*mc2*MB;
INDB3H = ma3*mb1 + ma3*mc2*HB;

!IMM at between level

IMMB1 = ma1*mc2;
IMMB2 = ma2*mc2;
IMMB3 = ma3*mc2;

!Differences at between level

DFB1 = INDB1H - INDB1L;
DFB2 = INDB2H - INDB2L;
DFB3 = INDB3H - INDB3L;

OUTPUT:
SAMPSTAT STANDARDIZED CINTERVAL TECH1 TECH8;'

writeLines(template, "/Users/private/Desktop/model_template.txt")

createModels("/Users/private/Desktop/model_template.txt")

Bradley

unread,
Jun 23, 2024, 4:07:17 PM6/23/24
to MplusAutomation
As it always seems to happen, right after I post here I find a solution. I believe when I was writing earlier versions of this code I had syntax error which was causing xQuartz to not do anything. I assumed the issue was with xQuartz and deleted it. As soon as I reinstalled it (and my syntax was much better than earlier versions) the function worked as expected!
Reply all
Reply to author
Forward
0 new messages