Skip to main content

Week 1 In-Class Exercise: Welcome & Modern Toolkit

GPH-GU 2182 · Statistical Programming in R

Author

YOUR NAME & PARTNER NAME

Published

September 2, 2026

NoteInstructions

Work in pairs during class.

  • 📥 Download week-01-inclass.qmd to open and edit in RStudio (or use the </> Source Code button 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}

# Write your calculations below:

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

  1. Load the r02pro package (install it in the Console with install.packages("r02pro") if you haven’t already).
  2. Display the first 6 rows of the ahp dataset using the head() function.
  3. 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:

  1. Is the AI-generated code correct? What error did it make?
  2. Correct the code below using R’s built-in constant pi and proper formula (\text{Area} = \pi r^2):
# Corrected code:

4.1 Submission Checklist