sim_trait_env: Simulate a complex trait

View source: R/sim_trait_env.R

sim_trait_envR Documentation

Simulate a complex trait

Description

Mostly a wrapper around simtrait::sim_trait(), but can optionally add a structured environment effect. However, in that case the heritability is no longer as specified.

Usage

sim_trait_env(
  X,
  p_anc,
  m_causal,
  herit,
  env = NA,
  env_var = 1,
  k_subpops = NA,
  fes = FALSE,
  verbose = TRUE
)

Arguments

X

The genotype matrix.

p_anc

The vector of ancestral allele frequencies.

m_causal

The number of causal loci for the trait, selected randomly from among the simulated loci.

herit

The trait heritability.

env

A string describing environment model. Only NA (no environment) or "gcta" are accepted.

env_var

The variance of the environment effect. Ignored if env is NA.

k_subpops

The number of intermediate subpopulations for admixture model. Used for env = 'gcat' only.

fes

If FALSE (default) constructs trait from Random Coefficients (RC) model. If TRUE, the Fixed Effect Sizes (FES) model is used instead.

verbose

If TRUE reports progress, otherwise it is silent.

Value

A list containing the following elements:

  • trait: The simulated trait vector.

  • causal_indexes: The vector of randomly selected causal loci indexes.

  • causal_coeffs: The vector of simulated regression coefficients for causal loci.

Examples

# draw population parameters using `sim_pop` first
# a small example
k_subpops <- 3
data_pop <- sim_pop( n_ind = 50, G = 3, k_subpops = k_subpops )

# then draw genotypes
m_loci <- 100
data_geno <- sim_geno(
    data_pop$admix_proportions_1,
    data_pop$inbr_subpops,
    data_pop$fam,
    data_pop$ids
)

# now draw trait!
m_causal <- 5
herit <- 0.5
data_trait <- sim_trait_env(
    data_geno$X,
    data_geno$p_anc,
    m_causal,
    herit,
    env = 'gcat',
    k_subpops = k_subpops
)

# the simulated trait
data_trait$trait
# indexes of randomly-selected causal loci
data_trait$causal_indexes
# coefficients of causal loci
data_trait$causal_coeffs


OchoaLab/simgenphen documentation built on Feb. 10, 2023, 3:32 p.m.