Skip to content

Commit

Permalink
make_mplus_gpcm_model_syntax() does not fail on items being a simple …
Browse files Browse the repository at this point in the history
…character vector.
  • Loading branch information
tzoltak committed Feb 9, 2023
1 parent 032f09c commit 6d81506
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Bug fixes

- `make_mplus_irtree_model_syntax()` works with `items` provided as a simple character vector.
- `make_mplus_irtree_model_syntax()` and `make_mplus_gpcm_model_syntax()` works with `items` provided as a simple character vector.

# rstyles 0.7.0 (9.02.2023)

Expand Down
22 changes: 15 additions & 7 deletions R/resp_styles_to_mplus.R
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ make_mplus_gpcm_model_syntax <- function(data, items, scoringMatrix,
reverseCoded = reverseCoded,
orthogonal = orthogonal,
weight = weight,
itemCategories = itemCategories)
itemCategories = itemCategories,
trySimpleGPCM = !any(grepl("STD",
output)))
if (is.na(weight)) weight = vector(mode = "character", length = 0L)
data <- data[, c(unique(unlist(items)), observedExogenous,
observedDependent, weight), drop = FALSE]
Expand Down Expand Up @@ -389,6 +391,9 @@ make_mplus_gpcm_model_syntax <- function(data, items, scoringMatrix,
#' @description Prepares components of Mplus model description syntax.
#' @inheritParams make_mplus_irtree_vmmc_syntax
#' @param itemCategories a list of values that a given item takes in the data
#' @param trySimpleGPCM a logical value indicating whether to try to use
#' a simple Mplus GPCM specification instead of the NRM when
#' \code{scoringMatrix} has only one column
#' @details Models are identified by fixing variances of the the latent
#' variables \strong{that are not mentioned in \code{fixSlopes}} to 1 and
#' by fixing \emph{slope} parameters to 1 (or -1 in a case of reverse coded
Expand Down Expand Up @@ -417,18 +422,21 @@ make_mplus_gpcm_vmmc_syntax <- function(items, scoringMatrix,
orthogonal = vector(mode = "character", length = 0L),
weight = NA_character_,
itemCategories = rep(list(rownames(scoringMatrix)),
length(items))) {
length(items)),
trySimpleGPCM = TRUE) {
stopifnot(is.character(items) | is.list(items),
is.matrix(scoringMatrix), is.numeric(scoringMatrix),
is.character(weight), length(weight) == 1L)
is.character(weight), length(weight) == 1L,
is.logical(trySimpleGPCM), length(trySimpleGPCM) == 1L,
trySimpleGPCM %in% c(TRUE, FALSE))
if (is.character(items)) {
stopifnot(!anyNA(items), length(items) > 0L,
all(!duplicated(items)))
latentTraits <- colnames(scoringMatrix)
names(latentTraits) <- latentTraits
items <- rep(list(items), ncol(scoringMatrix))
items <- mapply(setNames, items, colnames(scoringMatrix), SIMPLIFY = FALSE)
names(items) <- colnames(scoringMatrix)
items <- setNames(rep(list(list(items)), ncol(scoringMatrix)),
colnames(scoringMatrix))
items <- mapply(setNames, items, names(items), SIMPLIFY = FALSE)
} else { # a list
stopifnot(all(names(items) %in% colnames(scoringMatrix)),
all(colnames(scoringMatrix) %in% names(items)),
Expand Down Expand Up @@ -464,7 +472,7 @@ make_mplus_gpcm_vmmc_syntax <- function(items, scoringMatrix,
model <- constraints <- vector(mode = "character", length = 0L)

# simple GPCM specification
if (ncol(scoringMatrix) == 1L &
if (ncol(scoringMatrix) == 1L & trySimpleGPCM &
all(sapply(itemCategories, nrow) == nrow(scoringMatrix))) {
variable <- paste0("CATEGORICAL = ",
paste(unique(unlist(items)), collapse = " "), " (gpcm);")
Expand Down
2 changes: 1 addition & 1 deletion man/make_mplus_gpcm_model_syntax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/make_mplus_gpcm_vmmc_syntax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/make_mplus_irtree_model_syntax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/make_mplus_irtree_vmmc_syntax.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6d81506

Please sign in to comment.