Performing correlationa and linear regressions in R
These are all of the instructions for Lab 9. 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 9.
This lab will walk you through running correlations and regression in R, using functions like cor.test() and cor() for the former and summary() and lm() (linear model) for the latter. You’ll also practice using the {ggplot2} package to create scatterplots with regression lines.
To run the tutorial:
library(psychRstats)
psychRstats::lab("09-cor-reg")
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.)
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).
You should have downloaded the exercise and data already; today’s file is called “09-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("09-exercise")
A version of the document with solutions can be seen here.
For attribution, please cite this work as
Dainer-Best (2020, Nov. 2). psychRstats: Learning Statistics for Psychology in R: 09: Correlation and Regression. Retrieved from https://jdbest.github.io/psychRstats/labs/09-regression-correlation/
BibTeX citation
@misc{dainer-best202009:,
author = {Dainer-Best, Justin},
title = {psychRstats: Learning Statistics for Psychology in R: 09: Correlation and Regression},
url = {https://jdbest.github.io/psychRstats/labs/09-regression-correlation/},
year = {2020}
}