View source: R/long-grmtree-fscores.R
| fscores_longitudinal_grmtree | R Documentation |
Computes latent factor scores (theta) for both T1 and T2 within each terminal
node of a longitudinal GRM tree. Unlike the cross-sectional
fscores_grmtree which returns a single theta per person, this
function returns two scores per person: \theta_{T1} and
\theta_{T2}.
fscores_longitudinal_grmtree(object, method = "EAP", ...)
object |
A |
method |
Scoring method: "EAP" (default), "MAP", "ML", or "WLE". |
... |
Additional arguments (currently unused). |
A named list (one element per terminal node). Each element is a
data.frame with columns:
Estimated latent trait at Time 1
Estimated latent trait at Time 2
longitudinal_grmtree for fitting the tree,
generate_node_scores_dataset to generate node assignment and
factor scores
library(grmtree)
# Load the synthetic longitudinal data
data("grmtree_long_data", package = "grmtree")
# Prepare the wide-format response matrix
items_t1 <- c("MOS_Listen", "MOS_Info", "MOS_Advice_Crisis", "MOS_Confide",
"MOS_Advice_Want", "MOS_Fears", "MOS_Personal", "MOS_Understand")
ld <- prepare_longitudinal_data(
data = grmtree_long_data,
items_t1 = items_t1,
items_t2 = paste0(items_t1, "_year1"),
covariates = c("sex", "age", "residency", "job",
"education", "comorbidity_count", "ever_smoker")
)
# Phase 1: fit the longitudinal GRM tree
ltree <- longitudinal_grmtree(
resp_wide ~ sex + age + residency + job +
education + comorbidity_count + ever_smoker,
data = ld, n_items = 8,
control = grmtree.control(minbucket = 200)
)
# Print the factor scores
scores <- fscores_longitudinal_grmtree(ltree)
# Scores for node 2
head(scores[["2"]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.