## I ran this on W10 with CSOLNP Optimizer rm(list=ls()) doParallel::stopImplicitCluster() rep <- 200 library("OpenMx") library(doSNOW) mxOption(NULL,"Default optimizer","SLSQP") ## I changed optimizer per suggestion mxVersion() cat( toLatex(sessionInfo(), locale = FALSE) , file="rsessioninfoSLSQPW10.txt", sep = "\n" ) sim <- function(beta1=.14, beta2=.14, samp=100){ b1 <- beta1;b2 <- beta2; n <- samp s2x <- 1; s2m <- 1; s2y <- 1 manifests = c("x", "m", "y") popModel <- mxModel( name = "populationModel", type = "RAM", manifestVars = manifests, mxPath( from = 'one', to = manifests, free = TRUE, values = 0, labels = c("mu_x", "int_m", "int_y") ), mxPath( from = "x", to = "m", arrows = 1, free = TRUE, values = b1, labels = "b1" ), mxPath( from = "m", to = "y", arrows = 1, free = TRUE, values = b2, labels = "b2" ), mxPath( from = manifests, arrows = 2, free = TRUE, values = c(s2x, s2m, s2y), labels = c("s2x", "s2m", "s2y") ) ) popModel <- mxOption(popModel, "Standard Errors" , "No") ## Generating Data and Retrun the model that genberates Data sim_df <- mxGenerateData( model = popModel, nrows = n, returnModel = FALSE, use.miss = FALSE ) medModel <- mxModel(model = popModel, name = "Unconstrained Model", mxData(sim_df, type = "raw")) ## Constrained Model medModelconst <- mxModel( model = medModel, name = "constrained Model", mxAlgebra(b1 * b2, name = "ind"), mxConstraint(ind == 0, name = "ind0") ) medModelconstFit <- mxTryHard(medModelconst, extraTries = 5, checkHess = FALSE, paste = FALSE, verbose = 1) medModelFit <- mxRun(medModel) c( pop = omxGetParameters(popModel), uncosnt = omxGetParameters(medModelFit), const = omxGetParameters(medModelconstFit) ) } library(tcltk) #library(R.utils) set.seed(12387, "L'Ecuyer") mc <- parallel::detectCores() - 1 cl <- makeCluster(mc, type = "SOCK") registerDoSNOW(cl) pb <- txtProgressBar(max=100, style = 3) progress <- function(n) setTxtProgressBar(pb,n) opts <- list(progress=progress) it <- 1:rep resSim <- foreach( x = it, .combine = "rbind", .packages = c("OpenMx"), .inorder = FALSE , .options.snow=opts, .errorhandling = "pass" ) %dopar% sim() stopCluster(cl) doParallel::stopImplicitCluster() write.csv(resSim,"resultsSLSQPW10.csv")