lib/more_math/sequence.rb
# Returns the q value of the Ljung-Box statistic for the number of lags
# +lags+. A higher value might indicate autocorrelation in the elements of
# this Sequence instance. This method returns nil if there weren't enough
# (at least lags) lags available.
Returns the q value of the Ljung-Box statistic for the number of lags
+lags+. A higher value might indicate autocorrelation in the elements of
this Sequence instance. This method returns nil if there weren't enough
(at least lags) lags available.
Returns the q value of the Ljung - Box statistic for the number of lags + lags + . A higher value might indicate autocorrelation in the elements of this Sequence instance . This method returns nil if there weren ' t enough ( at least lags ) lags available .
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
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
Returns the q value of the Ljung-Box statistic for the number of lags
+lags+.
Returns the q value of the Ljung - Box statistic for the number of lags + lags + .
lags
<not_specific>