Esempio n. 1
0
        public RegressionGraphPane(RegressionGraphData graphData)
        {
            _graphData = graphData;

            Title.Text = graphData.Title;
            XAxis.Title.Text = graphData.LabelX;
            YAxis.Title.Text = graphData.LabelY;
            Border.IsVisible = false;
            Title.IsVisible = true;
            Chart.Border.IsVisible = false;
            XAxis.Scale.MaxAuto = true;
            XAxis.Scale.MinAuto = true;
            YAxis.Scale.MaxAuto = true;
            YAxis.Scale.MinAuto = true;
            Y2Axis.IsVisible = false;
            X2Axis.IsVisible = false;
            XAxis.MajorTic.IsOpposite = false;
            YAxis.MajorTic.IsOpposite = false;
            XAxis.MinorTic.IsOpposite = false;
            YAxis.MinorTic.IsOpposite = false;
            IsFontsScaled = false;
            YAxis.Scale.MaxGrace = 0.1;

            //            Legend.FontSpec.Size = 12;

            var curve = AddCurve(Resources.RegressionGraphPane_RegressionGraphPane_Values, graphData.XValues, graphData.YValues,
                                           Color.Black, SymbolType.Diamond);
            curve.Line.IsVisible = false;
            curve.Symbol.Border.IsVisible = false;
            curve.Symbol.Fill = new Fill(COLOR_REGRESSION);

            // Find maximum points for drawing the regression line
            var lineX = new[] { double.MaxValue, double.MinValue };
            var lineY = new[] { double.MaxValue, double.MinValue };

            for (int i = 0; i < graphData.XValues.Length; i++)
            {
                double xValue = graphData.XValues[i];
                double yValue = graphData.YValues[i];
                if (xValue < lineX[0])
                {
                    lineX[0] = xValue;
                    lineY[0] = yValue;
                }
                if (xValue > lineX[1])
                {
                    lineX[1] = xValue;
                    lineY[1] = yValue;
                }
            }

            if (graphData.RegressionLine != null)
            {
                // Recalculate the y values based on the maximum x values
                // and the regression.
                lineY[0] = graphData.RegressionLine.GetY(lineX[0]);
                lineY[1] = graphData.RegressionLine.GetY(lineX[1]);

                curve = AddCurve(Resources.RegressionGraphPane_RegressionGraphPane_Regression, lineX, lineY, COLOR_LINE_REGRESSION);
                curve.Line.IsAntiAlias = true;
                curve.Line.IsOptimizedDraw = true;

                Statistics statsX = new Statistics(_graphData.XValues);
                Statistics statsY = new Statistics(_graphData.YValues);
                double slope = statsY.Slope(statsX);
                double intercept = statsY.Intercept(statsX);

                _labelRegression = string.Format("{0} = {1:F04}, {2} = {3:F04}\n" + "r = {4:F02}",  // Not L10N
                                          Resources.Regression_slope,
                                          slope,
                                          Resources.Regression_intercept,
                                          intercept,
                                          statsY.R(statsX));

            }

            var regressionLineCurrent = graphData.RegressionLineCurrent;
            if (regressionLineCurrent != null)
            {
                lineY[0] = regressionLineCurrent.GetY(lineX[0]);
                lineY[1] = regressionLineCurrent.GetY(lineX[1]);

                curve = AddCurve(Resources.RegressionGraphPane_RegressionGraphPane_Current, lineX, lineY, COLOR_LINE_REGRESSION_CURRENT);
                curve.Line.IsAntiAlias = true;
                curve.Line.IsOptimizedDraw = true;
                curve.Line.Style = DashStyle.Dash;

                _labelRegressionCurrent = string.Format("{0} = {1:F04}, {2} = {3:F04}", // Not L10N
                                                        Resources.Regression_slope,
                                                        regressionLineCurrent.Slope,
                                                        Resources.Regression_intercept,
                                                        regressionLineCurrent.Intercept);
            }
        }
Esempio n. 2
0
        public void OkDialog()
        {
            double minIrt;
            double maxIrt;

            var helper = new MessageBoxHelper(this);
            if (!helper.ValidateDecimalTextBox(textMinIrt, null, null, out minIrt))
                return;
            if (!helper.ValidateDecimalTextBox(textMaxIrt, minIrt, null, out maxIrt))
                return;

            var peptide1 = (DbIrtPeptide) comboFixedPoint1.SelectedItem;
            var peptide2 = (DbIrtPeptide) comboFixedPoint2.SelectedItem;

            double minCurrent = Math.Min(peptide1.Irt, peptide2.Irt);
            double maxCurrent = Math.Max(peptide1.Irt, peptide2.Irt);

            var statX = new Statistics(minCurrent, maxCurrent);
            var statY = new Statistics(minIrt, maxIrt);

            LinearEquation = new RegressionLine(statY.Slope(statX), statY.Intercept(statX));

            // Convert all of the peptides to the new scale.
            foreach (var peptide in _irtPeptides)
            {
                peptide.Irt = LinearEquation.GetY(peptide.Irt);
            }

            DialogResult = DialogResult.OK;
        }
Esempio n. 3
0
        public static bool TryGetRegressionLine(IList<double> listIndependent, IList<double> listDependent, int minPoints, out RegressionLine line)
        {
            line = null;
            if (listIndependent.Count != listDependent.Count || listIndependent.Count < minPoints)
                return false;

            double correlation;
            while (true)
            {
                var statIndependent = new Statistics(listIndependent);
                var statDependent = new Statistics(listDependent);
                line = new RegressionLine(statDependent.Slope(statIndependent), statDependent.Intercept(statIndependent));
                correlation = statDependent.R(statIndependent);

                if (correlation >= MIN_IRT_TO_TIME_CORRELATION || listIndependent.Count <= minPoints)
                    break;

                var furthest = 0;
                var maxDistance = 0.0;
                for (var i = 0; i < listDependent.Count; i++)
                {
                    var distance = Math.Abs(line.GetY(listDependent[i]) - listIndependent[i]);
                    if (distance > maxDistance)
                    {
                        furthest = i;
                        maxDistance = distance;
                    }
                }

                listIndependent.RemoveAt(furthest);
                listDependent.RemoveAt(furthest);
            }

            return correlation >= MIN_IRT_TO_TIME_CORRELATION;
        }
Esempio n. 4
0
        private static RegressionLine CalcConversion(IList<TimeScorePair> listPepCorr, int minCount)
        {
            var listTime = listPepCorr.Select(p => p.Time).ToList();
            var listScore = listPepCorr.Select(p => p.Score).ToList();

            RegressionLine line;
            if (RCalcIrt.TryGetRegressionLine(listScore, listTime, minCount, out line))
                return line;

            // TODO: Figure out something better here
            var statTime = new Statistics(listTime);
            var statScore = new Statistics(listScore);
            return new RegressionLine(statTime.Slope(statScore), statTime.Intercept(statScore));
        }