Question

I am trying to perform a so called Ljung Box test on different data I have been given. I want to check whether my data is within a 0.95 quantile of the chi squared distribution. This value I can find in tables (such as http://www.unc.edu/~farkouh/usefull/chi.html). The data have varying sample size resulting in different degrees of freedom for the chi-squared distribution and looking up all values manually would take a lot of time.

I am wondering whether there is any way in matlab I can find these values automatically and then to use these different values in my for-loop?

Was it helpful?

Solution

You can do it with ncx2inv (Statistics Toolbox):

p = 0.02; %// probability (i.e. quantile)
df = 2; %// degrees of freedom
n = 0; %// non-centrality parameter. Set to 0 to generate the provided table
result = ncx2inv(1-p, df, n);

In this example the result is 7.824, in accordance with the provided table.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top