% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/long-grmtree-fscores.R
\name{fscores_longitudinal_grmtree}
\alias{fscores_longitudinal_grmtree}
\title{Compute Latent Factor Scores for Longitudinal GRM Tree}
\usage{
fscores_longitudinal_grmtree(object, method = "EAP", ...)
}
\arguments{
\item{object}{A \code{longitudinal_grmtree} object.}

\item{method}{Scoring method: "EAP" (default), "MAP", "ML", or "WLE".}

\item{...}{Additional arguments (currently unused).}
}
\value{
A named list (one element per terminal node). Each element is a
\code{data.frame} with columns:
\describe{
\item{Theta_T1}{Estimated latent trait at Time 1}
\item{Theta_T2}{Estimated latent trait at Time 2}
}
}
\description{
Computes latent factor scores (theta) for both T1 and T2 within each terminal
node of a longitudinal GRM tree. Unlike the cross-sectional
\code{\link{fscores_grmtree}} which returns a single theta per person, this
function returns two scores per person: \eqn{\theta_{T1}} and
\eqn{\theta_{T2}}.
}
\examples{
\dontshow{if (interactive()) withAutoprint(\{ # examplesIf}
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"]])
\dontshow{\}) # examplesIf}
}
\seealso{
\code{\link{longitudinal_grmtree}} for fitting the tree,
\code{\link{generate_node_scores_dataset}} to generate node assignment and
factor scores
}
