Methods in Political Science

Statistical Methods

Sirus Dehdari

Department of Political Science, Stockholm University

Practical information

  • My office: F758 in building F (7th floor). My email: sirus.dehdari@statsvet.su.se
  • The lectures follow the text by Marcus Österman & Olle Folke (available on Canvas)
  • Each “week” consists of: lecture, Stata workshop, office hours, seminars (except the first week), three weeks in total
  • At the end of each week you hand in that week’s “written assignment”
  • You hand in as a group through Canvas, the same groups as in the first part of the course

Written Assignment

  • Ahead of the seminars, your group should make a serious attempt at answering all the questions
  • All group members should participate in every part! If someone in your group is not participating, contact your seminar leader
  • The submission must be in pdf format and must not contain any photos or screenshots whatsoever
  • Write the group members’ names on the submission
  • You are not allowed to let AI write the assignments for you, but feel free to use AI tools to help you learn how to use Stata
  • Attendance at the seminars is mandatory

Office hours and other questions

  • Come to office hours if you have questions about the assignments or the course material: these sessions exist to support your learning
  • I have limited capacity to answer questions by email, so please make use of office hours instead
  • Contact the course admin with questions about e.g. how to register for the exam, where and when the exam is held, grades in Ladok, etc.
  • Contact your respective seminar leader with questions about the seminars, e.g. missed attendance

Resources

  • On Canvas there is a sample exam (without an answer key) so you can get a rough idea of what the exam will look like
  • There is also a document with practice exercises (with an answer key)
  • Statistikhjälpen: practical Stata guides covering regression analysis, descriptive statistics, and data management, with code and examples to follow along with
  • The Cheat Code: a free online textbook in math and statistics for social scientists, spanning from basic math through regression analysis, with exercises throughout
  • These lecture slides contain interactive figures, tables, and equations
  • Not displaying correctly in Safari on iPhone? Try turning off “Prevent Cross-Site Tracking” under Settings → Safari

This week we will learn the following

  • Today we will cover:
    • Data structure and different types of variables
    • Descriptive statistics (measures of central tendency and measures of spread)
    • Distributions
    • Statistical inference
  • More specifically: we will look at examples of data collection and different types of data
  • How to describe data using measures of central tendency and measures of spread
  • Understand the sampling distribution and the probability distribution
  • Understand what we mean by statistical significance

What’s the point of quantitative analysis?

  • We want to learn something about a larger population (e.g. all Swedish households)
  • Imagine the following scenario: you work for the Ministry of Rural Affairs and Infrastructure on energy issues
  • Because of high energy prices, the ministry wants to investigate indoor temperatures in Swedish households
  • How do we investigate this?
  • We can hardly visit every single Swedish household…

Data collection

  • We can carry out data collection through a random sample
  • We randomly select, say, 2000 households to answer a survey
  • The survey asks questions about indoor temperature, and the households’ answers make up our data
  • This data gives us information about those 2000 households, but the goal is to be able to say something about the entire population

Data

  • What we’ve said so far:
    • All Swedish households make up our population
    • Our sample consists of 2000 randomly selected households
    • Our data consists of information from the survey responses
  • Suppose we ask the households to report their indoor temperature and answer a number of other questions about their apartment/house

Data: example of collected data

ID Temp. Size Members Municipality Education
1 19 50 2 Järfälla B.Sc.
2 18 81 3 Gagnef High school
3 22 54 1 Hjo High school
4 21 115 4 Huddinge M.Sc.
\(\vdots\)
2000 21 180 2 Göteborg Elementary school

Variables, observations, values

  • Each row in the table represents an observation
  • In our example, each household is therefore an observation
  • The columns represent variables
  • Variables describe an object (in our example, you could think of the households’ homes as the objects)
  • A variable can take on different values (as opposed to a constant)
  • The values can be numerical or in text

When do we observe a variable?

  • In the social sciences we typically observe variable values through the collection of existing data
  • Register data, data from various archives, but also surveys, experiments, etc.
  • The units of analysis are e.g. voters, countries, political parties, or firms
  • Different types of data (click a type to see an example):
  1. Cross-sectional data: each individual (unit of analysis) appears at one point in time
  2. Panel data: the same individuals appear at several points in time
  3. Repeated cross-sectional data: data for several points in time, but not (necessarily) the same individuals
  4. Time-series data: data for several points in time for a single individual
