founderPop = quickHaplo(nInd=10, nChr=1, segSites=10)
SP = SimParam$new(founderPop)
SP$nThreads = 1L
trtMean = c(0, 0)
trtVarG = c(1, 2)
SP$addTraitA(nQtlPerChr = 10, mean = trtMean, var = trtVarG,
corA = matrix(data = c(1.0, 0.6,
0.6, 1.0), ncol = 2))
pop = newPop(founderPop)
trtVarE = c(1, 1)
trtVarP = trtVarG + trtVarE
pop = setPheno(pop, varE = trtVarE)
pheno(pop)
#Convert a single input trait
asCategorical(x = pheno(pop)[, 1])
#Demonstrate threshold argument (in units of pheno SD)
asCategorical(x = pheno(pop)[, 1], threshold = c(-1, 0, 1) * sqrt(trtVarP[1]))
asCategorical(x = pheno(pop)[, 1], threshold = c(-Inf, -1, 0, 1, Inf) * sqrt(trtVarP[1]))
asCategorical(x = pheno(pop)[, 1], threshold = c(-Inf, 0, Inf))
#Demonstrate p argument
asCategorical(x = pheno(pop)[, 1], p = 0.5, var = trtVarP[1])
asCategorical(x = pheno(pop)[, 1], p = c(0.5, 0.5), var = trtVarP[1])
asCategorical(x = pheno(pop)[, 1], p = c(0.25, 0.5, 0.25), var = trtVarP[1])
#Convert multiple input traits (via threshold or p argument)
try(asCategorical(x = pheno(pop)))
asCategorical(x = pheno(pop),
threshold = list(c(-Inf, 0, Inf),
NULL))
try(asCategorical(x = pheno(pop), p = c(0.5, 0.5)))
asCategorical(x = pheno(pop),
p = list(c(0.5, 0.5),
NULL),
mean = trtMean, var = trtVarP)
asCategorical(x = pheno(pop),
threshold = list(c(-Inf, 0, Inf),
c(-Inf, -2, -1, 0, 1, 2, Inf) * sqrt(trtVarP[2])))
q = c(-2, -1, 0, 1, 2)
p = pnorm(q)
p = c(p[1], p[2]-p[1], p[3]-p[2], p[4]-p[3], p[5]-p[4], 1-p[5])
asCategorical(x = pheno(pop),
p = list(c(0.5, 0.5),
p),
mean = trtMean, var = trtVarP)
Run the code above in your browser using DataLab