Revision Study Guide: tested code, worked output and exam tips
Git and GitHub, R fundamentals, simulation, regex and tidy data
Linear models, S3 classes, matrix computation, debugging and profiling
Maximum likelihood and optimisation, graphics, bootstrap, MCMC and JAGS
Every code block was run in R 4.3.3 and the printed output is genuine
Independent, original study material. Not affiliated with or endorsed by any university.
Statistical Programming in R | page 1
,Contents
1. Git and GitHub essentials
2. R fundamentals: vectors, structures, functions
3. Apply family, pipes and vectorisation
4. Simulation and Monte Carlo
5. Files, regular expressions and tidy data
6. Linear models
7. S3 classes
8. Matrix computation
9. Design, debugging, testing and profiling
10. Maximum likelihood and optimisation
11. Graphics
12. Bootstrap, MCMC and JAGS
13. R Markdown and reproducibility
14. Quick reference and common mistakes
Statistical Programming in R | page 2
, 1. Git and GitHub essentials
Version control records the history of a project as a chain of snapshots called commits. Git works
locally; GitHub hosts a remote copy so you can back up, share and collaborate. The everyday loop
is: edit files, stage the changes you want, commit them with a message, then push.
SHELL (DISPLAY ONLY)
git init # start a repository in the current folder
git status # what changed?
git add analysis.R # stage a file
git commit -m "Add model fit" # snapshot with a message
git log --oneline # compact history
git remote add origin <url> # link to GitHub
git push -u origin main # upload (first push sets upstream)
git pull # fetch and merge remote changes
git clone <url> # copy a remote repository
git checkout -b feature # new branch (or: git switch -c feature)
git merge feature # bring the branch into the current one
git diff # unstaged changes line by line
Ideas to be able to explain
• Staging area: git add chooses what goes into the next commit, so one commit can be one
logical change.
• Branches let you work on a feature without disturbing the stable line; merging combines them.
• A merge conflict happens when both sides edited the same lines. Git marks them with
<<<<<<<, =======, >>>>>>>; you edit to the final text, add the file and commit.
• A .gitignore file lists files not to track, such as large data, temporary output and secrets.
• Commit small and often, with messages that say why, not just what.
Exam tip: A common question is the difference between git and GitHub. Git is the version-control tool;
GitHub is a hosting service built around it.
Statistical Programming in R | page 3