createRegModel: createRegModel

View source: R/createRegModel.R

createRegModelR Documentation

createRegModel

Description

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

Usage

createRegModel(model, model_type = "ctsem", fitfun = "FIML",
  data_type = "raw", pen_type = "lasso", pen_value = 0,
  pen_on = "none", selectedDrifts = "none", driftexpo = TRUE,
  DRIFT_dt = 1, selectedA = "none", selectedS = "none")

Arguments

model

mxModel or ctsem object

model_type

specify the type of model provided: ctsem or mxModel

fitfun

fitfunction to be used in the fitting procedure. Either FML or FIML

data_type

type of data in the model. Either "cov" or "raw"

pen_value

numeric value of penalty size

pen_on

string vector with matrices that should be regularized. Possible are combinations of "A", "S", "DRIFT"

selectedDrifts

drift values to regularize. Possible are "all", "cross", "auto" or providing a matrix of the same size as the drift matrix with ones for every parameter to regularize and 0 for every non-regularized parameter

driftexpo

specifiy if the regularization will be performed on the raw drift matrix or on the exponential of the drift matrix (discrete time parameters)

DRIFT_dt

provide the discrete time points for which the drift will be regularized. A vector with multiple values is possible

selectedA

A values to regularize. Possible are "all", or providing a matrix of the same size as the A matrix with ones for every parameter to regularize and 0 for every non-regularized parameter

selectedS

S values to regularize. Possible are "all", or providing a matrix of the same size as the S matrix with ones for every parameter to regularize and 0 for every non-regularized parameter

penalty_type

so far only "lasso" implemented

Author(s)

Jannik Orzek

Examples

# The following example is taken from the regsem help to demonstrate the equivalence of both methods:

library(lavaan)
library(OpenMx)
# put variables on same scale for regsem
HS <- data.frame(scale(HolzingerSwineford1939[,7:15]))

# define variables:
latent = c("f1")
manifest = c("x1","x2","x3","x4","x5", "x6", "x7", "x8", "x9")

# define paths:
loadings <- mxPath(from = latent, to = manifest, free = c(F,T,T,T,T,T,T,T,T), values = 1)
lcov <- mxPath(from = latent, arrows = 2, free = T, values = 1)
lmanif <- mxPath(from = manifest, arrows =2 , free =T, values = 1)

# define model:
myModel <- mxModel(name = "myModel", latentVars = latent, manifestVars = manifest, type = "RAM",
                   mxData(observed = HS, type = "raw"), loadings, lcov, lmanif,
                   mxPath(from = "one", to = manifest, free = T)
)

fit_myModel <- mxRun(myModel)
round(fit_myModel$A$values,5)

# create regularized model:

selectedA <- matrix(0, ncol = ncol(fit_myModel$A$values), nrow = nrow(fit_myModel$A$values))
selectedA[c(2,3,7,8,9),10] <-1


reg_model <- createRegModel(model = fit_myModel, model_type = "mxModel", fitfun = "FIML", data_type = "raw",
                            pen_on = "A", selectedA = selectedA, pen_value = .05
)
fit_reg_model <- mxRun(reg_model)

round(fit_reg_model$BaseModel$A$values,5)


jhorzek/laremm documentation built on Sept. 16, 2022, 12:06 p.m.