Skip to content

Instantly share code, notes, and snippets.

View tbates's full-sized avatar
🙈

Tim Bates tbates

🙈
View GitHub Profile
@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
@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 / 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
@tbates
tbates / mpg.r
Created November 23, 2015 22:38
plot miles per gallon on x axis, l/100km on the y
library(ggplot2)
library(scales)
gal_per_l = 0.219969
mi_per_km = 0.621371
l100km = seq(2, 13, by = .1)
l_per_km = l100km/100
l_per_mi = l_per_km/mi_per_km
gal_per_mi = l_per_mi * gal_per_l
mpg = 1/gal_per_mi
if (mxOption(NULL, "Default optimizer") == 'NLOPT') stop("SKIP")
library("devtools"); library("ggplot2");
# library("umx")
# library("umx.twin")
devtools::document("~/bin/umx"); devtools::install("~/bin/umx");
devtools::document("~/bin/umx.twin"); devtools::install("~/bin/umx.twin");
demand("formula.tools") # for residualizing inline
@tbates
tbates / The Difference Pool.md
Last active August 29, 2015 14:10
Thoughts about a subject pool at Edinburgh

The Difference Pool

  1. Subjects: Population sample
  • N must be over 500, preferably 2,000
  • Ideally genetically informative
  1. Recruitment
  • Students
  • Public advertisements
  1. Content: There will be a set of basic features that will be tested at the outset
  • Need to compromise on this. Perhaps 2-hours of testing in the first instance?
@tbates
tbates / merge errors.r
Created August 22, 2014 15:02
names are a hassle here
require(OpenMx)
data(demoOneFactor)
manifests <- names(demoOneFactor)
latents <- c("G")
m1 <- mxModel("One Factor", type="RAM",
manifestVars = manifests,
latentVars = latents,
mxPath(from=latents, to=manifests),
mxPath(from=manifests, arrows=2),
mxPath(from=latents, arrows=2,
@tbates
tbates / boundbug.r
Created June 27, 2014 14:12
lbound = hard value?
data(myFADataRaw, package = "OpenMx")
latents = c("G")
manifests = names(myFADataRaw)
myFADataRaw = myFADataRaw[, manifests]
m1 <- mxModel("m1", type="RAM", manifestVars = manifests, latentVars = latents,
mxPath(from = latents, to = manifests, values = 0),
mxPath(from = manifests, arrows = 2), # manifest residuals
mxPath(from = latents, arrows = 2, free = F, values = 1), # latents fixed@1
mxData(cov(myFADataRaw, use = "complete"), type = "cov", numObs = nrow(myFADataRaw))
)

Bun&Patty Burgers in Brioche buns: Serves 4

Source: Waitrose Kitchen Magazine, May 2014: Food & Sport Special (page 49) by Pippa Middleton

Ingredients

  1. Burger
    • 500g beef mince, 20% fat
    • 4 slices red leicester
    • Lettuce