View source: R/regMultiGroup.R
regMultiGroup | R Documentation |
Note: regmx is based on the R package regsem. Because of the early status of regmx, it is recommended to use regsem instead! regMultiGroup a mutliple Group Model with a penalty on the difference in parameter estimates between the groups. Its is not tested and should not be used!
regMultiGroup( mxModelObjects, regOn, regType = "lasso", regIndicators, regValue = 0 )
mxModelObjects |
a list with mxModels for the different groups |
regOn |
string vector with matrices that should be regularized. The matrices must have the same name as the ones provided in the mxModelObjects (e.g., "A"). |
regType |
so far only "lasso" implemented |
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 |
regValue |
numeric value depicting the penalty size |
Jannik Orzek
# The following example is adapted from the OpenMx documentation library(OpenMx) # Simulate some data # Group 1 N1 = 100 x = rnorm(N1, mean= 0, sd= 1) y = 0.5*x + rnorm(N1, mean= 0, sd= 1) ds1 <- data.frame(x, y) dsNames <- names(ds1) # Group 2: higher regression weight N2= 1000 x= rnorm(N2, mean= 0, sd= 1) y= 0.6*x + rnorm(N2, mean= 0, sd= 1) ds2 <- data.frame(x, y) # Define the matrices (A matrix implementation of 2 RAM models) # I is identical for both groups: I <- mxMatrix(name="I", type="Iden", nrow=2, ncol=2) # means are identical for both groups: M <- mxMatrix(name = "M", type = "Full", nrow = 1, ncol = 2, values=0, free=TRUE, labels=c("Mean_x", "Mean_y")) # The A matrix can differ: A1 <- mxMatrix(name = "A", type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0), free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b1", NA, NA)) A2 <- mxMatrix(name = "A", type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0), free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b2", NA, NA)) # S is identical: S <- mxMatrix(name = "S", type = "Diag", nrow = 2, ncol = 2, values=1, free=TRUE, labels=c("Var_x", "Resid")) # Define the expectation expect <- mxExpectationRAM('A', 'S', 'I', 'M', dimnames= dsNames) # Choose a fit function fitFunction <- mxFitFunctionML(rowDiagnostics=TRUE) # Also return row likelihoods (the fit function value is still 1x1) # Multiple-group fit function sums the model likelihoods # from its component models mgFitFun <- mxFitFunctionMultigroup(c('g1model', 'g2model')) # Define model 1 and model 2 m1 = mxModel(model="g1model", M, S, A1, I, expect, fitFunction, mxData(cov(ds1), type="cov", numObs=N1, means=colMeans(ds1)) ) m2 = mxModel(model="g2model", M, S, A2, I, expect, fitFunction, mxData(cov(ds2), type="cov", numObs=N2, means=colMeans(ds2)) ) mg <- mxModel(model='multipleGroup', m1, m2, mgFitFun) # All paths except for b are constrained to equality # Fit the model and print a summary mg <- mxRun(mg) summary(mg) ############### Regularize A matrix: regIndicators <- list("A" = matrix(c(0,1,1,0), nrow = 2)) regValue <- 1 regOn <- "A" mxModelObjects <- list("model1" = m1, "model2" = m2) regModel <- regMultiGroup(mxModelObjects = mxModelObjects, regOn = regOn, regIndicators = regIndicators, regType = "lasso",regValue = regValue ) fit_regModel <- mxRun(regModel) summary(fit_regModel)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.