getH2

Share:

Description

Function for estimating broad-sense heritability.

Usage

1
getH2(data, snp.name, trait.name, covars = "")

Arguments

data
snp.name
trait.name
covars

Author(s)

Marcin Kierczak, Xia Shen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data, snp.name, trait.name, covars = "") 
{
    snp.num <- which(snpnames(data) == snp.name)
    gtypes <- as.factor(as.character(data@gtdata[, snp.num]))
    phtypes <- data@phdata[, trait.name]
    if (covars[1] == "") {
        covars <- c("1")
        dat <- data.frame(pheno = phtypes, geno = gtypes)
    }
    else {
        dat <- data.frame(pheno = phtypes, geno = gtypes, data@phdata[, 
            covars])
        names(dat) <- c("pheno", "geno", covars)
    }
    names.kept <- covars
    lm.form <- paste("pheno ~ ", paste(names.kept, collapse = "+"), 
        sep = "")
    lm.obj <- lm(lm.form, data = dat)
    r2.1 <- summary(lm.obj)$r.squared
    names.kept <- c("geno", covars)
    lm.form <- paste("pheno ~ ", paste(names.kept, collapse = "+"), 
        sep = "")
    lm.obj <- lm(lm.form, data = dat)
    r2.2 <- summary(lm.obj)$r.squared
    H2 <- abs(r2.2 - r2.1)
    H2
  }