Example #1
0
        private void CalculateRegression()
        {
            var x = Vector.Create(ChartValues.Select(v => v.NDouble).ToArray());
            var y = Vector.Create(ChartValues.Select(v => v.TotDouble).ToArray());

            _regression = new SimpleRegressionModel(y, x);
            _regression.Fit();

            UpperValues.Clear();
            LowerValues.Clear();
            RegressionValues.Clear();
            NToNValues.Clear();
            XAxis.Clear();
            YAxis.Clear();

            var max = ChartValues.Max(p => p.NDouble);

            XAxis.Add(new ObservablePoint(0, 0));
            XAxis.Add(new ObservablePoint(0, max));
            YAxis.Add(new ObservablePoint(0, 0));
            YAxis.Add(new ObservablePoint(max, 0));



            NToNValues.Add(new ObservablePoint(0, 0));
            NToNValues.Add(new ObservablePoint(max, max));

            var ci = _regression.GetPredictionInterval(0, .99);

            UpperValues.Add(new ObservablePoint(0, ci.UpperBound));
            LowerValues.Add(new ObservablePoint(0, ci.LowerBound));
            RegressionValues.Add(new ObservablePoint(0, ci.Center));

            ci = _regression.GetPredictionInterval(max, .99);
            UpperValues.Add(new ObservablePoint(max, ci.UpperBound));
            LowerValues.Add(new ObservablePoint(max, ci.LowerBound));
            RegressionValues.Add(new ObservablePoint(max, ci.Center));

            var above = 0.0;
            var below = 0.0;

            foreach (var point in ChartValues)
            {
                var interval = _regression.GetPredictionInterval(point.NDouble, .99);
                if (point.TotDouble <= interval.UpperBound && point.TotDouble > interval.Center)
                {
                    above++;
                }
                else if (point.TotDouble <= interval.Center && point.TotDouble >= interval.LowerBound)
                {
                    below++;
                }
            }
            Console.WriteLine("Above Center: " + above / ChartValues.Count);
            Console.WriteLine("Below Center: " + below / ChartValues.Count);
        }