public void MeanTest()
        {
            double[]         DataPoints = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
            DescriptiveStats statsCalc  = new DescriptiveStats();
            var result = statsCalc.Mean(DataPoints);

            Assert.AreEqual(3.5, result);
        }
        public void SkewnessTest()
        {
            double[]         DataPoints = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
            DescriptiveStats statsCalc  = new DescriptiveStats();
            var result = statsCalc.Skewness(DataPoints);

            Assert.AreEqual(0.0, result);
        }
        public void StdDevTest()
        {
            double[]         DataPoints = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
            DescriptiveStats statsCalc  = new DescriptiveStats();
            var result = statsCalc.StdDev(DataPoints);

            Assert.AreEqual(1.8708286933869707, result);
        }
        public void MeanDeviationTest()
        {
            double[]         DataPoints = { 12.0, 24.0, 41.0, 51.0, 67.0, 67.0, 85.0, 99.0 };
            DescriptiveStats statsCalc  = new DescriptiveStats();
            var result = statsCalc.MeanDeviation(DataPoints);

            Assert.AreEqual(23.75, result);
        }
        public void ZScoresTest()
        {
            double[]         DataPoints = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
            double[]         scores     = { -1.3363062095621219, -0.449056948958286, 0.05601104036639116, 0.5284884801832448, 1.0840732389765304, 1.926539846563328 };
            DescriptiveStats statsCalc  = new DescriptiveStats();
            var result = statsCalc.ZScore(DataPoints);

            CollectionAssert.AreEqual(scores, result);
        }
        public void PopCorrelationTest()
        {
            double[]         DataPointsX = { 1, 2, 3, 4, 5 };
            double[]         DataPointsY = { 11, 22, 34, 43, 56 };
            DescriptiveStats statsCalc   = new DescriptiveStats();
            var result = statsCalc.PopCoefficient(DataPointsX, DataPointsY);

            Assert.AreEqual(0.7991248857909374, result);
        }
        public void SamCorrelationTest()
        {
            double[]         DataPointsX = { 3.0, 3.0, 6.0 };
            double[]         DataPointsY = { 2.0, 3.0, 4.0 };
            DescriptiveStats statsCalc   = new DescriptiveStats();
            var result = statsCalc.SampleCoefficient(DataPointsX, DataPointsY);

            Assert.AreEqual(0.8660254037844387, result);
        }
Beispiel #8
0
        /// <summary>
        /// a hacked mess to show box-wisker plot for outlier manipulation
        /// </summary>
        /// <param name="iv">double array of independent variable values</param>
        /// <param name="tags">string array of what should be date/time tags</param>
        /// <returns>a graph pane to display in the master</returns>
        private GraphPane addPlotBW(double[] iv, string[] tags)
        {
            //http://www.sharpstatistics.co.uk/index.php?option=com_content&view=article&id=12&Itemid=13
            //and hacked by mog 4/1/11

            //For each set of data for the boxplot calculate the median and the inter quartile (IQR) range
            //which is just the value of the 75th percentile minus the 25th percentile. The median is where
            //the horizontal bar goes. Using the 25th and 75th percentile a HiLowBarIten can be set which is
            //just a bar where the top and base are specified.

            //An error bar that has upper and lower values of the 25th percentile minus 1.5 times the IQR and
            //the 75th percentile plus 1.5 times the IQR is set to give the whiskers. As with the HiLowItem
            //barList is a PointPairList with the high and low values.

            //All that is left to do is add any points that are above or below the end of the whiskers.
            SortedList <string, double> datevalue = getlist(tags, iv);

            GraphPane gp = new GraphPane();

            //    "Median designated within box.\n" +
            //    "Whiskers are +- 1.5 * IQR (IQR = 75th percentile - 25th percentile)\n" +
            //    "Points above/below whiskers are designated as outliers.";

            //median of each array
            PointPairList medians = new PointPairList();
            //75th and 25th percentile, defines the box
            PointPairList hiLowList = new PointPairList();
            //+/- 1.5*Interquartile range, extentent of wiskers
            PointPairList barList = new PointPairList();
            //outliers
            PointPairList outs = new PointPairList();

            //Add the values
            DescriptiveStats ds = new DescriptiveStats();

            ds.getStats(iv);
            double median = ds.Median;

            medians.Add(0, median);
            double hivalue = percentile(iv, 75);
            double lovalue = percentile(iv, 25);

            hiLowList.Add(0, hivalue, lovalue);
            double iqr        = 1.5 * (hivalue - lovalue);
            double upperLimit = hivalue + iqr;
            double lowerLimit = lovalue - iqr;
            //The wiskers must end on an actual data point
            double wiskerlo = ValueNearestButGreater(iv, lowerLimit);
            double wiskerhi = ValueNearestButLess(iv, upperLimit);

            barList.Add(0, wiskerlo, wiskerhi);

            var upperouts = (from kv in datevalue
                             where kv.Value > upperLimit
                             select kv);

            foreach (var v in upperouts)
            {
                outs.Add(0, v.Value, v.Key);
            }

            var lowerouts = (from kv in datevalue
                             where kv.Value < lowerLimit
                             select kv);

            foreach (var v in lowerouts)
            {
                outs.Add(0, v.Value, v.Key);
            }

            //Plot the items, first the median values
            CurveItem meadian = gp.AddCurve("", medians, Color.Black, SymbolType.HDash);
            LineItem  myLine  = (LineItem)meadian;

            myLine.Line.IsVisible   = false;
            myLine.Symbol.Fill.Type = FillType.Solid;

            //Box
            HiLowBarItem myCurve = gp.AddHiLowBar("", hiLowList, Color.Black);

            myCurve.Bar.Fill.Type = FillType.None;

            //Wiskers
            ErrorBarItem myerror = gp.AddErrorBar("", barList, Color.Black);

            //Outliers
            CurveItem upper = gp.AddCurve(_dt.Columns[intSelectedcol].ColumnName + " outliers", outs, Color.Green, SymbolType.Circle);
            LineItem  bLine = (LineItem)upper;

            bLine.Line.IsVisible = false;

            gp.YAxis.Title.Text = _dt.Columns[intSelectedcol].ColumnName;
            gp.BarSettings.Type = BarType.Overlay;
            gp.XAxis.IsVisible  = false;
            gp.Legend.IsVisible = true;

            gp.Tag        = "BWPlot";
            gp.Title.Text = "BoxWhisker Plot";

            return(gp);
        }
