Skip to content

Instantly share code, notes, and snippets.

View tbates's full-sized avatar
🙈

Tim Bates tbates

🙈
View GitHub Profile
@tbates
tbates / OpenMx Agenda.md
Last active August 29, 2015 14:02
OpenMx Agenda (next = 6 June 2014)

6 June 2014

  1. OpenMx source tarballs are now up on our webserver (oops)
  2. Nobody took the bait to build IFA models with OpenMx (as far as I know)
  3. LISREL help
  • Should we have type = “LISREL”?
  • Implement plot() for lisrel
  • Example in Rd using raw data and means matrices
@tbates
tbates / power.PD303929.R01.r
Created June 3, 2014 20:23
power calcs for PD303929 R01 grant
library(pwr)
power.t.test(n = 300, delta = NULL, sd = 1, sig.level = 0.05, power = .8, type = "paired", alternative = "one.sided")
# Paired t test power calculation
#
# n = 300
# delta = 0.1438957
# sd = 1
# sig.level = 0.05
# power = 0.8
# alternative = one.sided
@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),
@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 / 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 / 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 {
# 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 / 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 =
# ===================================
# 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 / 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
}