A study of conducted in Whickham, England recorded participants’ age, smoking status at baseline, and then 20 years later recorded their health outcome. In this lab we analyse the relationships between these variables, first two at a time, and then controlling for the third.
Click on the assignment link clone it in Posit and open the R Markdown document. Knit the document to make sure it compiles without errors.
Before we introduce the data, let’s warm up with some simple exercises. Update the YAML of your R Markdown file with your information, knit, commit, and push your changes. Make sure to commit with a meaningful commit message. Then, go to your repo on GitHub and confirm that your changes are visible in your Rmd and md files. If anything is missing, commit and push again.
We’ll use the tidyverse package for much of the data wrangling and visualisation and the data lives in the mosaicData package which you will want to install in the Console.
After installing, you can load them by running the following in your Console:
library(tidyverse)
library(mosaicData)
The dataset we’ll use is called Whickham from the mosaicData package.
You can find out more about the dataset by inspecting their documentation, which you can access by running ?Whickham
in the Console or using the Help menu in Posit to search for Whickham
.
What type of study do you think these data come from: observational or experiment? Why?
How many observations are in this dataset? What does each observation represent?
How many variables are in this dataset? What type of variable is each? Display each variable using an appropriate visualization.
What would you expect the relationship between smoking status and health outcome to be?
🧶 ✅ ⬆️ Knit, commit, and push your changes to GitHub with an appropriate commit message. Make sure to commit and push all changed files so that your Git pane is cleared up afterwards.
%>%
Whickham count(smoker, outcome)
age_cat
using the following scheme. Hint you’ll want to think about using if_else
or case_when
here:age <= 44 ~ "18-44"
age > 44 & age <= 64 ~ "45-64"
age > 64 ~ "65+"
age_cat
. What changed? What might explain this change? Extend the contingency table from earlier by breaking it down by age category and use it to help your narrative.%>%
Whickham count(smoker, age_cat, outcome)
🧶 ✅ ⬆️ Knit, commit, and push your changes to GitHub with an appropriate commit message. Make sure to commit and push all changed files so that your Git pane is cleared up afterwards and review the md document on GitHub to make sure you’re happy with the final state of your work.