Assignment 7
Due by 11:30am on Monday, October 26, 2026
RULES
You must use a RNotebook for this assignment:
- Sections should have appropriate headers
- All code must be contained within a code chunk. You are allowed to split up your code into many code chunks, or just have one large chunk per section. That is up to you. However, I do not want to see code located outside of a chunk (unless you’re making a quick note or telling us what you’re doing – but the code outside of a chunk shouldn’t be evaluated).
- Any explanations I ask for should be outside of a code chunk (aka formatted text). I personally would put this directly underneath the header, but it can come after the code chunk ends, as well. Whatever you prefer. However, I do not want to see any sentences as comments within a code chunk (e.g.,
#a long sentence like this). Comments within the code is fine in terms of describing what the code is doing. But when I ask for your opinion or an explanation of something, that needs to be formatted text.
You must use the ggplot2 package and syntax for all plotting. No plots in base R.
Correlations
Choose 2 continuous variables from your dataset that you think might be related to one another, and then do the following.
Here’s your to-do list:
- There are lots of ways to get a correlation in
R. Use all 3 of the following functions to get the correlation (of the same 2 variables):corcor.testcorr.test(from thepsychpackage)
- Write a sentence or two about which of the above functions you like best and explain why
- Make 2 scatter plots of your data with a best fit line indicating the correlation. In the first scatter plot use the raw data. In the second scatter plot, use the same variables but standardized (z-score) them. Write a sentence describing if the line is the same or if it’s different, and explain why this is the case.
It’s All Regression
For this exercise you will need:
- 2 continuous variables and 2 categorical variables
- One of your categorical variables should have 3 or more levels
- One of the continuous variables will be your OUTCOME measure (or your \(Y\) variable). Please use this same variable as the outcome for all of the analyses described below.
Here’s your to-do list:
- Get the correlation between your outcome variable and your second continuous variable. Store this as an object. Next, run a simple linear regression with these two variables. Lastly, re-run your simple linear regression with the same variables, but now standardized (z-scored). Print the output for all 3 analyses and write 2-3 sentences explaining what you find. What’s the same and what’s different?
- Run a oneway ANOVA with your categorical variable that has 3 or more levels and your outcome variable. Now re-run that same model but as a regression instead. Write 2-3 sentences interpreting your models and again describing what is the same and what is different. Do your best to interpret each regression coefficient and the overall model (omnibus test).
- Now run an ANOVA with both of your categorical variables predicting your outcome variable. Then re-run that same model as a regression. Write 2-3 sentences interpreting your models and again describing what is the same and what is different.
Boom!
Go ahead and submit your .Rmd and .html file to Canvas. If you used an outside dataset, please also submit that, too.