Chi-Square Test

Chi-Square Test

The Chi-Square Test is used to analyze the frequency table (i.e., contingency table), which is formed by two categorical variables. The chi-square test evaluates whether there is a significant relationship between the categories of the two variables.

The Chi-Square Test is a statistical method that is used to determine whether two categorical variables have a significant correlation between them. These variables should be from the same population and should be categorical like- Yes/No, Red/Green, Male/Female, etc.

R provides chisq.test() function to perform chi-square test. This function takes data as an input, which is in the tablet form, containing the count value of the variables in the observation.

In R, there is the following syntax of this. test() function:

chisq.test(data)  

Let’s see an example in which we will take the Cars93 data present in the “Mass” library. This data represents the sales of different models of cars in the year 1993.

Data:

library("MASS")  
print(str(Cars93))  

Output:

Example:

# Loading the Mass library.  
library("MASS")  
# Creating a data frame from the main data set.  
car_data<- data.frame(Cars93$AirBags, Cars93$Type)  
# Creating a table with the needed variables.  
car_data = table(Cars93$AirBags, Cars93$Type)   
print(car_data)  
# Performing the Chi-Square test.  
print(chisq.test(car_data))  

Output:

Next Topic: Click Here

This Post Has 2 Comments

  1. ikaria juice

    One thing I would really like to say is the fact that car insurance cancelling is a terrifying experience so if you’re doing the proper things being a driver you’ll not get one. Lots of people do have the notice that they’ve been officially dumped by the insurance company and many have to fight to get added insurance following a cancellation. Low-priced auto insurance rates are usually hard to get from cancellation. Having the main reasons for auto insurance cancellation can help owners prevent getting rid of in one of the most important privileges obtainable. Thanks for the tips shared by your blog.

Leave a Reply