calcG: Function to calculate a relationship matrix from marker data...

Description Usage Arguments Value See Also Examples

View source: R/gblup.R

Description

Function to calculate a relationship matrix from marker data. Option to return the inverse of matrix. Inverse calculated using Matrix package.

Usage

1

Arguments

M

Matrix of marker genotypes, usually the count of one of the two SNP alleles at each markers (0, 1, or 2).

data

Optional logical vector which can tell of which individuals we have phenotypes.

solve

Logic, if TRUE then function returns the inverse of the relationship matrix.

Value

Matrix of class dgeMatrix.

See Also

SamplePedigree, gblup, makeAinv,blup

Examples

1
2
3
example(gblup)
G <- calcG(M)
Ginv <- calcG(M,solve = TRUE)

Example output

Loading required package: Matrix
Loading required package: HaploSim
Loading required package: reshape

Attaching package: 'reshape'

The following object is masked from 'package:Matrix':

    expand


gblup> h2 <- 0.5

gblup> example(SamplePedigree)

SmplPd> example(SampleHaplotypes)

SmplHp> hList <- SampleHaplotypes(nHaplotypes = 20,nLoc = 100,genDist =
SmplHp+ 1,nDec = 3) ## create objects

SmplHp> for(g in 1:10)hList <- SampleHaplotypes(orig = hList,genDist
SmplHp+ = 1,nDec = 3)

SmplPd> ID <- 1:10

SmplPd> pID0 <- c(rep(0,5),1,1,3,3,5)

SmplPd> pID1 <- c(rep(0,4),2,2,2,4,4,6)

SmplPd> ped <- data.frame(ID,pID0,pID1)

SmplPd> phList <- SamplePedigree(orig = hList,ped = ped)

gblup> ped <- phList$ped

gblup> hList <- phList$hList

gblup> qtlList <- ListQTL(hList = hList,frqtl = 0.1,sigma2qtl = 1)

gblup> qtl <- tapply(unlist(qtlList),list(rep(names(qtlList),times = unlist(lapply(qtlList,length))),
gblup+                    unlist(lapply(qtlList,function(x)seq(1,length(x))))),mean,na.rm = TRUE)

gblup> qtl <- melt(qtl)

gblup> names(qtl) <- c("POS","TRAIT","a")

gblup> HH <- getAll(hList,translatePos = FALSE)

gblup> rownames(HH) <- sapply(hList,function(x)x@hID)

gblup> QQ <- HH[,match(qtl$POS,colnames(HH))]

gblup> g <- QQ

gblup> ped$G <- with(ped,g[match(hID0,rownames(g))]+g[match(hID1,rownames(g))])

gblup> sigmae <- sqrt(var(ped$G)/h2 - var(ped$G))

gblup> ped$P <- ped$G + rnorm(nrow(ped),0,sigmae)

gblup> M <- with(ped,HH[match(hID0,rownames(HH)),] + HH[match(hID1,rownames(HH)),]) 

gblup> rownames(M) <- ped$ID

gblup> sol <- gblup(P~1,data = ped[,c('ID','P')],M = M,lambda = 1/h2 - 1)

pedigree documentation built on May 2, 2019, 4:21 a.m.