View source: R/generate_nodescores_dataset.R
| generate_node_scores_dataset | R Documentation |
Creates a dataset by augmenting the original data with node assignments and computed factor scores. Unlike the previous version which only returned model frame variables, this version merges node and score information back to the full original data frame.
generate_node_scores_dataset(object, data = NULL, method = "EAP")
object |
A |
data |
The original data frame used to fit the tree. If provided, the output contains all columns from this data frame plus node and factor score columns. If NULL (default), returns only model frame variables (backward-compatible behavior). |
method |
Scoring method: "EAP" (default), "MAP", "ML", or "WLE". |
The function works by:
Predicting node membership for each observation using
predict(object, type = "node")
Computing factor scores within each terminal node using the node-specific model
Merging the results back to the original data by row position
When data is provided, the function ensures that the output
contains all columns from the original data frame, not just the
variables used in the model formula. This is important when the
original data contains clinical variables, identifiers, or other
columns not used as partitioning variables.
A data.frame containing:
From data if provided
Factor indicating terminal node membership
For cross-sectional grmtree: single latent score. For longitudinal: Theta_T1.
(Longitudinal only) Latent trait at T1
(Longitudinal only) Latent trait at T2
grmtree fits a Graded Response Model Tree,
grmforest for GRM Forests, fscores_grmtree for
computing factor scores, threshpar_grmtree for extracting
threshold parameters, discrpar_grmtree for extracting
discrimination parameters, itempar_grmtree for extracting item
parameters, longitudinal_grmtree for longitudinal GRMTree,
fscores_longitudinal_grmtree, for computing factor scores for longitudinal GRMTree
# Cross-sectional GRMTree
library(grmtree)
library(hlt)
data("asti", package = "hlt")
asti$resp <- data.matrix(asti[, 1:4])
# Fit GRM tree with gender and group as partitioning variables
tree <- grmtree(resp ~ gender + group,
data = asti,
control = grmtree.control(minbucket = 30))
# Generate combined dataset
scored_data <- generate_node_scores_dataset(tree, data = asti)
# Plot scores by node
boxplot(factor_score ~ node, data = scored_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.