Skip to content

Instantly share code, notes, and snippets.

# --- admixture analysis
# sample size
N = 5e3
# mate correlation
AM_cor = 0.75
# variance in ancestry transmission
genetic_sd = 0.025
# number of samples in each study
N = 2e3
# number of studies to run
seeds = 50
# vectors for storing results
est_a = rep(NA,seeds)
est_c = rep(NA,seeds)
est_e = rep(NA,seeds)
est_y1 = rep(NA,seeds)
set.seed(42)
# sample size
N = 10e3
# generate two groups
group = rbinom( N , 1 , 0.5 )
# generate group-specific environments
shared_env = rnorm(N,group*-15,1)
args = as.numeric(commandArgs(trailingOnly=TRUE))
# N,M,var_direct,var_indirect
# code for implementation of REML:
# https://github.com/sashagusev/SKK-REML-sim/blob/master/func_reml.R
source("reml_func.R")
# Num individuals
N = 1e3
@sashagusev
sashagusev / am_ld.R
Last active September 15, 2023 13:47
# Num individuals
N = 10e3
# Num markers
M = 10
# Assortative Mating
AM_cor = 0.75
# Minor allele frequency
maf = 0.5
# Heritability
set.seed(42)
# Num individuals
par( mfrow=c(1,4) )
# Num markers
M = 500
# Minor allele frequency
maf = 0.5
LABEL = TRUE
# Num individuals
N = 2e3
# Num markers
M = 1e3
# Affected cutoff
aff_thresh = 70
# Minor allele frequency
maf = 0.5
# simulate different parameter settings
@sashagusev
sashagusev / group_differences.R
Last active September 6, 2023 17:32
simple simulation of a phenotype in genetically distant populations
# reproducibility:
set.seed(42)
# number of causal variants:
M = 5e3
# number of individuals
N = 10e3
# heritability
hsq = 0.25
# sample individuals with admixture
get_correlated_trait = function(input,r) {
r * (input) + sqrt(1-r^2) * rnorm(length(input),0,1)
}
get_noisy_trait = function(input,noise) {
sqrt(1-noise) * (input) + sqrt(noise) * rnorm(length(input),0,1)
}
simulate_non_genetic = function(N,AM,ENV,err) {
set.seed(42)
N = 50000
get_correlated_trait = function(input,r) {
r * scale(input) + sqrt(1-r^2) * rnorm(length(input),0,1)
}
get_noisy_trait = function(input,noise) {
sqrt(1-noise) * scale(input) + sqrt(noise) * rnorm(length(input),0,1)
}
# good parameters from a 2-dof grid search