void CalcEstimates() { int n = XMat.GetLength(0), k = XMat.GetLength(1) - 1; // коэффициенты, необходимые далее double Qost = CalculatedY.Zip(RealY, (a, b) => (a - b) * (a - b)).Sum(); double QR = Matrix.ScalarMul(CalculatedY, CalculatedY); S2 = Qost / (n - k - 1); // точечная оценка регресии F = (QR / (k + 1)) / (Qost / (n - k - 1)); FCritical = FisherTable.GetValue(k + 1, n - k - 1); // точечная оценка параметров регрессии double[] Sb = Enumerable.Range(0, k + 1) .Select(j => Math.Sqrt(S2 * XTXInvMat[j, j])) .ToArray(); CoeffsT = Coeffs.Zip(Sb, (a, b) => Math.Abs(a / b)).ToArray(); TCritical = StudentTable.GetValue(n - k - 1); // интервальная оценка регрессии IntervalEstimates = new double[n]; for (int i = 0; i < n; i++) { var x0 = Enumerable.Range(0, XMat.GetLength(1)).Select(j => XMat[i, j]).ToArray(); IntervalEstimates[i] = TCritical * Math.Sqrt(S2 * Matrix.ScalarMul(x0, Matrix.MulVect(XTXInvMat, x0))); } // интервальная оценка параметров регрессии CoeffsIntervalEstimates = Sb.Select(s => Math.Abs(s * TCritical)).ToArray(); ApproximationError = RealY.Zip(CalculatedY, (a, b) => Math.Abs((a - b) / a)).Sum() / RealY.Length; }
public DescriptiveStatistics(string name, double[] vals) { ParameterName = name; Sum = vals.Sum(); Count = vals.Length; Average = Sum / Count; Dispersion = vals.Sum(e => Math.Pow(e - Average, 2)) / (Count - 1); StandardDeviation = Math.Sqrt(Dispersion); StandardError = StandardDeviation / Math.Sqrt(Count); Min = vals.Min(); Max = vals.Max(); Interval = Max - Min; Median = GetMedian(vals); Mode = GetMode(vals); Excess = GetExcess(vals, Average, StandardDeviation); Asymmetry = GetAsymmetry(vals, Average, StandardDeviation); double t = StudentTable.GetValue(Count - 1); MarginalError = t * StandardError; double neededError = 0.01; RequiredSize = (int)(t * t * Dispersion / (neededError * neededError)); MarginalErrorWithRequiredSize = t * StandardDeviation / Math.Sqrt(RequiredSize); }
public Correlations(Table tbl, DescriptiveStatistics[] dstats) { CalcCorrMatrix(tbl, dstats); CalcPartialCorrMatrix(tbl); CalcMultipleCorrelation(tbl); MultipleDeterminationCoeffs = MultipleCorreletaionCoeffs.Select(a => a * a).ToArray(); CalcMultipleSignificance(tbl); CalcSignificanceMatrix(tbl); Critical = StudentTable.GetValue(tbl.RowsCount - 2); }