-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulate-null.R
More file actions
40 lines (32 loc) · 1.19 KB
/
simulate-null.R
File metadata and controls
40 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
library(dplyr)
library(ggplot2)
library(broom)
library(mgcv)
library(pammtools)
mfrfile = snakemake@input[[1]] # "/mnt/HARVEST/ga_cleaned.csv"
outfile = snakemake@output[[1]] # "~/Documents/results/tv/null-pvals.RData"
## Run simulations to show that alpha is maintained under the null
## for the main pammtools model that we use
mfr_true = read.table(mfrfile, h=T, sep=";")
nrow(mfr_true) # 26908
mfr_true$GAc = mfr_true$SVLEN_DG - 169
mfr_true = mfr_true[,c("GAc", "hadevent")]
# simulate genotypes
MAF = 0.3
gt_sim = factor(rbinom(nrow(mfr_true), 2, MAF))
NITER = 400 # 1 h
pvals1 = pvals2 = rep(NA, NITER)
for(i in 1:NITER){
print(i)
# bootstrap the outcomes (to get a bit more varied distr than by permuting)
mfr_boot = sample_frac(mfr_true, 1, replace=T)
mfr_boot$GTcat = gt_sim
# run the model
ped = as_ped(mfr_boot, Surv(GAc, hadevent) ~ GTcat, id = "id", cut=c(0,seq(20, 130, by=7)))
mod = bam(ped_status ~ ti(tend,bs='cr',k=11) + GTcat + ti(tend, by=as.ordered(GTcat),bs='cr'),
data=ped, offset=offset, family=poisson())
ptable = tidy(mod)
pvals1[i] = ptable$p.value[2] # for GTcat=1
pvals2[i] = ptable$p.value[3] # for GTcat=2
}
save(pvals1, pvals2, file=outfile)