% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ctModel.R
\name{ctModel}
\alias{ctModel}
\title{Define a ctsem model}
\usage{
ctModel(
  LAMBDA,
  type = "ct",
  n.manifest = "auto",
  n.latent = "auto",
  Tpoints = NULL,
  manifestNames = "auto",
  manifesttype = rep(0, nrow(LAMBDA)),
  latentNames = "auto",
  id = "id",
  time = "time",
  silent = FALSE,
  T0VAR = "auto",
  T0MEANS = "auto",
  MANIFESTMEANS = "auto",
  MANIFESTVAR = "diag",
  DRIFT = "auto",
  CINT = 0,
  DIFFUSION = "auto",
  n.TDpred = "auto",
  TDpredNames = "auto",
  TDPREDEFFECT = "auto",
  TDPREDMEANS = "auto",
  TDPREDVAR = "auto",
  n.TIpred = "auto",
  TIpredNames = "auto",
  tipredDefault = TRUE,
  PARS = NULL
)
}
\arguments{
\item{LAMBDA}{n.manifest*n.latent loading matrix relating latent to manifest variables, 
with latent processes 1:n.latent along the columns, and manifest variables
1:n.manifest in the rows.}

\item{type}{character string. Use 'ct' (continuous time) or 'dt'
(discrete time) for Stan-based fitting with \code{\link{ctFit}}.
These return a modern ctsem model object whose \code{pars} data frame can
also be edited through the pars-backed \code{matrices} view.
For legacy workflows, 'omx' returns a matrix-list model object that can
be edited directly and then converted via \code{\link{ctModelConvertOMX}}.}

\item{n.manifest}{Number of manifest indicators per individual at each measurement occasion / time point.
Manifest variables are included as the first element of the wide data matrix, with all the 1:n.manifest manifest variables 
at time 1 followed by those of time 2, and so on.}

\item{n.latent}{Number of latent processes.}

\item{Tpoints}{Number of time points, or measurement occasions, in the data.  This will generally be the maximum 
number of time points for a single individual, but may be one extra if sample relative time intervals are used, 
see \code{\link{ctIntervalise}}.}

\item{manifestNames}{n.manifest length vector of manifest variable names as they appear in the data structure, 
without any _Tx time point suffix that may be present in wide data.  Defaults to Y1, Y2, etc.}

\item{manifesttype}{n.manifest length vector of manifest variable types,defaults to 0 for continuous vars, 1 for binary vars is also possible.}

\item{latentNames}{n.latent length vector of latent variable names 
(used for naming parameters, defaults to eta1, eta2, etc).}

\item{id}{character string denoting column name containing subject identification variables. 
id data may be of any form, though will be coerced internally to an integer sequence rising from 1.}

\item{time}{character string denoting column name containing timing data. Timing data must be numeric.}

\item{silent}{Suppress all output to console.}

\item{T0VAR}{lower triangular n.latent*n.latent cholesky matrix of latent process initial variance / covariance. 
"auto" freely estimates all parameters.}

\item{T0MEANS}{n.latent*1 matrix of latent process means at first time point, T0. 
"auto" freely estimates all parameters.}

\item{MANIFESTMEANS}{n.manifest*1 matrix of manifest intercept parameters.
"auto" frees all parameters.}

\item{MANIFESTVAR}{lower triangular n.manifest*n.manifest cholesky matrix of variance / covariance 
between manifests at each measurement occasion (i.e. measurement error / residual).  
"auto" freely estimates variance parameters, 
and fixes covariances between manifests to 0. "free" frees all values, including covariances.}

\item{DRIFT}{n.latent*n.latent DRIFT matrix of continuous auto and cross effects, 
relating the processes over time. 
"auto" freely estimates all parameters.}

\item{CINT}{n.latent * 1 matrix of latent process intercepts, allowing for non 0 
asymptotic levels of the latent processes. Generally only necessary for additional trends and more complex dynamics.}

\item{DIFFUSION}{lower triangular n.latent*n.latent cholesky matrix of diffusion process 
variance and covariance (latent error / dynamic innovation).
"auto" freely estimates all parameters.}

\item{n.TDpred}{Number of time dependent predictor variables in the dataset.}

\item{TDpredNames}{n.TDpred length vector of time dependent predictor variable names, 
as they appear in the data structure, without any _Tx time point suffix that may appear in wide data.  
Default names are TD1, TD2, etc.}

\item{TDPREDEFFECT}{n.latent*n.TDpred matrix of effects from time dependent predictors to latent processes.
Effects from 1:n.TDpred columns TDpredictors go to 1:n.latent rows of latent processes.
"auto" freely estimates all parameters.}

\item{TDPREDMEANS}{Legacy argument for time-dependent predictor means, mainly to
support data generation workflows. Expected dimensions are
(n.TDpred * Tpoints) rows and 1 column. "auto" creates a free-label matrix.}

\item{TDPREDVAR}{Legacy argument for time-dependent predictor covariance
structure, mainly to support data generation workflows. Expected dimensions are
(n.TDpred * Tpoints) square. "auto" creates a free-label matrix.}

\item{n.TIpred}{Number of time independent predictors. 
Each TIpredictor is inserted at the right of the data matrix, after the time intervals.}

\item{TIpredNames}{n.TIpred length vector of time independent predictor variable names,
as they appear in the data structure.  Default names are TI1, TI2, etc.}

\item{tipredDefault}{Logical. TRUE sets any parameters with unspecified time independent 
predictor effects to have effects estimated, FALSE fixes the effect to zero unless individually specified.}

\item{PARS}{for types 'ct' and 'dt' only. May be of any structure, only needed to contain extra parameters for certain non-linear models.}
}
\description{
This function is used to specify a continuous time structural equation model, 
which can then be fit to data with function \code{\link{ctFit}}.
}
\examples{
 ### Frequentist example:
 ### impulse and level change time dependent predictor 
 ### example from Driver, Oud, Voelkle (2015)
 data('ctExample2')
 tdpredmodel <- ctModel(type='omx', n.manifest = 2, n.latent = 3, n.TDpred = 1, 
 Tpoints = 8, manifestNames = c('LeisureTime', 'Happiness'), 
 TDpredNames = 'MoneyInt', 
 latentNames = c('LeisureTime', 'Happiness', 'MoneyIntLatent'),
 LAMBDA = matrix(c(1,0, 0,1, 0,0), ncol = 3))

 tdpredmodel$DIFFUSION[, 3] <- 0
 tdpredmodel$DIFFUSION[3, ] <- 0
 tdpredmodel$T0VAR[3, ] <- 0
 tdpredmodel$T0VAR[, 3] <- 0
 tdpredmodel$CINT[3] <- 0
 tdpredmodel$T0MEANS[3] <- 0
 tdpredmodel$DRIFT[3, ] <- 0
 
 
###Bayesian example:
model<-ctModel(type='ct',
n.latent=2, latentNames=c('eta1','eta2'),
n.manifest=2, manifestNames=c('Y1','Y2'),
n.TDpred=1, TDpredNames='TD1', 
n.TIpred=3, TIpredNames=c('TI1','TI2','TI3'),
LAMBDA=diag(2))


}
