示例#1
0
        public SenSlopeModel CompareTheilSen(SenSlopeModel bl, SenSlopeModel tx)
        {
            SenSlopeModel senClone = bl;

            senClone.SenSD  = System.Math.Sqrt(bl.SenVariance + tx.SenVariance);
            senClone.Sen    = bl.Sen - tx.Sen;
            senClone.Zscore = bl.Sen / System.Math.Sqrt(bl.SenVariance + tx.SenVariance);
            senClone.TS85   = bl.TS85;
            senClone.TS90   = bl.TS90;
            senClone.TS95   = bl.TS95;

            return(senClone);
        }
示例#2
0
        public SenSlopeModel GetInterceptTreatment(SenSlopeModel current, int prevLength)
        {
            /* Intercept derived based upon Conover's theorum */
            /* Median(y) = SenSlope * Median(x) + Intercept */
            /* Intercept = Median(y) - (SenSlope * Median(x)) */

            List <double> mx = new List <double>();

            for (int i = prevLength; i < current.Length + prevLength; i++)
            {
                mx.Add(i + 1);
            }

            List <double> my = new List <double>(current.Observations);

            mx.Sort();
            my.Sort();

            current.MedianX          = GetMedian(mx);
            current.MedianY          = GetMedian(my);
            current.ConoverIntercept = current.MedianY - current.Sen * current.MedianX;

            return(current);
        }
        private void Calculate()
        {
            if (BaselineRangeString.Length < 1 || InterventionRangeString.Length < 1)
            {
                MessageBox.Show("Please select ranges for both phases.");
                return;
            }

            List <double> blRange = mWindow.ParseRange(BaselineRangeString);
            List <double> txRange = mWindow.ParseRange(InterventionRangeString);

            mInterface.SendMessageToOutput("---------------------------------------------------");
            mInterface.SendMessageToOutput("Calculating T-Sen Slopes: Baseline");

            SenSlopeModel bl = mSenObj.ComputeTheilSen(blRange);

            mInterface.SendMessageToOutput(System.String.Format("Baseline --- TS: {0},  SE-Slope: {1}, Z: {2}, P value: {3}", bl.Sen, bl.SenSD, bl.Zscore, bl.P));
            mInterface.SendMessageToOutput((System.String.Format("Baseline --- @ 85% CI: ({0} - {1}", bl.TS85[0], bl.TS85[1])));
            mInterface.SendMessageToOutput((System.String.Format("Baseline --- @ 90% CI: ({0} - {1}", bl.TS90[0], bl.TS90[1])));
            mInterface.SendMessageToOutput((System.String.Format("Baseline --- @ 95% CI: ({0} - {1}", bl.TS95[0], bl.TS95[1])));

            SenSlopeModel tx = mSenObj.ComputeTheilSen(txRange);

            mInterface.SendMessageToOutput(System.String.Format("Treatment --- TS: {0},  SE-Slope: {1}, Z: {2}, P value: {3}", tx.Sen, tx.SenSD, tx.Zscore, tx.P));
            mInterface.SendMessageToOutput((System.String.Format("Treatment --- @ 85% CI: ({0} - {1}", tx.TS85[0], tx.TS85[1])));
            mInterface.SendMessageToOutput((System.String.Format("Treatment --- @ 90% CI: ({0} - {1}", tx.TS90[0], tx.TS90[1])));
            mInterface.SendMessageToOutput((System.String.Format("Treatment --- @ 95% CI: ({0} - {1}", tx.TS95[0], tx.TS95[1])));

            SenSlopeModel comp = mSenObj.CompareTheilSen(bl, tx);

            mInterface.SendMessageToOutput(System.String.Format("Difference --- TS: {0},  SE-Slope: {1}, Z: {2}, P value: {3}", comp.Sen, comp.SenSD, comp.Zscore, comp.P));
            mInterface.SendMessageToOutput((System.String.Format("Difference --- @ 85% CI: ({0} - {1}", comp.TS85[0], comp.TS85[1])));
            mInterface.SendMessageToOutput((System.String.Format("Difference --- @ 90% CI: ({0} - {1}", comp.TS90[0], comp.TS90[1])));
            mInterface.SendMessageToOutput((System.String.Format("Difference --- @ 95% CI: ({0} - {1}", comp.TS95[0], comp.TS95[1])));

            SenSlopeModel newBl          = mSenObj.ComputeTheilSen(new List <double>(blRange));
            SenSlopeModel blInterceptObj = mSenObj.GetInterceptBaseline(newBl);

            SenSlopeModel newTx          = mSenObj.ComputeTheilSen(new List <double>(txRange));
            SenSlopeModel txInterceptObj = mSenObj.GetInterceptTreatment(newTx, newBl.Observations.Count);

            var   chartWin = new ChartingWindow();
            Chart chart    = chartWin.FindName("MyWinformChart") as Chart;

            chart.Series.Clear();

            // Style chart areas
            chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
            chart.ChartAreas[0].AxisX.Minimum           = 0;
            chart.ChartAreas[0].AxisX.Title             = "Observation";
            chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
            chart.ChartAreas[0].AxisY.Minimum           = 0;
            chart.ChartAreas[0].AxisY.Title             = "Response";

            var series = new Series
            {
                Name              = "Baseline Observation",
                Color             = System.Drawing.Color.Blue,
                IsVisibleInLegend = true,
                IsXValueIndexed   = false,
                ChartType         = SeriesChartType.Point
            };

            chart.Series.Add(series);

            for (int i = 0; i < blRange.Count; i++)
            {
                chart.Series[0].Points.AddXY(i + 1, blRange[i]);
            }

            chart.Legends.Add(series.Name);

            var series2 = new Series
            {
                Name              = "Treatment Observation",
                Color             = System.Drawing.Color.Red,
                IsVisibleInLegend = true,
                IsXValueIndexed   = false,
                ChartType         = SeriesChartType.Point
            };

            chart.Series.Add(series2);

            for (int i = 0; i < txRange.Count; i++)
            {
                chart.Series[1].Points.AddXY(i + 1 + blRange.Count, txRange[i]);
            }

            chart.Legends.Add(series2.Name);

            /**  TS Projections **/

            var series3 = new Series
            {
                Name              = "Baseline Sen Slope",
                Color             = System.Drawing.Color.DarkBlue,
                IsVisibleInLegend = true,
                IsXValueIndexed   = false,
                ChartType         = SeriesChartType.Line
            };

            chart.Series.Add(series3);

            for (int i = 0; i < blRange.Count; i++)
            {
                double projection = newBl.Sen * (i + 1) + blInterceptObj.ConoverIntercept;
                chart.Series[2].Points.AddXY(i + 1, projection);
            }

            chart.Legends.Add(series3.Name);

            var series4 = new Series
            {
                Name              = "Treatment Sen Slope",
                Color             = System.Drawing.Color.DarkRed,
                IsVisibleInLegend = true,
                IsXValueIndexed   = false,
                ChartType         = SeriesChartType.Line
            };

            chart.Series.Add(series4);

            for (int i = 0; i < txRange.Count; i++)
            {
                double projection = newTx.Sen * (i + 1 + blRange.Count) + txInterceptObj.ConoverIntercept;
                chart.Series[3].Points.AddXY(i + 1 + blRange.Count, projection);
            }

            chart.Legends.Add(series4.Name);

            chart.Legends[0].IsDockedInsideChartArea = true;
            chartWin.Title  = "Theil Sen Slope Estimator";
            chartWin.Width  = 400;
            chartWin.Height = 300;
            chartWin.Owner  = windowRef;

            if (ChartFlag)
            {
                chartWin.Show();
            }
        }