To test the independence of variable using chi-squared test in R programming.
To test independence of the row and column variable.
p-value is calculated from the asymptotic chi-squared distribution of the test statistic
H0 : Two Variables are independent.
H1 : Two Variables are relative.
R Function :test()
Provides an exact test of independence.
R Function :test(x)
x - two dimensional contingency table in matrix form.
#Independence test
#Chi-Squared Test
#Input
attach(mtcars)
x<-mtcars$mpg
y<-mtcars$hp
#Table Function
tab<-table(x,y)
print(tab)
chisq.test(tab)
#Fisher Test
fisher.test(tab)