class MoreMath::Sequence

def ljung_box_statistic(lags = 20)

(at least lags) lags available.
this Sequence instance. This method returns nil if there weren't enough
+lags+. A higher value might indicate autocorrelation in the elements of
Returns the q value of the Ljung-Box statistic for the number of lags
def ljung_box_statistic(lags = 20)
  r = autocorrelation
  lags >= r.size and return
  n = size
  n * (n + 2) * (1..lags).inject(0.0) { |s, i| s + r[i] ** 2 / (n - i) }
end