/// <summary> /// Sets the false discovery rate by creating a histogram of the mass errors and comparing the proportion above a threshhold to the area below. /// </summary> private void SetMassErrorHistogramFdr() { // Populate the mass error list and create the histogram. var massErrorList = MatchList.Select(match => match.DifferenceVector[1, 1]).ToList(); var histogramList = MathUtilities.GetHistogramValues(massErrorList, m_matchParameters.HistogramBinWidth); var peakIndex = 0; var peakValue = 0.0; var upperBound = 0.0; var lowerBound = 0.0; var meanValue = 0.0; // Find the maximum and average values. for (var i = 0; i < histogramList.Count; i++) { var bin = histogramList[i]; if (bin.Y > peakValue) { peakValue = bin.Y; peakIndex = i; } meanValue += bin.Y; } meanValue /= histogramList.Count; // Set the threshold to a value between the peak and the average value. var threshold = meanValue + m_matchParameters.HistogramMultiplier * (peakValue - meanValue); // Find the upper bound. for (var i = peakIndex; i < histogramList.Count; i++) { var bin = histogramList[i]; var lowerBin = histogramList[i - 1]; if (bin.Y < threshold && lowerBin.Y >= threshold) { upperBound = lowerBin.X + (lowerBin.Y - threshold) / (lowerBin.Y - bin.Y) * (bin.X - lowerBin.X); } } // Find the lower bound. for (var i = peakIndex; i >= 0; i--) { var bin = histogramList[i]; var upperBin = histogramList[i + 1]; if (bin.Y < threshold && upperBin.Y >= threshold) { lowerBound = bin.X + (threshold - bin.Y) / (upperBin.Y - bin.Y) * (upperBin.X - bin.X); } } // Count the number of matches within the bounds and calculate the FDR. var countInBounds = massErrorList.Count(massDifference => massDifference >= lowerBound && massDifference <= upperBound); ErrorHistogramFdr = countInBounds / ((upperBound - lowerBound) * threshold); }