Skip to content

Instantly share code, notes, and snippets.

View tbates's full-sized avatar
🙈

Tim Bates tbates

🙈
View GitHub Profile
@tbates
tbates / object.r
Created February 2, 2016 18:47
Effect of 1st vs 3rd person on objectivity and accuracy ratings
# ================================================================ #
# = Task: Write a 1-paragraph summary of your thesis experiment, #
# = first in 1st person active, then in 3rd person passive #
# ================================================================ #
# Rated objectivity of text
objectivity1stPerson = c(7, 6.5, 7.2, 6, 6);
objectivity3rdPerson = c(9, 8.5, 8.0, 8, 8)
t.test(one, two, paired= TRUE, alt= "less")
# Mean difference: -1.76 [-Inf -1.25] (t(4) = -7.3, p = <.001)
@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

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
# ============================
# = 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", ]
@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),
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 / 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
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

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
@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