function results = testsofindependence(pdens,mom,lag)
% runs the Ljung-Box test for the pits
% INPUTS: pdens - PIT
%         mom - moments
%         lag - lag parameter for the serial correlation test
% OUTPUTS: h - indicator whether the null has been rejected or not
%          pvalue - pvalue of the test
%          stat - test statistics
%          cvalue - critical value of the test statistic
% The default level of signifiance is 5%
% the output is in a vector form reporting the results for the time series
% of the PITs from all the considered models
for i = 1:size(pdens,1)
    pit = cleanNaN(pdens(i,:));
    [h(i,1) pValue(i,1) stat(i,1) cValue(i,1)] = lbqtest((pit-mean(pit)).^mom,'Lags',lag);
end

results.h = h;
results.pValue = pValue;
results.stat = stat;
results.cValue = cValue;