# Write your calculations below:Week 1 In-Class Exercise: Welcome & Modern Toolkit
GPH-GU 2182 · Statistical Programming in R
Work in pairs during class.
- 📥 Download
week-01-inclass.qmdto open and edit in RStudio (or use the</> Source Codebutton at the top right). - Render this Quarto document to HTML and push it to your GitHub repository by the end of class for participation credit.
1 Cycle 1: R as a Calculator and Environment Setup
1.1 Basic Arithmetic & Calculations
In the code chunk below, compute the Body Mass Index (BMI) for three study participants:
- Participant A: Weight 70\text{ kg}, Height 1.75\text{ m}
- Participant B: Weight 85\text{ kg}, Height 1.80\text{ m}
- Participant C: Weight 58\text{ kg}, Height 1.62\text{ m}
\text{BMI} = \frac{\text{weight in kg}}{(\text{height in meters})^2}
1.2 Exploring Built-in Functions
Compute the mean of the three BMIs you calculated above. Round the result to 2 decimal places using round().
# Write your summary code below:1.3 R Packages and Documentation
- Load the
r02propackage (install it in the Console withinstall.packages("r02pro")if you haven’t already). - Display the first 6 rows of the
ahpdataset using thehead()function. - Open the help file for the
median()function using?median.
# Load library and inspect data:2 Cycle 2: Reproducible Reporting with Quarto
2.1 Text Formatting & Markdown
In the space below:
- Write a short 2-sentence paragraph describing the purpose of reproducible research in public health.
- Include at least one bold phrase and one italicized word.
- Add a bulleted list of two advantages of Quarto over traditional copy-pasting into Word.
(Type your text response here)
2.2 Code Chunk Customization
Create an R code chunk below with chunk option #| echo: true that creates a vector of systolic blood pressure readings: 120, 134, 118, 142, 128 and calculates their standard deviation using sd().
# Write your code here:3 Cycle 3: Git & GitHub Workflow
Confirm the following steps with your partner:
4 Cycle 4: AI Corner — Verification Exercise
An AI assistant was asked to write R code to compute the area of a circle with radius r = 7.5\text{ cm}.
The AI generated this code:
# AI-generated code:
radius <- 7.5
area <- 3.14 * (radius * 2)4.0.1 Questions:
- Is the AI-generated code correct? What error did it make?
- Correct the code below using R’s built-in constant
piand proper formula (\text{Area} = \pi r^2):
# Corrected code: