Learn R Programming

GRAB (version 0.2.2)

GRAB.SimuGMat: Simulate an R matrix of genotype data

Description

GRAB package provides functions to simulate genotype data. We support simulations based on unrelated subjects and related subjects.

Usage

GRAB.SimuGMat(
  nSub,
  nFam,
  FamMode,
  nSNP,
  MaxMAF = 0.5,
  MinMAF = 0.05,
  MAF = NULL
)

Value

an R list including genotype matrix and marker information

  • GenoMat a numeric matrix of genotype: each row is for one subject and each column is for one SNP

  • markerInfo a data frame with the following 2 columns: SNP ID and minor allele frequency

Arguments

nSub

the number of unrelated subjects in simulations, if nSub = 0, then all subjects are related to at least one of the others.

nFam

the number of families in simulation, if nFam = 0, then all subjects are unrelated to each other.

FamMode

"4-members", "10-members", or "20-members". Check Details section for more details.

nSNP

number of markers to simulate

MaxMAF

a numeric value (default=0.5), haplotype is simulated with allele frequency <= this value.

MinMAF

a numeric value (default=0.05), haplotype is simulated with allele frequency >= this value.

MAF

a numeric vector with a length of nSNP. If this argument is given, then arguments of MaxMAF and MinMAF would be ignored.

Details

Currently, function GRAB.SimuGMat supports both unrelated and related subjects. Genotype data is simulated following Hardy-Weinberg Equilibrium with allele frequency ~ runif(MinMAF, MaxMAF).

If FamMode = "4-members"

Total number of subjects is nSub + 4 * nFam. Each family includes 4 members with the family structure as below: 1+2->3+4.

If FamMode = "10-members"

Total number of subjects is nSub + 10 * nFam. Each family includes 10 members with the family structure as below: 1+2->5+6, 3+5->7+8, 4+6->9+10.

If FamMode = "20-members"

Total number of subjects is nSub + 20 * nFam. Each family includes 20 members with the family structure as below: 1+2->9+10, 3+9->11+12, 4+10->13+14, 5+11->15+16, 6+12->17, 7+13->18, 8+14->19+20.

See Also

GRAB.makePlink can make PLINK files using the genotype matrix.

Examples

Run this code
nSub <- 100
nFam <- 10
FamMode <- "10-members"
nSNP <- 10000
OutList <- GRAB.SimuGMat(nSub, nFam, FamMode, nSNP)
GenoMat <- OutList$GenoMat
markerInfo <- OutList$markerInfo
GenoMat[1:10, 1:10]
head(markerInfo)

## The following is to calculate GRM
MAF <- apply(GenoMat, 2, mean) / 2
GenoMatSD <- t((t(GenoMat) - 2 * MAF) / sqrt(2 * MAF * (1 - MAF)))
GRM <- GenoMatSD %*% t(GenoMatSD) / ncol(GenoMat)
GRM1 <- GRM[1:10, 1:10]
GRM2 <- GRM[100 + 1:10, 100 + 1:10]
GRM1
GRM2

Run the code above in your browser using DataLab