#' Single treatment (st) impute
#'
#' Impute the missing values for a phosphosite across replicates within a single treatment (or control)
#' if there are n or more quantified values of that phosphosite in that treatment.
#'
#' @usage stImpute(mat, n)
#'
#' @param mat a matrix with rows correspond to phosphosites and columns correspond to replicates within a treatment.
#' @param n an integer indicating n or more quantified values required for imputing missing values of a given phosphosite.
#' @export
#'
stImpute <- function(mat, n) {
for(i in 1:nrow(mat)) {
idx <- which(!is.na(mat[i,]))
if(length(idx) >= n) {
ms <- mean(mat[i,], na.rm = TRUE)
sds <- sd(mat[i,], na.rm=TRUE)
nid <- which(is.na(mat[i,]))
mat[i,nid] <- rnorm(length(nid), mean=ms, sd=sds)
}
}
return(mat)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.