Skip to content

Instantly share code, notes, and snippets.

View tbates's full-sized avatar
🙈

Tim Bates tbates

🙈
View GitHub Profile
@tbates
tbates / Everything OpenMx can do, with commented examples.md
Last active April 19, 2021 09:48
Everything OpenMx can do, with commented examples, how-to guides, and tutorials

This is a page of example models. To learn about installing click here, to learn about path-based model syntax click here.

Three basic methods of modeling supported in OpenMx

  • Path analysis
  • RAM - LISREL
  • Matrix algebra

Confirmatory Factor Analysis

  • One factor models
  • Multiple factor models
@tbates
tbates / HowToTeachOnline.md
Last active October 17, 2020 23:44
Resources and guides for online teaching
@tbates
tbates / model_synonyms.md
Last active October 20, 2019 10:57
A list of synonyms for modelling

Models

  1. Structural Equation Model
  • RAM or LISREL model where the entries of A and S are numeric
  1. Extended SEM
  • Model in which the RAM equivalent of A and S entries may be arbitrary algebras.
  1. Definition variable
  • Any value in an SEM that is replaced with a person-specific value such that it is different for every row or person.
  1. Multilevel model
  • Relational SEM (by analogy to the way in which a relational database links values in different tables. How OpenMx implements mulit-level
  1. Item Response Theory
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"
}

List of Topics for OpenMx Workshop

  1. Re-Introduction to SEM
  • Calculation of Linear Combinations
  • Notions of Path Analysis
  1. Introduction to the OpenMx Package
  • Loading in the Package
  • Basic Functions in the Package
  • Optimizer choice
  1. Univariate and Bivariate Regression
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
@tbates
tbates / Makevars
Created September 25, 2017 14:52
Makevars to build OpenMx on MacOS
# 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),
@tbates
tbates / lavaan_version.R
Created October 2, 2012 15:09
SEM model in lavaan
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"
@tbates
tbates / simulate GxE power.R
Last active June 12, 2017 21:06
Code used to determine power for GxSES in Bates et al (2016) doi http://dx.doi.org/10.1016/j.intell.2016.02.003
# 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