Country Year GDP/capita ($k)
Sweden 2020 52
Norway 2020 67
Denmark 2020 61
Country Year GDP/capita ($k)
Sweden 2019 51
Sweden 2020 52
Norway 2019 66
Norway 2020 67
Country Year GDP/capita ($k)
Sweden 2019 51
Norway 2019 66
Denmark 2020 61
Finland 2020 49
Country Year GDP/capita ($k)
Sweden 2017 48
Sweden 2018 49
Sweden 2019 51
Sweden 2020 52

Scales of measurement

  • We can categorize variables based on their scale of measurement:
    1. Nominal
    2. Ordinal
    3. Interval
    4. Ratio
  • Nominal variables (or categorical variables) are typically categories that cannot be ranked: country of birth, occupation, party affiliation, etc.
  • In our example: Municipality is a nominal variable
  • Ordinal variable: the categories can be ranked
  • In our example: level of education is an ordinal variable

Scale of measurement: interval/ratio

  • Interval and ratio variables: can be ranked and have a clear, meaningful difference between values
  • Interval: A clear difference between values, but comparing the values (as ratios) is not meaningful
  • Example of an interval variable: temperature (in Celsius or Fahrenheit), IQ-test score
  • Ratio variables additionally have an absolute zero point, which represents a total absence of the value
  • In our example: Temperature is interval, Size and Members are ratio

Descriptive statistics

  • Ok, so we’ve collected data… now what?
  • Remember our goal: we want to say something about the population
  • Describing each household individually isn’t very useful
  • We can summarize data by computing descriptive statistics
  • Typically we compute measures of central tendency and spread

Measures of central tendency

  • We can describe the variables in our data using a number of measures
  • It’s common to compute measures of central tendency: describing which values are commonly observed
    1. Mode
    2. Median
    3. Mean
  • The mode is the value that occurs most often
  • Useful for nominal and ordinal variables

Mean and median

  • The median separates the upper half from the lower half
  • I.e. half of all the values in our sample are greater than the median, half are smaller than the median
  • To be able to determine the median we need to know how our values are ranked
  • The mean gives us the average value in our sample
  • We compute the sample mean for a variable \(X\) using the following formula:
\(\bar{X}\) = \(\dfrac{1}{n}\) \(\displaystyle\sum_{i=1}^n\) \(x_i\) = \(\dfrac{1}{n}\) ( \(x_1\) + \(x_2\) + \(\ldots + x_n\) )

Mode, mean, median

  • Suppose that for 13 households we have the following values for the variable Temperature:

\[21, 22, 17, 19, 20, 21, 20, 21, 21, 20, 24, 22, 16\]

  • The mode is 21, since this value occurs most often (four times)
  • To compute the median we first need to rank the values:

\[16, 17, 19,20,20, 20, \mathbf{21}, 21, 21, 21, 22, 22, 24\]

  • We compute the mean:

\[ \bar{X} = \frac{1}{13} (21+ 22+ 17+ 19+ 20+ 21+ 20+ 21+ 21+ 20+ 24+22+16) \approx 20.3 \]

Measures of spread

  • A common measure of spread is the standard deviation
  • It represents how much the values in our data typically deviate from the mean
  • The sample standard deviation is computed using the following formula:
\(s\) = \(\sqrt{\dfrac{1}{n-1}\displaystyle\sum_{i=1}^n (X_i-\bar{X})^2}\)
  • Range: the difference between the largest and the smallest value in our data
  • Range and standard deviation are only sensible measures for interval/ratio variables

Distribution in the sample

  • We can describe the distribution of the values of our variables using histograms
  • These describe how frequently (in relative or absolute terms) each value occurs in our data

Household Temperature
1 21
2 22
3 17
4 19
5 20
6 21
7 20
8 21
9 21
10 20
11 24
12 22
13 16

Distribution in the sample

  • We can describe the distribution of the values of our variables using histograms
  • These describe how frequently (in relative or absolute terms) each value occurs in our data

Household Temperature
1 21
2 22
3 17
4 19
5 20
6 21
7 20
8 21
9 21
10 20
11 24
12 22
13 16

