Skip to content

Instantly share code, notes, and snippets.

View tbates's full-sized avatar
🙈

Tim Bates tbates

🙈
View GitHub Profile
@tbates
tbates / HowToTeachOnline.md
Last active October 17, 2020 23:44
Resources and guides for online teaching
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"
}
@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

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 / non-identified EFA.R
Last active April 16, 2017 15:38
This is an EFA-style model, which is not identified.
library("umx")
con <- url("https://www.dropbox.com/s/r9e3om73viquzfq/disc.rda?raw=1")
print(load(con)); close(con)
manifests = c("q1", "q2", "q3", "q4", "q5", "q6", "q7")
latents <- c("F1", "F2") # 2 factors
m1 <- mxModel("twoFactors", type="RAM", manifestVars = manifests, latentVars = latents,
mxPath("F1", to = manifests),
mxPath("F2", to = manifests),
mxPath(latents, arrows = 2, free = FALSE, values = 1),
# ============================
# = How heritable is height? =
# ============================
require(umx)
data(twinData) # ?twinData from Australian twins.
# Pick the variables
selDVs = c("ht1", "ht2")
mzData <- twinData[twinData$zygosity %in% "MZFF", ]
dzData <- twinData[twinData$zygosity %in% "DZFF", ]

Haimovitz, K., & Dweck, C. S. (2016). What Predicts Children's Fixed and Growth Intelligence Mind-Sets? Not Their Parents' Views of Intelligence but Their Parents' Views of Failure. Psychological Science. doi:10.1177/0956797616639727

    
require(umx)
data = sem::readMoments(file = "", diag = TRUE)
1
.29	1
.29	-.06	1
.24	.17	-.07	1