regCtModel: regCtModel

View source: R/regCtModel.R

regCtModelR Documentation

regCtModel

Description

Note: regmx is based on the R package regsem. Because of the early status of regmx, it is recommended to use regsem instead! regModel creates a regularized model from a ctsem.

Usage

regCtModel(
  ctsemModelObject,
  alpha = 1,
  gamma = 0,
  regOn,
  regIndicators,
  regValues = 0,
  link,
  dt = NULL,
  scaleFactors = NULL
)

Arguments

ctsemModelObject

an already run ctsem object

alpha

alpha controls the type of penalty. For lasso regularization, set alpha = 1, for ridge alpha = 0. Values between 0 and 1 implement elastic net regularization

gamma

gamma sets the power in the denominator of parameter specific weights when using adaptive lasso regularization. Make sure to set alpha to 1 when using a gamma other than 0.

regOn

string vector with matrices that should be regularized. The matrices must have the same name as the ones provided in the mxModelObject (e.g., "A")

regIndicators

list of matrices indicating which parameters to regularize in the matrices provided in regOn. The matrices in regIndicators must to have the same names as the matrices they correspond to (e.g., regIndicators = list("A" = diag(10))). 1 Indicates a parameter that will be regularized, 0 an unregularized parameter

regValues

numeric value depicting the penalty size

link

list with functions that will be applied to the regularized matrices. For example, if the discrete time autoregressive and cross-lagged parameters should be regularized, use list("DRIFT" = "expm"). If link = "ident" is provided, the ct parameters will be regularized directly.

dt

list with vectors depicting the time points for which the discrete time parameters should be regularized (e.g., list("DRIFT" = c(1)))

Author(s)

Jannik Orzek

Examples

library(ctsem)

set.seed(175446)

## define the population model:

# set the drift matrix. Note that drift eta_1_eta2 is set to equal 0 in the population.
ct_drift <- matrix(c(-.3,.2,0,-.5), ncol = 2)

generatingModel<-ctModel(Tpoints=10,n.latent=2,n.TDpred=0,n.TIpred=0,n.manifest=2,
                         MANIFESTVAR=diag(0,2),
                         LAMBDA=diag(1,2),
                         DRIFT=ct_drift,
                         DIFFUSION=matrix(c(.5,0,0,.5),2),
                         CINT=matrix(c(0,0),nrow=2),
                         T0MEANS=matrix(0,ncol=1,nrow=2),
                         T0VAR=diag(1,2))

# simulate a training data set
traindata <- ctGenerate(generatingModel,n.subjects = 100)

## Build the analysis model. Note that drift eta1_eta2 is freely estimated
# although it is 0 in the population.

myModel <- ctModel(Tpoints=10,n.latent=2,n.TDpred=0,n.TIpred=0,n.manifest=2,
                   LAMBDA=diag(1,2),
                   MANIFESTVAR=diag(0,2),
                   CINT=matrix(c(0,0),nrow=2),
                   DIFFUSION=matrix(c('eta1_eta1',0,0,'eta2_eta2'),2),
                   T0MEANS=matrix(0,ncol=1,nrow=2),
                   T0VAR=diag(1,2))

# fit the model using ctsem:
fit_myModel <- ctFit(traindata, myModel)
# discrete time parameters for deltaT = 1
expm(fit_myModel$mxobj$DRIFT$values)

# select DRIFT values:
regOn = "DRIFT"
regIndicators = list("DRIFT" = matrix(c(0,1,1,0), byrow = T, ncol = 2))

# regularize discrete time parameters for deltaT = 1
link = list("DRIFT" = "expm")
dt = list("DRIFT"= 1)

# set regValues
regValues = .2

# build regularized model
myRegCtModel <- regCtModel(ctsemModelObject = fit_myModel, alpha = 1, gamma = 0, regOn = regOn, regIndicators = regIndicators, regValues = regValues, link = link, dt = dt)
fit_myRegCtModel <- mxRun(myRegCtModel)
# extract DRIFT parameters for deltaT = 1
expm(fit_myRegCtModel$Submodel$DRIFT$values)

jhorzek/regmx documentation built on Sept. 19, 2022, 2:30 a.m.