Foundations of Programming in R for Political Analysis in the Age of AI

This course offers hands-on training in R programming for quantitative political analysis, paired with practical and responsible techniques for using AI assistants to write, debug, and verify data analysis code. 

Dr. Thiago Nascimento da Silva is a Senior Lecturer in the School of Politics and International Relations at ANU, where he also serves as Convenor of SPIR's Honours Program. He is Deputy Director of the Australian Centre for Federalism, co-chair of APSA's Quantitative Methods Group, and a Committee Member of the Australian Society for Quantitative Political Science (ASQPS). His research focuses on comparative politics, particularly political institutions and political economy. Using quantitative methods, he examines how institutional variation across democracies shapes government formation, policymaking, party competition, voter behaviour, and opposition dynamics. He is the co-author of the recently published books Learning to Govern Together in Representative Democracy (Oxford University Press) and Voter's Perceptions of Party Brands (Cambridge University Press).  Website: https://thiagosilvaphd.com/ 

Course Level
R progromming lanuage logo with code in background

 

This course teaches two skills at once: programming in R, and using large language models (LLMs) as a tools to learn and write code. R (free, open-source, and built for statistical computing) is the foundation of the course. AI is treated as a concrete, learnable skill in it's own right: not a shortcut around understanding, but a method for learning R faster, debugging more effectively, and writing code efficiently.

Designed for newcomers with no prior programming or AI experience, the course develops both tracks in parallel. On the R side students learn the core building blocks (e.g., basic commands, operators, package use, functions, conditionals, and loops0 and progress through the data science workflow underpinning political analysis: data types (categorical, continuous, discrete, nominal); data structures (vectors, matrices, data frames, lists); data wrangling from import/export to cleaning, missing values, outliers, and transformations; exploratory data analysis; and data visualisations producing professional academic tables and figures. On the AI side, students learn specific, transferable techniques: writing prompts that that produce usable R code, reading and adapting what an LLM returns, debugging with AI rather than guessing, and verifying that generated code does what it claims.

 

Learning outcomes

  • By the end of this course, students will be able to:
  • Write run and organise R code in RStudio, using objects, functions, conditionals, and loops;
  • Import, clean, transform, and explore political datasets from common formats (CSV, Stata, SPSS, RData);
  • Produce professional tables and figures with ggplot2 and interpret correlations and simple regression output;
  • Write effective prompts for an LLM assistant, then read, adapt, and debug the code it generates; 
  • Verify AI-generated analysis through systematic checks, within a transparent, reproducible workflow

 

This course is presented as part of the ANU Online Summer School in Political Analysis

Image
ANU logo

 

 

 

Day 1 – Introduction to R, RStudio ad AI Coding Assistants

  • RStudio interface; Console vs Script; objects, vectors,loops, and functions
  • Basic commands and operations; first steps in writing and running code
  • What LLMs can (and cannot) do for a beginning programmer; assistant set-up
  • First Prompts: asking an LLM to explain code and error messages

Exercise/ case study: Write and run a first R script; break it, then use an LLM to interpret the errors and explain the fix

 

Day 2 – Packages, Data Types and Prompting for Code

  • Installing/loading packages; reading data (CSV, RData, URLs)
  • Variables and measurement levels; creating and transforming variables
  • Anatomy of an effective coding prompt: context, task, constraints, examples
  • Reading and adapting AI-generated code before running it

Exercise / case study: Import a cross-national dataset twice (hand-written code vs prompted code) then compare and correct both.

 

Day 3 – Data Wrangling, Cleaning and AI-Assisted Debugging

  • Importing Stata, SPSS, and CSV data; subsetting, recoding, new variables
  • Handling missing values and basic cleaning
  • Debugging with AI: minimal reproducible examples; pasting errors productively
  • Verifying wrangling steps: row counts, before/ after cross-tabulations, spot checks

Exercise/ case Study: Political economy dataset: clean a messy country-year dataset with AI assistance, verifying every transformation.

 

Day 4 – Exploratory Data Analysis and Verifying AI output

  • Descriptive statistics, distributions, and outliers; intro to graphical illustrations
  • Drafting an exploratory analysis plan with an LLM; and auditing it against the data
  • Hallucination and overconfidence: checking generated interpretations against actual output
  • Sanity checks on summaries; plotting raw data; inspecting intermediate objects

Exercise / case study: Political survey data: exploratory analysis with a verification checklist for every AI-assisted step.

 

Day 5 – Visualisation, Correlation and a Responsible AI Workflow

  • ggplot2 basics (bar plots, histograms, box plots); correlation and scatterplots
  • Simple regression analysis: interpreting coefficients
  • Iterating on figures conversationally with an LLM to publication quality
  • Reproducibility and transparency: scripting, commenting and disclosing AI assistance

Exercise / case study: Capstone on systems and types of government: a fully scripted analysis from raw data to publication-quality figure, with verification notes.

 

 

 

This course will be run in one session per day running over over 5 days. 

The course hours are 9.30am - 12.00pm each day

This course is being held online via Zoom and run on Australian Eastern Daylight Time (GMT +11)

 

 

 

•    Install R and RStudio (https://www.dataquest.io/blog/tutorial-getting-started-with-r-and-rstudio/);
•    Create a free account with one LLM assistant;
•    Read the “Introduction” and “Workflow: basics” chapters of R for Data Science (2nd ed.) (free online: https://r4ds.hadley.nz/

 

 

 

I'm an R novice so spending four days working through the basics is excellent. I'll need to do a more advanced course after some practice so I become more familiar with advanced statistical tests.

The course was excellent

 

Notify me about the next course offering

Get notified by email when a new offering of this course is scheduled

Leave empty this text field if you are not a bot.