Skip to content

Instantly share code, notes, and snippets.

View mja's full-sized avatar
💭
🙊

Mark James Adams mja

💭
🙊
View GitHub Profile
@mja
mja / StableDiffusion-MPS.ipynb
Last active July 29, 2023 20:05
Jupyter notebook for installing and running StableDiffusion via 🧨diffusers on Apple Silicon
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mja
mja / stylegan3-on-colab.ipynb
Last active July 22, 2022 12:30
StyleGan3 on Colab.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mja
mja / read_grm_bin.R
Last active February 28, 2020 14:56
Read in a binary GRM from GCTA as square, symmetric matrix into R
## Read in a binary GRM from GCTA as a matrix
## see https://cnsgenomics.com/software/gcta/#MakingaGRM
library(Matrix)
read_grm_bin <- function(prefix, size=4) {
bin_filename <- paste(prefix, 'grm.bin', sep='.')
n_filename <- paste(prefix, 'grm.N.bin', sep='.')
id_filename <- paste(prefix, 'grm.id', sep='.')
@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 / gatk
Created April 7, 2015 12:22
gatk command line script
#!/bin/sh
java -jar /path/to/GenomeAnalysisTK.jar $@
@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 / 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',
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 / geoK
Last active December 24, 2015 13:39
Example of making a spatial kernel and using it as the inverse G matrix in a mixed-effects model with MCMCglmm.
# Spatial kernel for mixed-effects model
library(geosphere) # for distances between countries
library(ggplot2)
# Life-expectancy (le) and center coordinates
geo <- structure(list(ISO = structure(1:10, .Label = c("ALB", "BIH", "GRC", "HRV", "ITA", "MKD", "MLT", "MNE", "SRB", "TUN"), class = "factor"), Country = structure(c(1L, 2L, 4L, 3L, 5L, 6L, 7L, 8L, 9L, 10L), .Label = c("Albania", "Bosnia and Herzegovina", "Croatia", "Greece", "Italy", "Macedonia, FYR", "Malta", "Montenegro", "Serbia", "Tunisia"), class = "factor"), le = c(70.4, 70.7, 75.2, 70.5, 74.5, 69.6, 73.6, 74.1, 70.2, 64.1), longitude = c(20, 18, 22, 15.5, 12.8333, 22, 14.5833, 19, 21, 9), latitude = c(41, 44, 39, 45.1667, 42.8333, 41.8333, 35.8333, 42, 44, 34)), .Names = c("ISO", "Country", "le", "longitude", "latitude"), row.names = 1:10, class = "data.frame")
latlong <- geo[c('longitude', 'latitude')]
@mja
mja / gist:4705906
Created February 4, 2013 09:55
R packages enforce the permission culture
$ sudo R CMD INSTALL .
* installing to library ‘/usr/local/lib/R/library’
* installing *source* package ‘....’ ...
Error : Invalid DESCRIPTION file
Required fields missing:
License
See the information on DESCRIPTION files in section 'Creating R
packages' of the 'Writing R Extensions' manual.