With the above results, we can device a hypothesis test for a single population varince: Using the sample variance \(\small{s^2 }\) estimated from the data, compute the chi-square test statistics for a test value \(\small{\sigma=\sigma_0 }\) to be, \(\small{~~\chi^2~=~\dfrac{(n-1)s^2}{\sigma_0^2} }\) The two sided and one sided tests for their corresponding null ($H_0$) and alternate ($H_A$) hypothesis are devised as follows: 1. Two sided hypothesis \(\small{~~~~~~H_0~:~\sigma^2 = \sigma_0^2 }\) \(\small{~~~~~~H_A~:~\sigma^2 \neq \sigma_0^2 }\) Reject the null hypothesis $H_0$ if the computed statistic \(\small{\chi^2 \lt \chi^2_{\alpha/2}(n-1) }\) or \(\small{\chi^2 \gt \chi^2_{1-\alpha/2}(n-1) }\) For a two sided test, we can also reject null hypothesis if \(\small{\sigma_0^2 }\) is outside the \(\small{100(1-\alpha)\% }\) confidence interval \(~~\small{\left[\dfrac{n-1}{b}s^2,~\dfrac{(n-1)}{a}s^2 \right]}\) for the population standard deviation. 2. One sided hypothesis \(\small{~~~~~~H_0~:~\sigma^2 \leq \sigma_0^2 }\) \(\small{~~~~~~H_A~:~\sigma^2 \gt \sigma_0^2 }\) Reject the null hypothesis $H_0$ if the computed statistic \(\small{\chi^2 \gt \chi^2_{1-\alpha}(n-1) }\) 2. One sided hypothesis \(\small{~~~~~~H_0~:~\sigma^2 \geq \sigma_0^2 }\) \(\small{~~~~~~H_A~:~\sigma^2 \lt \sigma_0^2 }\) Reject the null hypothesis $H_0$ if the computed statistic \(\small{\chi^2 \lt \chi^2_{\alpha}(n-1) }\)
################################################## ## Script for testing a single population variance. ## x is the data vector ## test_sigma = value of population vaiance for testing ## alpha = significance level for the test one_sample_variance_test = function(x, test_sigma, alpha){ ## compute the standard deviation and sample size from the data s = sd(x) n = length(x) ## compute chi-square test statistic test_statistic = (n-1)*s^2/test_sigma^2 ## Two sided test a = qchisq(alpha/2, n-1) b = qchisq(1-alpha/2, n-1) test_statistic = round(test_statistic, 2) a = round(a, 2) b = round(b,2) print("Two sided alternate hypothesis : population variance not equal to test value :") if( (test_statistic <= a) | (test_statistic >= b) ){ print("Null hypothesis rejected, alternative accepted") print(paste("chi-square test statistic = ", test_statistic, " is outside the acceptance region [ ",a, ",", b," ]")) } else { print("Null hypothesis accepted, alternative rejected") print(paste("chi-square test statistic = ", test_statistic, " is inside the acceptance region [ ",a, ",", b," ]")) } print("-----------------------------------------------------") ## One sided test : Alternate hypothesis : population variance > test_variance print("One sided alternate hypothesis : population variance > test value :") chisq_critical = qchisq(1-alpha,n-1) chisq_critical = round(chisq_critical, 2) if(test_statistic > chisq_critical){ print("Null hypothesis rejected, alternative accepted") print(paste("chi-square test statistic = ", test_statistic, " is greater than the upper critical value ", chisq_critical)) } else { print("Null hypothesis accepted, alternative rejected ") print(paste("chi-square test statistic = ", test_statistic, " is less than the upper critical value ",chisq_critical )) } print("-----------------------------------------") ## One sided test : Alternate hypothesis : population variance < test_variance print("One sided alternate hypothesis : population variance < test value :") chisq_critical = qchisq(alpha,n-1) chisq_critical = round(chisq_critical, 2) if(test_statistic < chisq_critical){ print("Null hypothesis rejected, alternative accepted") print(paste("chi-square test statistic = ", test_statistic, " is less than the lower critical value ", chisq_critical)) } else { print("Null hypothesis accepted, alternative rejected") print(paste("chi-square test statistic = ", test_statistic, " is greater than the lowercritical value ",chisq_critical)) } } ### Testing the function "one_sample_variance_test" ## this data set is randomly drawn from a Gaussian of mean=140, sd=20 x = c(142.8, 135.0, 157.5, 148.4, 135.9, 153.4, 149.0, 130.2, 156.0, 189.7, 151.6, 156.5, 123.8, 152.9, 118.4, 145.8) one_sample_variance_test(x, 29, 0.05) ###############------------------------------------------------
Executing the above script in R prints the following results and figures of probability distribution on the screen:
[1] "Two sided alternate hypothesis : population variance not equal to test value :" [1] "Null hypothesis rejected, alternative accepted" [1] "chi-square test statistic = 4.91 is outside the acceptance region [ 6.26 , 27.49 ]" [1] "-----------------------------------------------------" [1] "One sided alternate hypothesis : population variance > test value :" [1] "Null hypothesis accepted, alternative rejected " [1] "chi-square test statistic = 4.91 is less than the upper critical value 25" [1] "-----------------------------------------" [1] "One sided alternate hypothesis : population variance < test value :" [1] "Null hypothesis rejected, alternative accepted" [1] "chi-square test statistic = 4.91 is less than the lower critical value 7.26"