Skip to content

Instantly share code, notes, and snippets.

View certifiedwaif's full-sized avatar

Mark Greenaway certifiedwaif

  • University of Sydney
  • Sydney, Australia
View GitHub Profile
@certifiedwaif
certifiedwaif / gist:d75cdf5005764624da7c
Created June 7, 2015 11:19
Construct a histogram of a million random numbers
-- hw3.hs
module Main where
import System.Random
import Data.Vector.Unboxed hiding (forM_, take, unfoldr, map)
import Data.Vector.Unboxed.Mutable hiding (take)
import Data.List
import Control.Monad.ST (runST)
import Control.Monad (forM_)
import Prelude hiding (read)
@certifiedwaif
certifiedwaif / gist:d26bc4a77f7277becd71
Created May 21, 2015 05:38
optim looping endlessly
trace: f.GVA(vtheta_prime, vy, vr, mC, mSigma.inv, gh, mR, Rinds, Dinds)
f.VGA: f 25441.43 vmu 4.18073 0.31266 -0.77725 -1.0205 -0.96467 -0.75745 -0.26577 0.08923 0.63935 0.61445 0.60797 0.30834 -0.23776 -0.40567 diag(mR) 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448
trace: f.GVA(vtheta_prime, vy, vr, mC, mSigma.inv, gh, mR, Rinds, Dinds)
f.VGA: f 25441.43 vmu 4.18073 0.31266 -0.77725 -1.0205 -0.96467 -0.75745 -0.26577 0.08923 0.63935 0.61445 0.60797 0.30834 -0.23776 -0.40567 diag(mR) 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448
trace: f.GVA(vtheta_prime, vy, vr, mC, mSigma.inv, gh, mR, Rinds, Dinds)
f.VGA: f 25441.43 vmu 4.18073 0.31266 -0.77725 -1.0205 -0.96467 -0.75745 -0.26577 0.08923 0.63935 0.61445 0.60797 0.30834 -0.23776 -0.40567 diag(mR) 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448 0.04448
trace: f.GVA(vtheta
The command was find /mnt/Seagate_Expansion4_No2 -name \*sra\* -print0 | parallel --null ./sra_to_fastq.sh {}
The script sra_to_fastq.sh contains:
----
#!/bin/bash -x
outdir=/home/mark/data
echo $1
@certifiedwaif
certifiedwaif / cronbachs_alpha.R
Created November 21, 2012 04:04
R code to compute Cronbach's alpha, using the formula interface
cronbach_alpha = function(formula, data=NULL)
{
terms = terms(formula, data=data)
variables = attr(terms, "variables")
var_list = eval(variables, envir=data)
var_mat = t(laply(var_list, identity))
var_mat = var_mat[complete.cases(var_mat),]
response_idx = attr(terms, "response")
response = var_mat[,response_idx]
covariates = var_mat[,-response_idx]
@certifiedwaif
certifiedwaif / gist:3903829
Created October 17, 2012 05:23
Recode survey data to be consistent across multiple time points
# Recode and score variables ----
# Input: Long data set
# Output: Long data set, with fat, fibre and psychosocial score variables consistently
# coded at baseline, three months and twelve months.
# Explanation: Different people entered the baseline and follow-up survey data, and they
# didn't talk to each other. So the data for some questions got coded differently at
# different timepoints. This is very confusing, and means we can't meaningfully compare
# the data, so I'm writing this code to fix it up.
make_coding_consistent = function(data)
{
@certifiedwaif
certifiedwaif / gist:3857052
Created October 9, 2012 06:55
lattice panel function to display a segmented regression
# FIXME: There's a bug where if data in one of the groups is shorter than the others, spurious predictions
# from the segmented linear model will be repeated until the number of predictions is the same as the other
# data sequences.
panel.segmented_lm <- function(x, y, groups, subscripts, ...)
{
g = groups[subscripts]
for (group in levels(g)) {
x2 = x[g==group]
y2 = y[g==group]