% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/generate_nodescores_dataset.R
\name{generate_node_scores_dataset}
\alias{generate_node_scores_dataset}
\title{Generate Dataset with Node Assignments and Factor Scores}
\usage{
generate_node_scores_dataset(object, data = NULL, method = "EAP")
}
\arguments{
\item{object}{A \code{grmtree} or \code{longitudinal_grmtree} object.}

\item{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).}

\item{method}{Scoring method: "EAP" (default), "MAP", "ML", or "WLE".}
}
\value{
A data.frame containing:
\describe{
\item{All original columns}{From \code{data} if provided}
\item{node}{Factor indicating terminal node membership}
\item{factor_score}{For cross-sectional grmtree: single latent score.
For longitudinal: Theta_T1.}
\item{Theta_T1}{(Longitudinal only) Latent trait at T1}
\item{Theta_T2}{(Longitudinal only) Latent trait at T2}
}
}
\description{
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.
}
\details{
The function works by:
\enumerate{
\item Predicting node membership for each observation using
\code{predict(object, type = "node")}
\item Computing factor scores within each terminal node using the
node-specific model
\item Merging the results back to the original data by row position
}

When \code{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.
}
\examples{
\dontshow{if (interactive()) withAutoprint(\{ # examplesIf}
# 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)
\dontshow{\}) # examplesIf}
}
\seealso{
\code{\link{grmtree}} fits a Graded Response Model Tree,
\code{\link{grmforest}} for GRM Forests, \code{\link{fscores_grmtree}} for
computing factor scores, \code{\link{threshpar_grmtree}} for extracting
threshold parameters, \code{\link{discrpar_grmtree}} for extracting
discrimination parameters, \code{\link{itempar_grmtree}} for extracting item
parameters, \code{\link{longitudinal_grmtree}} for longitudinal GRMTree,
\code{\link{fscores_longitudinal_grmtree}}, for computing factor scores for longitudinal GRMTree
}
