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; //} }
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; //} }