public void SampleTest(double mean, double sdv, int seed) { var dis = new Normal(mean, sdv); var hybrid = new UnivariateHybridMC(0, dis.DensityLn, 10, 0.1, 1000, 1, new System.Random(seed)) { BurnInterval = 0 }; double[] sample = hybrid.Sample(10000); double effective = MCMCDiagnostics.EffectiveSize(sample, x => x); var stats = new DescriptiveStatistics(sample); //Testing the mean using the normal distribution. double meanConvergence = 3 * sdv / Math.Sqrt(effective); Assert.AreEqual(stats.Mean, mean, meanConvergence, "Mean"); double deviationRation = Math.Pow(stats.StandardDeviation / sdv, 2); //Approximating chi-square with normal distribution. (Degree of freedom is large) double deviationConvergence = 3 * Math.Sqrt(2) / Math.Sqrt(effective); Assert.AreEqual(deviationRation, 1, deviationConvergence, "Standard Deivation"); }
public PointPairList getDensityCurve(IList <double> data, double bandwidth) { int intervals = 1000; var result = new PointPairList { Capacity = intervals }; //generate a base line var statistics = new DescriptiveStatistics(data); double minValue = data.Min() - (2 * statistics.StandardDeviation); double maxValue = data.Max() + (2 * statistics.StandardDeviation); double interval = (maxValue - minValue) / intervals * 1.0; for (int i = 0; i < intervals; i++) { result.Add(minValue + i * interval, 0); } if (bandwidth == 0) { bandwidth = 1.06 * statistics.StandardDeviation * Math.Pow(data.Count, -1.0 / 5); } var orderedData = data.OrderBy(o => o); foreach (var value in orderedData) { Normal nD = new Normal(0, 1); for (int q = 0; q < intervals; q++) { result[q].Y += (1 / (data.Count * bandwidth)) * nD.Density((value - result[q].X) / bandwidth); } } return(result); }
public SyncRunResult RunTest() { var waitTime = _startAt - DateTime.Now; _startEvent.Signal(); Thread.Sleep((int)(waitTime.TotalMilliseconds)); _runEvent.Signal(); var wr = _worker.Run(_workerId); double totalElapsed = 0; wr.InsertPerformance.ForEach(i => { totalElapsed += i; }); var sample = new DescriptiveStatistics(wr.InsertPerformance.ToArray()); Console.WriteLine($"{_workerId:000}: MIN/AVG/MAX: {sample.Minimum:#.00}, {sample.Mean:#.00}, {sample.Maximum:#.00} - STDEV/VAR: {sample.StandardDeviation:#.00}, {sample.Variance:#.00} - SUM: {totalElapsed}"); _finishEvent.Signal(); return(new SyncRunResult() { Documents = wr.InsertedDocuments, ElapsedMilliseconds = totalElapsed }); }
public void SetMonthlyWeatherFileStats(List <HourlyWeatherData> avails, string monthName, int monthNumber, int numDays, string[] interests) { Monthly m = new Monthly(); m.SimpleName = monthName; m.Id = monthNumber; m.ExpectedValCount = 24 * numDays; m.ActualValCount = avails.Count(); //loop through desired properties of interest and gather monthly statistics for (int s = 0; s < interests.Count(); s++) { string interest = interests[s]; List <double> values = new List <double>(); foreach (HourlyWeatherData wd in avails) { values.Add(Convert.ToDouble(wd.GetType().GetProperty(interest).GetValue(wd, null))); //reflection } PropertyInfo p = m.GetType().GetProperty(interest); var stats = new DescriptiveStatistics(values); if (p != null) { p.SetValue(m, stats, null); } else { //exception } if (s == interests.Count() - 1) { this.Monthly.Add(m); } } }
public void SampleTest() { double Mean = 5 * rnd.NextDouble(); double Sdv = 5 * rnd.NextDouble(); Normal dis = new Normal(Mean, Sdv); UnivariateHybridMC Hybrid = new UnivariateHybridMC(0, dis.DensityLn, 10, 0.1, 1000); Hybrid.BurnInterval = 0; double[] Sample = Hybrid.Sample(10000); double Effective = MCMCDiagnostics.EffectiveSize(Sample, x => x); DescriptiveStatistics Stats = new DescriptiveStatistics(Sample); //Testing the mean using the normal distribution. double MeanConvergence = 3 * Sdv / Math.Sqrt(Effective); Assert.AreEqual(Stats.Mean, Mean, MeanConvergence, "Mean"); double DeviationRation = Math.Pow(Stats.StandardDeviation / Sdv, 2); //Approximating chi-square with normal distribution. (Degree of freedom is large) double DeviationConvergence = 3 * Math.Sqrt(2) / Math.Sqrt(Effective); Assert.AreEqual(DeviationRation, 1, DeviationConvergence, "Standard Deivation"); }
public void ShortSequences() { var stats0 = new DescriptiveStatistics(new double[0]); Assert.That(stats0.Skewness, Is.NaN); Assert.That(stats0.Kurtosis, Is.NaN); var stats1 = new DescriptiveStatistics(new[] { 1.0 }); Assert.That(stats1.Skewness, Is.NaN); Assert.That(stats1.Kurtosis, Is.NaN); var stats2 = new DescriptiveStatistics(new[] { 1.0, 2.0 }); Assert.That(stats2.Skewness, Is.NaN); Assert.That(stats2.Kurtosis, Is.NaN); var stats3 = new DescriptiveStatistics(new[] { 1.0, 2.0, -3.0 }); Assert.That(stats3.Skewness, Is.Not.NaN); Assert.That(stats3.Kurtosis, Is.NaN); var stats4 = new DescriptiveStatistics(new[] { 1.0, 2.0, -3.0, -4.0 }); Assert.That(stats4.Skewness, Is.Not.NaN); Assert.That(stats4.Kurtosis, Is.Not.NaN); }
public void ZeroVarianceSequence() { var stats = new DescriptiveStatistics(new[] { 2.0, 2.0, 2.0, 2.0 }); Assert.That(stats.Skewness, Is.NaN); Assert.That(stats.Kurtosis, Is.NaN); }
public void Feed(IEnumerable <Row> rows, ColumnViewModel numerical) { DescriptiveStatisticsViewModel result = DescriptiveStatistics.Analyze( DataContext as MainPageViewModel, rows.Select(r => (Double)r.Cells[numerical.Index].Content) ); HistogramElement.VerticalAxisTitle = Const.Loader.GetString("Frequency"); HistogramElement.Width = this.Width - 20; // (Double)App.Current.Resources["ParagraphWidth"] - 20; HistogramElement.Height = this.Height - 70; BoxPlotElement.Width = this.Width - 90; // (Double)App.Current.Resources["ParagraphWidth"] - 90; BoxPlotElement.Min = result.Min; BoxPlotElement.Max = result.Max; BoxPlotElement.FirstQuartile = result.FirstQuartile; BoxPlotElement.Median = result.Median; BoxPlotElement.ThirdQuartile = result.ThirdQuartile; BoxPlotElement.Mean = result.Mean; BoxPlotElement.Update(); d3.Scale.Linear linear = new d3.Scale.Linear() { DomainStart = result.Min, DomainEnd = result.Max, RangeStart = 0, RangeEnd = 1 }; linear.Nice(); List <Bin> bins = HistogramCalculator.Bin( linear.DomainStart, linear.DomainEnd, linear.Step, rows, numerical ).ToList(); if (numerical.SortOption == SortOption.Descending) { bins = bins.OrderByDescending(b => b.Min).ToList(); } else { bins = bins.OrderBy(b => b.Min).ToList(); } HistogramElement.Data = bins .Select(d => new BarChartDatum() { Key = $"~{Formatter.Auto(d.Max)}", ColumnViewModel = numerical, Value = d.Rows.Count(), EnvelopeValue = d.Rows.Count(), Rows = null, EnvelopeRows = d.Rows }).ToList(); }
public static stats GenStats(List <List <round> > input) { List <double> faction_damage = new List <double> (); List <double> asset_damage = new List <double> (); foreach (var i in input) { faction_damage.Add(i.Select(e => Convert.ToDouble(e.direct_faction_damage)).Sum()); asset_damage.Add(i.Select(e => Convert.ToDouble(e.damage)).Sum()); } var statistics = new DescriptiveStatistics(faction_damage); var stats = new stats(); stats.faction_stats.Maximum = statistics.Maximum; stats.faction_stats.Minimum = statistics.Minimum; // stats.values.Median = statistics.Median; stats.faction_stats.Mean = statistics.Mean; stats.faction_stats.Variance = statistics.Variance; stats.faction_stats.StandardDeviation = statistics.StandardDeviation; stats.faction_stats.Kurtosis = statistics.Kurtosis; stats.faction_stats.Skewness = statistics.Skewness; statistics = new DescriptiveStatistics(asset_damage); stats.asset_stats.Maximum = statistics.Maximum; stats.asset_stats.Minimum = statistics.Minimum; // stats.values.Median = statistics.Median; stats.asset_stats.Mean = statistics.Mean; stats.asset_stats.Variance = statistics.Variance; stats.asset_stats.StandardDeviation = statistics.StandardDeviation; stats.asset_stats.Kurtosis = statistics.Kurtosis; stats.asset_stats.Skewness = statistics.Skewness; Normal fac_normal = new Normal(stats.faction_stats.Mean, stats.faction_stats.StandardDeviation, Program.rand); Normal asset_normal = new Normal(stats.asset_stats.Mean, stats.asset_stats.StandardDeviation, Program.rand); for (int i = Convert.ToInt32(Math.Floor(stats.faction_stats.Minimum)); i < stats.faction_stats.Maximum; i++) { double item1 = fac_normal.CumulativeDistribution(i); stats.faction_stats.normalized_dist.Add((i, item1)); } for (int i = Convert.ToInt32(Math.Floor(stats.asset_stats.Minimum)); i < stats.asset_stats.Maximum; i++) { double item1 = fac_normal.CumulativeDistribution(i); stats.asset_stats.normalized_dist.Add((i, item1)); } return(stats); }
public void TestDescriptiveStatisticsMeanVariance() { // Test around 10^9, potential stability issues NormalDistribution gaussian = new NormalDistribution(1e+9, 2); Assert.That(DescriptiveStatistics.Mean(gaussian.EnumerateDoubles(10000)), NumericIs.AlmostEqualTo(1e+9, 0.2), "Mean of (1e+9,2)"); Assert.That(DescriptiveStatistics.Variance(gaussian.EnumerateDoubles(10000)), NumericIs.AlmostEqualTo((double)4, 0.5), "Variance of (1e+9,2)"); Assert.That(DescriptiveStatistics.StandardDeviation(gaussian.EnumerateDoubles(10000)), NumericIs.AlmostEqualTo((double)2, 0.5), "StdDev of (1e+9,2)"); }
public void D2D10DivideByD2MultiplyBy2DistributionShouldBeGood() { var statistics = new DescriptiveStatistics(rolls); Assert.AreEqual(d2d10div2mul2.Minimum, statistics.Minimum, "Expected min differs from actual min"); Assert.AreEqual(d2d10div2mul2.Maximum, statistics.Maximum, "Expected max differs from actual max"); Assert.AreEqual(12.25, statistics.Mean, 1, "Expected mean differs to much from actual mean"); Assert.Greater(statistics.Skewness, 0.8, "Distribution is not skewed enough"); Assert.Less(statistics.Kurtosis, 0, "Distribution is not platykurtic at all"); }
public void TestDescriptiveStatisticsOrderMedian() { // -3 -1 -0.5 0 1 4 5 6 10 double[] samples = new double[] { -1, 5, 0, -3, 10, -0.5, 4, 1, 6 }; Assert.That(DescriptiveStatistics.Median(samples), Is.EqualTo(1), "Median"); Assert.That(DescriptiveStatistics.OrderStatistic(samples, 1), Is.EqualTo(-3), "Order-1"); Assert.That(DescriptiveStatistics.OrderStatistic(samples, 3), Is.EqualTo(-0.5), "Order-3"); Assert.That(DescriptiveStatistics.OrderStatistic(samples, 7), Is.EqualTo(5), "Order-7"); Assert.That(DescriptiveStatistics.OrderStatistic(samples, 9), Is.EqualTo(10), "Order-9"); }
public void PopulateStatsFromArrayAndRound(double[] array, int roundDigits) { var ArrayStats = new DescriptiveStatistics(array); Max = Math.Round(ArrayStats.Maximum, roundDigits); Min = Math.Round(ArrayStats.Minimum, roundDigits); Mean = Math.Round(ArrayStats.Mean, roundDigits); //StdDev = Math.Round(ArrayStats.StandardDeviation, roundDigits); uses Bessel's correction (N-1 pop size) StdDev = Math.Round(Statistics.PopulationStandardDeviation(array), roundDigits); }
public HistogramDataAndProperties(DenseVector data, int countOfBins = 10) { dvData = (DenseVector)data.Clone(); binsCount = countOfBins; color = Color.Black; description = "histogram"; stats = new DescriptiveStatistics(dvData); calculateProbDens(); CalculateQuantiles(); }
//пока что возводит в степень //надо посчитать Фурье, отрезать высокие гармоники, вернуть обратно //пока отрежем значения, лежащие за пределами интервала 3*sigma от среднего private ImageOperationalValue ImageOperationalValueCut(ImageOperationalValue a, double sigmaCount) { ImageOperationalValue res = new ImageOperationalValue(); if (a.operandType() == OperandTypes.DenseMatrix) { //DenseMatrix dmRes = (DenseMatrix)a.DmImageComponent.Clone(); //determining the new mean value DenseMatrix dmTmp = a.DmImageComponent.Copy(); DescriptiveStatistics stats = new DescriptiveStatistics(dmTmp.Values); double dataMeanTmp = stats.Mean; double standDevTmp = stats.StandardDeviation; double deviationMarginTmp = sigmaCount * standDevTmp; dmTmp.MapInplace(new Func <double, double>((dVal) => { if (Math.Abs(dVal - dataMeanTmp) > deviationMarginTmp) { //double theSign = (dVal - dataMeanTmp) / Math.Abs(dVal - dataMeanTmp); // return double.NaN; return(dataMeanTmp); } else { return(dVal); } })); //stats = new DescriptiveStatistics(dmTmp.Values); //double dataMean = stats.Mean; //double standDev = stats.StandardDeviation; //double deviationMargin = sigmaCount * standDev; ////dmRes.MapInplace(new Func<double, double>((x) => { return Math.Pow(x, sigmaCount); })); ////stats = new DescriptiveStatistics(dmRes.Values); //dmRes.MapInplace(new Func<double,double>((dVal) => //{ // if (Math.Abs(dVal - dataMean) > deviationMargin) // { // //double theSign = (dVal - dataMean)/Math.Abs(dVal - dataMean); // return dataMean; // } // else return dVal; //})); res.DmImageComponent = dmTmp.Copy(); } else { res.dNumber = a.dNumber; } return(res); }
public ITextRender Report(ITextRender output = null) { if (output == null) { output = new builderForMarkdown(); } var scores = items.Select(x => x.score); output.AppendHeading("Granularity"); var distinct = items.GetDistinctScores(); Int32 dC = distinct.Count(); output.AppendPair("Distinct", dC); output.AppendPair("Entries", scores.Count()); Double r = (Double)dC.GetRatio(scores.Count()); output.AppendPair("Distinct / Entries", r); output.AppendHeading("Cumulative histogram"); for (int i = 1; i < 11; i++) { Double l_min = (i - 1).GetRatio(10); Double l_max = i.GetRatio(10); var bin = scores.Where(x => (x > l_min) && (x < l_max)); Double per = bin.Count().GetRatio(scores.Count()); output.AppendPair("Bin [" + i + "][" + l_max.ToString("F2") + "]", per.ToString("P2")); } output.AppendHeading("Descriptive statistics"); DescriptiveStatistics desc = scores.GetStatistics(true); desc.Describe(output); output.AppendHeading("Document selection result"); foreach (DocumentSelectResultEntry result in items) { output.AppendLine(result.score.ToString("F5") + "\t\t" + result.AssignedID); } output.AppendHorizontalLine(); query.Describe(output); output.AppendHorizontalLine(); return(output); }
/// <summary> /// Publishes a new time-bound observation value of type 'Statistics' to the server. /// </summary> /// <param name="observationId">Observation identifier.</param> /// <param name="timestamp">Date and time in UTC.</param> /// <param name="value">Observation value.</param> /// <returns>True if successful, False otherwise.</returns> public bool PublishObservation(int observationId, DateTime timestamp, DescriptiveStatistics value) { StatisticsObservation o = new StatisticsObservation() { Timestamp = timestamp, Value = value }; string json = JsonConvert.SerializeObject(o); return(PublishObservationMessage(observationId, Encoding.UTF8.GetBytes(json))); }
public HistogramDataAndProperties() { dvData = DenseVector.Create(1, i => 0.0d); binsCount = 1; color = Color.Black; description = "histogram"; dvbinsCenters = (DenseVector)dvData.Clone(); stats = new DescriptiveStatistics(dvData); calculateProbDens(); CalculateQuantiles(); }
/// <summary> Determines whether a specified values are distributed in a 'uniformish' way: /// mean value is as expected, distribution is platykurtic and not skewed. </summary> /// <param name="randomValues">The random values.</param> /// <param name="minValue">The minimum possible value.</param> /// <param name="maxValue">The maximum possible value.</param> public static void IsUniformishDistribution(double[] randomValues, double minValue, double maxValue) { var statistics = new DescriptiveStatistics(randomValues); double meanMargin = (maxValue < 1) ? maxValue / 5 : 1; Assert.AreEqual((minValue + maxValue) / 2, statistics.Mean, meanMargin, "Expected mean differs to much from actual mean"); Assert.AreEqual(minValue, statistics.Minimum, "Expected min differs from actual min"); Assert.AreEqual(maxValue, statistics.Maximum, "Expected max differs from actual max"); Assert.AreEqual(0, statistics.Skewness, 0.1, "Distribution is skewed too much"); Assert.Less(statistics.Kurtosis, 0, "Distribution is not platykurtic at all"); }
public void D4D6DistributionShouldBeGood() { // We're combining several random dice, so distribution is not uniform at all, // since sums in lower range have higher chance of appearing. var statistics = new DescriptiveStatistics(rolls); Assert.AreEqual(cd4d6mr2t5.Minimum, statistics.Minimum, "Expected min differs from actual min"); Assert.AreEqual(cd4d6mr2t5.Maximum, statistics.Maximum, "Expected max differs from actual max"); Assert.AreEqual(5.25, statistics.Mean, 1, "Expected mean differs to much from actual mean"); Assert.Greater(statistics.Skewness, 0.2, "Distribution is not skewed enough"); Assert.Less(statistics.Kurtosis, 0, "Distribution is not platykurtic at all"); }
public void SampleTest() { //Variances and Means double[] Sdv = new double[2]; double[] Mean = new double[2]; for (int i = 0; i < 2; i++) { Sdv[i] = RandomVar(); Mean[i] = 5 * rnd.NextDouble(); } //Cross Variance double rho = 1.0 - RandomVar(); DensityLn <double[]> pdfLn = new DensityLn <double[]>(x => LogDen(x, Sdv, Mean, rho)); HybridMC Hybrid = new HybridMC(new double[2] { 0, 0 }, pdfLn, 10, 0.1, 1000); Hybrid.BurnInterval = 0; int SampleSize = 10000; double[][] Sample = Hybrid.Sample(SampleSize); double[][] NewSamples = ArrangeSamples(SampleSize, Sample); double[] Convergence = new double[2]; double[] SampleMean = new double[2]; double[] SampleSdv = new double[2]; for (int i = 0; i < 2; i++) { Convergence[i] = 1 / Math.Sqrt(MCMCDiagnostics.EffectiveSize(Sample, x => x[i])); DescriptiveStatistics Stats = new DescriptiveStatistics(NewSamples[i]); SampleMean[i] = Stats.Mean; SampleSdv[i] = Stats.StandardDeviation; } double SampleRho = Correlation.Pearson(NewSamples[0], NewSamples[1]); for (int i = 0; i < 2; i++) { string index = i.ToString(); Assert.AreEqual(Mean[i], SampleMean[i], 10 * Convergence[i], index + "Mean"); Assert.AreEqual(SampleSdv[i] * SampleSdv[i], Sdv[i] * Sdv[i], 10 * Convergence[i], index + "Standard Deviation"); } double ConvergenceRho = 1 / Math.Sqrt(MCMCDiagnostics.EffectiveSize(Sample, x => (x[0] - SampleMean[0]) * (x[1] - SampleMean[1]))); Assert.AreEqual(SampleRho * SampleSdv[0] * SampleSdv[1], rho * Sdv[0] * Sdv[1], 10 * ConvergenceRho, "Rho"); }
public void IEnumerableDoubleHighAccuracy(string dataSet, double skewness, double kurtosis, double median, double min, double max, int count) { var data = _data[dataSet]; var stats = new DescriptiveStatistics(data.Data, true); AssertHelpers.AlmostEqual(data.Mean, stats.Mean, 15); AssertHelpers.AlmostEqual(data.StandardDeviation, stats.StandardDeviation, 15); AssertHelpers.AlmostEqual(skewness, stats.Skewness, 9); AssertHelpers.AlmostEqual(kurtosis, stats.Kurtosis, 9); Assert.AreEqual(stats.Minimum, min); Assert.AreEqual(stats.Maximum, max); Assert.AreEqual(stats.Count, count); }
public DemoStats(double[][] dataMatrix) { var transpMatrix = MatrixFunction.TransposeMatrix(dataMatrix); Correlations = new CorrelationsAnalysis(transpMatrix, dataMatrix[0].Length - 1); Regressions = new RegressionAnalysis(dataMatrix, dataMatrix[0].Length - 1); Descriptive = new DescriptiveStatistics[transpMatrix.Length]; for (int i = 0; i < Descriptive.Length; ++i) { Descriptive[i] = new DescriptiveStatistics(transpMatrix[i]); } Forecast = new Forecast(dataMatrix, transpMatrix.Length - 1); }
public void IEnumerableNullableDoubleLowAccuracy(string dataSet, int digits, double skewness, double kurtosis, double median, double min, double max, int count) { var data = _data[dataSet]; var stats = new DescriptiveStatistics(data.DataWithNulls, false); AssertHelpers.AlmostEqualRelative(data.Mean, stats.Mean, 14); AssertHelpers.AlmostEqualRelative(data.StandardDeviation, stats.StandardDeviation, digits); AssertHelpers.AlmostEqualRelative(skewness, stats.Skewness, 7); AssertHelpers.AlmostEqualRelative(kurtosis, stats.Kurtosis, 7); Assert.AreEqual(stats.Minimum, min); Assert.AreEqual(stats.Maximum, max); Assert.AreEqual(stats.Count, count); }
public TimeSeries <T> ExtractDataDeviationValues() { if (typeof(T) != typeof(double)) { return(null); } DescriptiveStatistics stats = new DescriptiveStatistics(dataSeria as List <double>); List <double> lDevValues = (dataSeria as List <double>).ConvertAll <double>(dVal => dVal - stats.Mean); return(new TimeSeries <T>(lDevValues as List <T>, lDateTimeStamps)); }
void LoadFile(string path) { Table = new Table(path); Table.Normalize(); DescriptiveStatistics[] ds = new DescriptiveStatistics[Table.ColumnsCount]; for (int i = 0; i < Table.ColumnsCount; i++) { ds[i] = new DescriptiveStatistics(Table.Headers[i], Table.ColumnsValues[i]); } DS = ds; ChiSquaredIntervalsCount = 5; Correlations = new Correlations(Table, DS); }
public void ProcessATaxon(int taxon, double[] values) { var row = _dataTable.NewRow(); if (values.Length < _quantiles * LabTests.MinCountInQuantile) { return; } var stats = new DescriptiveStatistics(values); row["taxon"] = taxon; row["Mean"] = VerifyRange(stats.Mean); row["Minimum"] = VerifyRange(stats.Minimum); row["Maximum"] = VerifyRange(stats.Maximum); row["Skewness"] = VerifyRange(stats.Skewness); row["Kurtosis"] = VerifyRange(stats.Kurtosis); row["StandardDeviation"] = VerifyRange(stats.StandardDeviation); row["Variance"] = VerifyRange(stats.Variance); row["Count"] = VerifyRange(stats.Count); var index = 0.5 * (double)stats.Count; var indexLow = (int)Math.Floor(index); var indexHigh = (int)Math.Ceiling(index); if (indexHigh > values.Length - 1) { indexHigh = indexLow; } var qValue = (values[indexLow] + values[indexHigh]) / 2; row["Median"] = qValue; row["Mode"] = values.GroupBy(v => v) .OrderByDescending(g => g.Count()) .First() .Key; Array.Sort(values); for (double q = 1; q < _quantiles; q++) { index = q / _quantiles * (double)stats.Count; indexLow = (int)Math.Floor(index); indexHigh = (int)Math.Ceiling(index); if (indexHigh > values.Length - 1) { indexHigh = indexLow; } qValue = (values[indexLow] + values[indexHigh]) / 2; var colName = $"q{_quantiles}_{(int)q}"; row[colName] = qValue; } _dataTable.Rows.Add(row); }
public static MedidasEstadisticas DeterminarMedidasEstadisticas(IEnumerable <double> valores) { var medidas = new MedidasEstadisticas(); medidas.ValorMaximo = Statistics.Maximum(valores); medidas.ValorMinimo = Statistics.Minimum(valores); medidas.Media = Statistics.Mean(valores); medidas.TamanioDeLaMuestra = valores.Count(); medidas.Desviacion = Statistics.StandardDeviation(valores); var desc = new DescriptiveStatistics(samples); return(medidas); }
public void IEnumerableDouble(string dataSet, int digits, double skewness, double kurtosis, double median, double min, double max, int count) { StatTestData data = mData[dataSet]; DescriptiveStatistics stats = new DescriptiveStatistics(data.Data); AssertHelpers.AlmostEqual(data.Mean, stats.Mean, 15); AssertHelpers.AlmostEqual(data.StandardDeviation, stats.StandardDeviation, digits); AssertHelpers.AlmostEqual(skewness, stats.Skewness, 7); AssertHelpers.AlmostEqual(kurtosis, stats.Kurtosis, 7); AssertHelpers.AlmostEqual(median, stats.Median, 15); Assert.AreEqual(stats.Minimum, min); Assert.AreEqual(stats.Maximum, max); Assert.AreEqual(stats.Count, count); }
public void DescriptiveStatisticsDataContractSerializationTest() { var expected = new DescriptiveStatistics(new[] { 1.0, 2.0, 3.0 }); var serializer = new DataContractSerializer(typeof(DescriptiveStatistics)); var stream = new MemoryStream(); serializer.WriteObject(stream, expected); stream.Position = 0; var actual = (DescriptiveStatistics)serializer.ReadObject(stream); Assert.That(actual.Count, Is.EqualTo(expected.Count)); Assert.That(actual.Maximum, Is.EqualTo(expected.Maximum)); Assert.That(actual.Mean, Is.EqualTo(expected.Mean)); }
public void RunningStatisticsConsistentWithDescriptiveStatistics(string dataSet) { var data = _data[dataSet]; var running = new RunningStatistics(data.Data); var descriptive = new DescriptiveStatistics(data.Data); Assert.That(running.Minimum, Is.EqualTo(descriptive.Minimum), "Minimum"); Assert.That(running.Maximum, Is.EqualTo(descriptive.Maximum), "Maximum"); Assert.That(running.Mean, Is.EqualTo(descriptive.Mean).Within(1e-15), "Mean"); Assert.That(running.Variance, Is.EqualTo(descriptive.Variance).Within(1e-15), "Variance"); Assert.That(running.StandardDeviation, Is.EqualTo(descriptive.StandardDeviation).Within(1e-15), "StandardDeviation"); Assert.That(running.Skewness, Is.EqualTo(descriptive.Skewness).Within(1e-15), "Skewness"); Assert.That(running.Kurtosis, Is.EqualTo(descriptive.Kurtosis).Within(1e-14), "Kurtosis"); }
public void IEnumerableNullableDoubleLowAccuracy(string dataSet, int digits, double skewness, double kurtosis, double median, double min, double max, int count) { var data = _data[dataSet]; var stats = new DescriptiveStatistics(data.DataWithNulls, false); AssertHelpers.AlmostEqual(data.Mean, stats.Mean, 15); AssertHelpers.AlmostEqual(data.StandardDeviation, stats.StandardDeviation, digits); AssertHelpers.AlmostEqual(skewness, stats.Skewness, 7); AssertHelpers.AlmostEqual(kurtosis, stats.Kurtosis, 7); AssertHelpers.AlmostEqual(median, stats.Median, 15); Assert.AreEqual(stats.Minimum, min); Assert.AreEqual(stats.Maximum, max); Assert.AreEqual(stats.Count, count); }
/// <summary> /// Adds anova statistics to the gadget /// </summary> /// <param name="strataValue">The strata value associated with the results</param> /// <param name="stats">The descriptive statistics to process</param> private void AddAnova(string strataValue, DescriptiveStatistics stats) { Expander anovaExpander = new Expander(); anovaExpander.Margin = (Thickness)this.Resources["expanderMargin"]; anovaExpander.IsExpanded = true; StackPanel pnl = new StackPanel(); anovaExpander.Content = pnl; if (this.StrataCount > 1) { Expander expander = GetStrataExpander(strataValue); if (expander.Content is StackPanel) { StackPanel sPanel = expander.Content as StackPanel; sPanel.Children.Add(anovaExpander); } } else { panelMain.Children.Add(anovaExpander); } KeyValuePair<string, DescriptiveStatistics> ANOVAStatistics = new KeyValuePair<string, DescriptiveStatistics>(strataValue, stats); pnl.Tag = ANOVAStatistics; pnl.HorizontalAlignment = HorizontalAlignment.Center; pnl.VerticalAlignment = VerticalAlignment.Center; pnl.Margin = new Thickness(5); anovaBlocks.Add(pnl); TextBlock txt1 = new TextBlock(); txt1.Text = SharedStrings.ANOVA_DESCRIPTION_FOR_MEANS; txt1.HorizontalAlignment = HorizontalAlignment.Center; txt1.Margin = new Thickness(5); txt1.FontWeight = FontWeights.Bold; //pnl.Children.Add(txt1); anovaExpander.Header = txt1; #region Grid1 TextBlock txt2 = new TextBlock(); txt2.Text = SharedStrings.ANOVA_DESCRIPTION_FOR_MEANS_SUBTITLE; txt2.HorizontalAlignment = HorizontalAlignment.Center; pnl.Children.Add(txt2); Grid grid1 = new Grid(); grid1.SnapsToDevicePixels = true; grid1.HorizontalAlignment = HorizontalAlignment.Center; grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid1.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto }); pnl.Children.Add(grid1); for (int y = 0; y < grid1.ColumnDefinitions.Count; y++) { Rectangle rctHeader = new Rectangle(); rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style; Grid.SetRow(rctHeader, 0); Grid.SetColumn(rctHeader, y); grid1.Children.Add(rctHeader); } for (int y = 1; y < grid1.RowDefinitions.Count; y++) { Rectangle rctHeader = new Rectangle(); rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style; Grid.SetRow(rctHeader, y); Grid.SetColumn(rctHeader, 0); grid1.Children.Add(rctHeader); } TextBlock lblVariation = new TextBlock(); lblVariation.Text = SharedStrings.ANOVA_VARIATION; lblVariation.Margin = new Thickness(4, 0, 4, 0); lblVariation.FontWeight = FontWeights.Bold; lblVariation.Foreground = Brushes.White; lblVariation.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lblVariation.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(lblVariation); Grid.SetRow(lblVariation, 0); Grid.SetColumn(lblVariation, 0); TextBlock lblBetween = new TextBlock(); lblBetween.Text = SharedStrings.ANOVA_BETWEEN; lblBetween.Margin = new Thickness(4, 0, 4, 0); lblBetween.FontWeight = FontWeights.Bold; lblBetween.Foreground = Brushes.White; lblBetween.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lblBetween.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(lblBetween); Grid.SetRow(lblBetween, 1); Grid.SetColumn(lblBetween, 0); TextBlock lblWithin = new TextBlock(); lblWithin.Text = SharedStrings.ANOVA_WITHIN; lblWithin.Margin = new Thickness(4, 0, 4, 0); lblWithin.FontWeight = FontWeights.Bold; lblWithin.Foreground = Brushes.White; lblWithin.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lblWithin.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(lblWithin); Grid.SetRow(lblWithin, 2); Grid.SetColumn(lblWithin, 0); TextBlock lblTotal = new TextBlock(); lblTotal.Text = SharedStrings.ANOVA_TOTAL; lblTotal.Margin = new Thickness(4, 0, 4, 0); lblTotal.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lblTotal.VerticalAlignment = System.Windows.VerticalAlignment.Center; lblTotal.FontWeight = FontWeights.Bold; lblTotal.Foreground = Brushes.White; grid1.Children.Add(lblTotal); Grid.SetRow(lblTotal, 3); Grid.SetColumn(lblTotal, 0); TextBlock lblSS = new TextBlock(); lblSS.Text = SharedStrings.ANOVA_SS; lblSS.Margin = new Thickness(4, 0, 4, 0); lblSS.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lblSS.VerticalAlignment = System.Windows.VerticalAlignment.Center; lblSS.FontWeight = FontWeights.Bold; lblSS.Foreground = Brushes.White; grid1.Children.Add(lblSS); Grid.SetRow(lblSS, 0); Grid.SetColumn(lblSS, 1); TextBlock lblDf = new TextBlock(); lblDf.Text = SharedStrings.ANOVA_DF_SHORT; lblDf.Margin = new Thickness(4, 0, 4, 0); lblDf.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lblDf.VerticalAlignment = System.Windows.VerticalAlignment.Center; lblDf.FontWeight = FontWeights.Bold; lblDf.Foreground = Brushes.White; grid1.Children.Add(lblDf); Grid.SetRow(lblDf, 0); Grid.SetColumn(lblDf, 2); TextBlock lblMS = new TextBlock(); lblMS.Text = SharedStrings.ANOVA_MS; lblMS.Margin = new Thickness(4, 0, 4, 0); lblMS.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lblMS.VerticalAlignment = System.Windows.VerticalAlignment.Center; lblMS.FontWeight = FontWeights.Bold; lblMS.Foreground = Brushes.White; grid1.Children.Add(lblMS); Grid.SetRow(lblMS, 0); Grid.SetColumn(lblMS, 3); TextBlock lblF = new TextBlock(); lblF.Text = SharedStrings.ANOVA_F; lblF.Margin = new Thickness(4, 0, 4, 0); lblF.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; lblF.VerticalAlignment = System.Windows.VerticalAlignment.Center; lblF.FontWeight = FontWeights.Bold; lblF.Foreground = Brushes.White; grid1.Children.Add(lblF); Grid.SetRow(lblF, 0); Grid.SetColumn(lblF, 4); TextBlock txtSSBetween = new TextBlock(); txtSSBetween.Text = stats.ssBetween.Value.ToString("N4"); txtSSBetween.Margin = new Thickness(4, 0, 4, 0); txtSSBetween.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; txtSSBetween.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtSSBetween); Grid.SetRow(txtSSBetween, 1); Grid.SetColumn(txtSSBetween, 1); TextBlock txtSSWithin = new TextBlock(); txtSSWithin.Text = stats.ssWithin.Value.ToString("N4"); txtSSWithin.Margin = new Thickness(4, 0, 4, 0); txtSSWithin.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; txtSSWithin.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtSSWithin); Grid.SetRow(txtSSWithin, 2); Grid.SetColumn(txtSSWithin, 1); TextBlock txtSSTotal = new TextBlock(); txtSSTotal.Text = (stats.ssWithin.Value + stats.ssBetween.Value).ToString("N4"); txtSSTotal.Margin = new Thickness(4, 0, 4, 0); txtSSTotal.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; txtSSTotal.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtSSTotal); Grid.SetRow(txtSSTotal, 3); Grid.SetColumn(txtSSTotal, 1); TextBlock txtDFBetween = new TextBlock(); txtDFBetween.Text = stats.dfBetween.Value.ToString(); txtDFBetween.Margin = new Thickness(4, 0, 4, 0); txtDFBetween.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; txtDFBetween.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtDFBetween); Grid.SetRow(txtDFBetween, 1); Grid.SetColumn(txtDFBetween, 2); TextBlock txtDFWithin = new TextBlock(); txtDFWithin.Text = stats.dfWithin.Value.ToString(); txtDFWithin.Margin = new Thickness(4, 0, 4, 0); txtDFWithin.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; txtDFWithin.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtDFWithin); Grid.SetRow(txtDFWithin, 2); Grid.SetColumn(txtDFWithin, 2); TextBlock txtDFTotal = new TextBlock(); txtDFTotal.Text = (stats.dfWithin.Value + stats.dfBetween.Value).ToString(); txtDFTotal.Margin = new Thickness(4, 0, 4, 0); txtDFTotal.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; txtDFTotal.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtDFTotal); Grid.SetRow(txtDFTotal, 3); Grid.SetColumn(txtDFTotal, 2); TextBlock txtMSBetween = new TextBlock(); txtMSBetween.Text = stats.msBetween.Value.ToString("N4"); txtMSBetween.Margin = new Thickness(4, 0, 4, 0); txtMSBetween.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; txtMSBetween.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtMSBetween); Grid.SetRow(txtMSBetween, 1); Grid.SetColumn(txtMSBetween, 3); TextBlock txtMSWithin = new TextBlock(); txtMSWithin.Text = stats.msWithin.Value.ToString("N4"); txtMSWithin.Margin = new Thickness(4, 0, 4, 0); txtMSWithin.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; txtMSWithin.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtMSWithin); Grid.SetRow(txtMSWithin, 2); Grid.SetColumn(txtMSWithin, 3); TextBlock txtFStat = new TextBlock(); txtFStat.Text = stats.fStatistic.Value.ToString("N4"); txtFStat.Margin = new Thickness(4, 0, 4, 0); txtFStat.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; txtFStat.VerticalAlignment = System.Windows.VerticalAlignment.Center; grid1.Children.Add(txtFStat); Grid.SetRow(txtFStat, 1); Grid.SetColumn(txtFStat, 4); int rdcount = 0; foreach (RowDefinition rd in grid1.RowDefinitions) { int cdcount = 0; foreach (ColumnDefinition cd in grid1.ColumnDefinitions) { Border b = new Border(); b.Style = this.Resources["gridCellBorder"] as Style; if (rdcount == 0) { b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom); } if (cdcount == 0) { b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom); } Grid.SetRow(b, rdcount); Grid.SetColumn(b, cdcount); grid1.Children.Add(b); cdcount++; } rdcount++; } #endregion // Grid1 #region Grid2 Grid grid2 = new Grid(); grid2.SnapsToDevicePixels = true; grid2.Margin = new Thickness(5); grid2.HorizontalAlignment = HorizontalAlignment.Center; grid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(110) }); grid2.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(95) }); pnl.Children.Add(grid2); for (int y = 0; y < grid2.RowDefinitions.Count; y++) { Rectangle rctHeader = new Rectangle(); rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style; Grid.SetRow(rctHeader, y); Grid.SetColumn(rctHeader, 0); grid2.Children.Add(rctHeader); } TextBlock lblPValue = new TextBlock(); lblPValue.Text = SharedStrings.ANOVA_P_VAL; lblPValue.HorizontalAlignment = HorizontalAlignment.Center; lblPValue.VerticalAlignment = VerticalAlignment.Center; lblPValue.FontWeight = FontWeights.Bold; lblPValue.Foreground = Brushes.White; Grid.SetRow(lblPValue, 0); Grid.SetColumn(lblPValue, 0); grid2.Children.Add(lblPValue); TextBlock txtPValue = new TextBlock(); txtPValue.Text = stats.anovaPValue.Value.ToString("N4"); txtPValue.HorizontalAlignment = HorizontalAlignment.Center; txtPValue.VerticalAlignment = VerticalAlignment.Center; Grid.SetRow(txtPValue, 0); Grid.SetColumn(txtPValue, 1); grid2.Children.Add(txtPValue); rdcount = 0; foreach (RowDefinition rd in grid2.RowDefinitions) { int cdcount = 0; foreach (ColumnDefinition cd in grid2.ColumnDefinitions) { Border b = new Border(); b.Style = this.Resources["gridCellBorder"] as Style; if (rdcount == 0) { b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom); } if (cdcount == 0) { b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom); } Grid.SetRow(b, rdcount); Grid.SetColumn(b, cdcount); grid2.Children.Add(b); cdcount++; } rdcount++; } #endregion // Grid2 #region Grid3 TextBlock txt3 = new TextBlock(); txt3.Text = SharedStrings.ANOVA_BARTLETT; txt3.HorizontalAlignment = HorizontalAlignment.Center; txt3.Margin = new Thickness(5); txt3.FontWeight = FontWeights.Bold; pnl.Children.Add(txt3); Grid grid3 = new Grid(); grid3.SnapsToDevicePixels = true; grid3.Margin = new Thickness(5); grid3.HorizontalAlignment = HorizontalAlignment.Center; grid3.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid3.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid3.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid3.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(110) }); grid3.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(95) }); pnl.Children.Add(grid3); for (int y = 0; y < grid3.RowDefinitions.Count; y++) { Rectangle rctHeader = new Rectangle(); rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style; Grid.SetRow(rctHeader, y); Grid.SetColumn(rctHeader, 0); grid3.Children.Add(rctHeader); } TextBlock lblBartlettChi = new TextBlock(); lblBartlettChi.Text = SharedStrings.ANOVA_CHI; lblBartlettChi.HorizontalAlignment = HorizontalAlignment.Center; lblBartlettChi.VerticalAlignment = VerticalAlignment.Center; lblBartlettChi.FontWeight = FontWeights.Bold; lblBartlettChi.Foreground = Brushes.White; Grid.SetRow(lblBartlettChi, 0); Grid.SetColumn(lblBartlettChi, 0); grid3.Children.Add(lblBartlettChi); TextBlock lblBartlettDf = new TextBlock(); lblBartlettDf.Text = SharedStrings.ANOVA_DF_LONG; lblBartlettDf.HorizontalAlignment = HorizontalAlignment.Center; lblBartlettDf.VerticalAlignment = VerticalAlignment.Center; lblBartlettDf.FontWeight = FontWeights.Bold; lblBartlettDf.Foreground = Brushes.White; Grid.SetRow(lblBartlettDf, 1); Grid.SetColumn(lblBartlettDf, 0); grid3.Children.Add(lblBartlettDf); TextBlock lblBartlettP = new TextBlock(); lblBartlettP.Text = SharedStrings.ANOVA_P_VAL; lblBartlettP.HorizontalAlignment = HorizontalAlignment.Center; lblBartlettP.VerticalAlignment = VerticalAlignment.Center; lblBartlettP.FontWeight = FontWeights.Bold; lblBartlettP.Foreground = Brushes.White; Grid.SetRow(lblBartlettP, 2); Grid.SetColumn(lblBartlettP, 0); grid3.Children.Add(lblBartlettP); TextBlock txtBartlettChi = new TextBlock(); txtBartlettChi.Text = stats.chiSquare.Value.ToString("N4"); txtBartlettChi.HorizontalAlignment = HorizontalAlignment.Center; txtBartlettChi.VerticalAlignment = VerticalAlignment.Center; Grid.SetRow(txtBartlettChi, 0); Grid.SetColumn(txtBartlettChi, 1); grid3.Children.Add(txtBartlettChi); TextBlock txtBartlettDf = new TextBlock(); txtBartlettDf.Text = stats.dfBetween.Value.ToString(); txtBartlettDf.HorizontalAlignment = HorizontalAlignment.Center; txtBartlettDf.VerticalAlignment = VerticalAlignment.Center; Grid.SetRow(txtBartlettDf, 1); Grid.SetColumn(txtBartlettDf, 1); grid3.Children.Add(txtBartlettDf); TextBlock txtBartlettP = new TextBlock(); txtBartlettP.Text = stats.bartlettPValue.Value.ToString("N4"); txtBartlettP.HorizontalAlignment = HorizontalAlignment.Center; txtBartlettP.VerticalAlignment = VerticalAlignment.Center; Grid.SetRow(txtBartlettP, 2); Grid.SetColumn(txtBartlettP, 1); grid3.Children.Add(txtBartlettP); rdcount = 0; foreach (RowDefinition rd in grid3.RowDefinitions) { int cdcount = 0; foreach (ColumnDefinition cd in grid3.ColumnDefinitions) { Border b = new Border(); b.Style = this.Resources["gridCellBorder"] as Style; if (rdcount == 0) { b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom); } if (cdcount == 0) { b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom); } Grid.SetRow(b, rdcount); Grid.SetColumn(b, cdcount); grid3.Children.Add(b); cdcount++; } rdcount++; } TextBlock txt4 = new TextBlock(); txt4.Text = SharedStrings.ANOVA_SMALL_P; txt4.HorizontalAlignment = HorizontalAlignment.Center; txt4.Margin = new Thickness(5); pnl.Children.Add(txt4); TextBlock txt5 = new TextBlock(); txt5.Text = SharedStrings.ANOVA_MWWTST; txt5.HorizontalAlignment = HorizontalAlignment.Center; txt5.Margin = new Thickness(5); txt5.FontWeight = FontWeights.Bold; pnl.Children.Add(txt5); #endregion // Grid3 #region Grid4 Grid grid4 = new Grid(); grid4.SnapsToDevicePixels = true; grid4.Margin = new Thickness(5); grid4.HorizontalAlignment = HorizontalAlignment.Center; grid4.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid4.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid4.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(30) }); grid4.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(110) }); grid4.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(95) }); pnl.Children.Add(grid4); for (int y = 0; y < grid4.RowDefinitions.Count; y++) { Rectangle rctHeader = new Rectangle(); rctHeader.Style = this.Resources["gridHeaderCellRectangle"] as Style; Grid.SetRow(rctHeader, y); Grid.SetColumn(rctHeader, 0); grid4.Children.Add(rctHeader); } TextBlock lblKWChi = new TextBlock(); lblKWChi.Text = SharedStrings.ANOVA_KWH; lblKWChi.HorizontalAlignment = HorizontalAlignment.Center; lblKWChi.VerticalAlignment = VerticalAlignment.Center; lblKWChi.FontWeight = FontWeights.Bold; lblKWChi.Foreground = Brushes.White; Grid.SetRow(lblKWChi, 0); Grid.SetColumn(lblKWChi, 0); grid4.Children.Add(lblKWChi); TextBlock lblKWDf = new TextBlock(); lblKWDf.Text = SharedStrings.ANOVA_DF_LONG; lblKWDf.HorizontalAlignment = HorizontalAlignment.Center; lblKWDf.VerticalAlignment = VerticalAlignment.Center; lblKWDf.FontWeight = FontWeights.Bold; lblKWDf.Foreground = Brushes.White; Grid.SetRow(lblKWDf, 1); Grid.SetColumn(lblKWDf, 0); grid4.Children.Add(lblKWDf); TextBlock lblKWP = new TextBlock(); lblKWP.Text = SharedStrings.ANOVA_P_VAL; lblKWP.HorizontalAlignment = HorizontalAlignment.Center; lblKWP.VerticalAlignment = VerticalAlignment.Center; lblKWP.FontWeight = FontWeights.Bold; lblKWP.Foreground = Brushes.White; Grid.SetRow(lblKWP, 2); Grid.SetColumn(lblKWP, 0); grid4.Children.Add(lblKWP); TextBlock txtKWChi = new TextBlock(); txtKWChi.Text = stats.kruskalWallisH.Value.ToString("N4"); txtKWChi.HorizontalAlignment = HorizontalAlignment.Center; txtKWChi.VerticalAlignment = VerticalAlignment.Center; Grid.SetRow(txtKWChi, 0); Grid.SetColumn(txtKWChi, 1); grid4.Children.Add(txtKWChi); TextBlock txtWKDf = new TextBlock(); txtWKDf.Text = stats.dfBetween.Value.ToString(); txtWKDf.HorizontalAlignment = HorizontalAlignment.Center; txtWKDf.VerticalAlignment = VerticalAlignment.Center; Grid.SetRow(txtWKDf, 1); Grid.SetColumn(txtWKDf, 1); grid4.Children.Add(txtWKDf); TextBlock txtKWP = new TextBlock(); txtKWP.Text = stats.kruskalPValue.Value.ToString("N4"); txtKWP.HorizontalAlignment = HorizontalAlignment.Center; txtKWP.VerticalAlignment = VerticalAlignment.Center; Grid.SetRow(txtKWP, 2); Grid.SetColumn(txtKWP, 1); grid4.Children.Add(txtKWP); rdcount = 0; foreach (RowDefinition rd in grid4.RowDefinitions) { int cdcount = 0; foreach (ColumnDefinition cd in grid4.ColumnDefinitions) { Border b = new Border(); b.Style = this.Resources["gridCellBorder"] as Style; if (rdcount == 0) { b.BorderThickness = new Thickness(b.BorderThickness.Left, 1, b.BorderThickness.Right, b.BorderThickness.Bottom); } if (cdcount == 0) { b.BorderThickness = new Thickness(1, b.BorderThickness.Top, b.BorderThickness.Right, b.BorderThickness.Bottom); } Grid.SetRow(b, rdcount); Grid.SetColumn(b, cdcount); grid4.Children.Add(b); cdcount++; } rdcount++; } #endregion // Grid4 //panelMain.Children.Add(pnl); }
/// <summary> /// Converts the gadget's output to Html /// </summary> /// <returns></returns> public override string ToHTML(string htmlFileName = "", int count = 0) { StringBuilder htmlBuilder = new StringBuilder(); CustomOutputHeading = headerPanel.Text; CustomOutputDescription = descriptionPanel.Text; if (CustomOutputHeading == null || (string.IsNullOrEmpty(CustomOutputHeading) && !CustomOutputHeading.Equals("(none)"))) { htmlBuilder.AppendLine("<h2 class=\"gadgetHeading\">Means</h2>"); } else if (CustomOutputHeading != "(none)") { htmlBuilder.AppendLine("<h2 class=\"gadgetHeading\">" + CustomOutputHeading + "</h2>"); } htmlBuilder.AppendLine("<p class=\"gadgetOptions\"><small>"); htmlBuilder.AppendLine("<em>Main variable:</em> <strong>" + cbxField.Text + "</strong>"); htmlBuilder.AppendLine("<br />"); if (cbxFieldCrosstab.SelectedIndex >= 0) { htmlBuilder.AppendLine("<em>Crosstab variable:</em> <strong>" + cbxFieldCrosstab.Text + "</strong>"); htmlBuilder.AppendLine("<br />"); } if (cbxFieldWeight.SelectedIndex >= 0) { htmlBuilder.AppendLine("<em>Weight variable:</em> <strong>" + cbxFieldWeight.Text + "</strong>"); htmlBuilder.AppendLine("<br />"); } if (cbxFieldStrata.SelectedIndex >= 0) { htmlBuilder.AppendLine("<em>Strata variable:</em> <strong>" + cbxFieldStrata.Text + "</strong>"); htmlBuilder.AppendLine("<br />"); } htmlBuilder.AppendLine("</small></p>"); if (!string.IsNullOrEmpty(CustomOutputDescription)) { htmlBuilder.AppendLine("<p class=\"gadgetsummary\">" + CustomOutputDescription + "</p>"); } if (!string.IsNullOrEmpty(messagePanel.Text) && messagePanel.Visibility == Visibility.Visible) { htmlBuilder.AppendLine("<p><small><strong>" + messagePanel.Text + "</strong></small></p>"); } if (!string.IsNullOrEmpty(infoPanel.Text) && infoPanel.Visibility == Visibility.Visible) { htmlBuilder.AppendLine("<p><small><strong>" + infoPanel.Text + "</strong></small></p>"); } // Each grid in the 'strataGridList' has a tag associated with it which tells us which strata // that grid is for. For example, if we stratify by 'Sex' in the Oswego table (in Sample.prj) // we will have two grids in strataGridList, one for males and one for females. The tags will // be 'Sex = Male' and 'Sex = Female', respectively. foreach (Grid grid in this.strataGridList) { string gridName = grid.Tag.ToString(); string summaryText = "This tables contains several descriptive statistics for the field " + cbxField.Text + ". "; if (!string.IsNullOrEmpty(cbxFieldWeight.Text)) { summaryText += "The field " + cbxFieldWeight.Text + " has been specified as a weight. "; } if (!string.IsNullOrEmpty(cbxFieldStrata.Text)) { summaryText += "The data has been stratified. The data in this table is for the strata value " + grid.Tag.ToString() + ". "; } if (!string.IsNullOrEmpty(cbxFieldCrosstab.Text)) { summaryText += "The data has been cross-tabulated; there will be one data row for each value of " + cbxFieldCrosstab.Text + ". "; } summaryText += "The column headings are: The description of the data, the total number of observations, the sum of the observations, the mean, the variance, the standard deviation, the minimum observed value, the 25% value, the median value, the 75% value, the maximum, and the mode."; htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>"); htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"" + summaryText + "\">"); htmlBuilder.AppendLine("<caption>" + gridName + "</caption>"); foreach (UIElement control in grid.Children) { if (control is TextBlock) { int rowNumber = Grid.GetRow(control); int columnNumber = Grid.GetColumn(control); string tableDataTagOpen = "<td>"; string tableDataTagClose = "</td>"; if (rowNumber == 0) { tableDataTagOpen = "<th>"; tableDataTagClose = "</th>"; } if (columnNumber == 0) { htmlBuilder.AppendLine("<tr>"); } if (columnNumber == 0 && rowNumber > 0) { tableDataTagOpen = "<td class=\"value\">"; } string value = ((TextBlock)control).Text; string formattedValue = value; htmlBuilder.AppendLine(tableDataTagOpen + formattedValue + tableDataTagClose); if (columnNumber >= grid.ColumnDefinitions.Count - 1) { htmlBuilder.AppendLine("</tr>"); } } } htmlBuilder.AppendLine("</table>"); // We must find the specific stack panel that corresponds to this strata value from the list of // ANOVA panels in the gadget. The 'tag' property of the panel is a key value pair that contains // the strata value we need, plus the set of descriptive statistics that we must display in the // output. StackPanel anovaPanel = null; DescriptiveStatistics statistics = new DescriptiveStatistics(); foreach (StackPanel panel in anovaBlocks) { if(panel.Tag is KeyValuePair<string, DescriptiveStatistics>) { KeyValuePair<string, DescriptiveStatistics> kvp = ((KeyValuePair<string, DescriptiveStatistics>)panel.Tag); if (kvp.Key.Equals(gridName)) { anovaPanel = panel; statistics = kvp.Value; break; // no sense in continuning } } } // check to make sure we actually found one if (!(anovaPanel == null)) { string strssBetweenValue = SharedStrings.UNDEFINED; string strdfBetweenValue = SharedStrings.UNDEFINED; string strmsBetweenValue = SharedStrings.UNDEFINED; string strssWithinValue = SharedStrings.UNDEFINED; string strdfWithinValue = SharedStrings.UNDEFINED; string strmsWithinValue = SharedStrings.UNDEFINED; string strfStatisticValue = SharedStrings.UNDEFINED; string stranovaPValueValue = SharedStrings.UNDEFINED; string stranovaTValueValue = SharedStrings.UNDEFINED; string strchiSquareValue = SharedStrings.UNDEFINED; string strbartlettPValue = SharedStrings.UNDEFINED; string strTotalSSValue = SharedStrings.UNDEFINED; string strTotalDFValue = SharedStrings.UNDEFINED; string strKruskalWallisH = SharedStrings.UNDEFINED; string strKruskalPValue = SharedStrings.UNDEFINED; if (statistics.ssBetween.HasValue) { strssBetweenValue = statistics.ssBetween.Value.ToString("F4"); } if (statistics.dfBetween.HasValue) { strdfBetweenValue = statistics.dfBetween.Value.ToString("F0"); } if (statistics.msBetween.HasValue) { strmsBetweenValue = statistics.msBetween.Value.ToString("F4"); } if (statistics.ssWithin.HasValue) { strssWithinValue = statistics.ssWithin.Value.ToString("F4"); } if (statistics.dfWithin.HasValue) { strdfWithinValue = statistics.dfWithin.Value.ToString("F0"); } if (statistics.msWithin.HasValue) { strmsWithinValue = statistics.msWithin.Value.ToString("F4"); } if (statistics.fStatistic.HasValue) { strfStatisticValue = statistics.fStatistic.Value.ToString("F4"); } if (statistics.anovaPValue.HasValue) { stranovaPValueValue = statistics.anovaPValue.Value.ToString("F4"); } if (statistics.chiSquare.HasValue) { strchiSquareValue = statistics.chiSquare.Value.ToString("F4"); } if (statistics.bartlettPValue.HasValue) { strbartlettPValue = statistics.bartlettPValue.Value.ToString("F4"); } if (statistics.ssBetween.HasValue && statistics.ssWithin.HasValue) { strTotalSSValue = (statistics.ssBetween.Value + statistics.ssWithin.Value).ToString("F4"); } if (statistics.dfBetween.HasValue && statistics.dfWithin.HasValue) { strTotalDFValue = (statistics.dfBetween.Value + statistics.dfWithin.Value).ToString("F0"); } if (statistics.kruskalWallisH.HasValue) { strKruskalWallisH = statistics.kruskalWallisH.Value.ToString("F4"); } if (statistics.kruskalPValue.HasValue) { strKruskalPValue = statistics.kruskalPValue.Value.ToString("F4"); } summaryText = "This table contains analysis of variance (ANOVA) statistics for the field " + cbxField.Text + ", cross-tabulated by " + cbxFieldCrosstab.Text + ". "; summaryText += "The column headings for this table are: The variation, the SS value, the degrees of freedom, the MS value, and the F-statistic. There are three rows: The between, the within, and the total."; // ANOVA htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>"); htmlBuilder.AppendLine("<p><strong>" + SharedStrings.ANOVA_DESCRIPTION_FOR_MEANS + "</strong><br />"); htmlBuilder.AppendLine("<small>" + SharedStrings.ANOVA_DESCRIPTION_FOR_MEANS_SUBTITLE + "</small></p>"); htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"" + summaryText + "\">"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>Variation</th>"); htmlBuilder.AppendLine(" <th>SS</th>"); htmlBuilder.AppendLine(" <th>df</th>"); htmlBuilder.AppendLine(" <th>MS</th>"); htmlBuilder.AppendLine(" <th>F statistic</th>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>Between</th>"); htmlBuilder.AppendLine(" <td>" + strssBetweenValue + "</td>"); htmlBuilder.AppendLine(" <td>" + strdfBetweenValue + "</td>"); htmlBuilder.AppendLine(" <td>" + strmsBetweenValue + "</td>"); htmlBuilder.AppendLine(" <td>" + strfStatisticValue + "</td>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>Within</th>"); htmlBuilder.AppendLine(" <td>" + strssWithinValue + "</td>"); htmlBuilder.AppendLine(" <td>" + strdfWithinValue + "</td>"); htmlBuilder.AppendLine(" <td>" + strmsWithinValue + "</td>"); htmlBuilder.AppendLine(" <td> </td>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>Total</th>"); htmlBuilder.AppendLine(" <td>" + strTotalSSValue + "</td>"); htmlBuilder.AppendLine(" <td>" + strTotalDFValue + "</td>"); htmlBuilder.AppendLine(" <td> </td>"); htmlBuilder.AppendLine(" <td> </td>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine("</table>"); htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>"); htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" summary=\"This table contains the ANOVA p-value.\">"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>P Value</th>"); htmlBuilder.AppendLine(" <td>" + stranovaPValueValue + "</td>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine("</table>"); // Bartlett htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>"); htmlBuilder.AppendLine("<p><strong>Bartlett's Test for Inequality of Population Variances</strong></p>"); htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>Chi Square</th>"); htmlBuilder.AppendLine(" <td>" + strchiSquareValue + "</td>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>Degrees of freedom</th>"); htmlBuilder.AppendLine(" <td>" + strdfBetweenValue + "</td>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>P Value</th>"); htmlBuilder.AppendLine(" <td>" + strbartlettPValue + "</td>"); htmlBuilder.AppendLine("</table>"); htmlBuilder.AppendLine("<p><small>A small p-value (e.g., less than 0.05) suggests that the variances are not homogeneous and that the ANOVA may not be appropriate.</small></p>"); // Kruskal-Wallis htmlBuilder.AppendLine("<div style=\"height: 7px;\"></div>"); htmlBuilder.AppendLine("<p><strong>Mann-Whitney/Wilcoxon Two-Sample Test (Kruskal-Wallis test for two groups)</strong></p>"); htmlBuilder.AppendLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>Kruskal-Wallis H</th>"); htmlBuilder.AppendLine(" <td>" + strKruskalWallisH + "</td>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>Degrees of freedom</th>"); htmlBuilder.AppendLine(" <td>" + strdfBetweenValue + "</td>"); htmlBuilder.AppendLine(" </tr>"); htmlBuilder.AppendLine(" <tr>"); htmlBuilder.AppendLine(" <th>P Value</th>"); htmlBuilder.AppendLine(" <td>" + strKruskalPValue + "</td>"); htmlBuilder.AppendLine("</table>"); } } return htmlBuilder.ToString(); }
public void IEnumerableDoubleHighAccuracy(string dataSet, double skewness, double kurtosis, double median, double min, double max, int count) { var data = _data[dataSet]; var stats = new DescriptiveStatistics(data.Data, true); AssertHelpers.AlmostEqualRelative(data.Mean, stats.Mean, 14); AssertHelpers.AlmostEqualRelative(data.StandardDeviation, stats.StandardDeviation, 14); AssertHelpers.AlmostEqualRelative(skewness, stats.Skewness, 9); AssertHelpers.AlmostEqualRelative(kurtosis, stats.Kurtosis, 9); Assert.AreEqual(stats.Minimum, min); Assert.AreEqual(stats.Maximum, max); Assert.AreEqual(stats.Count, count); }
public void IEnumerableDouble( [Values("lottery", "lew", "mavro", "michelso", "numacc1", "numacc2", "numacc3", "numacc4")] string dataSet, [Values(15, 15, 12, 12, 15, 13, 9, 8)] int digits, [Values(-0.09333165310779, -0.050606638756334, 0.64492948110824, -0.0185388637725746, 0, 0, 0, 0)] double skewness, [Values(-1.19256091074856, -1.49604979214447, -0.82052379677456, 0.33968459842539, 0, -2.003003003003, -2.003003003003, -2.00300300299913)] double kurtosis, [Values(522.5, -162, 2.0018, 299.85, 10000002, 1.2, 1000000.2, 10000000.2)] double median, [Values(4, -579, 2.0013, 299.62, 10000001, 1.1, 1000000.1, 10000000.1)] double min, [Values(999, 300, 2.0027, 300.07, 10000003, 1.3, 1000000.3, 10000000.3)] double max, [Values(218, 200, 50, 100, 3, 1001, 1001, 1001)] int count) { var data = _data[dataSet]; var stats = new DescriptiveStatistics(data.Data); AssertHelpers.AlmostEqual(data.Mean, stats.Mean, 15); AssertHelpers.AlmostEqual(data.StandardDeviation, stats.StandardDeviation, digits); AssertHelpers.AlmostEqual(skewness, stats.Skewness, 7); AssertHelpers.AlmostEqual(kurtosis, stats.Kurtosis, 7); AssertHelpers.AlmostEqual(median, stats.Median, 15); Assert.AreEqual(stats.Minimum, min); Assert.AreEqual(stats.Maximum, max); Assert.AreEqual(stats.Count, count); }