weightEstimation: Predict weights of samples from ionomics data.

Description Usage Arguments Examples

Description

Takes a data frame of values with weights included, and a data frame of values that haven't been weighed. Finds list of stable elements (based on the assumption most samples should have a similar elemental concentraiton, so low RSDs), and uses those elements to estimate weights.

Usage

1
weightEstimation(x, y, predictx, maxRSD = 25, maxEl = 10, df = 500/9)

Arguments

x

Data frame of weight normalized elelmental concentrations.

y

Vector of weights for concentrations in x.

predictx

Data frame of values to predict weights for.

maxRSD

Maximum RSD threshold for elements to be included in estimation.

maxEl

Maximum number of elements to include in estimation.

df

Dilution factor for weight normalized concentrations.

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 (x, y, predictx, maxRSD = 25, maxEl = 10, df = 500/9) 
{
    normX <- x
    for (i in colnames(x)) {
        normX[, i] <- (x[, i]/y) * (df)
    }
    elRSD <- sapply(normX, sd, na.rm = TRUE)/sapply(normX, mean, 
        na.rm = TRUE) * 100
    elMean <- sapply(normX, mean, na.rm = TRUE)
    meetCutoff <- elRSD[which(elRSD < maxRSD)]
    if (length(meetCutoff) < maxEl) {
        numEl <- length(meetCutoff)
    }
    else {
        numEl <- maxEl
    }
    bestElements <- names(sort(meetCutoff)[1:numEl])
    weightEstimates <- predictx
    for (i in colnames(predictx)) {
        weightEstimates[, i] <- (predictx[, i]/elMean[i]) * (df)
    }
    weightEstimates <- as.data.frame(t(apply(weightEstimates[bestElements], 
        1, is.outlier, mcut = 3)))
    finalPrediction <- rowMeans(weightEstimates[bestElements], 
        na.rm = TRUE)
    return(list(weights = as.vector(finalPrediction), els = bestElements))
  }

gziegler/ionomicsUtils documentation built on June 20, 2019, 8:04 p.m.