Chi-Square Test, Fisher’s Exact Test, & Cross Tabulations in R | R Tutorial 4.10| MarinStatsLectures
Hi! I am Mike Marin and in this video we’ll talk about how to conduct the
“chi-square test of independence” as well as “Fisher’s exact test” using R programming language. the chi-square test of independence is a parametric method appropriate for
testing independence between two categorical variables.
we’ll be working with the lung capacity data that was introduced earlier in this
series of videos. I’ve already imported the data into R and attached it . we’ll explore the relationship between gender and smoking. we can use the “CHISQ.Test” command/function to do the chi-square test in R.
To access the Help menu in R type Help and in brackets the name of
the command/function you would like help for or place a question mark (?) in front of the
name. the first thing we will need to do is produce a contingency table (corss tabulation). this can be done using the table command/function. now let’s go ahead and save this table
in an object called TAB for use later.
the next thing we can do is produce a bar plot to examine the
relationship visually this can be done using the barplot
command .here I will set the “beside” argument equal to
True to produce cluster bar charts and also set the “legend” argument equal
to True to have a default legend produced.
see my earlier videos on producing bar plots to learn more about how to produce these. next we can produce the chi-square test using the “CHISQ.Test” command/function. here we would like a chi-square test for the contingency table. we can set the “correct” argument equal to True to have R statistical software do the Yate’s continuity correction for the chi-square test. we can see the test statistic of 1.744 and the corresponding p-value of 0.1866 recall earlier that we saw we can store the result of a
test in an object.
I am going to store the results of this test in the object CHI Earlier in the series of videos, we also learned about the “attributes” command/function we can ask what attributes R stored in this object CHI, if we would like to extract certain attributes from this object, we can do so using the
“$” sign here let’s take up the expected table if the assumptions are the chi-square
test are not met we may consider using Fisher’s exact
test Fisher’s exact test is a nonparametric equivalent to the chi-square test.
this test may be completed using the “Fisher.test” command .
again here we’d like to do the test on our contingency table.we can set the “conf.int” argument equal to True if you
would like to have a confidence interval for the odds ratio returned and we can
use the “conf.level” argument to set the desired level of confidence.
in the next video in this series we will discuss a package we can use to
calculate relative risks, odds ratios and so on.
thanks for watching this video Subscribe to marinstatslectures for more R programming and Statistics Videos