GitHub is a web based platform to host data, source code, projects. It’s useful for a variety of reasons, some perhaps more important than others in your own research.
Version Control: Track changes to your code and documents
Collaboration: Work with others on the same project
Project Management: Organize tasks and track progress
Backup: Store your work in the cloud
Questions, Instructions
Why Use GitHub?
For Your Research
GitHub makes computer code transparent, reproducible, and collaborative. It’s transparent because it’s open to the public, it’s reproducible because it allows others to recreate and expand upon your work, and it’s collaborative because it creates a platform for users to jointly contribute to a project.
Version Control. It allows you to track every change you make. It’s trivial to revert back to previous code.
Key Concepts
Repository (Repo)
A repository is a folder that contains: - Your code files - Data files - Documentation (README.md) - Configuration files - Complete history of changes - Let’s have a look at the structure of a repo
Search for this repository, fork it to your account, and clone it to your computer
And, createa sample repository to practice with.
RStudio
Generally you should work from the terminal to use Git commands.
You can access the terminal from within RStudio: Tools\(\rightarrow\)Terminal\(\rightarrow\)New Terminal
Alternatively, when using RStudio, you can use the Git tab to perform Git operations via a graphical interface, the Git tab.
We’ll use Git a lot in this course, but instead of an exhaustive presentation at the beginning, let’s take things in steps, starting with accessing the files for this course.
Understanding Git Workflows
Three Key Concepts
Forking: Creating your own copy of someone else’s repository
Committing: Saving changes to your local repository
Push/Pull: Synchronizing between local and remote repositories
Forking vs. Cloning
Fork
Creates a copy of a repository under your GitHub account
A forked repository is useful for collaboration
Use when you want to contribute to someone else’s project
Common in open-source collaboration
Clone
Downloads a repository to your local computer
You can clone your own repos or others’ repos
Changes are made locally until you push them
Clones are “read-only” unless it is a repo in your account.
Fork + Clone = Collaboration
A Fork + Clone allows you to generate a “pull request”
The Commit Workflow
What is a Commit?
A snapshot of your changes at a point in time
Each commit has a unique ID and message
Creates a history of your work
Basic Terminal Commands
# Check status of your filesgit status# Add files to staging areagit add data_683.Rgit add . # adds all changed files# Commit changes with a messagegit commit -m"My new 683 repo"
Pull, Push, and Staying in Sync
The Basic Workflow
# 1. Pull latest changes from remotegit pull origin main# 2. Make your changes to files# (edit your code, data, etc.)# 3. Stage and commit changesgit add .git commit -m"Update analysis"# 4. Push changes to remotegit push origin main
Some Practical Advice:: Always pull before you start working to avoid conflicts!
When to Use What?
Action
When to Use
Command
Fork
Contributing to others’ projects
Done on GitHub website
Clone
Getting a repo onto your computer
git clone <url>
Pull
Getting latest changes from remote
git pull origin main
Commit
Saving changes locally
git commit -m "message"
Push
Sending local changes to remote
git push origin main
## Class Activity
Fork the Class Repository
Clone the Repo to your Computer
Create a .qmd file in the tmp folder
Add content and save
Add, Commit, and Push
The Linear Regression Model
Linear regression is one of the most widely used statistical methods for several reasons:
Straightforward and foundational - ideal starting point for advanced techniques
Data Exploration and Inference - descriptive analysis, exploratory data analysis, inference
Practical utility - hypothesis testing and predictive modeling
The Logic Underlying the Regression Model
A Brief (Troubled) History
Francis Galton (1886) used regression and coined the term to denote a “regression to the mean” often in the heritability of physical charateristics.
For instance, he compared characteristics using inter-generational data (e.g., average height in father-son pairs; Pearl & Mackenzie 2018)
Observed “regression to the mean”: If a father is 5’2’’ (unusually short), his son tends to be short but closer to the population average (taller than the father, closer to the mean; problematically referred to as “regression to mediocrity” by Galton)
Galton was a founder of the eugenics movement
The broader method – a statistical model that can be used to quantify the relationship between two variables – is value neutral
But a word of caution: Statistical methods are routinely abused and misinterpreted, sometimes in tragic and unexpected ways; all the more reason to thoroughly understand how they work
A Linear Model
Linear regression is a common technique in the social sciences.
Distills complex relationships to a simple linear relationship.
\[y_i = \alpha + \beta x_i\]
Intercept (\(\alpha\)): The point at which the regression line crosses the \(y\)-axis, or the value of \(y\) when \(x=0\).
Slope (\(\beta\)): The change in \(y\) for every unit change in \(x\). Formally: \(\frac{\partial y}{\partial x} = \beta\)
Examples…..
Some Common Misconceptions
Reverse Causality
\(x\) may be caused by \(y\) rather than the reverse.
Confounding
\(x\) may be related to \(y\), but there is a common variable affecting both.
Mediation
A relationship may be indirect through another variable.
The Challenge
It is difficult to sort these out using a regression model with observed cross-sectional data.
In most applications, we observe the outcome of a process. It is often difficult to make claims about the process itself.
Observation versus Manipulation
Experimental versus Observational
Is \(x\) observed or under the control of the researcher?
If observational: We can examine whether a relationship exists, but that relationship does not imply causation.
Correlation versus Regression
The two are intimately related, but we make several key assumptions in the regression equation.
Dependent variable (regressand): The outcome
Explanatory variable (regressor): The predictor
The explanatory variable is fixed and exogenous; the dependent variable is random and endogenous *
Data Types
Random/Stochastic Variables
Variables that take on a set of values drawn from a probability distribution.
Cross-Sectional Data
Units observed once. Indexed with \(i\): \(x_i\)
Time Series Data
A single unit observed multiple times. Indexed with \(t\): \(x_t\) - May trend (systematic change) or be stationary (randomly varying around a mean)
Panel Data
Multiple units observed over multiple time periods. Indexed with \(i\) and \(t\): \(x_{it}\)
Variable Types
Type
Zero Point
Distances
Ordering
Examples
Ratio
Natural
Meaningful
Natural
Income, height, age
Interval
None
Meaningful
Natural
Temperature (°C), IQ
Ordinal
None
Meaningless
Natural
Education level, satisfaction
Nominal
None
Meaningless
None
Religion, ethnicity, region
Quantitative variables: Ratio and Interval Qualitative variables: Ordinal and Nominal
The Linear Model
The basic functional form:
\[y_i = \alpha + \beta x_i\]
Where:
\(\alpha\) = intercept (value of \(y\) when \(x=0\))
\(\beta\) = slope (change in \(y\) for every unit change in \(x\))
More formally: \(\partial y / \partial x = \beta\)
The Stochastic Model
Real-world relationships are stochastic rather than deterministic