This function simulates a quantitative trait based on additive and epistatic genetic effects using genotype data from a PLINK dataset. The simulated trait is saved to a specified output file in a phenotype format compatible with PLINK.
Usage
simulate_traits(
plink_file,
output_file,
additive_heritability,
gxg_heritability,
additive_indices,
gxg_indices_1,
gxg_indices_2,
log_level = "WARNING"
)
Arguments
- plink_file
Character. Path to the PLINK dataset (without file extension). The function will append
.bed
,.bim
, and.fam
extensions as needed.- output_file
Character. Path to the output file where the simulated trait will be saved.
- additive_heritability
Numeric. A value between 0 and 1 specifying the proportion of trait variance due to additive genetic effects.
- gxg_heritability
Numeric. A value between 0 and 1 specifying the proportion of trait variance due to gene-by-gene (epistatic) interactions. The sum of
additive_heritability
andgxg_heritability
must not exceed 1.- additive_indices
Integer vector. Indices of SNPs contributing to additive genetic effects.
- gxg_indices_1
Integer vector. Indices of SNPs in the first group for epistatic interactions.
- gxg_indices_2
Integer vector. Indices of SNPs in the second group for epistatic interactions.
- log_level
Character. Logging level for messages (e.g., "DEBUG", "INFO", "WARNING"). Default is "WARNING".
Details
The function uses the following components to simulate the trait:
Additive genetic effects: Determined by
additive_indices
and the specifiedadditive_heritability
.Epistatic interactions: Simulated using pairs of SNPs from
gxg_indices_1
andgxg_indices_2
, contributing to thegxg_heritability
.Environmental effects: Any remaining variance not explained by genetic effects is assigned to random environmental noise.
The output file is in PLINK-compatible phenotype format with three columns:
Family ID (FID
), Individual ID (IID
), and the simulated trait (TRAIT
).
Examples
plink_file <- gsub("\\.bed", "", system.file("testdata", "test.bed", package = "smer"))
out_file <- tempfile()
additive_heritability <- 0.3
gxg_heritability <- 0.1
additive_snps <- sort(sample(1:100, 50, replace = FALSE))
gxg_group_1 <- sort(sample(additive_snps, 10, replace = FALSE))
gxg_group_2 <- sort(sample(setdiff(additive_snps, gxg_group_1), 10, replace = FALSE))
n_samples <- 200
simulate_traits(
plink_file,
out_file,
additive_heritability,
gxg_heritability,
additive_snps,
gxg_group_1,
gxg_group_2
)
from_file <- read.table(out_file, header = TRUE)
head(from_file)
#> FID IID TRAIT
#> 1 1 1 0.07327543
#> 2 2 1 -0.82216034
#> 3 3 1 -2.31319310
#> 4 4 1 0.74270008
#> 5 5 1 -2.53693229
#> 6 6 1 1.26249797