trajeR: Fitting longitudinal mixture models

View source: R/main.R

trajeRR Documentation

Fitting longitudinal mixture models

Description

Fitting longitudinal mixture models

Usage

trajeR(
  Y,
  A = NULL,
  Risk = NULL,
  TCOV = NULL,
  data = NULL,
  ng = NULL,
  degre = NULL,
  degre.nu = 0,
  degre.phi = 0,
  Model,
  Method = "L",
  ssigma = FALSE,
  ymax = NULL,
  ymin = NULL,
  hessian = TRUE,
  itermax = 100,
  paraminit = NULL,
  ProbIRLS = TRUE,
  refgr = 1,
  fct = NULL,
  diffct = NULL,
  nbvar = NULL,
  ng.nl = NULL,
  nls.lmiter = 50,
  control = list()
)

Arguments

Y

Matrix, Formula, or a list of Formulas. A matrix containing the response variables, a single formula (e.g., Y ~ A + I(A^2)), or a list of formulas for models with different degrees.

A

Matrix. A matrix containing the time variable data. Can be omitted if specified in the RHS of the Y formula.

Risk

Matrix or Formula. An optional matrix (or one-sided formula like ~ X1 + X2) of covariates that modify the probability of belonging to a group.

TCOV

Matrix or Formula. An optional matrix (or one-sided formula) containing time-dependent covariates that influence the trajectories.

data

data.frame. An optional data frame containing the variables named in the formulas.

ng

Integer. The number of groups. Required if using a single formula or if 'degre' is not provided.

degre

Vector of integers. The degree of each polynomial function. The code adds 1 to these values internally.

degre.nu

Vector of integers. The degree of the polynomial for the zero-inflation part of a ZIP model.

degre.phi

Vector of integers. The degree of the polynomial for the precision parameter (phi) of a BETA model. The code adds 1 to these values internally.

Model

String. The model to be used. One of "LOGIT", "CNORM", "ZIP", "BETA", "POIS", or a non-linear model.

Method

String. The estimation method. "L" for Likelihood, "EM" for Expectation-Maximization.

ssigma

Logical. For the CNORM model, if TRUE, a single shared standard deviation (sigma) is estimated for all groups. Default is FALSE.

ymax

Real. For the CNORM model, the maximum value for censoring. Defaults to max(Y) + 1.

ymin

Real. For the CNORM model, the minimum value for censoring. Defaults to min(Y) - 1.

hessian

Logical. If TRUE, the Hessian matrix is computed. Default is TRUE.

itermax

Integer. The maximum number of iterations for the optimization algorithm (like 'optim' or the EM loop). Default is 100.

paraminit

Vector. The vector of initial parameters.

ProbIRLS

Logical. Indicates the method to use for searching predictor probabilities. Default is TRUE.

refgr

Integer. The reference group number. Default is 1.

fct

Function. The definition of the function f in the definition in nonlinear model.

diffct

Function. The differential of the function f in the nonlinear model.

nbvar

Integer. The number of variable in the nonlinear model.

ng.nl

Integer. The number of group for a non linear model.

nls.lmiter

Integer. In the case of non linear model, the maximum number of iterations allowed.

control

A list of control parameters for the 'ucminf' optimization algorithm.

  • 'trace': If positive, detailed tracing information is printed for each iteration.

  • 'grtol': The algorithm stops when the largest absolute value of the gradient is less than 'grtol'. Default is 1e-6.

  • 'xtol': The algorithm stops when the last relative step length is sufficiently small. Default is 1e-12.

  • 'stepmax': Initial maximal allowed step length (radius of trust-region). The value is updated during the optimization. Default is 1.

  • 'maxeval': The maximum number of function evaluations (objective and gradient). Default is 500.

  • ‘grad': Method for finite difference approximation of the gradient if not provided. Can be ’forward' (default) or 'central'.

  • 'gradstep': Vector of length 2 for the step length in finite difference approximation. Default is c(1e-6, 1e-8).

Value

Returns an object of a class corresponding to the chosen model (e.g., 'Trajectory.CNORM', 'Trajectory.LOGIT').

Returns an object of a class corresponding to the chosen model (e.g., 'Trajectory.CNORM', 'Trajectory.LOGIT'). This object, referred to as a 'Trajectory' object, contains the following elements:

  • 'beta': Vector of the final beta parameters for the trajectory shapes.

  • 'sigma': Vector of the final sigma parameters (standard deviations), for CNORM and NL models.

  • 'nu': Vector of final nu parameters for the zero-inflation part of a ZIP model.

  • 'phi': Vector of final phi parameters (precision) for a BETA model.

  • 'delta': Vector of the final delta parameters for time-dependent covariates (if any).

  • 'theta': Vector of the final theta parameters for group membership probabilities.

  • 'sd': Vector of the standard deviations of the estimated parameters.

  • 'tab': A data frame with parameter estimates, standard errors, T-values, and p-values.

  • 'Model': A string indicating the fitted model (e.g., "CNORM", "LOGIT").

  • 'groups': The number of groups.

  • 'Names': The names of the parameters.

  • 'Method': The estimation method used ("L" for Likelihood or "EM" for Expectation-Maximization).

  • 'Size': The number of individuals (observations).

  • 'Likelihood': The final log-likelihood value.

  • 'Time': The time points for the first individual, or min/max time for ZIP model.

  • ‘degre': A vector with the polynomial degrees for each group’s trajectory.

  • 'degre.nu': For ZIP models, a vector with the polynomial degrees for the zero-inflation part.

  • 'degre.phi': For BETA models, a vector with the polynomial degrees for the precision part.

  • 'min', 'max': For CNORM models, the censoring limits used.

  • 'fct': For NL models, the non-linear function provided.

  • 'varcov': The variance-covariance matrix of the parameters.

  • 'convergence': An integer code indicating the convergence status of the optimization algorithm. The meaning depends on the method used.

    • For 'Method = "L"' (using 'ucminf'):

    • '1': Stopped by small gradient ('grtol'). The current iterate is probably a solution.

    • '2': Stopped by small step ('xtol'). Successive iterates are within tolerance.

    • '3': Stopped by function evaluation limit ('maxeval').

    • '4': Stopped by zero step from line search. May be a solution.

    • '-2': Computation did not start: length of parameters is 0.

    • '-4': Computation did not start: 'stepmax' is too small.

    • '-5': Computation did not start: 'grtol' or 'xtol' is not positive.

    • '-6': Computation did not start: 'maxeval' is not positive.

    • '-7': Computation did not start: The provided Hessian was not positive definite.

    • For 'Method = "EM"':

    • '1': Indicates that the EM algorithm has completed its run (convergence is assessed by the user by checking the stability of parameters across iterations).


trajeR documentation built on Aug. 4, 2026, 1:09 a.m.