Welcome to EPI 553: Principles of Statistical Inference II! This document will verify that your R environment is properly configured for the course. Work through each section carefully and note any errors or warnings. If you encounter problems, refer to the troubleshooting resources on Brightspace before contacting the instructor.
Goal: By the end of this document, you should have confirmed that: - ✓ R and RStudio are installed and functional - ✓ Required packages load without errors - ✓ A working folder/project structure is set up - ✓ You can render R Markdown files (HTML/PDF) - ✓ You can upload files to Brightspace
Let’s start by checking your R installation. Run the code below:
## R Version: 4.5.2
## Platform: aarch64-apple-darwin20
## OS: Darwin
# Version requirement check
if (as.numeric(R.version$major) >= 4 & as.numeric(R.version$minor) >= 0) {
cat("\n✓ R version is current (4.0 or later). Perfect!\n")
} else {
cat("\n⚠ WARNING: R version is older than 4.0. Consider updating from https://www.r-project.org/\n")
}##
## ✓ R version is current (4.0 or later). Perfect!
What to look for: - R version should be 4.0 or later - If you have an older version, visit https://www.r-project.org/ to update
You’re already in RStudio if you’re viewing this document! Let’s confirm the details:
# Check if running in RStudio
if (exists("RStudio.Version")) {
cat("✓ RStudio is running\n")
cat("✓ RStudio Version:", RStudio.Version()$version, "\n\n")
cat("Tip: You can update RStudio from Help → Check for Updates\n")
} else {
cat("⚠ This script should be run in RStudio for best experience.\n")
cat("Download RStudio Desktop (Free) from: https://posit.co/download/rstudio-desktop/\n")
}## ⚠ This script should be run in RStudio for best experience.
## Download RStudio Desktop (Free) from: https://posit.co/download/rstudio-desktop/
RStudio Features You’ll Use: - Console (bottom left): Run R commands directly - Script Editor (top left): Write and save R code - Environment/History (top right): See variables and command history - Files/Plots/Packages/Help (bottom right): Manage files and view output - Knit Button: Render this R Markdown file to HTML (top of editor)
This course relies on specific R packages, particularly the tidyverse ecosystem. Let’s check if they’re installed and load them:
# Define required packages for EPI 553
required_packages <- c(
"tidyverse", # Data manipulation (includes ggplot2, dplyr, tidyr, etc.)
"rmarkdown", # R Markdown support
"knitr", # Dynamic document generation
"ggplot2", # Visualization (included in tidyverse)
"dplyr", # Data manipulation (included in tidyverse)
"car", # Companion to Applied Regression - diagnostics
"lmtest", # Linear Regression Testing
"sandwich", # Robust covariance matrices
"stargazer", # Create nice statistical tables
"broom" # Convert statistical objects to data frames
)
cat("Checking for required packages...\n\n")## Checking for required packages...
# Check and load packages
packages_ok <- TRUE
for (pkg in required_packages) {
if (require(pkg, character.only = TRUE, quietly = TRUE)) {
cat("✓", pkg, "\n")
} else {
cat("✗", pkg, "NOT INSTALLED\n")
packages_ok <- 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.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.2
## ✔ purrr 1.2.0
## ── 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
## ✓ rmarkdown
## ✓ knitr
## ✓ ggplot2
## ✓ dplyr
##
## Attaching package: 'car'
##
## The following object is masked from 'package:dplyr':
##
## recode
##
## The following object is masked from 'package:purrr':
##
## some
## ✓ car
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
## ✓ lmtest
## ✓ sandwich
## ✗ stargazer NOT INSTALLED
## ✓ broom
## Some packages need to be installed. Running installation...
If any packages showed an ✗ above, run the code below to install them:
# Install all required packages
required_packages <- c(
"tidyverse", "rmarkdown", "knitr", "ggplot2", "dplyr",
"car", "lmtest", "sandwich", "stargazer", "broom"
)
for (pkg in required_packages) {
if (!require(pkg, character.only = TRUE)) {
install.packages(pkg, dependencies = TRUE)
}
}
cat("\n✓ Installation complete! Restart R (Ctrl+Shift+F10) and run this document again.\n")Troubleshooting Package Installation: - Firewall blocking downloads? Connect to UAlbany WiFi or use VPN - Permission errors? Run RStudio as administrator (Windows) or check permissions (Mac) - Installation still failing? Contact the instructor by January 27
Your working directory is where R looks for files and saves outputs. Let’s check yours:
## Your current working directory:
## /Users/mm992584/Library/CloudStorage/OneDrive-UniversityatAlbany-SUNY/Spring 2026/Epi 553/Week 1 R Setup Chunk
# Check for R Project
if (file.exists(".Rproj")) {
cat("✓ You are working in an R Project (.Rproj file detected)\n")
cat("✓ This is the RECOMMENDED way to organize your work\n\n")
} else {
cat("⚠ No R Project detected.\n")
cat("RECOMMENDED: Create an R Project for this course\n")
cat("How to create one: File → New Project → New Directory → New Project\n\n")
}## ⚠ No R Project detected.
## RECOMMENDED: Create an R Project for this course
## How to create one: File → New Project → New Directory → New Project
Organize your files like this for the course:
# Define suggested folders
suggested_folders <- c("data", "scripts", "outputs", "figures")
cat("Suggested folder structure:\n")## Suggested folder structure:
## epi553-coursework/
## ├── data/ (store datasets here)
## ├── scripts/ (save your R scripts here)
## ├── outputs/ (save your results/reports here)
## └── figures/ (save plots here)
## Current status:
for (folder in suggested_folders) {
if (dir.exists(folder)) {
cat("✓", folder, "/ exists\n")
} else {
cat("○", folder, "/ (does not exist yet)\n")
}
}## ○ data / (does not exist yet)
## ○ scripts / (does not exist yet)
## ○ outputs / (does not exist yet)
## ○ figures / (does not exist yet)
## To create missing folders, run:
## dir.create('data')
## dir.create('scripts')
## dir.create('outputs')
## dir.create('figures')
One of the key skills for this course is creating reproducible reports with R Markdown. Let’s verify you can render documents:
# Check R Markdown capabilities
if (require("rmarkdown", quietly = TRUE)) {
cat("✓ rmarkdown package loaded successfully\n")
cat("✓ You can render R Markdown files to HTML and PDF\n\n")
cat("To render an R Markdown file in RStudio:\n")
cat("1. Open the .Rmd file\n")
cat("2. Click the 'Knit' button (Ctrl+Shift+K)\n")
cat("3. Choose output format (HTML, PDF, etc.)\n")
cat("4. View the rendered document\n")
} else {
cat("✗ rmarkdown package not loaded\n")
cat("Run: install.packages('rmarkdown')\n")
}## ✓ rmarkdown package loaded successfully
## ✓ You can render R Markdown files to HTML and PDF
##
## To render an R Markdown file in RStudio:
## 1. Open the .Rmd file
## 2. Click the 'Knit' button (Ctrl+Shift+K)
## 3. Choose output format (HTML, PDF, etc.)
## 4. View the rendered document
Let’s do a quick analysis to make sure everything works. We’ll use
the built-in mtcars dataset:
# Load tidyverse for nice data manipulation
library(tidyverse)
# Explore the mtcars dataset
cat("Dataset: mtcars (Motor Trend Car Road Tests)\n")## Dataset: mtcars (Motor Trend Car Road Tests)
## Number of observations: 32
## Number of variables: 11
## Summary of Miles Per Gallon (mpg):
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10.40 15.43 19.20 20.09 22.80 33.90
# Create a plot using ggplot2 (part of tidyverse)
mtcars %>%
ggplot(aes(x = wt, y = mpg, color = factor(cyl))) +
geom_point(size = 3, alpha = 0.7) +
labs(
title = "Fuel Efficiency vs Weight",
subtitle = "EPI 553 - Setup Test",
x = "Weight (1000 lbs)",
y = "Miles Per Gallon (mpg)",
color = "Cylinders"
) +
theme_minimal() +
theme(plot.title = element_text(size = 14, face = "bold"))# Fit a linear regression model
model <- lm(mpg ~ wt + factor(cyl), data = mtcars)
# Print results
cat("Linear Regression Model: mpg ~ weight + cylinders\n\n")## Linear Regression Model: mpg ~ weight + cylinders
##
## 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
If you see: - ✓ A plot above → Graphics rendering works! - ✓ Model output → Linear regression works! - ✓ No errors → Your setup is working!
Use this checklist to confirm your setup is complete:
## ═══════════════════════════════════════════════════════════════
## WEEK 1 SETUP CHECKLIST
## ═══════════════════════════════════════════════════════════════
checklist <- tibble(
Item = c(
"R installed (version 4.0+)",
"RStudio installed and running",
"Required packages installed",
"Working directory set up",
"R Project created (.Rproj)",
"Folder structure created",
"Can render R Markdown to HTML",
"Can knit this document to HTML",
"Understand RStudio layout",
"Comfortable running R code"
),
Status = rep("☐ Complete", 10)
)
print(as.data.frame(checklist), row.names = FALSE)## Item Status
## R installed (version 4.0+) ☐ Complete
## RStudio installed and running ☐ Complete
## Required packages installed ☐ Complete
## Working directory set up ☐ Complete
## R Project created (.Rproj) ☐ Complete
## Folder structure created ☐ Complete
## Can render R Markdown to HTML ☐ Complete
## Can knit this document to HTML ☐ Complete
## Understand RStudio layout ☐ Complete
## Comfortable running R code ☐ Complete
##
## ═══════════════════════════════════════════════════════════════
One of the key skills in modern reproducible research is sharing your work publicly. In this course, you will publish your R Markdown documents to RPubs, a free hosting platform for R Markdown files. This demonstrates:
RPubs (https://rpubs.com/) is a free publishing platform created by RStudio (now Posit). It allows you to: - Publish R Markdown documents with one click - Share a public URL with anyone - Display your data analysis work professionally - Build a portfolio of your work
Example: Dr. Masum’s EPI 552 review is published at https://rpubs.com/muntasir_masum/review_552
firstname_lastname or ualbany_ID)html_document in the YAML
headerepi553_week1_setup)https://rpubs.com/yourusername/epi553_week1_setupFor Course Work: - Use consistent naming:
epi553_weekN_lastname - Include your full name in the
document author field - Add the course number and date in the
title/subtitle - Update your publication when you make corrections
Privacy & Professionalism: - RPubs documents are public by default (anyone can see them) - Only publish work you’re comfortable sharing publicly - Don’t include sensitive or confidential information - Your username appears in the URL, so keep it professional
Building a Portfolio: - Organize your RPubs documents chronologically - Link to them from your resume or GitHub profile - Employers can see your data analysis and communication skills
For RPubs/Publishing Questions: - Visit https://rpubs.com/about/getting-started - See RStudio’s publishing guide: https://posit.co/blog/r-markdown-and-rpubs/ - Ask during office hours
For Course Content:
Instructor (Dr. Muntasir Masum): - Email: mmasum@albany.edu - Office: Pine Bush 255 - Office Hours: Tuesdays & Thursdays, 10:20 am - 11:30 am (right after class)
Teaching Assistant (Yiming Wang): - Email: ywang98@albany.edu - Office Hours: Mondays & Wednesdays, 11:30 am - 4:30 pm
Technical Support: - UAlbany IT Help Desk: 518-442-3700 or helpdesk@albany.edu
Congratulations! If you were able to render this document to HTML, you’re ready for EPI 553. See you in class!
# Display your R environment information (helpful for troubleshooting)
cat("\n\nSession Information:\n")##
##
## Session Information:
## R version 4.5.2 (2025-10-31)
## Platform: aarch64-apple-darwin20
## Running under: macOS Tahoe 26.2
##
## Matrix products: default
## BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: America/New_York
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] broom_1.0.11 sandwich_3.1-1 lmtest_0.9-40 zoo_1.8-15
## [5] car_3.1-3 carData_3.0-5 knitr_1.51 rmarkdown_2.30
## [9] lubridate_1.9.4 forcats_1.0.1 stringr_1.6.0 dplyr_1.1.4
## [13] purrr_1.2.0 readr_2.1.6 tidyr_1.3.2 tibble_3.3.0
## [17] ggplot2_4.0.1 tidyverse_2.0.0
##
## loaded via a namespace (and not attached):
## [1] sass_0.4.10 generics_0.1.4 stringi_1.8.7 lattice_0.22-7
## [5] hms_1.1.4 digest_0.6.39 magrittr_2.0.4 evaluate_1.0.5
## [9] grid_4.5.2 timechange_0.3.0 RColorBrewer_1.1-3 fastmap_1.2.0
## [13] jsonlite_2.0.0 backports_1.5.0 Formula_1.2-5 scales_1.4.0
## [17] jquerylib_0.1.4 abind_1.4-8 cli_3.6.5 rlang_1.1.6
## [21] withr_3.0.2 cachem_1.1.0 yaml_2.3.12 otel_0.2.0
## [25] tools_4.5.2 tzdb_0.5.0 vctrs_0.6.5 R6_2.6.1
## [29] lifecycle_1.0.4 pkgconfig_2.0.3 pillar_1.11.1 bslib_0.9.0
## [33] gtable_0.3.6 glue_1.8.0 xfun_0.55 tidyselect_1.2.1
## [37] rstudioapi_0.17.1 farver_2.1.2 htmltools_0.5.9 labeling_0.4.3
## [41] compiler_4.5.2 S7_0.2.1