Skip to contents

Simulates a phenotype based on genotype data with specified per-SNP heritability. Causal variants can be constrained to be approximately independent (low LD).

Usage

simulate_phenotype(X, n_causal = 5, h2_per_snp = 0.01, independent = TRUE)

Arguments

X

Standardized genotype matrix (individuals x SNPs).

n_causal

Number of causal variants.

h2_per_snp

Desired heritability per causal SNP (e.g., 0.01).

independent

Logical; if TRUE, causal SNPs are chosen to be approximately independent (low LD).

Value

A list containing:

G

The input genotype matrix.

y

Phenotype vector.

beta

Vector of true effect sizes.

causal

Indices of causal variants.

h2_total

Total heritability (h2_per_snp * n_causal).

h2_per_snp

Per-SNP heritability used.

residual_variance

Residual variance of the phenotype.

Examples

G <- matrix(rbinom(1000, 2, 0.5), nrow = 100, ncol = 10)
G <- scale(G)
result <- simulate_phenotype(G, n_causal = 3, h2_per_snp = 0.05)