Skip to content

Instantly share code, notes, and snippets.

View tbates's full-sized avatar
🙈

Tim Bates tbates

🙈
View GitHub Profile
@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 / 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 / factor.R
Last active December 15, 2015 08:09
How does factor analysis work? eigenvalues and eigenvectors
x <- data.frame(matrix(ncol = 2, byrow = T, c(
-0.7, 0.2,
2.1, 2.7,
1.7, 2.3,
1.4, 0.8,
1.9, 2.0,
1.8, 1.0,
0.4, -0.4,
1.1, 0.3,
0.9, 0.4,
# Above are some results from the a matrix of a
# trivariate cholesky with the above diag cells filled in
A = matrix(nrow = 3, byrow = T, c(.71, -.28, .15, -.28, .61, -.38, .15, -.38, .000001))
[,1] [,2] [,3]
[1,] 0.71 -0.28 1.5e-01
[2,] -0.28 0.61 -3.8e-01
[3,] 0.15 -0.38 1.0e-06
# Yeah... so that's wrong. that's the lower a matrix.
@tbates
tbates / age.R
Created November 20, 2012 13:11
persons = rnorm(100, 20,10)
nYearsToRun = 500
births = deaths = pop = rep(NA,nYearsToRun)
for (y in 1:nYearsToRun) {
populationSize = length(persons)
persons = persons+1 # age everybody
# death
persons <- persons[persons < rnorm(populationSize, 77, 15)]
if (identical(options[["Standard Errors"]], "Yes") &&
identical(options[["Calculate Hessian"]], "No")) {
msg <- paste('The "Standard Errors" option is enabled and',
'the "Calculate Hessian" option is disabled. Generating',
'standard errors requires the Hessian calculation. Please',
'disable standard errors or enable the Hessian calculation.\n',
'You can do this with\n',
'model <- mxOption(model, "Standard Errors", "No")\n',
'or\n',
'model <- mxOption(model, "Calculate Hessian", "Yes")'
setMethod("imxVerifyModel", "MxRAMModel",
function(model) {
if ((length(model$A) == 0) ||
(length(model$S) == 0) ||
(length(model$F) == 0)) {
msg <- paste("The RAM model", omxQuotes(model@name),
"does not contain any paths.",
" Are you just starting out? you need to add paths like",
umxSaturated <- function(m1, evaluate = T) {
# Use case
# m1_sat = umxSaturated(m1)
# summary(m1, SaturatedLikelihood=m1_sat$SaturatedLikelihood, IndependenceLikelihood=m1_sat$IndependenceLikelihood)
manifests = m1@manifestVars
nVar = length(manifests)
theData = m1@data@observed
dataMeans = colMeans(theData)
meansLabels = paste("mean", 1:nVar, sep="")
loadingsLabels = paste("F", 1:nVar, "loading", sep="")
@tbates
tbates / searchlink.rb
Created October 19, 2012 09:55 — forked from ttscoff/searchlink.rb
SearchLink creates Markdown links from automatic searches based on special syntax.
@tbates
tbates / p.R
Created October 14, 2012 20:54
distribution of p-values at high power
library(MASS)
library(ggplot2)
# move n around to alter sample size
# move r around to alter effect size
n = 1000; r = .5
desiredCovMatrix = matrix(c(1,r,r, 1) ,nrow=2, ncol=2);
count = 1000 # number of replications
out = rep(NA,count) # array to store the results
for (i in 1:count) {