1 Introduction

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


2 1. R Version Check

Let’s start by checking your R installation. Run the code below:

# Check R version
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
cat("OS:", Sys.info()["sysname"], "\n")
## 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


3 2. RStudio Environment

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)


4 3. Required Packages

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
cat("\n")
if (!packages_ok) {
  cat("Some packages need to be installed. Running installation...\n\n")
}
## Some packages need to be installed. Running installation...

4.1 Installing Missing Packages

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


5 4. Working Directory & Project Structure

Your working directory is where R looks for files and saves outputs. Let’s check yours:

# Current working directory
current_wd <- getwd()
cat("Your current working directory:\n")
## Your current working directory:
cat(current_wd, "\n\n")
## /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

6 5. Test Your R Markdown Rendering

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

7 6. Practice: Simple Analysis

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)
cat("Number of observations:", nrow(mtcars), "\n")
## Number of observations: 32
cat("Number of variables:", ncol(mtcars), "\n\n")
## Number of variables: 11
# Summary statistics
cat("Summary of Miles Per Gallon (mpg):\n")
## Summary of Miles Per Gallon (mpg):
summary(mtcars$mpg)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   10.40   15.43   19.20   20.09   22.80   33.90

7.1 Create a Simple Visualization

# 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"))

7.2 Fit a Simple Model

# 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
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

If you see: - ✓ A plot above → Graphics rendering works! - ✓ Model output → Linear regression works! - ✓ No errors → Your setup is working!


8 7. Final Checklist

Use this checklist to confirm your setup is complete:

cat("═══════════════════════════════════════════════════════════════\n")
## ═══════════════════════════════════════════════════════════════
cat("WEEK 1 SETUP CHECKLIST\n")
## WEEK 1 SETUP CHECKLIST
cat("═══════════════════════════════════════════════════════════════\n\n")
## ═══════════════════════════════════════════════════════════════
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
cat("\n═══════════════════════════════════════════════════════════════\n")
## 
## ═══════════════════════════════════════════════════════════════

9 Next Steps

9.1 Immediate (This Week)

  1. If you see errors above:
    • Check the troubleshooting section in the syllabus on Brightspace
    • Contact the instructor if problems persist ()
    • Deadline: January 27, 2026
  2. Render this document:
    • Click the “Knit” button at the top of this window
    • Select “Knit to HTML”
    • View the rendered version
    • Save it (File → Save)
  3. Set up your folder structure:
    • Create the recommended folders in your course project
    • Use consistent naming (lowercase, no spaces)
  4. Upload to Brightspace:
    • Go to Brightspace → EPI 553 → Assignments → Week 1 Setup
    • Upload the rendered HTML file
    • This demonstrates you can work with R Markdown

9.2 Before First Class (January 22)

  • Complete this setup check
  • Resolve any technical issues
  • Familiarize yourself with RStudio layout
  • Review the R basics in the course notes on Brightspace

9.3 Helpful Resources


10 Publishing Your Work to RPubs

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:

  • Your ability to create reproducible, professional documents
  • Your R programming skills to colleagues and potential employers
  • Transparent, open science practices
  • Your commitment to reproducible research

10.1 What is RPubs?

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

10.2 How to Publish This Document to RPubs

10.2.1 Step 1: Create an RPubs Account (One-Time Setup)

  1. Go to https://rpubs.com/
  2. Click “Register” in the top right
  3. Choose a username (this will appear in your URLs)
    • Tip: Use something professional (e.g., firstname_lastname or ualbany_ID)
    • Avoid usernames with spaces or special characters
  4. Enter your email and create a password
  5. Click “Register”
  6. Check your email for a confirmation link
  7. Click the confirmation link to activate your account

10.2.2 Step 2: Connect RStudio to Your RPubs Account

  1. In RStudio, go to Tools → Global Options
  2. Click “Publishing” in the left sidebar
  3. Click “Connect” button
  4. Select “RPubs”
  5. A browser window will open to RPubs
  6. Log in with your RPubs credentials
  7. Click “Authorize” to allow RStudio to publish on your behalf
  8. Return to RStudio (should show successful connection)

10.2.3 Step 3: Render and Publish This Document

  1. Knit to HTML: Click the “Knit” button (or Ctrl+Shift+K)
    • Make sure output is html_document in the YAML header
  2. Publish: Once rendered, click the blue “Publish” button in the top right of the Viewer pane
    • Or click the ▼ arrow next to “Knit” → “Publish Document”
  3. Configure Publication:
    • Choose “RPubs”
    • Add a Title (e.g., “EPI 553: Week 1 Setup Check - Student Name”)
    • Add a Slug (short URL identifier, e.g., epi553_week1_setup)
    • This creates a URL like: https://rpubs.com/yourusername/epi553_week1_setup
  4. Click “Publish”
    • RPubs will process and host your document
    • Your document is now publicly available!
  5. Share Your Link:
    • Copy the URL and save it
    • Submit the RPubs link to Brightspace
    • You can update the document anytime by publishing again

10.2.4 RPubs Best Practices

For 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


11 Questions? Need Help?

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: - Office: Pine Bush 255 - Office Hours: Tuesdays & Thursdays, 10:20 am - 11:30 am (right after class)

Teaching Assistant (Yiming Wang): - Email: - Office Hours: Mondays & Wednesdays, 11:30 am - 4:30 pm

Technical Support: - UAlbany IT Help Desk: 518-442-3700 or


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:
sessionInfo()
## 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