# #An implementation of Ljung-Box. #It assumes that tsx is a vector or time series. #The number of lags parameter is k. # myLB<-function(tsx,k){ Tx<-length(tsx); weight<-rep(0,k); for(j in 1:k){weight[j]<-1/(Tx-j)}; rho<-acf(tsx, plot=F)$acf[2:(k+1)]; wrhosq<-rho^2*weight; value<-Tx*(Tx+2)*sum(wrhosq); return(value) }