getDrift: Mean of residuals from drifting CpGs.

Description Usage Arguments Value Author(s) Examples

View source: R/getDrift.R

Description

Calculate mean of residuals from user-specified drifting CpGs.

Usage

1
getDrift(df, driftcg,chrage,showStatusDrift=TRUE,keepres=TRUE)

Arguments

df

Beta-value data frame, where columns are samples and rows are markers.

driftcg

List of drifting CpGs for which to calculate residuals.

chrage

Sample chronological (patient) age, in same order as columns in df.

showStatusDrift

Whether to show detailed output of calculation status.

keepres

Whether to retain CpG-level residuals used in calculation of mean.

Value

Returns age estimate and specified additional information.

Author(s)

Sean K Maden

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
## The function is currently defined as
function(df, driftcg,chrage,showStatusDrift=TRUE,keepres=FALSE){
  # note: chrage sample age order must correspond to order of columns in df
  message("Beginning Drift CpG residuals calculations...")

  dfdrift <- df[rownames(df) 
  reslist <- c()
  for(i in 1:nrow(dfdrift)){
    reslist[[i]] <- lm(dfdrift[i,]~chrage)$residuals
    names(reslist)[i] <- rownames(dfdrift)[i]
    if(showStatusDrift){
#      message("Drift Residuals Status: finished ",i," or ",round((100*(i/nrow(dfdrift))),3),"%.")
    }
  }

  xvecti <- c(rep(0,ncol(dfdrift)))
  for(i in 1:ncol(dfdrift)){
    xvecti[i] <- mean(sapply(reslist, "[", i))
    names(xvecti)[i] <- colnames(dfdrift)[i]
  }
  driftlm <- data.frame(Mean.Residual=xvecti,Chr.Age=chrage)
  rownames(driftlm) <- colnames(dfdrift)

  return.list <- list(driftlm)

  if(keepres){
    return.list <- append(return.list,list(reslist))
    names(return.list)[[length(return.list)]] <- "All.Drift.Residuals"
  }
  return(return.list)
}

metamaden/cgageR documentation built on May 20, 2019, 5:07 p.m.