## Generate random data
set.seed(5)
ploidy <- 4
nloc <- 100
size <- 1000
r <- 0.25
alpha <- 1/12
qvec <- hwefreq(r = r, alpha = alpha, ploidy = ploidy)
nmat <- t(rmultinom(n = nloc, size = size, prob = qvec))
## Uncomment to run the analysis in parallel on the local
## computer with two workers
# future::plan(future::multisession, workers = 2)
hout <- hwefit(nmat = nmat, type = "ustat")
## Shut down parallel workers
future::plan(sequential)
## Show that p-values are uniform
## QQ-plot on -log10 scale
qqpvalue(pvals = hout$p_hwe, method = "base")
## Kolmogorov-Smirnov Test
stats::ks.test(hout$p_hwe, "qunif")
## Can control for Type I error
mean(hout$p_hwe < 0.05)
## Consistent estimate for alpha
alpha
mean(hout$alpha1)
Run the code above in your browser using DataLab