train: Training function for binary predictors

View source: R/train.R

trainR Documentation

Training function for binary predictors

Description

This function build a model from data to predict class in classify.

Usage

  train(peakMatrix, group, filter.p = 0.05, groupColors = c("red", "blue"),
    threshold = 0.9)

Arguments

peakMatrix

Numeric matrix of normalized peak heights with samples in rows and peaks in columns.

group

Two-level factor defining the group of every samples in peaks.

filter.p

Single numeric value, if not NA only genes for which the t-test p is lower than this will be used in the model.

groupColors

Vector of length two, defining the colors to use to represent the two groups in future plots.

threshold

Single numeric value, the likelihood threshold above which make a call when classifying (classification will return NA is this threshold is met for none of the two groups).

Value

Returns an S3 object of class fsaModel.

Author(s)

Sylvain Mareschal

See Also

add.model, classify

Examples

  # Underlying truth for pseudo-data (10 genes)
  geneNames <- paste("gene", LETTERS[1:10], sep=".")
  geneMean <- abs(rnorm(10))
  groupShift <- rnorm(10, sd=0.1)
  
  # Generate pseudo-data for 50 samples
  mtx <- NULL
  for(g in 1:10) {
    x <- rnorm(n=50, mean=geneMean[g], sd=0.1)
    x[1:25] <- x[1:25] + groupShift[g]
    x[26:50] <- x[26:50] - groupShift[g]
    mtx <- cbind(mtx, x)
  }
  colnames(mtx) <- geneNames
  rownames(mtx) <- c(
    paste("group1", 1:25, sep="."),
    paste("group2", 26:50, sep=".")
  )
  
  # Train model
  group <- c(
    rep("group1", 25),
    rep("group2", 25)
  )
  model <- train(mtx, group)
  plot(model)
  
  # Compare model to truth
  i <- match(geneNames, model$geneNames)
  out <- data.frame(
    gene = geneNames,
    true.M = geneMean,
    model.M = model$geneMs[i],
    true.shift = groupShift,
    model.T = model$geneTs[i]
  )
  print(out)

FSAtools documentation built on Aug. 19, 2023, 1:06 a.m.