The Chi Square Analysis determines the relationship between categorical variables by using a null and alternative hypothesis. The null hypothesis is usually that there are no relationships between the given categorical variables. The alternative hypothesis is that there is a relationship between the variables and knowing the value of one variable helps predict another. The goal is to prove that the null hypothesis is not true. This can be done by looking at the p value and the significance level(which is usually 0.5). If the p value is less than or equal to the significance level we can reject the null hypothesis. In a Chi square test we need to convert the numerical values into categorical values. This is done to reduce the size of the dataset and get a more accurate value.
The first step we took was to create a table with categorical variables using the Census Gender column and the Census Literate column. The first step was to create a Matrix with 2 rows and columns(the rows and columns being the parameters). The next step was to put the categorical variables we created into the table. The first table was :
table_gender_literacy <- matrix(nrow = 2, ncol = 2)
row.names(table_gender_literacy) <- c("literate_y", "literate_n")
colnames(table_gender_literacy) <- c("id_m", "id_f")
Table:
id_m id_f
literate_y 37 10
literate_n 0 1
The second table was:
table_data_farmer <- matrix(nrow = 2, ncol = 2)
row.names(table_data_farmer) <- c("farmer", "notfarmer")
colnames(table_data_farmer) <- c("over50", "lessthan50")
Table:
over50 lessthan50
farmer 5 10
notfarmer 26 7
The first table has literate as the rows and census gender as the column. The second one has whether the person is a farmer or not as the rows. The columns for the second row consist of the amount the person donated. We performed a Chi square test on these tables:
chisq.test(table_gender_literacy)
Output:
Pearson's Chi-squared test with Yates' continuity correction
data: table_gender_literacy
X-squared = 0.42407, df = 1, p-value = 0.5149
chisq.test(table_data_farmer)
Output:
Pearson's Chi-squared test with Yates' continuity correction
data: table_data_farmer
X-squared = 7.4339, df = 1, p-value = 0.006401
For the table having gender and literacy, we accept the null hypothesis. This is because the p value is greater than the significance level i.e. 0.5. This suggests that there is less relation between gender and literacy. But we can also see that there is no one that is male and illiterate.
For the table with profession and amount, we reject the null hypothesis. This is because the p value is less than the significance level. This means that there is some relation between being/not being a farmer and age. In this case one variable can be used to predict the other.