## Example 1 ##
# true response pattern: dominant model c=(1, 1, -2)
set.seed(326584)
x <- c(
rlnorm(130, meanlog = 0.91, sdlog = 0.1),
rlnorm( 90, meanlog = 0.91, sdlog = 0.1),
rlnorm( 10, meanlog = 0.85, sdlog = 0.25)
)
g <- rep(1:3, c(130, 90, 10))
boxplot(
x ~ g,
width=c(length(g[g==1]),length(g[g==2]),
length(g[g==3])),
main="Dominant model (sample data)",
xlab="Genotype", ylab="PK parameter"
)
# coefficient matrix
# c_1: additive, c_2: recessive, c_3: dominant
contrast <- cbind(
c(-1, 0, 1), c(-2, 1, 1), c(-1, -1, 2)
)
y <- mmcm.resamp(x, g, contrast, 20000, 5784324)
y
## Example 2 ##
# for dataframe
# true response pattern: pos = 1 dominant model c=( 1, 1, -2)
# 2 additive model c=(-1, 0, 1)
# 3 recessive model c=( 2, -1, -1)
set.seed(8415849)
x <- c(
rlnorm(130, meanlog = 0.91, sdlog = 0.1),
rlnorm( 90, meanlog = 0.91, sdlog = 0.1),
rlnorm( 10, meanlog = 0.85, sdlog = 0.25),
rlnorm(130, meanlog = 0.79, sdlog = 0.1),
rlnorm( 90, meanlog = 0.85, sdlog = 0.1),
rlnorm( 10, meanlog = 0.91, sdlog = 0.25),
rlnorm(130, meanlog = 0.85, sdlog = 0.1),
rlnorm( 90, meanlog = 0.91, sdlog = 0.1),
rlnorm( 10, meanlog = 0.91, sdlog = 0.25)
)
g <- rep(rep(1:3, c(130, 90, 10)), 3)
pos <- rep(c("rsXXXX", "rsYYYY", "rsZZZZ"), each=230)
xx <- data.frame(pos = pos, x = x, g = g)
# coefficient matrix
# c_1: additive, c_2: recessive, c_3: dominant
contrast <- cbind(
c(-1, 0, 1), c(-2, 1, 1), c(-1, -1, 2)
)
mmcmtapply <- function(r) {
mmcm.resamp(
xx$x[xx$pos==r[1]], xx$g[xx$pos==r[1]],
contrast, 10000, 5784324+as.numeric(r[1])
)
}
y <- tapply(xx$pos, xx$pos, mmcmtapply)
yy <- data.frame(
Pos = as.vector(names(y)),
Pval = as.vector(sapply(y, "[[", 5)),
Pattern = as.vector(sapply(y, "[[", 6))
)
yy
Run the code above in your browser using DataLab