Beispiel #9
0
        /// <summary>
        /// shows some stats for the selected variable
        /// </summary>
        private void showColInfo()
        {
            string varName   = _dt.Columns[_selectedcol].Caption;
            var    count     = (from DataRow r in _dt.Rows select r[_selectedcol]).Count();
            var    max       = (from DataRow r in _dt.Rows select r[_selectedcol]).Max();
            var    min       = (from DataRow r in _dt.Rows select r[_selectedcol]).Min();
            var    avg       = (from DataRow r in _dt.Rows select r[_selectedcol]).Average(r => (double)r);
            var    unique    = (from DataRow r in _dt.Rows select r[_selectedcol]).Distinct().Count();
            var    zerocount = (from DataRow r in _dt.Rows where (double)r[_selectedcol] == 0 select r[_selectedcol]).Count();

            double dmax = Convert.ToDouble(max);
            double dmin = Convert.ToDouble(min);

            AndersonDarlingNormality adtest = new AndersonDarlingNormality();

            double[] vals = (from DataRow r in _dt.Rows select(double) r[_selectedcol]).ToArray <double>();
            adtest.getADstat(vals);

            double norm   = adtest.ADStat;
            double pvnorm = adtest.ADStatPval;

            DescriptiveStats ds = new DescriptiveStats();

            ds.getStats(vals);


            double median = ds.Median;     //nv.Median;
            double range  = ds.Range;      // nv.Range;

            double mean     = ds.Mean;     // nv.Mean;
            double stddev   = ds.StdDev;   // nv.StandardDeviation;
            double variance = ds.Variance; // nv.Variance;
            double kurtosis = ds.Kurtosis; //nv.Kurtosis;
            double skewness = ds.Kurtosis; //nv.Skewness;


            listView1.View = View.Details;

            ListViewItem lvi;

            if (listView1.Items.Count > 0)
            {
                lvi = new ListViewItem("*****");
                lvi.SubItems.Add("");
                listView1.Items.Add(lvi);
            }


            lvi = new ListViewItem("Variable Name");
            lvi.SubItems.Add(varName);
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Row Count");
            lvi.SubItems.Add(count.ToString());
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Maximum Value");
            lvi.SubItems.Add(dmax.ToString("n2"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Minimum Value");
            lvi.SubItems.Add(dmin.ToString("n2"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Average Value");
            lvi.SubItems.Add(avg.ToString("n2"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Unique Values");
            lvi.SubItems.Add(unique.ToString());
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Zero Count");
            lvi.SubItems.Add(zerocount.ToString());
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Median Value");
            lvi.SubItems.Add(median.ToString("n3"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Data Range");
            lvi.SubItems.Add(range.ToString("n3"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("");
            lvi.SubItems.Add("");
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("AD Statistic");
            lvi.SubItems.Add(_regressionadstat.ToString("n4"));
            //lvi.SubItems.Add(norm.ToString("n3"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("AD Stat P-Value");
            lvi.SubItems.Add(_regressionadpval.ToString("n4"));
            //lvi.SubItems.Add(pvnorm.ToString("n3"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Mean Value");
            lvi.SubItems.Add(mean.ToString("n3"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Standard Deviation");
            lvi.SubItems.Add(stddev.ToString("n3"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Variance");
            lvi.SubItems.Add(variance.ToString("n3"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Kurtosis");
            lvi.SubItems.Add(kurtosis.ToString("n3"));
            listView1.Items.Add(lvi);

            lvi = new ListViewItem("Skewness");
            lvi.SubItems.Add(skewness.ToString("n3"));
            listView1.Items.Add(lvi);


            //magic numbers for widths: -1 set to max characters in subitems, -2 == autosize
            listView1.Columns.Add("Data", -1, HorizontalAlignment.Right);
            listView1.Columns.Add("Value", -2, HorizontalAlignment.Left);
        }