private void button1_Click(object sender, EventArgs e)
        {
            foreach (int n in listDS.SelectedIndices)
            {
                dataList = new List <double>();
                foreach (double[] dataRow in myVal)
                {
                    if (dataRow != null)//if rows were ommitted in row prepare, then there will be null arrays in myVal
                    {
                        dataList.Add(dataRow[n]);
                    }
                }
                result = Mathtool.GetDescriptiveStat(dataList);
                FrmMain.Instance.descriptiveStatResults(result, colNames[n], clearData); //colNames populated by GetVList
            }

            FrmMain.Instance.Refresh();
            FormDS.instance.Close();
            Debug.WriteLine(FormDS.instance);
        }
Exemple #2
0
        public void descriptiveStatResults(DescriptiveStat newResult, string index, bool clearData)
        //^populates the textbox on results tab with results from the FormDS
        {
            if (clearData)
            {
                tcStat.Text = "";
            }

            txtStat.Text += "For " + index +
                            ", Max: " + newResult.max.ToString("#.##") +
                            ", Min: " + newResult.min.ToString("#.##") +
                            ", Sum: " + newResult.sum.ToString("#.##") +
                            ", Average: " + newResult.avg.ToString("#.##") +
                            ", Variance: " + newResult.var.ToString("#.##") +
                            ", Standard Deviation: " + newResult.stddev.ToString("#.##") +
                            ", 1/4 Percentile: " + newResult.percentile1Quarter.ToString("#.##") +
                            ", 3/4 Percentile: " + newResult.percentile3Quarter.ToString("#.##") +
                            "." + Environment.NewLine;

            tcStat.SelectedTab = tp2;
        }
Exemple #3
0
        public static DescriptiveStat GetDescriptiveStat(List <double> data)
        {
            DescriptiveStat result = new DescriptiveStat();
            double          sqSum = 0, loopMax, loopMin;

            result.sum = 0;
            int           n = data.Count;
            List <double> maxes = new List <double>();
            List <double> mins = new List <double>();
            int           maxIndex, minIndex;

            while (data.Count > 2)
            {
                loopMax  = data[0];
                loopMin  = data[0];
                maxIndex = 0;
                minIndex = 0;

                foreach (double d in data)
                {
                    if (d > loopMax)
                    {
                        loopMax  = d;
                        maxIndex = data.IndexOf(d);
                    }
                    if (d < loopMin)
                    {
                        loopMin  = d;
                        minIndex = data.IndexOf(d);
                    }
                }
                result.sum += loopMax + loopMin;
                sqSum      += Math.Pow(loopMin, 2) + Math.Pow(loopMax, 2);
                maxes.Insert(0, loopMax);

                mins.Add(loopMin);

                if (maxIndex > minIndex)
                {
                    data.RemoveAt(maxIndex);
                    data.RemoveAt(minIndex);
                }
                else
                {
                    data.RemoveAt(minIndex);
                    data.RemoveAt(maxIndex);
                }
            }
            if (data.Count == 2)
            {
                mins.Add(data.Min());
            }
            maxes.Add(data.Max());
            result.median = maxes[0];
            data.Clear();
            data.AddRange(mins);
            data.AddRange(maxes);
            result.max    = data[n - 1];
            result.min    = data[0];
            result.avg    = result.sum / n;
            result.var    = (sqSum - n * Math.Pow(result.avg, 2)) / n;
            result.stddev = Math.Sqrt(result.var);

            for (int i = 0; i < data.Count; i++)
            {
                double percentile = ((double)i / (double)n);
                if (percentile > .25 && result.percentile1Quarter == 0)
                {
                    result.percentile1Quarter = data[i];
                }
                if (percentile > .75 && result.percentile3Quarter == 0)
                {
                    result.percentile3Quarter = data[i];
                }
            }
            return(result);
        }