public static bool Test(Distribution distribution) { var dataCount = 10000000; var dataSampling = new List <double>(); for (var i = 0; i < dataCount; i++) { dataSampling.Add(distribution.GetNewRandomValue()); } dataSampling.Sort(); // Определяем кол-во интервалов для разбиения по формуле Стерджеса var numberOfIntervals = (int)Math.Ceiling(1 + 3.322 * Math.Log10(dataCount)); numberOfIntervals = 100; var(pdfValuesExpected, pdfValuesActual) = CalculateExpectedAndActualPDFValues(distribution, dataSampling.ToArray()); var chiSquareTest = new Test(pdfValuesExpected, pdfValuesActual, numberOfIntervals - 1); var significant = chiSquareTest.Significant; return(!significant); }
public void getReport(double alpha) { if (gConf == null) { buildModel(); } Forms.RunningProcess.frmRunningProcessDialog rd = new Forms.RunningProcess.frmRunningProcessDialog(false); rd.Text = "Accuracy Assessment"; rd.TopLevel = true; rd.pgbProcess.Visible = false; rd.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; string[] hd = new string[labels.Count]; for (int i = 0; i < hd.Length; i++) { string s = labels[i]; if (s.Length > 4) { hd[i] = s.Substring(0, 4); } else { hd[i] = s.PadRight(3); } } rd.addMessage(" " + String.Join(" ", hd)); rd.addMessage("------".PadRight((labels.Count + 1) * 7, '-')); for (int i = 0; i < labels.Count; i++) { string[] lnArr = new string[labels.Count + 1]; string vl = labels[i]; if (vl.Length > 4) { vl = vl.Substring(0, 4); } else { vl = vl.PadRight(4); } lnArr[0] = vl; for (int j = 0; j < labels.Count; j++) { vl = xtable[i, j].ToString(); if (vl.Length < 4) { vl = vl.PadRight(4); } lnArr[j + 1] = vl; } rd.addMessage(String.Join(" | ", lnArr) + "|"); rd.addMessage("------".PadRight((labels.Count + 1) * 7, '-')); } Accord.Statistics.Testing.ChiSquareTest ct = new Accord.Statistics.Testing.ChiSquareTest(ChiSquare, System.Convert.ToInt32(Math.Pow(labels.Count - 1, 2))); rd.addMessage("Chi-square = " + ChiSquare + " DF = " + ct.DegreesOfFreedom.ToString() + " p-value = " + ct.PValue.ToString()); rd.addMessage("Overall = " + Overall.ToString()); rd.addMessage("Kappa = " + Kappa.ToString()); rd.addMessage("STE = " + STE.ToString()); ci conf = getConfidenceInterval(alpha); rd.addMessage("Kappa CI = " + conf.LowerBound.ToString() + " - " + conf.UpperBound.ToString()); rd.addMessage("Cohen Kappa Variance = " + CohenKappaVariance.ToString()); rd.Show(); rd.enableClose(); }
public void getReport(double alpha) { if(gConf==null)buildModel(); Forms.RunningProcess.frmRunningProcessDialog rd = new Forms.RunningProcess.frmRunningProcessDialog(false); rd.Text = "Accuracy Assessment"; rd.TopLevel = true; rd.pgbProcess.Visible = false; rd.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; string[] hd = new string[labels.Count]; for (int i = 0; i < hd.Length; i++) { string s = labels[i]; if(s.Length>4) { hd[i] = s.Substring(0, 4); } else { hd[i] = s.PadRight(3); } } rd.addMessage(" "+String.Join(" ", hd)); rd.addMessage("------".PadRight((labels.Count+1)*7,'-')); for (int i = 0; i < labels.Count; i++) { string[] lnArr = new string[labels.Count+1]; string vl = labels[i]; if (vl.Length > 4) { vl = vl.Substring(0, 4); } else { vl = vl.PadRight(4); } lnArr[0] = vl; for (int j = 0; j < labels.Count; j++) { vl = xtable[i,j].ToString(); if (vl.Length < 4) { vl = vl.PadRight(4); } lnArr[j + 1] = vl; } rd.addMessage(String.Join(" | ", lnArr)+"|"); rd.addMessage("------".PadRight((labels.Count+1) * 7, '-')); } Accord.Statistics.Testing.ChiSquareTest ct = new Accord.Statistics.Testing.ChiSquareTest(ChiSquare, System.Convert.ToInt32(Math.Pow(labels.Count - 1, 2))); rd.addMessage("Chi-square = " + ChiSquare + " DF = " + ct.DegreesOfFreedom.ToString() + " p-value = " + ct.PValue.ToString()); rd.addMessage("Overall = " + Overall.ToString()); rd.addMessage("Kappa = " + Kappa.ToString()); rd.addMessage("STE = " + STE.ToString()); ci conf = getConfidenceInterval(alpha); rd.addMessage("Kappa CI = " + conf.LowerBound.ToString() + " - " + conf.UpperBound.ToString()); rd.addMessage("Cohen Kappa Variance = " + CohenKappaVariance.ToString()); rd.Show(); rd.enableClose(); }
private void buildModel() { if (independentVls == null) { getMatrix(); } Accord.Statistics.Links.ILinkFunction lFunc = new Accord.Statistics.Links.IdentityLinkFunction(); switch (Link) { case LinkFunction.Absolute: lFunc = new Accord.Statistics.Links.AbsoluteLinkFunction(); break; case LinkFunction.Cauchit: lFunc = new Accord.Statistics.Links.CauchitLinkFunction(); break; case LinkFunction.Inverse: lFunc = new Accord.Statistics.Links.InverseLinkFunction(); break; case LinkFunction.InverseSquared: lFunc = new Accord.Statistics.Links.InverseSquaredLinkFunction(); break; case LinkFunction.Logit: lFunc = new Accord.Statistics.Links.LogitLinkFunction(); break; case LinkFunction.Log: lFunc = new Accord.Statistics.Links.LogLinkFunction(); break; case LinkFunction.LogLog: lFunc = new Accord.Statistics.Links.LogLogLinkFunction(); break; case LinkFunction.Probit: lFunc = new Accord.Statistics.Links.ProbitLinkFunction(); break; case LinkFunction.Sin: lFunc = new Accord.Statistics.Links.SinLinkFunction(); break; case LinkFunction.Threshold: lFunc = new Accord.Statistics.Links.ThresholdLinkFunction(); break; default: break; } glm = new Accord.Statistics.Models.Regression.GeneralizedLinearRegression(lFunc, NumberOfVariables); Accord.Statistics.Models.Regression.Fitting.IterativeReweightedLeastSquares isl = new Accord.Statistics.Models.Regression.Fitting.IterativeReweightedLeastSquares(glm); delta = 0; do { delta = isl.Run(independentVls, dependentVls); iterations += 1; }while (delta > converge && iterations < totiterations); coefficients = glm.Coefficients; stdError = glm.StandardErrors; loglikelihood = glm.GetLogLikelihood(independentVls, dependentVls); if (Double.IsNaN(loglikelihood)) { loglikelihood = 0; } loglikelihoodratio = glm.GetLogLikelihoodRatio(independentVls, dependentVls, glm); if (Double.IsNaN(loglikelihoodratio)) { loglikelihoodratio = 0; } deviance = glm.GetDeviance(independentVls, dependentVls); if (Double.IsNaN(deviance)) { deviance = 0; } Accord.Statistics.Testing.ChiSquareTest chiTest = glm.ChiSquare(independentVls, dependentVls); pv = chiTest.PValue; if (Double.IsNaN(pv)) { pv = 0; } chisqr = chiTest.Statistic; if (double.IsNaN(chisqr)) { chisqr = 0; } waldTestValues = new double[IndependentFieldNames.Length]; waldTestPValues = new double[waldTestValues.Length]; for (int i = 0; i < waldTestValues.Length; i++) { Accord.Statistics.Testing.WaldTest wTest = glm.GetWaldTest(i); double wS = wTest.Statistic; double wP = wTest.PValue; //if (Double.IsNaN(wS)) wS = 0; //if (Double.IsNaN(wP)) wP = 0; waldTestValues[i] = wS; waldTestPValues[i] = wP; } //if (stdError.Length != coefficients.Length) stdError = new double[coefficients.Length]; //for (int i = 0; i < stdError.Length; i++) //{ // double vl = stdError[i]; // if (Double.IsNaN(vl)) stdError[i] = 0; //} }