Skip to content

Instantly share code, notes, and snippets.

View mja's full-sized avatar
💭
🙊

Mark James Adams mja

💭
🙊
View GitHub Profile
library(MCMCglmm)
library(mvtnorm)
# separate covariances for each sex
Rf <- matrix(c(1, .4, .4, 1), nrow=2)
Rm <- matrix(c(1, 0, 0, 1), nrow=2)
# Simulate correlated phenotypes
females <- data.frame(rmvnorm(100, mean=c(0, 0), sigma=Rf))
males <- data.frame(rmvnorm(100, mean=c(0, 0), sigma=Rm))
@mja
mja / world_bym2.R
Created May 6, 2014 09:32
Running the bym2 model in INLA
> n <- nrow(CC)
> Q <- INLA:::inla.pc.bym.Q(border, scale.model=TRUE)
> u <- .2/.31
> alpha <- .01
> phi.u <- .5
> phi.alpha <- 2/3
> formula2 <- agr ~ age + sex + age:sex +
+ f(geo, model='bym2', graph=border,
+ constr=TRUE, scale.model=TRUE,
+ hyper=list(phi=list(prior='pc',
@mja
mja / bivariate_2sample_power.R
Created October 9, 2014 10:49
Bivariate analysis (traits measured on different sets of individuals)
# GCTA-power analysis
# see http://spark.rstudio.com/ctgg/gctaPower/
# http://www.plosgenetics.org/article/info%3Adoi%2F10.1371%2Fjournal.pgen.1004269
# Bivariate analysis (traits measured on different sets of individuals)
bivariate_2sample_power <- function (N1=4000, N2=4000, rG=0.5, h2_1=0.2, h2_2=0.2, varA=0.00002, alpha=0.05) {
# variance of genetic correlation (Equation 10)
var_rG <-
@mja
mja / gatk
Created April 7, 2015 12:22
gatk command line script
#!/bin/sh
java -jar /path/to/GenomeAnalysisTK.jar $@
@mja
mja / zig.R
Last active August 29, 2015 14:19
Zero-inflated gaussian model in MCMCglmm
dat <- data.frame(obs=c(rep(0, times=100), rnorm(100, 10, 1)))
# observed data looks something like
hist(dat$obs)
# break into the zero-part and the normal part of the distribution
# observed zeros get zero for the first part, otherwise 1
# observed zeros get NA for the second part, otherwise observed value
dat <- transform(dat, zero_part=ifelse(obs == 0, yes=0, no=1),
norm_part=ifelse(obs != 0, yes=obs, no=NA))
@mja
mja / .bashrc
Created January 17, 2009 13:28 — forked from boosty/git_status.sh
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
#
# boosty likes it like that:
# ~/dev/dir[master]$ # clean working directory
# ~/dev/dir[master⚡]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
}
*** caught bus error ***
address 0x8, cause 'non-existent physical address'
Traceback:
1: .C("MCMCglmm", as.double(data$MCMC_y), as.double(data$MCMC_y.additional), as.double(data$MCMC_liab), as.integer(mvtype), as.integer(length(data$MCMC_y)), as.integer(X@i), as.integer(X@p), as.double(X@x), as.integer(X@Dim), as.integer(length(X@x)), as.integer(Z@i), as.integer(Z@p), as.double(Z@x), as.integer(Z@Dim), as.integer(length(Z@x)), as.integer(A@i), as.integer(A@p), as.double(A@x), as.integer(A@Dim), as.integer(length(A@x)), as.double(MSsd), as.integer(id - 1), as.integer(dam - 1), as.integer(sire - 1), as.integer(PedDim), as.integer(Aterm), as.integer(nfl), as.integer(nrl), as.integer(update), as.integer(split - 1), as.integer(c(nG, nR)), as.double(GRinv), as.double(GRvpP), as.double(GRnpP), as.integer(nitt), as.integer(thin), as.integer(burnin), as.integer(c(pr, pl)), as.double(Loc), as.double(Var), as.double(PLiab), as.integer(data$MCMC_family.names),
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
survey_id
1
@mja
mja / ezproxy.rb
Created March 29, 2010 16:27
EZproxy Service Workflow
require 'uri'
ARGV.first.split.each do |f|
article = URI.parse(f)
article.host = article.host + ".ezproxy.YOUR-INSTITUTION"
puts article.to_s
end
@mja
mja / ggplot options.R
Created May 24, 2010 13:04
Options for ggplot2
# Options for ggplot + opts(...)
# These don't seem to be documented on the web. Listed here for reference.
# list current setting
theme_get()
# Make a plot
g <- ggplot(...)
# Print the plot with options