ljungBoxAuto function

LjungBoxResult ljungBoxAuto(
  1. List<double> resid, {
  2. int nParams = 0,
  3. String rule = 'sqrt',
})

Implementation

LjungBoxResult ljungBoxAuto(List<double> resid, {int nParams=0, String rule='sqrt'}) {
  final n=resid.length;
  int h;
  switch (rule){
    case 'n5':   h = math.max(5, (n/5).floor()); break;
    case 'log':  h = math.max(5, (2*math.log(n)).floor()); break;
    default:     h = math.max(10, (math.sqrt(n) + 10).floor());
  }
  h = h.clamp(1, math.min(2*24, n-1)); // üst: 48
  final r = acf(resid, h);
  double Q=0.0; for (int k=1;k<=h;k++) Q += (r[k]*r[k])/(n-k);
  Q *= n*(n+2);
  final df = math.max(1, h - nParams);
  final p = _chiSf(Q, df);
  return LjungBoxResult(Q, df, p);
}