Chi-Square Tests of Independence
( Chi - Square Tests for two-way table )
===========================
For effective execution and analysis of the Chi-square test in R language we are going to do the following steps :
data <- c(40,25,19,37,39)
This "data" vector holds the data for all the students who are registered for the different classes in a school . These are 40 students in class 1 , 25 students for class 2 , 19 students for class 3 , 37 students for class 4 and 39 students for the class 5 .
2) Step no. 2 - In R we are going to evaluate whether the values as have been specified in the data variable object "data" are same in value and this equality condition is going to be tested in the NULLHypothesis for the test for evaluation of the data object .
The Null Hypothesis and the Alternative Hypothesis for checking the validity of both the conditions can be stated and represented in the given manner with the null hypothesis being represented by the symbol (H0) and Null Hypothesis being represented by the symbol (H1) .
# H0 is the null
hypothesis
H0 : p1 = p2 = p3 = p4
= p5
The alternative Hypothesis can be given in the alternate manner i.e,
# H1 is the alternative hypothesis
H1 : p1 != p2 != p3 !=
p4 !=p5
3) In the 3rd step , we will run the chi - square
test over the function by calling the appropriate function for the evaluation
of the same
·
chisq.test(data)
On the console one can see that the entire data
item which had been fed to the prompt has been registed as a memory object .
And when one wants to run the Chi-squared test upon the data item object , the
values that come as a result of execution of the test are in the given format :
X-squared = 11.125, df
= 4 , p-value - 0.02519
# from the given evaluation one can analyse with
the help of the Chi-square table that the critical value which is also acronymised
as (T-crit) is found to be as 9.488 with a degree of freedom for the data as 4
and alpha ( degree of significance is found out to be as 0.05 )
which can be found out from the p-value obtained
after running the test is that we are basically not wrong in our assumption
while framing the null and alternative hypothesis which means that the p-value
for the evaluation is less than 0.025 which is less than the alpha value set
for the test which is 0.05 then we can reject the null hypothesis as again stating
.. we found out the P-value to be lesser than that of the Alpha set for the
test.
But had it been the case that the value of the alpha level had also been set at 0.25 then we would not have been at a position to reject the null hypothesis .
Conclusion and Verification
For the sake of analysing the obtained values if we are again running the chi-square test upon another pair of data in the given format .
data1 <- c(35,31,38,27,29)
And again , we are running the chi-square test on these numbers in the "data1" vector , then the following results would be obtained .
> chisq.test(data1)
X-squared statistic is 2.5 , degrees of freedom is
4 , p-value is obtained as 0.644 .This means that since one is looking at the
alpha value of 0.05 and the p-value is lying towards the left of the normal
distribution line then we can say that the Null Hypothesis for the given set of
values within the vector "data1" cannot be rejected .. I repeat , for
the data values presented in the second vector item , the null hypothesis
cannot be rejected .
Again drawing a general conclusion from the experiment .. if we obtain the value of the p-value to be greater than that of the alpha value , then the null hypothesis cannot be rejected .