Population mean and estimates

  • Quick recap: we want to say something about the variable \(X\) = indoor temperature among Swedish households
  • Population mean, \(\mu_X\): The average temperature in the population
  • We use the sample mean (\(\bar{X}\)) from our random sample as an estimate of the population mean
  • The sample mean from a random sample is probably not equal to the population mean
  • Due to chance we might “oversample” households whose indoor temperature is higher than average (or lower)

Random and systematic sampling error

  • Random sampling error: since the sample is random, the sample mean can differ from the population mean
  • Or we might make random measurement errors
  • The margin of error accounts for these deviations (more on this later)
  • Systematic sampling error: non-representative samples, e.g. due to non-response, or systematic measurement errors
  • Systematic sampling error is harder to do anything about

Illustration: random and systematic sampling error

100 fictional individuals by monthly income (thousands of SEK). Click a button to draw a random sample of 10 — point at (or tap) a figure to see their income

How confident can we be?

  • Suppose we only have random sampling error; then the sample mean (our estimate) is not necessarily equal to the population mean
  • Example: we randomly select 2000 households and compute a sample mean of \(\bar{X} = 18\)
  • Our boss asks us to say something about the average indoor temperature among Swedish households — what should we answer?
  • In this particular sample we got \(\bar{X} = 18\), so that’s our best “guess”, but how confident are we that the population mean isn’t, say, 17?
  • The sample mean we compute might, due to chance, differ from the population mean, so perhaps \(\mu_{X} = 17\)

An interval

  • What if we could present an interval symmetric around our estimate \(\bar{X}\)?
  • We say that we believe the true population mean lies between the lower and upper bounds of the interval
  • For example, 18 \(\pm\) 3, i.e. that the true population mean is somewhere between 15 (18-3 = 15) and 21 (18+3 = 21)
  • We can then use the interval to dismiss (reject) claims that the average indoor temperature in the population is a value outside the interval
  • How do we decide how wide the interval should be? Is there a scientific method?

Random variables

  • To understand this method we first need to learn about the following concepts/ideas:
    1. random variables,
    2. probability distributions,
    3. the sample mean is a random variable,
    4. and has a known probability distribution,
    5. which is (approximately) a normal distribution,
    6. and has properties that help us determine the width of the interval
  • First and foremost, random variables: the values we observe are determined by random events
  • Example: the weather tomorrow at 9am; the value of a randomly drawn card from a deck
  • Or, the indoor temperature of a randomly chosen household that answers our survey

Random variables and probabilities

  • For many random variables, the different outcomes have different probabilities: some outcomes are more likely than others
  • Suppose we have a random variable that measures the age of the next person to walk into the lecture hall
  • Is it likely that a four-year-old walks in? Or that the person is between 20 and 40?
  • For this random variable it’s obvious that some outcomes, and thus values, are more likely than others

Probability distribution

  • A probability distribution shows how likely different values are to be observed (compare with a histogram)
  • The area under the curve between two points shows the probability that the random variable takes a value in between

Example: probability distributions

Back to our scenario

  • All random variables follow a probability distribution
  • In most cases, however, we don’t know which probability distribution it is
  • The variable \(X\) = indoor temperature is a random variable: we don’t know which value we’ll observe until we randomly select a household
  • We can define new random variables based on \(X\) using mathematical operations
  • Example:
    • \(Y = X + 5\)
    • \(Z = X_1 + X_2\)
    • \(\bar{X} = (X_1 + X_2 + X_3 + X_4 + X_5)/5 \quad\) (=the sample mean)
  • \(\bar{X}\) is therefore also a random variable — Visualization

The sample mean is a random variable

  • \(\bar{X}\) is a random variable and therefore follows a probability distribution
  • Because \(\bar{X}\) is computed from a sample, its probability distribution is called the sampling distribution
  • Quick summary:
    • There’s a thing called random variables,
    • all random variables have a probability distribution,
    • the sample mean (from a random sample) is a random variable,
    • and therefore follows a probability distribution (which we call the sampling distribution)
  • The Central Limit Theorem: the sampling distribution of the sample mean can be approximated by a normal distribution Simulation

Normal distribution

  • The normal distribution has a number of desirable properties
  • It is symmetric around its mean, \(\mu\)
  • The same probability of getting a value less than the mean \(\mu\) as getting a value greater than the mean \(\mu\)
  • A normal distribution can be fully described by two parameters: the mean \(\mu\) and the standard deviation \(\sigma\)
  • The mean \(\mu\) determines the “center” of the distribution, while the standard deviation \(\sigma\) describes the spread

