calc_m2: Calculate the M2

View source: R/m2.R

calc_m2R Documentation

Calculate the M2

Description

Calculate the M2

Usage

calc_m2(
  data,
  struc_params,
  pi_matrix,
  qmatrix,
  ci = 0.9,
  link = "logit",
  model_type = c("LCDM", "GDINA", "ACDM", "LLM", "RRUM", "DINO", "DINA", "BUGDINO")
)

Arguments

data

A data frame containing the raw data, where there is one row per respondent and one column per item

struc_params

A vector containing the structural parameters of the estimated model

pi_matrix

An item-by-class matrix containing the probability of a correct response by members of each latent class

qmatrix

A data frame containing the Q-matrix

ci

The confidence interval for the RMSEA, computed from the M2

link

A character containing the link function.

model_type

A character containing the model type (e.g., LCDM) that was estimated.

Value

A data frame containing:

  • m2: The M2 statistic

  • df: Degrees of freedom for the M2 statistic

  • pval: p-value for the M2 statistic

  • rmsea: Root mean square error of approximation

  • ci_lower: Lower end of ci interval for RMSEA

  • ci_upper: Upper end of ci interval for RMSEA

  • srmsr: Standardized root mean square residual

Examples

possible_prof <- dcm2::as_binary(ncol(sample_data$q_matrix))

fit_dat <- sample_data$data %>%
             tidyr::pivot_wider(names_from = "item_id",
                                values_from = "score") %>%
             dplyr::select(-"resp_id") %>%
             as.matrix() %>%
             unname()
gdina_mod <- GDINA::GDINA(dat = fit_dat,
                          Q = data.frame(sample_data$q_matrix),
                          model = "logitGDINA",
                          control = list(conv.type = "neg2LL"))
struc_params <- gdina_mod$struc.parm
pi_matrix <- gdina_mod$LC.prob %>%
               as.matrix() %>%
               unname()
calc_m2(data = fit_dat, struc_params, pi_matrix,
        qmatrix = data.frame(sample_data$q_matrix), ci = 0.9, link = "logit",
        model_type = "LCDM")


dcm2 documentation built on April 1, 2023, 12:14 a.m.