% Section 7.5 from book. barnett 2/27/06 % plot the chi-squared pdf for different m = degrees of freedom... w = 0:0.1:20; figure; plot(w, [chi2pdf(w,1); chi2pdf(w,2); chi2pdf(w,5); chi2pdf(w,10)], '-'); legend('1', '2', '5', '10'); title('Chi-squared pdf'); xlabel w; ylabel('f_{\chi^2}(w, v)'); axis([0 15 0 0.6]); % look up w-values which fall on 2.5% and 97.5% percentiles of chi-squared... n = 4; alpha = 0.05; a = chi2inv(alpha/2, n-1) b = chi2inv(1-alpha/2, n-1) % find a confidence interval on variance, given data with eg S^2 = 5. S = sqrt(5); disp(sprintf('95%% Conf Int on variance: [%f, %f]', (n-1)*S^2/b, (n-1)*S^2/a));