Skip to content

Instantly share code, notes, and snippets.

View tbates's full-sized avatar
🙈

Tim Bates tbates

🙈
View GitHub Profile
@tbates
tbates / table.md
Created June 2, 2013 23:16
Example table in markdown. how shall we highlight this in TM?

| | Grouping ||

First Header Second Header Third Header
Content Long Cell
Content Cell Cell

| New section | More | Data | | And more | And more || [ Table Caption ]

@tbates
tbates / umxRun.r
Last active December 19, 2015 15:28
ez run function. Let's modify this to compute the ind/saturated model?
# umxRun now detects raw RAM, and runs sat and ind. worth speeding this bit up a bit?
m3 <- mxModel("independence",
# TODO: slightly inefficient, as this has an analytic solution
mxMatrix(name = "variableLoadings" , type="Diag", nrow = nVar, ncol = nVar, free=T, values = independenceStarts),
# labels = loadingsLabels),
mxAlgebra(name = "expCov", expression = variableLoadings %*% t(variableLoadings)),
mxMatrix(name = "expMean", type = "Full", nrow = 1, ncol = nVar, values = dataMeans, free = T, labels = meansLabels),
mxFIMLObjective(covariance = "expCov", means = "expMean", dimnames = manifests),
mxData(theData, type = "raw")
)
@tbates
tbates / attraction_of_jupiter.r
Last active December 20, 2015 23:08
Does a midwife or Jupiter exert more gravitational pull on a baby at birth?
# Things you should learn in school: Be able to answer any question of the form:
# "Which has more gravitational pull on a baby as it is born: the midwife, or the planet Jupiter?"
# baby ~ 5 kg
# Distance and mass of [Jupiter](http://en.wikipedia.org/wiki/Jupiter)
gravitationalAttraction <- function(G = 6.674E-11, m1, m2, r){
# G = 6.674E-11 # [Gravitational constant](http://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation): N m^2 kg^-2
G * (m1 * m2)/r^2
}
# mixture distribution..
n = 100000;
distOne = rnorm(n, 50, 10)
distTwo = rnorm(n, 120, 15)
x = c(distOne,distTwo)
hist(x)
psych::kurtosi(x);psych::skew(x);
# DV <- sum of unobserved IVs
x = distOne + distTwo
@tbates
tbates / naplan.r
Last active December 27, 2015 11:09
Effect of guessing on reading
# Generate a 25-item test
nItems = 25
nOptions = 4
passCriterion = 3 # or better
correct_answers = sample(c(1:nOptions), nItems, replace = TRUE)
# ===================================
# = Generate 10000 random responses =
# ===================================
# http://openmx.psyc.virginia.edu/getOpenMx.R
# run this as
# source_gist(11294078)
if (.Platform$OS.type == "windows") {
if (!is.null(.Platform$r_arch) && .Platform$r_arch == "x64") {
repos <- c('http://openmx.psyc.virginia.edu/packages/')
} else {
repos <- c('http://openmx.psyc.virginia.edu/32bit/')
}
install.packages(pkgs = c('OpenMx'), repos = repos)
@tbates
tbates / getOpenMxBeta.R
Last active August 29, 2015 14:00
Beta download script
# http://openmx.psyc.virginia.edu/getOpenMxBeta.R
if(version$major < 3) {
stop("We don't have beta for R 2.15 or below. Consider upgrading to R 3.1?\n
You can get this from http://cran.r-project.org/")
}
if (.Platform$OS.type == "windows") {
if (!is.null(.Platform$r_arch) && .Platform$r_arch == "x64") {
repos <- c('http://openmx.psyc.virginia.edu/testing/')
} else {
@tbates
tbates / source_gist.r
Last active August 29, 2015 14:00
how to use source_gist to load a gist
message("load me with devtools::source_gist('11326436')")
@tbates
tbates / parallel play.r
Created May 19, 2014 12:59
Mucking around with parallel
# R version 3.0.3 (2014-03-06) -- "Warm Puppy"
source("http://openmx.psyc.virginia.edu/getOpenMxBeta.R")
library("OpenMx")
packageVersion("OpenMx") # [1] ‘999.0.0.3473’
data(demoOneFactor)
manifests <- names(demoOneFactor)
latents <- c("G")
model <- mxModel(model="One Factor", type="RAM",
@tbates
tbates / bad results.r
Last active August 29, 2015 14:02
Why is this independence model not getting the means and variance in the data?
library(OpenMx)
manifests = c("mpg", "disp", "gear")
# =============================
# = simple independence model =
# =============================
m1 <- mxModel("ind", type = "RAM",
manifestVars = manifests,
mxPath(from = manifests, arrows = 2),
mxPath(from = "one", to = manifests),