Normal distribution: different \(\mu\) and \(\sigma\)

For different values of the mean \(\mu\) and the standard deviation \(\sigma\), the normal distribution takes on a different location and shape

Probabilities in the normal distribution

  • The probability that a certain value is observed for a random variable that follows a normal distribution is shown in the graph below
  • For example, out of 100 trials, about 68 of them will take on a value between \(\mu - \sigma\) and \(\mu + \sigma\)

Example: pizza delivery

  • Suppose the time it takes for an ordered pizza to be delivered follows a normal distribution with mean \(\mu = 30\) minutes and standard deviation \(\sigma = 5\) minutes
  • Each button press below simulates a single order: a pizza is randomly drawn and “lands” on the number line at its delivery time

\(\bar{X}\) (roughly) follows a normal distribution

  • Again: the Central Limit Theorem shows that the sample mean (roughly) follows a normal distribution
  • Moreover, we know that \(\bar{X}\) for the random variable \(X\) computed from our sample comes from a normal distribution whose \(\mu\) equals the population mean of \(X\)
  • But we don’t know the values of \(\mu\) or \(\sigma\) (called the standard error in a sampling distribution)
  • We do know, however, that about 95 percent of all possible random samples will give a sample mean within the interval \(\mu - 2 \times \sigma\) and \(\mu + 2 \times \sigma\)

Confidence interval

  • If we draw 100 random samples, 95 of them will give us a sample mean \(\bar{X}\) within the interval \(\mu - 2 \times \sigma\) and \(\mu + 2 \times \sigma\) (symmetric around \(\mu\))
  • We don’t know the value of \(\sigma\), though; but what if we could estimate it?
  • Then we’d know the “width” of the interval around the mean \(\mu\) that covers 95 out of 100 of the sample means
  • Remember the goal: present an estimate of the population mean together with an interval of plausible values
  • If the \(\bar{X}\) we compute falls within that interval around \(\mu\), then \(\mu\) must also fall within a similar interval around our \(\bar{X}\)

Does the interval cover \(\mu\)?

The shaded area covers \(\mu \pm 2\sigma\), that is, 95.45% of all realizations of \(\bar{X}\) that fall closest to \(\mu\). Draw a sample mean \(\bar{X}\) to see whether an equally wide interval around \(\bar{X}\) covers \(\mu\)

Using confidence intervals

  • \(\bar{X}\) is our best guess of what the population mean, \(\mu_X\), is
  • We believe our confidence interval covers \(\mu_X\), i.e. that \(\mu_X\) is equal to some value within the interval
  • What can we actually say about \(\mu_X\)?
  • If someone claims that \(\mu_X = 25\): if our confidence interval does not cover 25, we do not believe \(\mu_X\) can equal 25
  • If the confidence interval covers 25, we could not rule out that \(\mu_X = 25\)

How confident are we? Confidence level

  • Are we completely certain that our interval around \(\bar{X}\) covers the true population mean?
  • In 95 out of 100 cases the sample will give a sample mean (\(\bar{X}\)) that lies within that interval around the population mean — but what about the remaining 5 cases?
  • We call the interval a 95 percent confidence interval
  • We can’t know whether our particular \(\bar{X}\) is one of the 95 that fall within the interval, but it’s quite likely to be the case (95% chance)
  • The width of the confidence interval determines how confident we want to be when we claim to cover the true population mean

Confidence level and interval width

Draw a sample mean \(\bar{X}\) and try 90%, 95%, and 99% confidence level — see how the interval gets wider the more confident you want to be

Calculating a confidence interval

  • Remember that we don’t know the value of \(\sigma\), but there’s a way to estimate it:

\[ \mbox{Estimate of } \sigma = \hat{\sigma} = \frac{s_X}{\sqrt{n}} \]

  • \(s_X\) is the sample standard deviation for the variable \(X\), and \(n\) is the sample size
  • The confidence interval is computed using the following formula:

\[ \bar{X} \pm t \times \frac{s_X}{\sqrt{n}} \]

  • The \(t\)-value determines how wide the confidence interval should be

