Skip to content

[Feature] make it easier to simulate multiple famlies at once #149

Description

@smasongarrison

make it easier to simulate multiple famlies at once, right now the solution is # True variance components
true_var <- list(
ad2 = 0.70, cn2 = 0.00, ee2 = 0.20,
ce2 = 0, mt2 = 0.10, dd2 = 0, am2 = 0
)

n_families <- 15
start_vars <- list(
ad2 = 0.3, # additive genetic
cn2 = 0.1, # common nuclear environment
ce2 = 0, # common extended (not estimated here)
mt2 = 0.1, # mitochondrial
dd2 = 0, # dominance (not estimated here)
am2 = 0, # A x Mt interaction (not estimated here)
ee2 = 0.5 # unique environment
)

Pre-allocate storage

add_list <- vector("list", n_families)
cn_list <- vector("list", n_families)
mt_list <- vector("list", n_families)
obs_ids_list <- vector("list", n_families)
pheno_list <- vector("list", n_families)
ped_list <- vector("list", n_families)
for (i in seq_len(n_families)) {
ped_i <- simulatePedigree(kpc = 3, Ngen = 6, marR = 0.6)

A_i <- as.matrix(ped2add(ped_i, sparse = FALSE))
Cn_i <- as.matrix(ped2cn(ped_i, sparse = FALSE))
Mt_i <- as.matrix(ped2mit(ped_i, sparse = FALSE))
n_i <- nrow(A_i)

Implied covariance from true parameters

V_i <- true_var$ad2 * A_i +
true_var$cn2 * Cn_i +
true_var$mt2 * Mt_i +
true_var$ee2 * diag(1, n_i)

y_i <- rmvnorm(1, sigma = V_i)
y_binary_i <- ifelse(y_i > 0, 1, 0)

ped_i$y <- y_i
ped_i$y_binary <- y_binary_i

ids_i <- make.names(rownames(A_i))
rownames(A_i) <- colnames(A_i) <- ids_i
rownames(Cn_i) <- colnames(Cn_i) <- ids_i
rownames(Mt_i) <- colnames(Mt_i) <- ids_i

add_list[[i]] <- A_i
cn_list[[i]] <- Cn_i
mt_list[[i]] <- Mt_i
obs_ids_list[[i]] <- ids_i
pheno_list[[i]] <- matrix(y_binary_i, nrow = 1, dimnames = list(NULL, ids_i))
ped_list[[i]] <- ped_i

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions