This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(42) | |
# Num individuals | |
par( mfrow=c(1,4) ) | |
# Num markers | |
M = 500 | |
# Minor allele frequency | |
maf = 0.5 | |
LABEL = TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Num individuals | |
N = 2e3 | |
# Num markers | |
M = 1e3 | |
# Affected cutoff | |
aff_thresh = 70 | |
# Minor allele frequency | |
maf = 0.5 | |
# simulate different parameter settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reproducibility: | |
set.seed(42) | |
# number of causal variants: | |
M = 5e3 | |
# number of individuals | |
N = 10e3 | |
# heritability | |
hsq = 0.25 | |
# sample individuals with admixture |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("RColorBrewer") | |
# function for generating twis | |
make_all_twins = function(N,rge,rgc,h2g,h2c,h2e,h2gxe=0,h2gxc=0,pop_strat=0,env_strat=0){ | |
# --- generate MZs | |
# generate MZ twins | |
gv_MZ1 = scale(rnorm(N)) | |
gv_MZ2 = scale(gv_MZ1) | |
# generate rGE | |
ev_MZ1 = scale(rge * gv_MZ1 + sqrt(1 - rge^2) * scale(rnorm(N))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("RColorBrewer") | |
clr = brewer.pal(3,"Set1") | |
# unrelated samples | |
N = 50000 | |
# heritability parameter | |
h2g = 0.4 | |
# shared environment parameter | |
h2c = 0.4 | |
# environment parameter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("survival") | |
library("cmprsk") | |
library("RColorBrewer") | |
set.seed(66) | |
# Standard function for simulating survival with a Weibull baseline hazard | |
# https://stats.stackexchange.com/questions/135124/how-to-create-a-toy-survival-time-to-event-data-with-right-censoring | |
# baseline hazard: Weibull |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("survival") | |
library("cmprsk") | |
library("reshape2") | |
library("ggplot2") | |
library("RColorBrewer") | |
# Standard function for simulating survival with a Weibull baseline hazard | |
# https://stats.stackexchange.com/questions/135124/how-to-create-a-toy-survival-time-to-event-data-with-right-censoring | |
# baseline hazard: Weibull |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("NMF") | |
library("ggplot2") | |
library("reshape2") | |
N_cells = 500 | |
N_genes = 100 | |
N_cells_program = 20 | |
N_genes_program = 20 |