Calculating a confidence interval: example

  • Example: We measure the height of 10 randomly selected students at SU and compute the sample mean \(\bar{X} = 171\)
  • We know that estimated sample means follow a normal distribution with some \(\mu_X\) and \(\sigma\)
  • We don’t know \(\mu_X\), though — our best guess is \(\bar{X}\)
  • Suppose someone claims that the mean height among the students in the population equals 185
  • Could that really be true, given that we computed \(\bar{X} = 171\) for our sample?

Does the confidence interval cover it?

  • We compute a confidence interval for our estimate and compare it with the value 185
  • First we decide on the confidence level
  • The more confident we want to be, the wider our confidence interval becomes
  • Suppose a 95% confidence interval covers 185
  • We cannot reject the claim (hypothesis) that \(\bar{X}\) comes from a population where the mean is 185
  • In other words: these 10 students may well come from a population where the mean height is 185

Does the confidence interval not cover it?

  • Suppose the confidence interval does not cover 185

  • We can then, with 95% confidence, say that \(\bar{X}\) does not come from a population where the mean is 185

  • Why? Well, our interval covers the true population mean, and if the interval does not cover 185, then 185 cannot be the true population mean

  • We conclude that these 10 students do not come from a population where the mean height is 185

  • Note: this doesn’t necessarily mean that the true population mean equals 171 Worked example

Statistical significance

  • Confidence intervals are related to statistical significance
  • In our example we asked whether the difference between our estimated mean and 185 is statistically significant
  • Statistical inference means that we compare our estimate with another value
  • If the confidence interval covers a value, \(a\), we say that the difference between our estimate and \(a\) is not statistically significant
  • This is also commonly described as the difference being “within the margin of error”

One more example

  • The week before the election, your friend claims that the Liberal Party (L) won’t get enough votes to clear the parliamentary threshold
  • Your friend points to a survey of 1900 respondents, in which L got 3.6% of the votes
  • Assume the survey was based on a random sample
  • We want to test whether the estimated mean (3.6%) comes from a population in which L gets 4% of voters’ votes
  • If so, we cannot rule out that L would currently clear the threshold, despite the survey result
  • We therefore construct a confidence interval for the estimated mean of 0.036 (expressed as a proportion)

Statistical inference

  • We use the formula:

\[ \bar{X} \pm t \times \frac{s}{\sqrt{n}}, \quad \mbox{or} \quad \bar{X} \pm t \times \sqrt{\frac{s^2}{n}} \]

  • \(\bar{X}\) equals 0.036 and \(n = 1900\)
  • \(s^2\) is the sample variance for \(X\), obtained by computing \(p(1-p)\), where \(p\) is the share who vote for L in the sample (i.e. 0.036)
  • We compute a 95% confidence interval, so \(t = 1.96\)

\[ 0.036 \pm 1.96 \times \sqrt{\frac{(0.036\times(1-0.036))}{1900}} \]

  • The confidence interval is [0.028, 0.044], which covers 0.04

Simulation: the Central Limit Theorem

\(X\) follows a Gamma distribution with population mean \(\mu = 7\)

Worked example: confidence interval

← Back

Step 1: Sample standard deviation and standard error

  • We have collected data for a sample of 10 students. The sample mean is \(\bar{X} = 171\)
  • Suppose someone argues that the population mean \(\mu\) is actually 185 — how do we test whether 171 is statistically different from 185?
  • The sample standard deviation is \(s = 8\). We estimate the standard error for the sampling distribution of \(\bar{X}\):

\[ \hat{\sigma} = \frac{s}{\sqrt{n}} = \frac{8}{\sqrt{10}} = \frac{8}{3.162} \approx 2.529 \]

Step 2: Constructing a 95% confidence interval

  • We use the critical value \(1.96\) for a 95% confidence level:

\[ \bar{X} \pm 1.96 \times \hat{\sigma} = 171 \pm 1.96 \times 2.529 \]

  • The margin of error: \(1.96 \times 2.529 \approx 4.957\)
  • The confidence interval:

\[ 171 \pm 4.957 \]

\[ [171 - 4.957,\ 171 + 4.957] = [166.043,\ 175.957] \]

Step 3: Comparing 185 to the confidence interval

  • We compare 185 to the confidence interval \([166.043,\ 175.957]\)
  • Since 185 does not lie within this interval, we conclude:

We can reject the hypothesis that the population mean is 185, at the 95% confidence level.

The sample mean as a random draw

Two ways of looking at exactly the same event: drawing individuals into a sample (left) is the same thing as drawing one of many possible samples directly (right)