R and Statistics Labs
The four labs form the quantitative spine of the course. They teach R programming and foundational statistics through practical survey problems, with the live Univision project providing the principal application.
No prior mastery of R is required. Most lab work will be completed together during class: the instructor will introduce the statistical idea, build the code with students, pause for interpretation and troubleshooting, and model how to check the results. Students will then complete a shorter On Your Own section individually.
Lab materials
Optional R Basics Review
R Basics Review: Working in R and RStudio · Video Part 1 · Video Part 2 — coming soon
This optional reference reviews the basic R workflow used throughout the course. There is nothing to submit. Use it while following the review recording, print it if useful, or return to individual sections when you need a reminder.
Lab 1: Your First Reproducible Survey Analysis
Read Lab 1 · Download the Lab 1 student template · Download the LNS data
Lab 2: Describing and Visualizing Survey Responses
Lab 3: From a Sample to an Estimate
Read Lab 3 · Lab 3 student template · October Texas poll CSV · Codebook · Statewide crosstabs · Latino crosstabs
Lab 4: From Respondents to Poll Estimates
Due: Wednesday, December 2, at 11:59 p.m.
Read Lab 4 · Lab 4 student template · October Texas poll CSV · Codebook
Lab sequence
| Lab | R and statistical foundations | Survey application |
|---|---|---|
| 1 | RStudio projects, Quarto, objects, functions, packages, importing data, variable types, missing values, filtering, recoding, summarizing, and readable code | Importing a survey, reading its codebook, cleaning variables, and creating a documented analysis file |
| 2 | Distributions, proportions, means and medians, cross-tabulations, grouped summaries, scales and indexes, and ggplot2 | Describing respondents, evaluating measures, and visualizing survey responses accurately |
| 3 | Probability, random sampling, simulation, sampling distributions, standard errors, margins of error, confidence intervals, and basic hypothesis tests | Understanding why poll estimates vary and evaluating topline and subgroup differences |
| 4 | Building a simple post-stratification weight, weighted means, weight distributions, and the logic of effective sample size/design effects | Comparing raw and weighted Texas poll estimates and producing defensible toplines |
Lab format
Each lab has two connected parts.
Guided workshop
Most of the lab is completed together during class. We will:
- introduce the statistical logic through a survey question;
- build and run the R code step by step;
- interpret the output in plain language;
- diagnose common errors;
- check whether the result is plausible; and
- connect the technique to the Univision project.
On Your Own
Students will independently complete a shorter application using a new variable, question, or subset of the data. This section assesses whether each student can adapt the guided workflow, make appropriate choices, and explain the result.
The individual portion should normally be finishable in approximately 60–90 minutes after class when a student has participated in the guided workshop.
What students should learn
By the end of the lab sequence, students should be able to:
- create and navigate an RStudio project;
- import and inspect common survey-data formats;
- use a codebook and distinguish variable types;
- clean, label, recode, and document variables;
- identify and handle missing values appropriately;
- calculate and interpret descriptive statistics;
- create cross-tabulations and clear survey graphics;
- explain sampling variability, standard errors, margins of error, and confidence intervals;
- evaluate basic differences across groups;
- calculate and interpret weighted survey estimates;
- recognize the consequences of extreme weights and design effects;
- produce a reproducible Quarto analysis.
The objective is not memorizing formulas or R commands. Students should understand the logic of a method, recognize when it is appropriate, implement it with a documented workflow, check the output, and explain the result to a nontechnical audience.
Submission and evaluation
Students submit the completed Quarto source file and rendered output. Labs are evaluated on:
- completion of the independent section;
- correct statistical reasoning;
- functioning and readable code;
- appropriate checks and documentation;
- accurate interpretation; and
- reproducibility.
Because programming involves troubleshooting, a minor syntax error will matter less than evidence that the student understands the intended analysis, can diagnose the problem, and can explain what the code and output mean.
Relationship to existing materials
The repository already contains useful foundations in introductory R, data manipulation, probability, inference, regression, predicted probabilities, and a Latino National Survey case study. These materials have been adapted into the four-lab sequence. Outdated syntax will be updated as needed.