Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/readModels.R
Copy link
Author

@jenniferdguay jenniferdguay May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we specify group labels (e.g., G1 and G2) in “GROUPING =“ of the model syntax, mplus knows how to label the levels in the grouping variable of the dataset (e.g., G1 refers to 1 and G2 refers to 2). The output does not print group levels in parenthesis (e.g., the (1) in Group G1 (1)) and the original code from mplusAutomation works.

So if we specify the model syntax with group labels (e.g., G1 and G2) in "GROUPING =", for instance:

alignment.mdl2 <- mplusObject(
  TITLE =     "Run alignment with oblimin rotation;",
  VARIABLE =  "USEVARIABLES = group x1-x10; GROUPING =  group(1 = G1 2 = G2);",
  MODEL= "F1-F2 BY x1-x10(*1);",
  ANALYSIS =  "ROTATION = OBLIMIN; alignment = fixed",
  OUTPUT = "align tech1;",
  rdata = simout$data
)

The original code can be used:

if (isTRUE(length(obs) %% 2 == 0)) {
            Observations <- as.numeric(obs[seq(2, to = length(obs), by = 2)])
            names(Observations) <- obs[seq(1, to = length(obs), by = 2)]
            attr(summaries, "Observations") <- Observations
          }

Whereas if we do not specify group labels in "Grouping =", but specify the number of levels in the group variable:

alignment.mdl <- mplusObject(
  TITLE =     "Run alignment with oblimin rotation;",
  VARIABLE =  "USEVARIABLES = group x1-x10; GROUPING =  group(2);",
  MODEL= "F1-F2 BY x1-x10(*1);",
  ANALYSIS =  "ROTATION = OBLIMIN; alignment = fixed",
  OUTPUT = "align tech1;",
  rdata = simout$data
)

Then the original code produces an error because it does not account for the group levels in parenthesis (e.g., (1) and (2) that have been printed next to G1 and G2 in the output). In this case, the proposed changes work:

if (isTRUE(length(obs) %% 2 == 0)) {
            Observations <- as.numeric(obs[seq(3, to = length(obs), by = 3)])
            names(Observations) <- obs[seq(1, to = length(obs), by = 3)]
            attr(allFiles[[listID]]$summaries, "Observations") <- Observations
          }

Thus, it could be good to check if group labels have been added in “Grouping =” argument, so that the original code can be used to parse the output, otherwise the proposed changes can be used.

Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ readModels <- function(target=getwd(), recursive=FALSE, filefilter, what="all",
obs <- gsub("Group", "", obs)
obs <- unlist(strsplit(trimws(obs), "\\s+"))
if (isTRUE(length(obs) %% 2 == 0)) {
Observations <- as.numeric(obs[seq(2, to = length(obs), by = 2)])
names(Observations) <- obs[seq(1, to = length(obs), by = 2)]
Observations <- as.numeric(obs[seq(3, to = length(obs), by = 3)])
names(Observations) <- obs[seq(1, to = length(obs), by = 3)]
attr(allFiles[[listID]]$summaries, "Observations") <- Observations
}
}
Expand Down