QmatrixToBlatentSyntax {blatent} | R Documentation |
Convert a rectangular Q-matrix into blatent model syntax
Description
Converts a rectangular Q-matrix into blatent model syntax. Q-matrix must have observed variables listed across columns and latent variables listed across rows.
Usage
QmatrixToBlatentSyntax(
Qmatrix,
observedVariables = "rownames",
latentVariables = "colnames",
lvDist = "joint"
)
Arguments
Qmatrix |
A data frame or matrix containing a Q-matrix. |
observedVariables |
If |
latentVariables |
A vector of the variable or column names of the latent variables. Defaults to |
lvDist |
A character that indicates the type of latent variable distribution to be used. |
Value
A character vector containing blatent model syntax.
Examples
# Example 1: Joint distribution using data.frame
# empty data.frame
exampleQmatrixDF = data.frame(matrix(data = 0, nrow = 10, ncol = 3))
# name columns of Qmatrix
names(exampleQmatrixDF) = c("observedVariableName", "Attribute1", "Attribute2")
# names of observed variables
exampleQmatrixDF[1:10, "observedVariableName"] = paste0("Item",1:10)
# Entries for Qmatrix
exampleQmatrixDF[1:5,"Attribute1"] = 1
exampleQmatrixDF[3:10,"Attribute2"] = 1
# produce blatentSyntax using QmatrixToBlatentSyntax() function
blatentSyntaxJoint = QmatrixToBlatentSyntax(
Qmatrix = exampleQmatrixDF,
observedVariables = "observedVariableName",
latentVariables = c("Attribute1", "Attribute2"),
lvDist = "joint"
)
cat(blatentSyntaxJoint)
# Example 2: Univariate distributions using matrix
# empty data.frame
exampleQmatrixM = matrix(data = 0, nrow = 10, ncol = 2)
# name columns of Qmatrix as latent variable names
colnames(exampleQmatrixM) = c("Attribute1", "Attribute2")
# name rows of Qmatrix as observed variable names
rownames(exampleQmatrixM) = paste0("Item",1:10)
# Entries for Qmatrix
exampleQmatrixM[1:5,"Attribute1"] = 1
exampleQmatrixM[3:10,"Attribute2"] = 1
# produce blatentSyntax using QmatrixToBlatentSyntax() function
# (with default options for observedVariables and latentVariables)
blatentSyntaxM = QmatrixToBlatentSyntax(Qmatrix = exampleQmatrixM, lvDist = "univariate")
cat(blatentSyntaxM)