library(tidyverse)
library(rmarkdown)
library(knitr)
library(ggplot2)
library(dplyr)
library(car)
library(lmtest)
library(sandwich)
library(stargazer)
library(broom)
Ensure all packages are downloaded
cat("R Version:", paste(R.version$major, R.version$minor, sep="."), "\n")
## R Version: 4.5.2
cat("Platform:", R.version$platform, "\n")
## Platform: aarch64-apple-darwin20
Reflection Question 1: What version of R and RStudio are you
running? (Screenshot or write the versions below)
Version: 4.5.2
required_packages <- c(
"tidyverse", "rmarkdown", "knitr", "ggplot2", "dplyr",
"car", "lmtest", "sandwich", "stargazer", "broom"
)
cat("Loading required packages...\n\n")
## Loading required packages...
all_loaded <- TRUE
for (pkg in required_packages) {
tryCatch({
library(pkg, character.only = TRUE)
cat("✓", pkg, "loaded successfully\n")
}, error = function(e) {
cat("✗", pkg, "FAILED to load\n")
all_loaded <<- FALSE
})
}
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.6
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.1 ✔ tibble 3.3.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.2
## ✔ purrr 1.2.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
## ✓ tidyverse loaded successfully
## ✓ rmarkdown loaded successfully
## ✓ knitr loaded successfully
## ✓ ggplot2 loaded successfully
## ✓ dplyr loaded successfully
## Loading required package: carData
##
## Attaching package: 'car'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
## ✓ car loaded successfully
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## ✓ lmtest loaded successfully
## ✓ sandwich loaded successfully
##
## Please cite as:
##
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
## ✓ stargazer loaded successfully
## ✓ broom loaded successfully
cat("\n")
if (all_loaded) {
cat("✓ All packages loaded successfully!\n")
} else {
cat("âš Some packages failed. Run the code in Appendix A to install them.\n")
}
## ✓ All packages loaded successfully!
Reflection Question 2: Did any packages fail to load initially? If
yes, which ones and how did you resolve it?
Answer: I downloaded the packages
Set working directories
cat("Your current working directory:\n")
## Your current working directory:
cat(getwd(), "\n\n")
## /Users/mattgoldman/Documents/PhD in Epi/Spring 2026/EPI 553/EPI 553 Projects/outputs
if (file.exists(".Rproj")) {
cat("✓ R Project file (.Rproj) detected\n")
} else {
cat("âš No R Project file found\n")
cat(" Create one: File → New Project → New Directory\n")
}
## âš No R Project file found
## Create one: File → New Project → New Directory
## âš No R Project file found
## Create one: File → New Project → New Directory
# Check for suggested folders
cat("\nFolder structure check:\n")
##
## Folder structure check:
#Create Folders
dir.create("data")
## Warning in dir.create("data"): 'data' already exists
dir.create("scripts")
## Warning in dir.create("scripts"): 'scripts' already exists
dir.create("outputs")
## Warning in dir.create("outputs"): 'outputs' already exists
dir.create("figures")
## Warning in dir.create("figures"): 'figures' already exists
## Folder structure check:
folders <- c("data", "scripts", "outputs", "figures")
for (folder in folders) {
if (dir.exists(folder)) {
cat("✓", folder, "/ exists\n")
} else {
cat("â—‹", folder, "/ (needs to be created)\n")
}
}
## ✓ data / exists
## ✓ scripts / exists
## ✓ outputs / exists
## ✓ figures / exists
Reflection Question 3: Describe your folder structure. What is the
full path to your project directory?
Answer: In my EPI 553 folder I have an EPI 553 Projects folder,
which contains my data, figures, outputs, and scripts folders
The path is Documents/PhD in Epi/Spring 2026/EPI 553/EPI 553
Projects
Rmarkdown
if (require("rmarkdown", quietly = TRUE)) {
cat("✓ rmarkdown package is installed and loaded\n")
cat("✓ You can render to HTML, PDF, and Word formats\n\n")
cat("To render a document:\n")
cat("1. Click the 'Knit' button (top of editor) or press Ctrl+Shift+K\n")
cat("2. Select output format (HTML, PDF, Word)\n")
cat("3. View the rendered document in RStudio Viewer\n")
} else {
cat("✗ rmarkdown not found. Run: install.packages('rmarkdown')\n")
}
## ✓ rmarkdown package is installed and loaded
## ✓ You can render to HTML, PDF, and Word formats
##
## To render a document:
## 1. Click the 'Knit' button (top of editor) or press Ctrl+Shift+K
## 2. Select output format (HTML, PDF, Word)
## 3. View the rendered document in RStudio Viewer
Reflection Question 4: Describe the process you followed to render
this checklist to HTML. What did you click and what happened?
Answer: I converted my rscript into an rmarkdown file. Then I
pressed knit to html.
Reflection Question 5: What is the exact filename (including .html
extension) of the rendered version of this document?
Answer: Goldman_Matthew_Setup_Checklist.html
Data and Code Practice
cat("Dataset: mtcars (Motor Trend Car Road Tests)\n")
## Dataset: mtcars (Motor Trend Car Road Tests)
cat("Sample of data:\n")
## Sample of data:
## Sample of data:
print(head(mtcars, 3))
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
cat("\n\nBasic Summary Statistics:\n")
##
##
## Basic Summary Statistics:
summary(mtcars$mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10.40 15.43 19.20 20.09 22.80 33.90
Create a simple visualization:
mtcars %>%
ggplot(aes(x = wt, y = mpg, color = factor(cyl))) +
geom_point(size = 3, alpha = 0.7) +
geom_smooth(method = "lm", se = FALSE, alpha = 0.5) +
labs(
title = "Fuel Efficiency vs Weight",
subtitle = "EPI 553 - Setup & Workflow Checklist",
x = "Weight (1000 lbs)",
y = "Miles Per Gallon (mpg)",
color = "Cylinders"
) +
theme_minimal() +
theme(
plot.title = element_text(size = 14, face = "bold"),
legend.position = "bottom"
)
## `geom_smooth()` using formula = 'y ~ x'

Fit a simple linear regression model
model <- lm(mpg ~ wt + factor(cyl), data = mtcars)
cat("Linear Regression Model: mpg ~ weight + cylinders\n\n")
## Linear Regression Model: mpg ~ weight + cylinders
print(summary(model))
##
## Call:
## lm(formula = mpg ~ wt + factor(cyl), data = mtcars)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.5890 -1.2357 -0.5159 1.3845 5.7915
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 33.9908 1.8878 18.006 < 2e-16 ***
## wt -3.2056 0.7539 -4.252 0.000213 ***
## factor(cyl)6 -4.2556 1.3861 -3.070 0.004718 **
## factor(cyl)8 -6.0709 1.6523 -3.674 0.000999 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.557 on 28 degrees of freedom
## Multiple R-squared: 0.8374, Adjusted R-squared: 0.82
## F-statistic: 48.08 on 3 and 28 DF, p-value: 3.594e-11
cat("\n\nKey Results:\n")
##
##
## Key Results:
cat("R-squared:", round(summary(model)$r.squared, 4), "\n")
## R-squared: 0.8374
cat("Residual Std. Error:", round(summary(model)$sigma, 4), "\n")
## Residual Std. Error: 2.5569
Reflection Question 6: Looking at the plot above, describe the
relationship between vehicle weight (x-axis) and fuel efficiency
(y-axis). What does the model suggest?
Answer: The model suggests that vehicle weight is strongly inversely
related with fuel efficiency (p-value = 0.000213).
The r-squared value showing that ~84% of the variation in fuel
efficiency is due to vehicle weight.