This is a page of example models. To learn about installing click here, to learn about path-based model syntax click here.
- Path analysis
- RAM - LISREL
- Matrix algebra
- One factor models
- Multiple factor models
https://uoe.sharepoint.com/sites/PPLSLearningResources
Sections of this guide are:
create.vechsR <- function (A0, S0, F0 = NULL, Ax = NULL, Sx = NULL) { | |
if (is.matrix(A0)) { | |
A0 = as.mxMatrix(A0, name = "A0") | |
}else{ | |
A0@name = "A0" | |
} if (is.matrix(S0)) { | |
S0 = as.mxMatrix(S0, name = "S0") | |
}else{ | |
S0@name = "S0" | |
} |
These code snippets have been tested on R 3.1.0 and Mac OS 10.9.3. They presumably do *not* work on R 2.X! | |
## Enter these commands in the Mac OS Terminal | |
# use faster vecLib library | |
cd /Library/Frameworks/R.framework/Resources/lib | |
ln -sf /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib libRblas.dylib | |
# return to default settings | |
cd /Library/Frameworks/R.framework/Resources/lib |
# mate ~/.R/Makevars | |
# The following statements are required to use the clang4 binary | |
CC=/usr/local/clang4/bin/clang | |
CXX=/usr/local/clang4/bin/clang++ | |
CXX1X=/usr/local/clang4/bin/clang++ | |
CXX98=/usr/local/clang4/bin/clang++ | |
CXX11=/usr/local/clang4/bin/clang++ | |
CXX14=/usr/local/clang4/bin/clang++ | |
CXX17=/usr/local/clang4/bin/clang++ | |
LDFLAGS=-L/usr/local/clang4/lib |
data(demoOneFactor) | |
manifests <- names(demoOneFactor) | |
latents <- c("G1", "G2") | |
fit2 <- mxRun(mxModel("Two Factor", type="RAM", | |
manifestVars = manifests, latentVars = latents, | |
mxPath(from = latents[1], to=manifests[1:3]), | |
mxPath(from = latents[2], to=manifests[4:5]), | |
mxPath(from = manifests, arrows = 2), | |
mxPath(from = latents, arrows = 2, free = FALSE, values = 1.0), |
require(lavaan) | |
bifactor <- " | |
general.factor =~ Easy_Reservation + Preferred_Seats + Flight_Options + Ticket_Prices | |
+ Seat_Comfort + Seat_Roominess + Overhead_Storage | |
+ Clean_Aircraft + Courtesy + Friendliness + Helpfulness + Service | |
ticketing =~ Easy_Reservation + Preferred_Seats + Flight_Options + Ticket_Prices | |
aircraft =~ Seat_Comfort + Seat_Roominess + Overhead_Storage + Clean_Aircraft | |
service =~ Courtesy + Friendliness + Helpfulness + Service" | |
# Updated for umx 1.7+ 2017-06-12 04:28PM | |
# Notes: If you're on Mac or Unix, install the parallelOpenMx to get parallel (4x speedup or more) | |
# source('http://openmx.psyc.virginia.edu/getOpenMx.R') | |
library(umx) | |
umx_set_optimizer("NPSOL") # good optimizer for these data | |
umx_set_cores(detectCores()) # Max cores for speed | |
nSimulations = 1000 # Number of simulations | |
nMZpairs = nDZpairs = 500 # Number of twin pairs | |
pvalues = rep(NA, nSimulations) # placeholder for the p-values from mxCompare-ing the 2 models you are testing |