10: Chi-square and factorial ANOVA

Using R to perform chi-square analyses and basic factorial ANOVA

Justin Dainer-Best true
11-16-2020

These are all of the instructions for Lab 10. The list of labs is here.

This repository contains R labs for R package ({psychRstats}) based on Bard College’s Statistics for Psychology (PSY 203, Fall 2020), taught by Assistant Professor of Psychology Justin Dainer-Best.

For each lab, you should expect to download the lab’s files locally to your computer, and run them there. If you’re using https://rstudio.cloud/ instead of running things locally, the same instructions should work today.

Below are instructions for Lab 10.

Today’s tutorial

This lab will walk you through how to plot and run chi-squared (\(\chi^2\)) tests in R, as well as how to plot and run basic factorial ANOVAs. You’ll use the lm() and anova() functions for the latter, much as you did with one-way ANOVAs in lab 8. You’ll use the table() function to create contingency tables and then the chisq.test() function to run chi-squared tests for independence and goodness of fit. You’ll also practice using the {ggplot2} package to create a variety of plots.

To run the tutorial:

library(psychRstats)
psychRstats::lab("10-X2-fANOVA")

Once you’ve completed the tutorial, return here for the exercise that you will complete at the end of the lab. (If you’d like to keep the tutorial open, refer to this page on the wiki.)

Make sure you’re in the right working directory

In the first lab, we set the working directory to a specific folder where every lab for this class will live. If you don’t remember, look at the wiki page I’ve created on setting a working directory.

Check that you’re in the directory you expect by running getwd() (the parentheses should have nothing in them).

Exercise

You should have downloaded the exercise and data already; today’s file is called “10-exercise.Rmd”. Either open the file (in R through the Files pane, or by double-clicking on the file in your file browser), or you may be able to open the file from the correct working directory by running the following code:

library(psychRstats)
run_exercise("10-exercise")

Solutions

A version of the document with solutions can be seen here.

Citation

For attribution, please cite this work as

Dainer-Best (2020, Nov. 16). psychRstats: Learning Statistics for Psychology in R: 10: Chi-square and factorial ANOVA. Retrieved from https://jdbest.github.io/psychRstats/labs/10-chi-square-factorial-ANOVA/

BibTeX citation

@misc{dainer-best202010:,
  author = {Dainer-Best, Justin},
  title = {psychRstats: Learning Statistics for Psychology in R: 10: Chi-square and factorial ANOVA},
  url = {https://jdbest.github.io/psychRstats/labs/10-chi-square-factorial-ANOVA/},
  year = {2020}
}