Download Theory of Regression - Jeremy Miles`s Page

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Types of artificial neural networks wikipedia , lookup

Foundations of statistics wikipedia , lookup

Bootstrapping (statistics) wikipedia , lookup

Degrees of freedom (statistics) wikipedia , lookup

History of statistics wikipedia , lookup

Taylor's law wikipedia , lookup

Regression toward the mean wikipedia , lookup

Categorical variable wikipedia , lookup

Transcript
Applying Regression
1
The Course
β€’ 14 (or so) lessons
– Some flexibility
β€’ Depends how we feel
β€’ What we get through
2
Part I: Theory of Regression
1. Models in statistics
2. Models with more than one parameter:
regression
3. Samples to populations
4. Introducing multiple regression
5. More on multiple regression
3
Part 2: Application of regression
6.
7.
8.
9.
10.
11.
12.
Categorical predictor variables
Assumptions in regression analysis
Issues in regression analysis
Non-linear regression
Categorical and count variables
Moderators (interactions) in regression
Mediation and path analysis
Part 3:Taking Regression Further
(Kind of brief)
13. Introducing longitudinal multilevel models
4
Bonuses
Bonus lesson1: Why is it called
regression?
Bonus lesson 2: Other types of
regression.
5
House Rules
β€’ Jeremy must remember
– Not to talk too fast
β€’ If you don’t understand
– Ask
– Any time
β€’ If you think I’m wrong
– Ask. (I’m not always right)
6
The Assistants
β€’ Carla Xena - [email protected]
β€’ Eugenia Suarez
Moran [email protected]
β€’ Arian [email protected]
Learning New Techniques
β€’ Best kind of data to learn a new technique
– Data that you know well, and understand
β€’ Your own data
– In computer labs (esp later on)
– Use your own data if you like
β€’ My data
– I’ll provide you with
– Simple examples, small sample sizes
β€’ Conceptually simple (even silly)
8
Computer Programs
β€’ Stata
– Mostly
β€’ I’ll explain SPSS options
β€’ You’ll like Stata more
β€’ Excel
– For calculations
– Semi-optional
β€’ GPower
9
Lesson 1: Models in statistics
Models, parsimony, error, mean,
OLS estimators
10
What is a Model?
11
What is a model?
β€’ Representation
– Of reality
– Not reality
β€’ Model aeroplane represents a real
aeroplane
– If model aeroplane = real aeroplane, it
isn’t a model
12
β€’ Statistics is about modelling
– Representing and simplifying
β€’ Sifting
– What is important from what is not
important
β€’ Parsimony
– In statistical models we seek parsimony
– Parsimony  simplicity
13
Parsimony in Science
β€’ A model should be:
– 1: able to explain a lot
– 2: use as few concepts as possible
β€’ More it explains
– The more you get
β€’ Fewer concepts
– The lower the price
β€’ Is it worth paying a higher price for a better
model?
14
The Mean as a Model
15
The (Arithmetic) Mean
β€’ We all know the mean
– The β€˜average’
– Learned about it at school
– Forget (didn’t know) about how clever the mean is
β€’ The mean is:
– An Ordinary Least Squares (OLS) estimator
– Best Linear Unbiased Estimator (BLUE)
16
Mean as OLS Estimator
β€’ Going back a step or two
β€’ MODEL was a representation of DATA
– We said we want a model that explains a lot
– How much does a model explain?
DATA = MODEL + ERROR
ERROR = DATA - MODEL
– We want a model with as little ERROR as possible
17
β€’ What is error?
Data (Y)
Model (b0)
mean
Error (e)
1.40
-0.20
1.55
-0.05
1.80
1.60
0.20
1.62
0.02
1.63
0.03
18
β€’ How can we calculate the β€˜amount’ of
error?
β€’ Sum of errors?
β€’ Sum of absolute errors?
ERROR ο€½ ei
ο€½ (Yi ο€­ YΛ†)
ο€½ (Yi ο€­ b0 )
ο€½  0.20    0.05   0.20  0.02  0.03
ο€½0
19
β€’ Are small and large errors equivalent?
– One error of 4
– Four errors of 1
– The same?
– What happens with different data?
β€’ Y = (2, 2, 5)
– b0 = 2
– Not very representative
β€’ Y = (2, 2, 4, 4)
– b0 = any value from 2 - 4
– Indeterminate
β€’ There are an infinite number of solutions which would satisfy
our criteria for minimum error
20
β€’ Sum of squared errors (SSE)
2
i
ERROR ο€½ e
2
Λ†
ο€½ (Yi ο€­ Y )
ο€½ (Yi ο€­ b0 )
2
ο€½  0.20    0.05   0.202  0.022  0.032
2
2
ο€½ 0.08
21
β€’ Determinate
– Always gives one answer
β€’ If we minimise SSE
– Get the mean
β€’ Shown in graph
– SSE plotted against b0
– Min value of SSE occurs when
– b0 = mean
22
2
1.8
1.6
1.4
SSE
1.2
1
0.8
0.6
0.4
0.2
0
1
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2
b0
23
The Mean as an OLS Estimate
24
Mean as OLS Estimate
β€’ The mean is an Ordinary Least Squares
(OLS) estimate
– As are lots of other things
β€’ This is exciting because
– OLS estimators are BLUE
– Best Linear Unbiased Estimators
– Proven with Gauss-Markov Theorem
β€’ Which we won’t worry about
25
BLUE Estimators
β€’ Best
– Minimum variance (of all possible unbiased
estimators)
– Narrower distribution than other estimators
β€’ e.g. median, mode
Y ο€½Y
26
SSE and the Standard
Deviation
β€’ Tying up a loose end
2
Λ†
SSE ο€½ (Yi ο€­ Y )
sο€½
2
Λ†
(Yi ο€­ Y )
n

2
Λ†
(Yi ο€­ Y )
n ο€­1
27
β€’ SSE closely related to SD
β€’ Sample standard deviation – s
– Biased estimator of population SD
β€’ Population standard deviation - 
– Need to know the mean to calculate SD
β€’ Reduces N by 1
β€’ Hence divide by N-1, not N
– Like losing one df
28
Proof
β€’ That the mean minimises SSE
– Not that difficult
– As statistical proofs go
β€’ Available in
– Maxwell and Delaney – Designing
experiments and analysing data
– Judd and McClelland – Data Analysis: a
model comparison approach
β€’ (out of print?)
29
What’s a df?
β€’ The number of parameters free to vary
– When one is fixed
β€’ Term comes from engineering
– Movement available to structures
30
Back to the Data
β€’ Mean has 5 (N) df
– 1st moment
β€’  has N –1 df
– Mean has been fixed
– 2nd moment
– Can think of it as amount of cases vary
away from the mean
31
While we are at it …
β€’ Skewness has N – 2 df
– 3rd moment
β€’ Kurtosis has N – 3 df
– 4rd moment
– Amount cases vary from 
32
Parsimony and df
β€’ Number of df remaining
– Measure of parsimony
β€’ Model which contained all the data
– Has 0 df
– Not a parsimonious model
β€’ Normal distribution
– Can be described in terms of mean and 
β€’ 2 parameters
– (z with 0 parameters)
33
Summary of Lesson 1
β€’ Statistics is about modelling DATA
– Models have parameters
– Fewer parameters, more parsimony, better
β€’ Models need to minimise ERROR
– Best model, least ERROR
– Depends on how we define ERROR
– If we define error as sum of squared deviations
from predicted value
– Mean is best MODEL
34
Lesson 1a
β€’ A really brief introduction to Stata
35
Command
review
Commands
Output
Variable list
Commands
36
Stata Commands
β€’ Can use menus
– But commands are easy
β€’ All have similar format:
β€’ command variables , options
β€’ Stata is case sensitive
– BEDS, beds, Beds
β€’ Stata lets you shorten
– summarize sqft
– su sq
37
More Stata Commands
β€’ Open exercise 1.4.dta
– Run
β€’ summarize sqm
β€’ table beds
β€’ mean price
β€’ histogram price
– Or
β€’ su be
β€’ tab be
β€’ mean pr
β€’ hist pr
38
Lesson 2: Models with one
more parameter - regression
39
In Lesson 1 we said …
β€’ Use a model to predict and describe
data
– Mean is a simple, one parameter model
40
More Models
Slopes and Intercepts
41
More Models
β€’ The mean is OK
– As far as it goes
– It just doesn’t go very far
– Very simple prediction, uses very little
information
β€’ We often have more information than
that
– We want to use more information than that
42
House Prices
β€’ Look at house prices in one area of Los
Angeles
β€’ Predictors of house prices
β€’ Using:
– Sale price, size, number of bedrooms, size
of lot, year built …
43
House Prices
address
listprice
beds
baths
sqft
3628 OLYMPIAD Dr
649500
4
3
2575
3673 OLYMPIAD Dr
450000
2
3
1910
3838 CHANSON Dr
489900
3
2
2856
3838 West 58TH Pl
330000
4
2
1651
3919 West 58TH Pl
349000
3
2
1466
3954 FAIRWAY Blvd
514900
3
2.25
2018
4044 OLYMPIAD Dr
649000
4
2.5
3019
4336 DON LUIS Dr
474000
2
2.5
2188
4421 West 59TH St
460000
3
2
1519
4518 WHELAN Pl
388000
2
1.5
1403
4670 West 63RD St
259500
3
2
1491
5000 ANGELES
VISTA Blvd
678800
5
4
3808
46
One Parameter Model
β€’ The mean
Y ο€½ 415.69
Yˆ  b0  Y
SSE ο€½ 341683
β€œHow much is that house worth?”
$415,689
Use 1 df to say that
47
Adding More Parameters
β€’ We have more information than this
– We might as well use it
– Add a linear function of number of size
(square feet) (x1)
YΛ† ο€½ b0  b1 x1
48
Alternative Expression
β€’ Estimate of Y (expected value of Y)
YΛ† ο€½ b0  b1 x1
β€’ Value of Y
Yi ο€½ b0  b1 xi1  ei
49
Estimating the Model
β€’ We can estimate this model in four different,
equivalent ways
– Provides more than one way of thinking about it
1.
2.
3.
4.
Estimating the slope which minimises SSE
Examining the proportional reduction in SSE
Calculating the covariance
Looking at the efficiency of the predictions
50
Estimate the Slope to Minimise
SSE
51
Estimate the Slope
β€’ Stage 1
– Draw a scatterplot
– x-axis at mean
β€’ Not at zero
β€’ Mark errors on it
– Called β€˜residuals’
– Sum and square these to find SSE
52
700
500
600
160
140
120
300
400
100
80
1.5
2
2.5
3
3.5
4
4.5
5
5.5
60
200
40
20
1000
0
2000
3000
4000
SQFT
LAST SALE PRICE
Fitted values
53
160
140
120
100
80
60
40
20
0
1.5
2
2.5
3
3.5
4
4.5
5
5.5
β€’ Add another slope to the chart
– Redraw residuals
– Recalculate SSE
– Move the line around to find slope which
minimises SSE
β€’ Find the slope
55
β€’ First attempt:
56
β€’ Any straight line can be defined with
two parameters
– The location (height) of the slope
β€’ b0
– Sometimes called a
– The gradient of the slope
β€’ b1
57
β€’ Gradient
b1 units
1 unit
58
β€’ Height
b0 units
59
β€’ Height
β€’ If we fix slope to zero
– Height becomes mean
– Hence mean is b0
β€’ Height is defined as the point that the
slope hits the y-axis
– The constant
– The y-intercept
60
β€’ Why the constant?
β€’
beds (x1) x0
£ (000s)
– b0x0
1
1
77
– Where x0 is 1.00 for every case
2
1
74
β€’ i.e. x0 is constant
1
1
88
3
1
62
Implicit in Stata
5
1
90
– (And SPSS, SAS, R)
5
1
136
– Some packages force you to2 make1it
35
explicit
5
1
134
– (Later on we’ll need to make
4 it explicit)
1
138
1
1
55
61
β€’ Why the intercept?
– Where the regression line intercepts the yaxis
– Sometimes called y-intercept
62
Finding the Slope
β€’ How do we find the values of b0 and b1?
– Start with we jiggle the values, to find the
best estimates which minimise SSE
– Iterative approach
β€’ Computer intensive – used to matter, doesn’t
really any more
β€’ (With fast computers and sensible search
algorithms – more on that later)
63
β€’ Start with
– b0=416 (mean)
– b1=0.5 (nice round number)
β€’ SSE = 365,774
– b0=300, b1=0.5, SSE=341,683
– b0=300, b1=0.6, SSE=310,240
– b0=300, b1=0.8, SSE=264,573
– b0=300, b1=1, SSE=301, 797
– b0=250, b1=1, SSE=255,366
– …..
64
β€’ Quite a long time later
– b0 = 216.357
– b1 = 1.084
– SSE = 145,636.78
β€’ Gives the position of the
– Regression line (or)
– Line of best fit
β€’ Better than guessing
β€’ Not necessarily the only method
– But it is OLS, so it is the best (it is BLUE)
65
700
160
600
140
100
Price
400
500
120
80
300
60
Actual Price
Predicted Price
40
200
20
0
1000
0.5
1
1.5
2000
2
2.5
3
SQFT
3.5 30004
4.5
5
4000
5.5
Number of Bedrooms
Fitted values
LAST SALE PRICE
66
β€’ We now know
– A zero square metre house is worth ο‚»
$216,000
– Adding a square meter adds $1,080
β€’ Told us two things
– Don’t extrapolate to meaningless values of
x-axis
– Constant is not necessarily useful
β€’ It is necessary to estimate the equation
67
Exercise 2a, 2b
68
Standardised Regression Line
β€’ One big but:
– Scale dependent
β€’ Values change
– £ to €, inflation
β€’ Scales change
– £, £000, £00?
β€’ Need to deal with this
69
β€’ Don’t express in β€˜raw’ units
– Express in SD units
– x1=183.82
– y=114.637
β€’ b1 = 1.103
β€’ We increase x1 by 1, and ΕΆ increases by
1.084
1.084 ο€½ (1.084 / 114.637) SDs ο€½ 0.00945SDs
β€’ So we increase x1 by 1 and ΕΆ increases
by 0.0094 SDs
70
β€’ Similarly, 1 unit of x1 = 1/69.017 SDs
– Increase x1 by 1 SD
– ΕΆ increases by 1.103 ο‚΄ (69.017/1) =
76.126
β€’ Put them both together
b1 ο‚΄  x1
y
71
1.080 ο‚΄ 69.071
ο€½ 0.653
114.637
β€’ The standardised regression line
– Change (in SDs) in ΕΆ associated with a
change of 1 SD in x1
β€’ A different route to the same answer
– Standardise both variables (divide by SD)
– Find line of best fit
72
β€’ The standardised regression line has a
special name
The Correlation Coefficient
(r)
(r stands for β€˜regression’, but more on that
later)
β€’ Correlation coefficient is a standardised
regression slope
– Relative change, in terms of SDs
73
Exercise 2c
74
Proportional Reduction in
Error
75
Proportional Reduction in Error
β€’ We might be interested in the level of
improvement of the model
– How much less error (as proportion) do we
have
– Proportional Reduction in Error (PRE)
β€’ Mean only
– Error(model 0) = 341,683
β€’ Mean + slope
– Error(model 1) = 196,046
76
ERROR(0) ο€­ ERROR(1)
PRE ο€½
ERROR(0)
ERROR(1)
PRE ο€½ 1 ο€­
ERROR(0)
196046
PRE ο€½ 1 ο€­
341683
PRE ο€½ 0.426
77
β€’ But we squared all the errors in the first
place
– So we could take the square root
0.426 ο€½ 0.653
β€’ This is the correlation coefficient
β€’ Correlation coefficient is the square root
of the proportion of variance explained
78
Standardised Covariance
79
Standardised Covariance
β€’ We are still iterating
– Need a β€˜closed-form’ equation
– Equation to solve to get the parameter
estimates
β€’ Answer is a standardised covariance
– A variable has variance
– Amount of β€˜differentness’
β€’ We have used SSE so far
80
β€’ SSE varies with N
– Higher N, higher SSE
β€’ Divide by N
– Gives SSE per person (or house)
– (Actually N – 1, we have lost a df to the
mean)
β€’ Gives us the variance
β€’ Same as SD2
– We thought of SSE as a scattergram
β€’ Y plotted against X
– (repeated image follows)
81
160
140
120
100
80
1.5
2
2.5
3
3.5
4
4.5
5
5.5
60
40
20
0
82
β€’ Or we could plot Y against Y
– Axes meet at the mean (415)
– Draw a square for each point
– Calculate an area for each square
– Sum the areas
β€’ Sum of areas
– SSE
β€’ Sum of areas divided by N
– Variance
83
Plot of Y against Y
180
160
140
120
100
0
20
40
60
80
80
100
120
140
160
180
60
40
20
0
84
Draw Squares
180
Area =
40.1 x 40.1
= 1608.1
160
138 – 88.9
= 40.1
140
138 – 88.9
= 40.1
120
100
0
20
35 – 88.9
= -53.9
40
60
80
80
100
120
140
160
180
60
40
35 – 88.9
= -53.9
20
Area =
-53.9 x -53.9
= 2905.21
0
85
β€’ What if we do the same procedure
– Instead of Y against Y
– Y against X
β€’
β€’
β€’
β€’
Draw rectangles (not squares)
Sum the area
Divide by N - 1
This gives us the variance of x with y
– The Covariance
– Shortened to Cov(x, y)
86
87
Area
= (-33.9) x (-2)
= 67.8
55 – 88.9
= -33.9
138-88.9
= 49.1
4-3=1
1 - 3 = -2
Area =
49.1 x 1
= 49.1
88
β€’ More formally (and easily)
β€’ We can state what we are doing as an
equation
– Where Cov(x, y) is the covariance
( x ο€­ x )( y ο€­ y )
Cov( x , y ) ο€½
N ο€­1
β€’ Cov(x,y)=5165
β€’ What do points in different sectors do
to the covariance?
89
β€’ Problem with the covariance
– Tells us about two things
– The variance of X and Y
– The covariance
β€’ Need to standardise it
– Like the slope
β€’ Two ways to standardise the covariance
– Standardise the variables first
β€’ Subtract from mean and divide by SD
– Standardise the covariance afterwards
90
β€’ First approach
– Much more computationally expensive
β€’ Too much like hard work to do by hand
– Need to standardise every value
β€’ Second approach
– Much easier
– Standardise the final value only
β€’ Need the combined variance
– Multiply two variances
– Find square root (were multiplied in first
place)
91
β€’ Standardised covariance
ο€½
Cov( x, y )
Var ( x ) ο‚΄ Var ( y )
5165
ο€½
69.02 ο‚΄ 114.64
ο€½ 0.653
92
β€’ The correlation coefficient
– A standardised covariance is a correlation
coefficient
rο€½
Covariance
 variance ο‚΄ variance 
93
β€’ Expanded …
rο€½
 ( x ο€­ x )( y ο€­ y ) οƒΆ

οƒ·
N ο€­1

οƒΈ
2
2
 ( x ο€­ x )
( y ο€­ y ) οƒΆ

οƒ·οƒ·
ο‚΄
N ο€­1 οƒΈ
 N ο€­1
94
β€’ This means …
– We now have a closed form equation to
calculate the correlation
– Which is the standardised slope
– Which we can use to calculate the
unstandardised slope
95
We know that:
rο€½
b1 ο‚΄  x1
y
We know that:
b1 ο€½
r  y
x
1
96
b1 ο€½
r  y
x
1
0.659 ο‚΄ 114.64
b1 ο€½
69.017
b1 ο€½ 1.080
β€’ So value of b1 is the same as the iterative
approach
97
β€’ The intercept
– Just while we are at it
β€’ The variables are centred at zero
– We subtracted the mean from both
variables
– Intercept is zero, because the axes cross at
the mean
98
β€’ Add mean of y to the constant
– Adjusts for centring y
β€’ Subtract mean of x
– But not the whole mean of x
– Need to correct it for the slope
c ο€½ y ο€­ b1 x1
c ο€½ 415.7 ο€­ 1.08 ο‚΄ 183.81
c ο€½ 216.35
99
Accuracy of Prediction
100
One More (Last One)
β€’ We have one more way to calculate the
correlation
– Looking at the accuracy of the prediction
β€’ Use the parameters
– b0 and b1
– To calculate a predicted value for each
case
101
Beds
239.2
177.4
265.3
153.4
136.2
187.5
280.5
203.3
141.1
130.3
Actual Predicted
Price
Price
605.0
475.8
400.0
408.8
529.5
504.1
315.0
382.7
341.0
364.0
525.0
419.7
585.0
520.5
430.0
436.8
436.0
369.4
390.0
357.7
β€’ Plot actual price
against
predicted price
– From the model
102
600
140
500
Predicted Value
120
100
80
400
60
40
300
20
20
40
200
60
300
80
100
400Actual Value
500
LAST
SALE PRICE
120
600
140
160
700
103
β€’ r = 0.653
β€’ The correlation between actual and predicted
value
β€’ Seems a futile thing to do
– And at this stage, it is
– But later on, we will see why
104
Some More Formulae
β€’ For hand calculation
rο€½
xy
x 2 y 2
β€’ Point biserial

M
rο€½
y1
ο€­ M y 0  PQ
sd y
105
β€’ Phi (f)
– Used for 2 dichotomous variables
Vote P
Vote Q
Homeowner
A: 19
B: 54
Not homeowner
C: 60
D:53
BC ο€­ AD
rο€½
( A  B)(C  D)( A  C )( B  D)
106
β€’ Problem with the phi correlation
– Unless Px= Py (or Px = 1 – Py)
β€’ Maximum (absolute) value is < 1.00
β€’ Tetrachoric correlation can be used to correct
this
β€’ Rank (Spearman) correlation
– Used where data are ranked
6d
rο€½
2
n(n ο€­ 1)
2
107
Summary
β€’ Mean is an OLS estimate
– OLS estimates are BLUE
β€’ Regression line
– Best prediction of outcome from predictor
– OLS estimate (like mean)
β€’ Standardised regression line
– A correlation
108
β€’ Four ways to think about a correlation
– 1.
– 2.
– 3.
– 4.
Standardised regression line
Proportional Reduction in Error (PRE)
Standardised covariance
Accuracy of prediction
109
Regression and Correlation in
Stata
β€’ Correlation:
β€’ correlate x y
β€’ correlate x y , cov
β€’ regress y x
β€’ Or
β€’ regress price sqm
110
Post-Estimation
β€’ Stata commands β€˜leave behind’
something
β€’ You can run post-estimation commands
– They mean β€˜from the last regression’
β€’ Get predicted values:
– predict my_preds
This comes after
the comma, so it’s
an option
β€’ Get residuals:
– predict my_res, residuals
111
Graphs
β€’ Scatterplot
β€’ scatter price beds
β€’ Regression line
– lfit price beds
β€’ Both graphs
– twoway (scatter price beds)
(lfit price beds)
112
β€’ What happens if you run reg without a
predictor?
– regress price
113
Exercises
114
Lesson 3: Samples to
Populations – Standard Errors
and Statistical Significance
115
The Problem
β€’ In Social Sciences
– We investigate samples
β€’ Theoretically
– Randomly taken from a specified
population
– Every member has an equal chance of
being sampled
– Sampling one member does not alter the
chances of sampling another
β€’ Not the case in (say) physics, biology,
etc.
116
Population
β€’ But it’s the population that we are
interested in
– Not the sample
– Population statistic represented with Greek
letter
– Hat means β€˜estimate’
Λ†
b
x 
Λ†x
117
β€’ Sample statistics (e.g. mean) estimate
population parameters
β€’ Want to know
– Likely size of the parameter
– If it is > 0
118
Sampling Distribution
β€’ We need to know the sampling
distribution of a parameter estimate
– How much does it vary from sample to
sample
β€’ If we make some assumptions
– We can know the sampling distribution of
many statistics
– Start with the mean
119
Sampling Distribution of the
Mean
β€’ Given
– Normal distribution
– Random sample
– Continuous data
β€’ Mean has a known sampling distribution
– Repeatedly sampling will give a known
distribution of means
– Centred around the true (population) mean
()
120
Analysis Example: Memory
β€’ Difference in memory for different
words
– 10 participants given a list of 30 words to
learn, and then tested
– Two types of word
β€’ Abstract: e.g. love, justice
β€’ Concrete: e.g. carrot, table
121
Concrete Abstract
12
4
11
7
4
6
9
12
8
6
12
10
9
8
8
5
12
10
8
4
Diff (x)
8
4
-2
-3
2
2
1
3
2
4
x ο€½ 2.1
 x ο€½ 3.11
N ο€½ 10
122
Confidence Intervals
β€’ This means
– If we know the mean in our sample
– We can estimate where the mean in the
population () is likely to be
β€’ Using
– The standard error (se) of the mean
– Represents the standard deviation of the
sampling distribution of the mean
123
1 SD contains
68%
Almost 2 SDs
contain 95%
124
β€’ We know the sampling distribution of
the mean
– t distributed if N < 30
– Normal with large N (>30)
β€’ Asymptotically normal
β€’ Know the range within means from
other samples will fall
– Therefore the likely range of 
x
se( x ) ο€½
n
125
β€’ Two implications of equation
– Increasing N decreases SE
β€’ But only a bit (SE halfs if N is 400 times bigger)
– Decreasing SD decreases SE
β€’ Calculate Confidence Intervals
– From standard errors
β€’ 95% is a standard level of CI
– 95% of samples the true mean will lie within
the 95% CIs
– In large samples: 95% CI = 1.96 ο‚΄ SE
– In smaller samples: depends on t
distribution (df=N-1=9)
126
x ο€½ 2.1,
 x ο€½ 3.11,
N ο€½ 10
x
3.11
se( x ) ο€½
ο€½
ο€½ 0.98
n
10
127
95% CI ο€½ 2.26 ο‚΄ 0.98 ο€½ 2.22
x ο€­ CI ο‚£  ο‚£ x  CI
-0.12 ο‚£  ο‚£ 4.32
128
What is a CI?
β€’ (For 95% CI):
β€’ 95% chance that the true (population)
value lies within the confidence
interval? No;
β€’ 95% of samples, true mean will land
within the confidence interval?
129
Significance Test
β€’ Probability that  is a certain value
– Almost always 0
β€’ Doesn’t have to be though
β€’ We want to test the hypothesis that the
difference is equal to 0
– i.e. find the probability of this difference
occurring in our sample IF =0
– (Not the same as the probability that =0)
130
β€’ Calculate SE, and then t
– t has a known sampling distribution
– Can test probability that a certain value is
included
x
tο€½
se(x )
2.1
tο€½
ο€½ 2.14
0.98
p ο€½ 0.061
131
Other Parameter Estimates
β€’ Same approach
– Prediction, slope, intercept, predicted
values
– At this point, prediction and slope are the
same
β€’ Won’t be later on
β€’ One predictor only
– More complicated with > 1
132
Testing the Degree of
Prediction
β€’ Prediction is correlation of Y with ΕΆ
– The correlation – when we have one IV
β€’ Use F, rather than t
β€’ Started with SSE for the mean only
– This is SStotal
– Divide this into SSresidual
– SSregression
β€’ SStot = SSreg + SSres
133
Fο€½
SSreg df1
SS res df 2
df1 ο€½ k
df 2 ο€½ N ο€­ k ο€­ 1,
134
β€’ Back to the house prices
– Original SSE (SStotal) = 341683
– SSresidual = 196046
β€’ What is left after our model
– SSregression = 341683– 196046= 145636
β€’ What our model explains
135
SSreg df1
Fο€½
SS res df 2
145636 1
Fο€½
ο€½ 18.57
196046 ( 25 ο€­ 1 ο€­ 1)
df1 ο€½ k ο€½ 1
df 2 ο€½ N ο€­ k ο€­ 1 ο€½ 8
136
β€’ F = 18.6, df = 1, 25, p = 0.0002
– Can reject H0
β€’ H0: Prediction is not better than chance
– A significant effect
137
Statistical Significance:
What does a p-value (really)
mean?
138
A Quiz
β€’ Six questions, each true or false
β€’ Write down your answers (if you like)
β€’ An experiment has been done. Carried out
perfectly. All assumptions perfectly satisfied.
Absolutely no problems.
β€’ P = 0.01
– Which of the following can we say?
139
1. You have absolutely disproved the null
hypothesis (that is, there is no
difference between the population
means).
140
2. You have found the probability of the
null hypothesis being true.
141
3. You have absolutely proved your
experimental hypothesis (that there is
a difference between the population
means).
142
4. You can deduce the probability of the
experimental hypothesis being true.
143
5. You know, if you decide to reject the
null hypothesis, the probability that
you are making the wrong decision.
144
6. You have a reliable experimental
finding in the sense that if,
hypothetically, the experiment were
repeated a great number of times, you
would obtain a significant result on
99% of occasions.
145
OK, What is a p-value
β€’ Cohen (1994)
β€œ[a p-value] does not tell us what we
want to know, and we so much want to
know what we want to know that, out
of desperation, we nevertheless believe
it does” (p 997).
146
OK, What is a p-value
β€’ Sorry, didn’t answer the question
β€’ It’s β€œThe probability of obtaining a
result as or more extreme than the
result we have in the study, given that
the null hypothesis is true”
β€’ Not probability the null hypothesis is
true
147
A Bit of Notation
β€’ Not because we like notation
– But we have to say a lot less
β€’
β€’
β€’
β€’
Probability – P
Null hypothesis is true – H
Result (data) – D
Given - |
148
What’s a P Value
β€’ P(D|H)
– Probability of the data occurring if the null
hypothesis is true
β€’ Not
β€’ P(H|D) (what we want to know)
– Probability that the null hypothesis is true,
given that we have the data = p(H)
β€’ P(H|D) β‰  P(D|H)
149
β€’ What is probability you are prime minister
– Given that you are British
– P(M|B)
– Very low
β€’ What is probability you are British
– Given you are prime minister
– P(B|M)
– Very high
β€’ P(M|B) β‰  P(B|M)
150
β€’ There’s been a murder
– Someone murdered an instructor (perhaps
they talked too much)
β€’ The police have DNA
β€’ The police have your DNA
– They match(!)
β€’ DNA matches 1 in 1,000,000 people
β€’ What’s the probability you didn’t do the
murder, given the DNA match (H|D)
151
β€’ Police say:
– P(D|H) = 1/1,000,000
β€’ Luckily, you have Jeremy on your defence
team
β€’ We say:
– P(D|H) β‰  P(H|D)
β€’ Probability that someone matches the
DNA, who didn’t do the murder
– Incredibly high
152
Back to the Questions
β€’ Haller and Kraus (2002)
– Asked those questions of groups in
Germany
– Psychology Students
– Psychology lecturers and professors (who
didn’t teach stats)
– Psychology lecturers and professors (who
did teach stats)
153
1. You have absolutely disproved the null
hypothesis (that is, there is no difference
between the population means).
β€’
True
β€’
β€’
β€’
β€’
β€’
34% of students
15% of professors/lecturers,
10% of professors/lecturers teaching statistics
False
We have found evidence against the null
hypothesis
154
2. You have found the probability of the
null hypothesis being true.
– 32% of students
– 26% of professors/lecturers
– 17% of professors/lecturers teaching
statistics
β€’
β€’
False
We don’t know
155
3. You have absolutely proved your
experimental hypothesis (that there is a
difference between the population means).
–
–
–
β€’
20% of students
13% of professors/lecturers
10% of professors/lecturers teaching statistics
False
156
4. You can deduce the probability of the
experimental hypothesis being true.
– 59% of students
– 33% of professors/lecturers
– 33% of professors/lecturers teaching
statistics
β€’
False
157
5. You know, if you decide to reject the null
hypothesis, the probability that you are
making the wrong decision.
β€’
β€’
β€’
β€’
β€’
68% of students
67% of professors/lecturers
73% of professors professors/lecturers
teaching statistics
False
Can be worked out
– P(replication)
158
6. You have a reliable experimental finding
in the sense that if, hypothetically, the
experiment were repeated a great
number of times, you would obtain a
significant result on 99% of occasions.
– 41% of students
– 49% of professors/lecturers
– 37% of professors professors/lecturers
teaching statistics
β€’
β€’
False
Another tricky one
– It can be worked out
159
One Last Quiz
β€’ I carry out a study
– All assumptions perfectly satisfied
– Random sample from population
– I find p = 0.05
β€’ You replicate the study exactly
– What is probability you find p < 0.05?
160
β€’ I carry out a study
– All assumptions perfectly satisfied
– Random sample from population
– I find p = 0.01
β€’ You replicate the study exactly
– What is probability you find p < 0.05?
161
β€’ Significance testing creates boundaries
and gaps where none exist.
β€’ Significance testing means that we find
it hard to build upon knowledge
– we don’t get an accumulation of
knowledge
162
β€’ Yates (1951)
"the emphasis given to formal tests of significance
... has resulted in ... an undue concentration of
effort by mathematical statisticians on
investigations of tests of significance applicable
to problems which are of little or no practical
importance ... and ... it has caused scientific
research workers to pay undue attention to the
results of the tests of significance ... and too
little to the estimates of the magnitude of the
effects they are investigating
163
Testing the Slope
β€’ Same idea as with the mean
– Estimate 95% CI of slope
– Estimate significance of difference from a
value (usually 0)
β€’ Need to know the SD of the slope
– Similar to SD of the mean
164
s y. x ο€½
2
Λ†
(Y ο€­ Y )
N ο€­ k ο€­1
s y.x ο€½
SSres
N ο€­ k ο€­1
s y.x ο€½
5921
ο€½ 27.2
8
165
β€’ Similar to equation for SD of mean
β€’ Then we need standard error
- Similar (ish)
β€’ When we have standard error
– Can go on to 95% CI
– Significance of difference
166
se(by. x ) ο€½
s y.x
( x ο€­ x )
2
27.2
se(by. x ) ο€½
ο€½ 5.24
26.9
167
β€’ Confidence Limits
β€’ 95% CI
– t dist with N - k - 1 df is 2.31
– CI = 5.24 ο‚΄ 2.31 = 12.06
β€’ 95% confidence limits
14.8 ο€­ 12.1 ο‚£  ο‚£ 14.8  12.1
2.7 ο‚£  ο‚£ 26.9
168
β€’ Significance of difference from zero
– i.e. probability of getting result if =0
β€’ Not probability that  = 0
b
14.7
tο€½
ο€½
ο€½ 2.81
se(b)
5.2
df ο€½ N ο€­ k ο€­ 1 ο€½ 8
p ο€½ 0.02
β€’ This probability is (of course) the same
as the value for the prediction
169
Testing the Standardised
Slope (Correlation)
β€’ Correlation is bounded between –1 and +1
– Does not have symmetrical distribution, except
around 0
β€’ Need to transform it
– Fisher z’ transformation – approximately
normal
zο‚’ ο€½ 0.5[ln( 1  r ) ο€­ ln( 1 ο€­ r )]
1
SE zο‚’ ο€½
nο€­3
170
zο‚’ ο€½ 0.5[ln( 1  0.706) ο€­ ln( 1 ο€­ 0.706)]
zο‚’ ο€½ 0.879
1
1
SEzο‚’ ο€½
ο€½
ο€½ 0.38
nο€­3
10 ο€­ 3
β€’ 95% CIs
– 0.879 – 1.96 * 0.38 = 0.13
– 0.879 + 1.96 * 0.38 = 1.62
171
β€’ Transform back to correlation
e ο€­1
r ο€½ 2y
e 1
2y
β€’ 95% CIs = 0.13 to 0.92
β€’ Very wide
– Because of small sample size
– Maybe that’s why CIs are not reported?
172
Using Excel
β€’ Functions in excel
– Fisher() – to carry out Fisher
transformation
– Fisherinv() – to transform back to
correlation
173
The Others
β€’ Same ideas for calculation of CIs and
SEs for
– Predicted score
– Gives expected range of values given X
β€’ Same for intercept
– But we have probably had enough
174
One more tricky thing
β€’ (Don’t worry if you don’t understand)
β€’ For means, regression estimates, etc
– Estimate
β€’ 1.0000
– 95% confidence intervals
β€’ 0.0000, 2.0000
– P = 0.05000
β€’ They match
175
β€’ For correlations, odds ratios, etc
– No longer match
β€’ 95% CIs
– 0.0000, 0.50000
β€’ P-value
– 0.052000
β€’ Because of the sampling distribution of the
mean
– Does not depend on the value
β€’ The sampling distribution of a proportion
– Does depend on the value
– More certainty around 0.9 than around 0.00.
176
Lesson 4: Introducing Multiple
Regression
177
Residuals
β€’ We said
Y = b0 + b1x1
β€’ We could have said
Yi = b0 + b1xi1 + ei
β€’ We ignored the i on the Y
β€’ And we ignored the ei
– It’s called error, after all
β€’ But it isn’t just error
– Trying to tell us something
178
What Error Tells Us
β€’ Error tells us that a case has a different
score for Y than we predict
– There is something about that case
β€’ Called the residual
– What is left over, after the model
β€’ Contains information
– Something is making the residual ο‚Ή 0
– But what?
179
700
160
600
140
100
Price
400
500
120
80
300
60
Actual Price
Predicted Price
40
200
20
0
1000
0.5
1
1.5
2000
2
2.5
3
SQFT
3.5 30004
Number of Bedrooms
LAST SALE PRICE
4.5
Fitted values
5
4000
5.5
181
β€’ The residual (+ the mean) is the
expected value of Y
If all cases were equal on X
β€’ It is the value of Y, controlling for X
β€’ Other words:
– Holding constant
– Partialling
– Residualising (residualised scores)
– Conditioned on
182
β€’ Sometimes adjustment is enough on its own
– Measure performance against criteria
β€’ Teenage pregnancy rate
– Measure pregnancy and abortion rate in areas
– Control for socio-economic deprivation, religion,
rural/urban and anything else important
– See which areas have lower teenage pregnancy
and abortion rate, given same level of deprivation
β€’ Value added education tables
– Measure school performance
– Control for initial intake
183
Adj Value
(mean +
resid)
Sqm
Price
Predicted
Residual
239.2
605.0
475.77
129.23
544.8
177.4
400.0
408.78
-8.78
406.8
265.3
529.5
504.08
25.42
441.0
153.4
315.0
382.69
-67.69
347.9
136.2
341.0
364.05
-23.05
392.6
187.5
525.0
419.66
105.34
520.9
280.5
585.0
520.51
64.49
480.1
203.3
430.0
436.79
-6.79
408.8
141.1
436.0
369.39
66.61
482.2
130.3
390.0
357.70
32.30
447.9
184
Control?
β€’ In experimental research
– Use experimental control
– e.g. same conditions, materials, time of
day, accurate measures, random
assignment to conditions
β€’ In non-experimental research
– Can’t use experimental control
– Use statistical control instead
185
Analysis of Residuals
β€’ What predicts differences in crime rate
– After controlling for socio-economic
deprivation
– Number of police?
– Crime prevention schemes?
– Rural/Urban proportions?
– Something else
β€’ This is (mostly) what multiple
regression is about
186
β€’ Exam performance
– Consider number of books a student read
(books)
– Number of lectures (max 20) a student
attended (attend)
β€’ Books and attend as IV, grade as
outcome
187
Book s
Attend
0
1
0
2
4
4
1
4
3
0
9
15
10
16
10
20
11
20
15
15
Grade
45
57
45
51
65
88
44
87
89
59
First 10 cases
188
β€’ Use books as IV
– R=0.492, F=12.1, df=1, 28, p=0.001
– b0=52.1, b1=5.7
– (Intercept makes sense)
β€’ Use attend as IV
– R=0.482, F=11.5, df=1, 38, p=0.002
– b0=37.0, b1=1.9
– (Intercept makes less sense)
189
100
90
80
70
Grade (100)
60
50
40
30
-1
0
1
2
3
4
5
Books
190
100
90
80
70
60
Grade
50
40
30
5
7
9
11
13
15
17
19
21
Attend
191
Problem
β€’ Use R2 to give proportion of shared
variance
– Books = 24%
– Attend = 23%
β€’ So we have explained 24% + 23% =
47% of the variance
– NO!!!!!
192
β€’ Look at the correlation matrix
BOOKS
1
ATTEND
0.44
1
GRADE
0.49
0.48
1
BOOKS
ATTEND
GRADE
β€’ Correlation of books and attend is
(unsurprisingly) not zero
– Some of the variance that books shares
with grade, is also shared by attend
193
β€’ I have access to 2 cars
β€’ My wife has access to 2 cars
– We have access to four cars?
– No. We need to know how many of my 2
cars are shared
β€’ Similarly with regression
– But we can do this with the residuals
– Residuals are what is left after (say) books
– See if residual variance is explained by
attend
– Can use this new residual variance to
calculate SSres, SStotal and SSreg
194
β€’ Well. Almost.
– This would give us correct values for SS
– Would not be correct for slopes, etc
β€’ Because assumes that the variables
have a causal priority
– Why should attend have to take what is
left from books?
– Why should books have to take what is left
by attend?
β€’ Use OLS again; take variance they
share
195
β€’ Simultaneously estimate 2 parameters
– b1 and b2
– Y = b0 + b1x1 + b2x2
– x1 and x2 are IVs
β€’ Shared variance
β€’ Not trying to fit a line any more
– Trying to fit a plane
β€’ Can solve iteratively
– Closed form equations better
– But they are unwieldy
196
3D scatterplot
(2points only)
y
x2
x1
197
b2
y
b1
b0
x2
x1
198
199
Increasing Power
β€’ What if the predictors don’t correlate?
β€’ Regression is still good
– It increases the power to detect effects
– (More on power later)
β€’ Less variance left over
β€’ When do we know the two predictors
don’t correlate?
200
(Really) Ridiculous Equations
2

 y ο€­ y x1 ο€­ x1 x2 ο€­ x2   ο€­  y ο€­ y x2 ο€­ x2 x1 ο€­ x1 x2 ο€­ x2 
b1 ο€½
2
2
2
x1 ο€­ x1  x2 ο€­ x2  ο€­ x1 ο€­ x1 x2 ο€­ x2 
2

 y ο€­ y x2 ο€­ x2 x1 ο€­ x1   ο€­  y ο€­ y x1 ο€­ x1 x2 ο€­ x2 x1 ο€­ x1 
b2 ο€½
2
2
2
x2 ο€­ x2  x1 ο€­ x1  ο€­ x2 ο€­ x2 x1 ο€­ x1 
b0 ο€½ y ο€­ b1 x1 ο€­ b2 x2
201
β€’ The good news
– There is an easier way
β€’ The bad news
– It involves matrix algebra
β€’ The good news
– We don’t really need to know how to do it
202
β€’ We’re not programming computers
– So we usually don’t care
β€’ Very, very occasionally it helps to know
what the computer is doing
203
Back to the Good News
β€’ We can calculate the standardised
parameters as
B=Rxx-1 x Rxy
β€’ Where
– B is the vector of regression weights
– Rxx-1 is the inverse of the correlation matrix
of the independent (x) variables
– Rxy is the vector of correlations of the
correlations of the x and y variables
204
Exercise 4.2
205
Exercises
β€’ Exercise 4.1
– Grades data in Excel
β€’ Exercise 4.2
– Repeat in Stata
β€’ Exercise 4.3
– Zero correlation
β€’ Exercise 4.4
– Repeat therapy data
β€’ Exercise 4.5
– PTSD in families.
206
Lesson 5: More on Multiple
Regression
207
Contents
β€’ More on parameter estimates
– Standard errors of coefficients
β€’ R, R2, adjusted R2
β€’ Extra bits
– Suppressors
– Decisions about control variables
– Standardized estimates > 1
– Variable entry techniques
208
More on Parameter Estimates
209
Parameter Estimates
β€’ Parameter estimates (b1, b2 … bk) were
standardised
– Because we analysed a correlation matrix
β€’ Represent the correlation of each IV
with the outcome
– When all other IVs are held constant
210
β€’ Can also be unstandardised
β€’ Unstandardised represent the unit (rather
than SD’s) change in the outcome
associated with a 1 unit change in the
IV
– When all the other variables are held
constant
β€’ Parameters have standard errors
associated with them
– As with one IV
– Hence t-test, and associated probability
can be calculated
β€’ Trickier than with one IV
211
Standard Error of Regression
Coefficient
β€’ Standardised is easier
1ο€­ R
1
SEi ο€½
2
n ο€­ k ο€­1 1 ο€­ R i
2
Y
– R2i is the value of R2 when all other predictors are
used as predictors of that variable
β€’ Note that if R2i = 0, the equation is the same as for
previous
212
Multiple R
213
Multiple R
β€’ The degree of prediction
– R (or Multiple R)
– No longer equal to b
β€’ R2 Might be equal to the sum of squares
of B
– Only if all x’s are uncorrelated
214
In Terms of Variance
β€’ Can also think of R2 in terms of
variance explained.
– Each IV explains some variance in the
outcome
– The IVs share some of their variance
β€’ Can’t share the same variance twice
215
Variance in Y
accounted for by x1
rx1y2 = 0.36
The total
variance of Y
=1
Variance in Y
accounted for by x2
rx2y2 = 0.36
216
β€’ In this model
– R2 = ryx12 + ryx22
– R2 = 0.36 + 0.36 = 0.72
– R = οƒ–0.72 = 0.85
β€’ But
– If x1 and x2 are correlated
– No longer the case
217
Variance in Y
accounted for by x1
rx1y2 = 0.36
The total
variance of Y
=1
Variance shared
between x1 and x2
(not equal to rx1x2)
Variance in Y
accounted for by x2
rx2y2 = 0.36
218
β€’ So
– We can no longer sum the r2
– Need to sum them, and subtract the
shared variance – i.e. the correlation
β€’ But
– It’s not the correlation between them
– It’s the correlation between them as a
proportion of the variance of Y
β€’ Two different ways
219
β€’ Based on estimates
2
R ο€½ b1ryx1  b2 ryx2
β€’ If rx1x2 = 0
– rxy = bx1
– Equivalent to ryx12 + ryx22
220
β€’ Based on correlations
2
R ο€½
2
yx1
r
2
yx2
r
ο€­ 2ryx1 ryx2 rx1 x2
2
x1 x2
1ο€­r
β€’ rx1x2 = 0
– Equivalent to ryx12 + ryx22
221
β€’ Can also be calculated using methods
we have seen
– Based on PRE (predicted value)
– Based on correlation with prediction
β€’ Same procedure with >2 IVs
222
Adjusted R2
β€’ R2 is on average an overestimate of
population value of R2
– Any x will not correlate 0 with Y
– Any variation away from 0 increases R
– Variation from 0 more pronounced with
lower N
β€’ Need to correct R2
– Adjusted R2
223
β€’ Calculation of Adj. R2
N ο€­1
Adj. R ο€½ 1 ο€­ (1 ο€­ R )
N ο€­ k ο€­1
2
2
β€’ 1 – R2
– Proportion of unexplained variance
– We multiple this by an adjustment
β€’ More variables – greater adjustment
β€’ More people – less adjustment
224
N ο€­1
N ο€­ k ο€­1
N ο€½ 20, k ο€½ 3
20 ο€­ 1
19
ο€½
ο€½ 1.1875
20 ο€­ 3 ο€­ 1 16
N ο€½ 10, k ο€½ 8
N ο€½ 10, k ο€½ 3
10 ο€­ 1
9
ο€½ ο€½9
10 ο€­ 8 ο€­ 1 1
10 ο€­ 1
9
ο€½ ο€½ 1.5
10 ο€­ 3 ο€­ 1 6
225
Extra Bits
β€’ Some stranger things that can
happen
– Counter-intuitive
226
Suppressor variables
β€’ Can be hard to understand
– Very counter-intuitive
β€’ Definition
– A predictor which increases the size of the
parameters associated with other
predictors above the size of their
correlations
227
β€’ An example (based on Horst, 1941)
– Success of trainee pilots
– Mechanical ability (x1), verbal ability (x2),
success (y)
β€’ Correlation matrix
Mech
Mech
Verb
Success
1
0.5
0.3
Verb
0.5
1
0
Success
0.3
0
1
228
– Mechanical ability correlates 0.3 with
success
– Verbal ability correlates 0.0 with success
– What will the parameter estimates be?
– (Don’t look ahead until you have had a
guess)
229
β€’ Mechanical ability
– b = 0.4
– Larger than r!
β€’ Verbal ability
– b = -0.2
– Smaller than r!!
β€’ So what is happening?
– You need verbal ability to do the mechanical
ability test
– Not actually related to mechanical ability
β€’ Measure of mechanical ability is contaminated by verbal
ability
230
β€’ High mech, low verbal
– High mech
β€’ This is positive (.4)
– Low verbal
β€’ Negative, because we are talking about
standardised scores (-(-.2) οƒ  (.2)
β€’ Your mech is really high – you did well on the
mechanical test, without being good at the
words
β€’ High mech, high verbal
– Well, you had a head start on mech,
because of verbal, and need to be brought
down a bit
231
Another suppressor?
x1
x2
y
x1
1
0.5
0.3
x2
0.5
1
0.2
y
0.3
0.2
1
b1 =
b2 =
232
Another suppressor?
x1
x2
y
x1
1
0.5
0.3
x2
0.5
1
0.2
y
0.3
0.2
1
b1 =0.26
b2 = -0.06
233
And another?
x1
x2
y
x1
1
0.5
0.3
x2
0.5
1
-0.2
y
0.3
-0.2
1
b1 =
b2 =
234
And another?
x1
x2
y
x1
1
0.5
0.3
x2
0.5
1
-0.2
y
0.3
-0.2
1
b1 = 0.53
b2 = -0.47
235
One more?
x1
x2
y
x1
1
-0.5
0.3
x2
-0.5
1
0.2
y
0.3
0.2
1
b1 =
b2 =
236
One more?
x1
x2
y
x1
1
-0.5
0.3
x2
-0.5
1
0.2
y
0.3
0.2
1
b1 = 0.53
b2 = 0.47
237
β€’ Suppression happens when two opposing
forces are happening together
– And have opposite effects
β€’ Don’t throw away your IVs,
– Just because they are uncorrelated with the
outcome
β€’ Be careful in interpretation of regression
estimates
– Really need the correlations too, to interpret what
is going on
– Cannot compare between studies with different
predictors
– Think about what you want to know
β€’ Before throwing variables into the analysis
238
What to Control For?
β€’ What is the added value of a β€˜better’
college
– In terms of salary
– More academic people go to β€˜better’
colleges
– Control for:
β€’ Ability? Social class? Mother’s education?
Parent’s income? Course? Ethnic group? …
239
β€’ Decisions about control variables
– Guided from theory
β€’ Effect of gender
– Controlling for hair length and skirt
wearing?
240
241
β€’ Do dogs make kids healthier?
– What to control for? Parent’s weight?
β€’ Yes: Obese parents are more likely to have
obese kids, kids who are thinner, relative to the
parents are thinner.
β€’ No: Dog might make parent thinner. By
controlling for parental weight, you’re
controlling for the effect of dog
242
Bad control
vars
Bad control
vars
Kid’s health
Dog
Good
control vars
Parent
Weight
Child
Asthma
Kid’s health
Dog
Rural/Urban?
House/apartment?
Income
Standardised Estimates > 1
β€’ Correlations are bounded
-1.00 ≀ r ≀ +1.00
– We think of standardised regression
estimates as being similarly bounded
β€’ But they are not
– Can go >1.00, <-1.00
– R cannot, because that is a proportion of
variance
246
β€’ Three measures of ability
– Mechanical ability, verbal ability 1, verbal
ability 2
– Score on science exam
Mech
Mech
Verbal1
Verbal2
Scores
1
0.1
0.1
0.6
Verbal1
0.1
1
0.9
0.6
Verbal2
0.1
0.9
1
0.3
Scores
0.6
0.6
0.3
1
–Before reading on, what are the parameter
estimates?
247
Mech
Verbal1
Verbal2
0.56
1.71
-1.29
β€’ Mechanical
– About where we expect
β€’ Verbal 1
– Very high
β€’ Verbal 2
– Very low
248
β€’ What is going on
– It’s a suppressor again
– a predictor which increases the size of the
parameters associated with other
predictors above the size of their
correlations
β€’ Verbal 1 and verbal 2 are correlated so
highly
– They need to cancel each other out
249
Variable Selection
β€’ What are the appropriate predictors to
use in a model?
– Depends what you are trying to do
β€’ Multiple regression has two separate
uses
– Prediction
– Explanation
250
β€’ Prediction
– What will happen in
the future?
– Emphasis on
practical application
– Variables selected
(more) empirically
– Value free
β€’ Explanation
– Why did something
happen?
– Emphasis on
understanding
phenomena
– Variables selected
theoretically
– Not value free
251
β€’ Visiting the doctor
– Precedes suicide attempts
– Predicts suicide
β€’ Does not explain suicide
β€’ More on causality later on …
β€’ Which are appropriate variables
– To collect data on?
– To include in analysis?
– Decision needs to be based on theoretical knowledge
of the behaviour of those variables
– Statistical analysis of those variables (later)
β€’ Unless you didn’t collect the data
– Common sense (not a useful thing to say)
252
Variable Entry Techniques
β€’ Entry-wise
– All variables entered simultaneously
β€’ Hierarchical
– Variables entered in a predetermined order
β€’ Stepwise
– Variables entered according to change in
R2
– Actually a family of techniques
253
β€’ Entrywise regression
– All variables entered simultaneously
– All treated equally
β€’ Hierarchical regression
– Entered in a theoretically determined order
– Change in R2 is assessed, and tested for
significance
– e.g. sex and age
β€’ Should not be treated equally with other variables
β€’ Sex and age MUST be first (unchangeable)
– Confused with hierarchical linear modelling (MLM)
254
R-Squared Change

SSE1 ο€­ SSE0  /( df1 ο€­ df 0 )
Fο€½
SSE0 / df 0
β€’ SSE0, df0
β€’ SSE and df for first (smaller) model
β€’ SSE1, df1
β€’ SSE and df for second (larger) model
255
β€’ Stepwise
– Variables entered empirically
– Variable which increases R2 the most goes
first
β€’ Then the next …
– Variables which have no effect can be
removed from the equation
β€’ Example
– House prices – what’s important?
– Size, lot size, list price,
256
β€’ Stepwise Analysis
– Data determines the order
– Model 1: listing price, R2 = 0.87
– Model 2: listing price + lot size, R2 = 0.89
List
Lot size
b
0.81
0.02
p
<0.001
0.02
257
β€’ Hierarchical analysis
– Theory determines the order
– Model 1: Lot size+ House size, R2 = 0.499
– Model 2: + List price, R2 = 0.905
– Change in R2 = 0.41, p < 0.001
2
House size
Lot size
List price
0.18
0.15
0.75
0.20
0.03
<0.001
258
β€’ Which is the best model?
– Entrywise – OK
– Stepwise – excluded age
β€’ Excluded size
– MOST IMPORTANT PREDICTOR
– Hierarchical
β€’ Listing price accounted for additional variance
– Whoever decides the price has information that we
don’t
β€’ Other problems with stepwise
– F and df are wrong (cheats with df)
– Unstable results
β€’ Small changes (sampling variance) – large
differences in models
259
– Uses a lot of paper
– Don’t use a stepwise procedure to pack
your suitcase
260
Is Stepwise Always Evil?
β€’ Yes
β€’ All right, no
β€’ Research goal is entirely predictive
(technological)
– Not explanatory (scientific)
– What happens, not why
β€’ N is large
– 40 people per predictor, Cohen, Cohen, Aiken, West
(2003)
β€’ Cross validation takes place
261
β€’ Alternatives to stepwise regression
– More recently developed
– Used for genetic studies
β€’ 1000s of predictors, one outcome, small
samples
– Least Angle Regression
β€’ LARS (least angle regression)
β€’ Lasso (Least absolute shrinkage and selection
operator)
262
Entry Methods in Stata
β€’ Entrywise
– What regress does
β€’ Hierarchical
– Two ways
– Use hireg
– Add on module
β€’ net search hireg
β€’ Then install
263
Hierarchical Regression
β€’ Use (on one line)
– hireg outcome (block1var1
block1var2) (block2var1
block2var2)
β€’ Hireg reports
– Parameter estimates for the two
regressions
– R2 for each model, change in R2
264
Model R2
1: 0.022
2: 0.513
p
0.136
0.000
F(df)
2.256(1,98)
50.987(2,97)
R2 change
0.490
P value for
the R2
F(df)change
97.497(1,97)
p
0.000
P value for
the change
in R2
265
Hierarchical Regression (Cont…)
β€’ I don’t like hireg, for two reasons
– It’s different to regression
– It only works for OLS regression, not
logistic, multinomial, Poisson, etc
β€’ Alternative 2:
– Use test
– The p-value associated with the change in
R2 for a variable
β€’ Equal to the p-value for that variable.
266
Hierarchical Regression (Cont…)
β€’ Example (using cars)
– Parameters from final model:
– hireg price () (extro)
car
|
extro |
Coef.
.463
Std. Err.
.1296
t
3.57
P>|t|
0.001
[95% Conf. Interval]
.2004
.72626
– R2 change statistics
R2 change
0.128
F(df) change
12.773(1,36)
p
0.001
– (What is relationship between t and F?)
β€’ We know the p-value of the R2 change
– When there is one predictor in the block
– What about when there’s more than one?
267
Hierarchical Regression (Cont)
β€’ test isn’t exactly what we want
– But it is the same as what we want
β€’ Advantage of test
– You can always use it
β€’ (I can always remember how it works)
268
(For SPSS)
β€’ SPSS calls them β€˜blocks’
β€’ Enter some variables, click β€˜next block’
– Enter more variables
β€’ Click on β€˜Statistics’
– Click on R-squared change
269
Stepwise Regression
β€’ Add stepwise: prefix
β€’ With
– Pr() – probability value to be removed from
equation
– Pe() – probability value to be entered into
equation
β€’ stepwise, pe(0.05) pr(0.2):
reg price sqm lotsize
originallis
270
A quick note on R2
R2 is sometimes regarded as the β€˜fit’ of a
regression model
– Bad idea
β€’ If good fit is required – maximise R2
– Leads to entering variables which do not
make theoretical sense
271
Propensity Scores
β€’ Another method of controlling for
variables
β€’ Ensure that predictors are uncorrelated
with one predictor
– Don’t need to control for them
272
x’s Uncorrelated?
β€’ Two cases when x’s are uncorrelated
β€’ Experimental design
– Predictors are uncorrelated
– We randomly assigned people to conditions
to ensure that was the case
β€’ Sample weights
– We can deliberately sample
β€’ Ensure that they are uncorrelated
273
β€’ 20
β€’ 20
β€’ 20
β€’ 20
women with college degree
women without college degree
men with college degree
men without college degree
– Or use post hoc sample weights
β€’ Propensity weighting
– Weight to ensure that variables are uncorrelated
– Usually done to avoid having to control
– E.g. ethnic differences in PTSD symptoms
– Can incorporate many more control
variables
β€’ 100+
274
Propensity Scores
β€’ Race profiling of police stops
– Same time, place, area, etc
– www.youtube.com/watch?v=Oot0BOaQTZI
275
Critique of Multiple Regression
β€’ Goertzel (2002)
– β€œMyths of murder and multiple regression”
– Skeptical Inquirer (Paper B1)
β€’ Econometrics and regression are β€˜junk
science’
– Multiple regression models (in US)
– Used to guide social policy
276
More Guns, Less Crime
– (controlling for other factors)
β€’ Lott and Mustard: A 1% increase in gun
ownership
– 3.3% decrease in murder rates
β€’ But:
– More guns in rural Southern US
– More crime in urban North (crack cocaine
epidemic at time of data)
277
Executions Cut Crime
β€’ No difference between crimes in states
in US with or without death penalty
β€’ Ehrlich (1975) controlled all variables
that affect crime rates
– Death penalty had effect in reducing crime
rate
β€’ No statistical way to decide who’s right
278
Legalised Abortion
β€’ Donohue and Levitt (1999)
– Legalised abortion in 1970’s cut crime in 1990’s
β€’ Lott and Whitley (2001)
– β€œLegalising abortion decreased murder rates by …
0.5 to 7 per cent.”
β€’ It’s impossible to model these data
– Controlling for other historical events
– Crack cocaine (again)
279
β€’ Crime is still dropping in the US
– Despite the recession
β€’ Levitt says it’s mysterious, because the
abortion effect should be over
β€’ Some suggest Xboxes, Playstations, etc
β€’ Netflix, DVRs
– (Violent movies reduce crime).
280
Another Critique
β€’ Berk (2003)
– Regression analysis: a constructive critique (Sage)
β€’ Three cheers for regression
– As a descriptive technique
β€’ Two cheers for regression
– As an inferential technique
β€’ One cheer for regression
– As a causal analysis
281
Is Regression Useless?
β€’ Do regression carefully
– Don’t go beyond data which you have a
strong theoretical understanding of
β€’ Validate models
– Where possible, validate predictive power
of models in other areas, times, groups
β€’ Particularly important with stepwise
282
Lesson 6: Categorical
Predictors
283
Introduction
284
Introduction
β€’ So far, just looked at continuous
predictors
β€’ Also possible to use categorical
(nominal, qualitative) predictors
– e.g. Sex; Job; Religion; Region; Type (of
anything)
β€’ Usually analysed with t-test/ANOVA
285
Historical Note
β€’ But these (t-test/ANOVA) are special
cases of regression analysis
– Aspects of General Linear Models (GLMs)
β€’ So why treat them differently?
– Fisher’s fault
– Computers’ fault
β€’ Regression, as we have seen, is
computationally difficult
– Matrix inversion and multiplication
– Can’t do it, without a computer
286
β€’ In the special cases where:
β€’ You have one categorical predictor
β€’ Your IVs are uncorrelated
– It is much easier to do it by partitioning of
sums of squares
β€’ These cases
– Very rare in β€˜applied’ research
– Very common in β€˜experimental’ research
β€’ Fisher worked at Rothamsted agricultural
research station
β€’ Never have problems manipulating wheat, pigs,
cabbages, etc
287
β€’ In psychology
– Led to a split between β€˜experimental’
psychologists and β€˜correlational’
psychologists
– Experimental psychologists (until recently)
would not think in terms of continuous
variables
β€’ Still (too) common to dichotomise a
variable
– Too difficult to analyse it properly
– Equivalent to discarding 1/3 of your data
288
The Approach
289
The Approach
β€’ Recode the nominal variable
– Into one, or more, variables to represent that
variable
β€’ Names are slightly confusing
– Some texts talk of β€˜dummy coding’ to refer to all
of these techniques
– Some (most) refer to β€˜dummy coding’ to refer to
one of them
– Most have more than one name
290
β€’ If a variable has g possible categories it
is represented by g-1 variables
β€’ Simplest case:
– Smokes: Yes or No
– Variable 1 represents β€˜Yes’
– Variable 2 is redundant
β€’ If it isn’t yes, it’s no
291
The Techniques
292
β€’ We will examine two coding schemes
– Dummy coding
β€’ For two groups
β€’ For >2 groups
– Effect coding
β€’ For >2 groups
β€’ Look at analysis of change
– Equivalent to ANCOVA
– Pretest-posttest designs
293
Dummy Coding – 2 Groups
β€’ Sometimes called β€˜simple coding’
β€’ A categorical variable with two groups
β€’ One group chosen as a reference group
– The other group is represented in a variable
β€’ e.g. 2 groups: Experimental (Group 1) and
Control (Group 0)
– Control is the reference group
– Dummy variable represents experimental group
β€’ Call this variable β€˜group1’
294
β€’ For variable β€˜group1’
– 1 = β€˜Yes’, 0=β€˜No’
Original
Category
Exp
Con
New
Variable
1
0
295
β€’ Some data
β€’ Group is x, score is y
Control
Group
Experiment 1
Experiment 2
Experiment 3
Experimental
Group
10
10
10
20
10
30
296
β€’ Control Group = 0
– Intercept = Score on Y when x = 0
– Intercept = mean of control group
β€’ Experimental Group = 1
– b = change in Y when x increases 1 unit
– b = difference between experimental
group and control group
297
35
30
Gradient of slope
25
represents
difference
between means
20
15
10
5
0
Control Group
Experiment 1
Experimental Group
Experiment 2
Experiment 3
298
Dummy Coding – 3+ Groups
β€’ With three groups the approach is the
similar
β€’ g = 3, therefore g-1 = 2 variables
needed
β€’ 3 Groups
– Control
– Experimental Group 1
– Experimental Group 2
299
Original
Category
Con
Gp1
Gp2
Gp1
Gp2
0
1
0
0
0
1
β€’ Recoded into two variables
– Note – do not need a 3rd variable
β€’ If we are not in group 1 or group 2 MUST be in
control group
β€’ 3rd variable would add no information
β€’ (What would happen to determinant?)
300
β€’ F and associated p
– Tests H0 that
g1 ο€½ g 2 ο€½ g3
β€’ b1 and b2 and associated p-values
– Test difference between each experimental group
and the reference group
β€’ To test difference between experimental
groups
– Need to rerun analysis (or just do ANOVA with
post-hoc tests)
301
β€’ One more complication
– Have now run multiple comparisons
– Increases a – i.e. probability of type I error
β€’ Need to correct for this
– Bonferroni correction
– Multiply given p-values by two/three
(depending how many comparisons were
made)
302
Effect Coding
β€’ Usually used for 3+ groups
β€’ Compares each group (except the reference
group) to the mean of all groups
– Dummy coding compares each group to the
reference group.
β€’ Example with 5 groups
– 1 group selected as reference group
β€’ Group 5
303
β€’ Each group (except reference) has a
variable
– 1 if the individual is in that group
– 0 if not
– -1 if in reference group
group
1
2
3
4
5
group_1 group_2 group_3 group_4
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
-1
-1
-1
-1
304
Examples
β€’ Dummy coding and Effect Coding
β€’ Group 1 chosen as reference group
each time
β€’ Data
Group
Mean
SD
1
52.40
4.60
2
56.30
5.70
3
60.10
5.00
Total
56.27
5.88
305
β€’ Dummy
Group
dummy2
dummy3
1
2
3
0
1
0
0
0
1
Group
Effect2
effect3
1
2
3
-1
1
0
-1
0
1
β€’ Effect
306
Dummy
R=0.543, F=5.7,
df=2, 27, p=0.009
b0 = 52.4,
b1 = 3.9, p=0.100
b2 = 7.7, p=0.002
Effect
R=0.543, F=5.7, df=2,
27, p=0.009
b0 = 56.27,
b1 = 0.03, p=0.980
b2 = 3.8, p=0.007
b0 ο€½ g1
b0 ο€½ G
b1 ο€½ g2 ο€­ g1
b1 ο€½ g2 ο€­ G
b2 ο€½ g3 ο€­ g1
b2 ο€½ g3 ο€­ G
307
In Stata
β€’ Use xi: prefix for dummy coding
β€’ Use xi3: module for more codings
β€’ But
– I don’t like it, I do it by hand
– I don’t understand what it’s doing
– It makes very long variables
β€’ And then I can’t use test
– BUT: If doing stepwise, you need to keep the variables
together
β€’ Example:
xi: reg outcome contpred i.catpred
This has changed
in Stata 11. xi: no
longer needed
Put i. in front of
categorical
308
predictors
xi: reg salary i.job_description
-----------------------------------------------------salary |
Coef.
Std. Err.
t
P>|t|
-------------+---------------------------------------_Ijob_desc~2 |
3100.34
2023.76
1.53
0.126
_Ijob_desc~3 |
36139.2
1228.352
29.42
0.000
_cons
|
27838.5
532.4865
52.28
0.000
------------------------------------------------------
309
Exercise 6.1
β€’ 5 golf balls
– Which is best?
310
In SPSS
β€’ SPSS provides two equivalent procedures for
regression
– Regression
– GLM
– GLM will:
– Automatically code categorical variables
– Automatically calculate interaction terms
– Allow you to not understand
β€’ GLM won’t:
– Give standardised effects
– Give hierarchical R2 p-values
311
ANCOVA and Regression
312
β€’ Test
– (Which is a trick; but it’s designed to make
you think about it)
β€’ Use bank data (Ex 5.3)
– Compare the pay rise (difference between
salbegin and salary)
– For ethnic minority and non-minority staff
β€’ What do you find?
313
ANCOVA and Regression
β€’ Dummy coding approach has one special use
– In ANCOVA, for the analysis of change
β€’ Pre-test post-test experimental design
– Control group and (one or more) experimental
groups
– Tempting to use difference score + t-test / mixed
design ANOVA
– Inappropriate
314
β€’ Salivary cortisol levels
– Used as a measure of stress
– Not absolute level, but change in level over
day may be interesting
β€’ Test at: 9.00am, 9.00pm
β€’ Two groups
– High stress group (cancer biopsy)
β€’ Group 1
– Low stress group (no biopsy)
β€’ Group 0
315
High Stress
Low Stress
AM
20.1
22.3
PM
6.8
11.8
Diff
13.3
10.5
β€’ Correlation of AM and PM = 0.493
(p=0.008)
β€’ Has there been a significant difference
in the rate of change of salivary
cortisol?
– 3 different approaches
316
β€’ Approach 1 – find the differences, do a
t-test
– t = 1.31, df=26, p=0.203
β€’ Approach 2 – mixed ANOVA, look for
interaction effect
– F = 1.71, df = 1, 26, p = 0.203
– F = t2
β€’ Approach 3 – regression (ANCOVA)
based approach
317
– IVs: AM and group
– outcome: PM
– b1 (group) = 3.59, standardised b1=0.432,
p = 0.01
β€’ Why is the regression approach better?
– The other two approaches took the
difference
– Assumes that r = 1.00
– Any difference from r = 1.00 and you add
error variance
β€’ Subtracting error is the same as adding error
318
β€’ Using regression
– Ensures that all the variance that is
subtracted is true
– Reduces the error variance
β€’ Two effects
– Adjusts the means
β€’ Compensates for differences between groups
– Removes error variance
β€’ Data is am-pm cortisol
319
More on Change
β€’ If difference score is correlated with
either pre-test or post-test
– Subtraction fails to remove the difference
between the scores
– If two scores are uncorrelated
β€’ Difference will be correlated with both
β€’ Failure to control
– Equal SDs, r = 0
β€’ Correlation of change and pre-score =0.707
320
Even More on Change
β€’ A topic of surprising complexity
– What I said about difference scores isn’t
always true
β€’ Lord’s paradox – it depends on the precise
question you want to answer
– Collins and Horn (1993). Best methods for
the analysis of change
– Collins and Sayer (2001). New methods for
the analysis of change
– More later
321
Lesson 7: Assumptions in
Regression Analysis
322
The Assumptions
1. The distribution of residuals is normal (at
each value of the outcome).
2. The variance of the residuals for every set
of values for the predictor is equal.
β€’ violation is called heteroscedasticity.
3. The error term is additive
β€’
no interactions.
4. At every value of the outcome the expected
(mean) value of the residuals is zero
β€’
No non-linear relationships
323
5. The expected correlation between residuals,
for any two cases, is 0.
β€’
The independence assumption (lack of
autocorrelation)
6. All predictors are uncorrelated with the
error term.
7. No predictors are a perfect linear function
of other predictors (no perfect
multicollinearity)
8. The mean of the error term is zero.
324
What are we going to do …
β€’ Deal with some of these assumptions in
some detail
β€’ Deal with others in passing only
– look at them again later on
325
Assumption 1: The
Distribution of Residuals is
Normal at Every Value of the
outcome
326
Look at Normal Distributions
β€’ A normal distribution
– symmetrical, bell-shaped (so they say)
327
What can go wrong?
β€’ Skew
– non-symmetricality
– one tail longer than the other
β€’ Kurtosis
– too flat or too peaked
– kurtosed
β€’ Outliers
– Individual cases which are far from the
distribution
328
Effects on the Mean
β€’ Skew
– biases the mean, in direction of skew
β€’ Kurtosis
– mean not biased
– standard deviation is
– and hence standard errors, and
significance tests
329
Examining Univariate
Distributions
β€’ Graphs
– Histograms
– Boxplots
– P-P plots
β€’ Calculation based methods
330
Histograms
30
A and B
30
20
20
10
10
0
0
331
β€’ C and D
40
14
12
30
10
8
20
6
4
10
2
0
0
332
β€’E&F
20
10
0
333
Histograms can be tricky ….
7
6
6
5
5
4
4
3
3
2
2
1
1
0
0
0
7
7
6
6
6
5
5
6
5
4
3
2
1
5
4
4
4
3
3
2
2
1
1
0
0
3
2
1
0
334
Boxplots
335
P-P Plots
β€’A&B
1.00
1.00
.75
.75
.50
.50
.25
.25
0.00
0.00
.25
.50
.75
1.00
0.00
0.00
.25
.50
.75
1.00
336
β€’C&D
1.00
1.00
.75
.75
.50
.50
.25
.25
0.00
0.00
.25
.50
.75
1.00
0.00
0.00
.25
.50
.75
1.00
337
β€’E&F
1.00
1.00
.75
.75
.50
.50
.25
.25
0.00
0.00
.25
.50
.75
1.00
0.00
0.00
.25
.50
.75
1.00
338
Calculation Based
β€’ Skew and Kurtosis statistics
β€’ Outlier detection statistics
339
Skew and Kurtosis Statistics
β€’ Normal distribution
– skew = 0
– kurtosis = 0
β€’ Two methods for calculation
– Fisher’s and Pearson’s
– Very similar answers
β€’ Associated standard error
– can be used for significance (t-test) of departure
from normality
– not actually very useful
β€’ Never normal above N = 400
340
Skewness Kurtosis
A
B
C
D
E
F
-0.12
0.271
0.454
0.117
2.106
0.171
-0.084
0.265
1.885
-1.081
5.75
-0.21
341
Outlier Detection
β€’ Calculate distance from mean
– z-score (number of standard deviations)
– deleted z-score
β€’ that case biased the mean, so remove it
– Look up expected distance from mean
β€’ 1% 3+ SDs
342
Non-Normality in Regression
343
Effects on OLS Estimates
β€’ The mean is an OLS estimate
β€’ The regression line is an OLS estimate
β€’ Lack of normality
– biases the position of the regression slope
– makes the standard errors wrong
β€’ probability values attached to statistical
significance wrong
344
Checks on Normality
β€’ Check residuals are normally distributed
– Draw histogram residuals
β€’ Use regression diagnostics
– Lots of them
– Most aren’t very interesting
345
Regression Diagnostics
β€’ Residuals
– Standardised, studentised-deleted
– look for cases > |3| (?)
β€’ Influence statistics
– Look for the effect a case has
– If we remove that case, do we get a different
answer?
– DFBeta, Standardised DFBeta
β€’ changes in b
346
– DfFit, Standardised DfFit
β€’ change in predicted value
β€’ Distances
– measures of β€˜distance’ from the centroid
– some include IV, some don’t
347
More on Residuals
β€’ Residuals are trickier than you might
have imagined
β€’ Raw residuals
– OK
β€’ Standardised residuals
– Residuals divided by SD
se ο€½
e
n ο€­ k ο€­1
2
348
Standardised / Studentised
β€’ Now we can calculate the standardised
residuals
– SPSS calls them studentised residuals
– Also called internally studentised residuals
ei
eiο‚’ ο€½
se 1 ο€­ hi
349
Deleted Studentised Residuals
β€’ Studentised residuals do not have a
known distribution
– Cannot use them for inference
β€’ Deleted studentised residuals
– Externally studentised residuals
– Studentized (jackknifed) residuals
β€’ Distributed as t
β€’ With df = N – k – 1
350
Testing Significance
β€’ We can calculate the probability of a
residual
– Is it sampled from the same population
β€’ BUT
– Massive type I error rate
– Bonferroni correct it
β€’ Multiply p value by N
351
Bivariate Normality
β€’ We didn’t just say β€œresiduals normally
distributed”
β€’ We said β€œat every value of the
outcomes”
β€’ Two variables can be normally
distributed – univariate,
– but not bivariate
352
β€’ Couple’s IQs
– male and female
FEMALE
MALE
8
6
5
6
4
4
3
2
Frequency
2
0
60.0
70.0
80.0
90.0
100.0
110.0
120.0
130.0
1
0
140.0
60.0
70.0
80.0
90.0
100.0
110.0
120.0
130.0
140.0
–Seem reasonably normal
353
β€’ But wait!!
160
140
120
100
80
MALE
60
40
40
60
80
100
120
140
160
FEMALE
354
β€’ When we look at bivariate normality
– not normal – there is an outlier
β€’ So plot X against Y
β€’ OK for bivariate
– but – may be a multivariate outlier
– Need to draw graph in 3+ dimensions
– can’t draw a graph in 3 dimensions
β€’ But we can look at the residuals instead
…
355
β€’ IQ histogram of residuals
12
10
8
6
4
2
0
356
Multivariate Outliers …
β€’ Will be explored later in the exercises
β€’ So we move on …
357
What to do about NonNormality
β€’ Skew and Kurtosis
– Skew – much easier to deal with
– Kurtosis – less serious anyway
β€’ Transform data
– removes skew
– positive skew – log transform
– negative skew - square
358
Transformation
β€’ May need to transform IV and/or outcome
– More often outcome
β€’ time, income, symptoms (e.g. depression) all positively
skewed
– can cause non-linear effects (more later) if only
one is transformed
– alters interpretation of unstandardised parameter
– May alter meaning of variable
β€’ Some people say that this is such a big problem
– Never transform
– May add / remove non-linear and moderator
effects
359
β€’ Change measures
– increase sensitivity at ranges
β€’ avoiding floor and ceiling effects
β€’ Outliers
– Can be tricky
– Why did the outlier occur?
β€’ Error? Delete them.
β€’ Weird person? Probably delete them
β€’ Normal person? Tricky.
360
– You are trying to model a process
β€’ is the data point β€˜outside’ the process
β€’ e.g. lottery winners, when looking at salary
β€’ yawn, when looking at reaction time
– Which is better?
β€’ A good model, which explains 99% of your
data? (because we threw outliers out)
β€’ A poor model, which explains all of it (because
we keep outliers in)
β€’ I prefer a good model
361
More on House Prices
β€’ Zillow.com tracks and predicts house
prices
– In the USA
β€’ Sometimes detects outliers
– We don’t trust this selling price
– We haven’t used it
362
Example in Stata
β€’ reg salary educ
β€’ predict res, res
β€’ hist res
β€’ gen logsalary= log(salary)
β€’ reg logsalary educ
β€’ predict logres, res
β€’ hist logres
363
4.0e-05
3.0e-05
0
Density
2.0e-05
1.0e-05
-20000
0
20000
40000
Residuals
60000
80000
2
1
0
Density
1.5
.5
-1
-.5
0
Residuals
.5
1
But …
β€’ Parameter estimates change
β€’ Interpretation of parameter estimate is
different
β€’ Exercise 7.0, 7.1
366
Bootstrapping
β€’ Bootstrapping is very, very cool
β€’ And very, very clever
β€’ But very, very simple
367
Bootstrapping
β€’ When we estimate a test statistic (F or r
or t or c2)
β€’ We rely on knowing the sampling
distribution
β€’ Which we know
– If the distributional assumptions are
satisfied
368
Estimate the Distribution
β€’ Bootstrapping lets you:
– Skip the bit about distribution
– Estimate the sampling distribution from the
data
β€’ This shouldn’t be allowed
– Hence bootstrapping
– But it is
369
How to Bootstrap
β€’ We resample, with replacement
β€’ Take our sample
– Sample 1 individual
β€’ Put that individual back, so that they can be
sampled again
– Sample another individual
β€’ Keep going until we’ve sampled as many
people as were in the sample
β€’ Analyze the data
β€’ Repeat the process B times
– Where B is a big number
370
Example
Original
1
2
3
4
5
6
7
8
9
10
B1
1
1
3
3
3
3
7
7
9
9
B2
1
2
3
4
4
4
8
8
9
10
B3
2
2
3
2
4
4
6
7
9
9
371
β€’ Analyze each dataset
– Sampling distribution of statistic
β€’ Gives sampling distribution
β€’ 2 approaches to CI or P
β€’ Semi-parametric
– Calculate standard error of statistic
– Call that the standard deviation
– Does not make assumption about
distribution of data
β€’ Makes assumption about sampling distribution
372
β€’ Non-parametric
– Stata calls this percentile
β€’ Count.
– If you have 1000 samples
– 25th is lower CI
– 975th is upper CI
– P-value is proportion that cross zero
β€’ Non-parametric needs more samples
373
Bootstrapping in Stata
β€’ Very easy:
– Use bootstrap: (or bs: or bstrap: ) prefix or
– (Better) use vce(bootstrap) option
β€’ By default does 50 samples
– Not enough
– Use reps()
– At least 1000
374
Example
reg salary salbegin educ, vce(bootstrap,
reps(50))
|
Observed
Bootstrap
|
Coef.
Std. Err.
z
-----------+--------------------------------salbegin |
1.672631
.0863302
19.37
β€’ Again
salbegin |
1.672631
.0737315
22.69
375
More Reps
β€’ 1,000 reps
– Z = 17.31
β€’ Again
– Z = 17.59
β€’ 10,000 reps
– 17.23
– 17.02
376
β€’ Exercise 7.2, 7.3
377
Assumption 2: The variance of
the residuals for every set of
values for the predictor is
equal.
378
Heteroscedasticity
β€’ This assumption is a about
heteroscedasticity of the residuals
– Hetero=different
– Scedastic = scattered
β€’ We don’t want heteroscedasticity
– we want our data to be homoscedastic
β€’ Draw a scatterplot to investigate
379
160
140
120
100
80
MALE
60
40
40
60
80
100
120
140
160
380
FEMALE
β€’ Only works with one IV
– need every combination of IVs
β€’ Easy to get – use predicted values
– use residuals there
β€’ Plot predicted values against residuals
β€’ A bit like turning the scatterplot to
make the line of best fit flat
381
Good – no heteroscedasticity
Predicted Value
382
Bad – heteroscedasticity
Predicted Value
383
Testing Heteroscedasticity
β€’
White’s test
1.
2.
3.
4.
Do regression, save residuals.
Square residuals
Square IVs
Calculate interactions of IVs
– e.g. x1β€’x2, x1β€’x3, x2 β€’ x3
384
5. Run regression using
– squared residuals as outcome
– IVs, squared IVs, and interactions as IVs
6. Test statistic = N x R2
– Distributed as c2
– Df = k (for second regression)
β€’
Use education and salbegin to predict
salary (employee data.sav)
–
R2 = 0.113, N=474, c2 = 53.5, df=5, p <
0.0001
β€’ Automatic in Stata
– estat imtest, white
385
60000
40000
0
20000
-20000
-40000
Residuals
Plot of Predicted and Residual
0
50000
100000
150000
Linear prediction
386
White’s Test as Test of
Interest
β€’ Possible to have a theory that predicts
heteroscedasticity
β€’ Lupien, et al, 2006
– Heteroscedasticity in relationship of
hippocampal volume and age
387
Magnitude of
Heteroscedasticity
β€’ Chop data into 5 β€œslices”
– Calculate variance of each slice
– Check ratio of smallest to largest
– Less than 5
β€’ OK
388
gen slice = 1
replace slice
replace slice
replace slice
replace slice
=
=
=
=
2
3
4
5
if
if
if
if
pred
pred
pred
pred
>
>
>
>
30000
60000
90000
120000
bysort slice: su pred
1: 3954
5: 17116
(Doesn’t look too bad, thanks to skew in
predictors)
389
Dealing with
Heteroscedasticity
β€’
Use Huber-White (robust) estimates
–
–
β€’
Also called sandwich estimates
Also called empirical estimates
Use survey techniques
–
–
Relatively straightforward in SAS and
Stata, fiddly in SPSS
Google: SPSS Huber-White
390
Why’s it a Sandwich?
β€’ SE can be calculated with:
ο€­1
n (X ' X )
ο€­1
β€’ Sandwich estimator:
ο€­1
ο€­1
ο€­1
ο€­1
( n X ' X ) ( n X ' X )( n X ' X )
ο€­1
391
Example
β€’ reg salary educ
– Standard errors:
– 204, 2821
β€’ reg salary educ , robust
– Standard errors:
– 267
– 3347
β€’ SEs usually go up, can go down
392
Heteroscedasticity –
Implications and Meanings
Implications
β€’ What happens as a result of
heteroscedasticity?
– Parameter estimates are correct
β€’ not biased
– Standard errors (hence p-values) are
incorrect
393
However …
β€’ If there is no skew in predicted scores
– P-values a tiny bit wrong
β€’ If skewed,
– P-values can be very wrong
β€’ Exercise 7.4
394
Robust SE Haiku
T-stat looks too good.
Use robust standard errors
significance gone
395
Meaning
β€’ What is heteroscedasticity trying to tell
us?
– Our model is wrong – it is misspecified
– Something important is happening that we
have not accounted for
β€’ e.g. amount of money given to charity
(given)
– depends on:
β€’ earnings
β€’ degree of importance person assigns to the
charity (import)
396
β€’ Do the regression analysis
– R2 = 0.60,, p < 0.001
β€’ seems quite good
– b0 = 0.24, p=0.97
– b1 = 0.71, p < 0.001
– b2 = 0.23, p = 0.031
β€’ White’s test
– c2 = 18.6, df=5, p=0.002
β€’ The plot of predicted values against
residuals …
397
20
10
0
-10
-20
30
40
50
Linear prediction
60
70
β€’ Plot shows heteroscedastic relationship
398
β€’ Which means …
– the effects of the variables are not additive
– If you think that what a charity does is
important
β€’ you might give more money
β€’ how much more depends on how much money
you have
399
70
60
50
40
30
20
5
10
import
given
Fitted values
15
given
Fitted values
400
β€’ One more thing about
heteroscedasticity
– it is the equivalent of homogeneity of
variance in ANOVA/t-tests
401
β€’ Exercise 7.4, 7.5, 7.6
402
Assumption 3: The Error Term
is Additive
403
Additivity
β€’ What heteroscedasticity shows you
– effects of variables need to be additive (assume
no interaction between the variables)
β€’ Heteroscedasticity doesn’t always show it to
you
– can test for it, but hard work
– (same as homogeneity of covariance assumption
in ANCOVA)
β€’ Have to know it from your theory
β€’ A specification error
404
Additivity and Theory
β€’ Two IVs
– Alcohol has sedative effect
β€’ A bit makes you a bit tired
β€’ A lot makes you very tired
– Some painkillers have sedative effect
β€’ A bit makes you a bit tired
β€’ A lot makes you very tired
– A bit of alcohol and a bit of painkiller
doesn’t make you very tired
– Effects multiply together, don’t add
together
405
β€’ If you don’t test for it
– It’s very hard to know that it will happen
β€’ So many possible non-additive effects
– Cannot test for all of them
– Can test for obvious
β€’ In medicine
– Choose to test for salient non-additive
effects
– e.g. sex, race
β€’ More on this, when we look at
moderators
406
β€’ Exercise 7.6
β€’ Exercise 7.7
407
Assumption 4: At every value of
the outcome the expected
(mean) value of the residuals
is zero
408
Linearity
β€’ Relationships between variables should be
linear
– best represented by a straight line
β€’ Not a very common problem in social
sciences
– measures are not sufficiently accurate (much measurement
error) to make a difference
β€’ R2 too low
β€’ unlike, say, physics
409
Fuel
β€’ Relationship between speed of travel
and fuel used
Speed
410
β€’ R2 = 0.938
– looks pretty good
– know speed, make a good prediction of
fuel
β€’ BUT
– look at the chart
– if we know speed we can make a perfect
prediction of fuel used
– R2 should be 1.00
411
Detecting Non-Linearity
β€’ Residual plot
– just like heteroscedasticity
β€’ Using this example
– very, very obvious
– usually pretty obvious
412
Residual plot
413
Linearity: A Case of Additivity
β€’ Linearity = additivity along the range of the
IV
β€’ Jeremy rides his bicycle harder
– Increase in speed depends on current speed
– Not additive, multiplicative
– MacCallum and Mar (1995). Distinguishing
between moderator and quadratic effects in
multiple regression. Psychological Bulletin.
414
Assumption 5: The expected
correlation between residuals, for
any two cases, is 0.
The independence assumption (lack of
autocorrelation)
415
Independence Assumption
β€’ Also: lack of autocorrelation
β€’ Tricky one
– often ignored
– exists for almost all tests
β€’ All cases should be independent of one
another
– knowing the value of one case should not tell you
anything about the value of other cases
416
How is it Detected?
β€’ Can be difficult
– need some clever statistics (multilevel
models)
β€’ Better off avoiding situations where it
arises
– Or handling it when it does arise
β€’ Residual Plots
417
Residual Plots
β€’ Were data collected in time order?
– If so plot ID number against the residuals
– Look for any pattern
β€’ Test for linear relationship
β€’ Non-linear relationship
β€’ Heteroscedasticity
418
2
Residual
1
0
-1
-2
0
10
20
30
40
Participant Number
419
How does it arise?
Two main ways
β€’ time-series analyses
– When cases are time periods
β€’ weather on Tuesday and weather on Wednesday
correlated
β€’ inflation 1972, inflation 1973 are correlated
β€’ clusters of cases
– patients treated by three doctors
– children from different classes
– people assessed in groups
420
Why does it matter?
β€’ Standard errors can be wrong
– therefore significance tests can be wrong
β€’ Parameter estimates can be wrong
– really, really wrong
– from positive to negative
β€’ An example
– students do an exam (on statistics)
– choose one of three questions
β€’ IV: time
β€’ outcome: grade
421
β€’Result, with line of best fit
90
80
70
60
50
40
Grade
30
20
10
10
Time
20
30
40
50
60
70
422
β€’ Result shows that
– people who spent longer in the exam,
achieve better grades
β€’ BUT …
– we haven’t considered which question
people answered
– we might have violated the independence
assumption
β€’ outcome will be autocorrelated
β€’ Look again
– with questions marked
423
β€’ Now somewhat different
90
80
70
60
50
40
Question
30
Grade
3
20
2
10
10
1
20
30
40
50
60
70
Time
424
β€’ Now, people that spent longer got
lower grades
– questions differed in difficulty
– do a hard one, get better grade
– if you can do it, you can do it quickly
425
Dealing with NonIndependence
β€’ For time series data
– Time series analysis (another course)
– Multilevel models (hard, some another
course)
β€’ For clustered data
– Robust standard errors
– Generalized estimating equations
– Multilevel models
426
Cluster Robust Standard
Errors
β€’ Predictor: School size
β€’ Outcome: Grades
β€’ Sample:
– 20 schools
– 20 children per school
β€’ What is the N?
427
Robust Standard Errors
β€’ Sample is:
– 400 children – is it 400?
– Not really
β€’ Each child adds information
β€’ First child in a school adds lots of information
about that school
– 100th child in a school adds less information’
– How much less depends on how similar the children
in the school are
– 20 schools
β€’ It’s more than 20
428
Robust SE in Stata
β€’ Very easy
β€’ reg predictor outcome ,
robust cluster(clusterid)
β€’ BUT
– Only to be used where clustering is a
nuisance only
β€’ Only adjusts standard errors, not parameter
estimates
β€’ Only to be used where parameter estimates
shouldn’t be affected by clustering
429
Example of Robust SE
β€’ Effects of incentives for attendance at
adult literacy class
– Some students rewarded for attendance
– Others not rewarded
β€’ 152 classes randomly assigned to each
condition
– Scores measured at mid term and final
430
Example of Robust SE
β€’ Naïve
– reg postscore tx midscore
– Est: -.6798066 SE: .7218797
β€’ Clustered
– reg postscore tx midscore,
robust cluster(classid)
– Est: -.6798066 SE .9329929
431
Problem with Robust
Estimates
β€’ Only corrects standard error
– Does not correct estimate
β€’ Other predictors must be uncorrelated
with predictors of group membership
– Or estimates wrong
β€’ Two alternatives:
– Generalized estimating equations (gee)
– Multilevel models
432
Independence +
Heteroscedasticity
β€’ Assumption is that residuals are:
– Independently and identically distributed
β€’ i.i.d.
β€’ Same procedure used for both problems
– Really, same problem
433
β€’ Exercise 7.9, exercise 7.10
434
Assumption 6: All predictor
variables are uncorrelated
with the error term.
435
Uncorrelated with the Error
Term
β€’ A curious assumption
– by definition, the residuals are uncorrelated
with the predictors (try it and see, if you
like)
β€’ There are no other predictors that are
important
– That correlate with the error
– i.e. Have an effect
436
β€’ Problem in economics
– Demand increases supply
– Supply increases wages
– Higher wages increase demand
β€’ OLS estimates will be (badly) biased in
this case
– need a different estimation procedure
– two-stage least squares
β€’ simultaneous equation modelling
– Instrumental variables
437
Another Haiku
Supply and demand:
without a good instrument,
not identified.
438
Assumption 7: No predictors are
a perfect linear function of
other predictors
no perfect multicollinearity
439
No Perfect Multicollinearity
β€’ IVs must not be linear functions of one
another
– matrix of correlations of IVs is not positive definite
– cannot be inverted
– analysis cannot proceed
β€’ Have seen this with
– age, age start, time working (can’t have all three
in the model)
– also occurs with subscale and total in model at the
same time
440
β€’ Large amounts of collinearity
– a problem (as we shall see) sometimes
– not an assumption
β€’ Exercise 7.11
441
Assumption 8: The mean of the
error term is zero.
You will like this one.
442
Mean of the Error Term = 0
β€’ Mean of the residuals = 0
β€’ That is what the constant is for
– if the mean of the error term deviates from
zero, the constant soaks it up
Y ο€½  0  1 x1  ο₯
Y ο€½ (  0  3)  1 x1  (ο₯ ο€­ 3)
- note, Greek letters because we are
talking about population values
443
β€’ Can do regression without the constant
– Usually a bad idea
– E.g R2 = 0.995, p < 0.001
β€’ Looks good
444
13
12
y
11
10
9
8
7
6
7
8
9
10
11
12
13
x1
445
Lesson 8: Issues in
Regression Analysis
Things that alter the
interpretation of the regression
equation
446
The Four Issues
β€’
β€’
β€’
β€’
Causality
Sample sizes
Collinearity
Measurement error
447
Causality
448
What is a Cause?
β€’ Debate about definition of cause
– some statistics (and philosophy) books try
to avoid it completely
– We are not going into depth
β€’ just going to show why it is hard
β€’ Two dimensions of cause
– Ultimate versus proximal cause
– Determinate versus probabilistic
449
Proximal versus Ultimate
β€’ Why am I here?
– I walked here because
– This is the location of the class because
– Eric Tanenbaum asked me because
– (I don’t know)
– because I was in my office when he rang
because
– I was a lecturer at Derby University
because
– I saw an advert in the paper because
450
– I exist because
– My parents met because
– My father had a job …
β€’ Proximal cause
– the direct and immediate cause of
something
β€’ Ultimate cause
– the thing that started the process off
– I fell off my bicycle because of the bump
– I fell off because I was going too fast
451
Determinate versus Probabilistic
Cause
β€’ Why did I fall off my bicycle?
– I was going too fast
– But every time I ride too fast, I don’t fall
off
– Probabilistic cause
β€’ Why did my tyre go flat?
– A nail was stuck in my tyre
– Every time a nail sticks in my tyre, the tyre
goes flat
– Deterministic cause
452
β€’ Can get into trouble by mixing them
together
– Eating deep fried Mars Bars and doing no
exercise are causes of heart disease
– β€œMy Grandad ate three deep fried Mars
Bars every day, and the most exercise he
ever got was when he walked to the shop
next door to buy one”
– (Deliberately?) confusing deterministic and
probabilistic causes
453
Criteria for Causation
β€’ Association (correlation)
β€’ Direction of Influence (a οƒ  b)
β€’ Isolation (not c οƒ  a and c οƒ  b)
454
Association
β€’ Correlation does not mean causation
– we all know
β€’ But
– Causation does mean correlation
β€’ Need to show that two things are related
– may be correlation
– may be regression when controlling for third (or
more) factor
455
β€’ Relationship between price and sales
– suppliers may be cunning
– when people want it more
β€’ stick the price up
Price
Price
Demand
Sales
1
0.6
0
Demand
0.6
1
0.6
Sales
0
0.6
1
– So – no relationship between price
and sales
456
– Until (or course) we control for demand
– b1 (Price) = -0.56
– b2 (Demand) = 0.94
β€’ But which variables do we enter?
457
Direction of Influence
β€’ Relationship between A and B
– three possible processes
A
B
A
B
B causes A
A
B
C causes A & B
C
A causes B
458
β€’ How do we establish the direction of
influence?
– Longitudinally?
Barometer
Drops
Storm
– Now if we could just get that barometer
needle to stay where it is …
β€’ Where the role of theory comes in
(more on this later)
459
Isolation
β€’ Isolate the outcome from all other
influences
– as experimenters try to do
β€’ Cannot do this
– can statistically isolate the effect
– using multiple regression
460
Role of Theory
β€’ Strong theory is crucial to making
causal statements
β€’ Fisher said: to make causal statements
β€œmake your theories elaborate.”
– don’t rely purely on statistical analysis
β€’ Need strong theory to guide analyses
– what critics of non-experimental research
don’t understand
461
β€’ S.J. Gould – a critic
– says correlate price of petrol and his age,
for the last 10 years
– find a correlation
– Ha! (He says) that doesn’t mean there is a
causal link
– Of course not! (We say).
β€’ No social scientist would do that analysis
without first thinking (very hard) about the
possible causal relations between the variables
of interest
β€’ Would control for time, prices, etc …
462
β€’ Atkinson, et al. (1996)
– relationship between college grades and
number of hours worked
– negative correlation
– Need to control for other variables –
ability, intelligence
β€’ Gould says β€œMost correlations are noncausal” (1982, p243)
– Of course!!!!
463
I drink a lot of
beer
16 causal
relations
120 non-causal
correlations
laugh
bathroom
jokes (about statistics)
children wake early
karaoke
curtains closed
sleeping
headache
equations (beermat)
thirsty
fried breakfast
no beer
curry
chips
falling over
lose keys
464
β€’ Abelson (1995) elaborates on this
– β€˜method of signatures’
β€’ A collection of correlations relating to
the process
– the β€˜signature’ of the process
β€’ e.g. tobacco smoking and lung cancer
– can we account for all of these findings
with any other theory?
465
1.
2.
3.
4.
5.
6.
7.
8.
The longer a person has smoked cigarettes, the
greater the risk of cancer.
The more cigarettes a person smokes over a given
time period, the greater the risk of cancer.
People who stop smoking have lower cancer rates
than do those who keep smoking.
Smoker’s cancers tend to occur in the lungs, and be of
a particular type.
Smokers have elevated rates of other diseases.
People who smoke cigars or pipes, and do not usually
inhale, have abnormally high rates of lip cancer.
Smokers of filter-tipped cigarettes have lower cancer
rates than other cigarette smokers.
Non-smokers who live with smokers have elevated
cancer rates.
(Abelson, 1995: 183-184)
466
– In addition, should be no anomalous
correlations
β€’ If smokers had more fallen arches than nonsmokers, not consistent with theory
β€’ Failure to use theory to select
appropriate variables
– specification error
– e.g. in previous example
– Predict wealth from price and sales
β€’ increase price, price increases
β€’ Increase sales, price increases
467
β€’ Sometimes these are indicators of the
process, not the process itself
– e.g. barometer – stopping the needle won’t
help
– e.g. inflation? Indicator or cause of
economic health?
468
No Causation without
Experimentation
β€’ Blatantly untrue
– I don’t doubt that the sun shining makes
us warm
β€’ Why the aversion?
– Pearl (2000) says problem is that there is
no mathematical operator (e.g. β€œ=β€œ)
– No one realised that you needed one
– Until you build a robot
469
AI and Causality
β€’ A robot needs to make judgements
about causality
β€’ Needs to have a mathematical
representation of causality
– Suddenly, a problem!
– Doesn’t exist
β€’ Most operators are non-directional
β€’ Causality is directional
470
Sample Sizes
β€œHow many subjects does it take
to run a regression analysis?”
471
Introduction
β€’ Social scientists don’t worry enough about the
sample size required
– β€œWhy didn’t you get a significant result?”
– β€œI didn’t have a large enough sample”
β€’ Not a common answer, but very common reason
β€’ More recently awareness of sample size is
increasing
– use too few – no point doing the research
– use too many – waste their time
472
β€’ Research funding bodies
β€’ Ethical review panels
– both become more interested in sample
size calculations
β€’ We will look at two approaches
– Rules of thumb (quite quickly)
– Power Analysis (more slowly)
473
Rules of Thumb
β€’ Lots of simple rules of thumb exist
– 10 cases per IV
– and at least 100 cases
– Green (1991) more sophisticated
β€’ To test significance of R2 – N = 50 + 8k
β€’ To test significance of slopes, N = 104 + k
β€’ Rules of thumb don’t take into account
all the information that we have
– Power analysis does
474
Power Analysis
Introducing Power Analysis
β€’ Hypothesis test
– tells us the probability of a result of that
magnitude occurring, if the null hypothesis is
correct (i.e. there is no effect in the population)
β€’ Doesn’t tell us
– the probability of that result, if the null hypothesis
is false (i.e., there actually is an effect in the
population)
475
β€’ According to Cohen (1982) all null
hypotheses are false
– everything that might have an effect, does
have an effect
β€’ it is just that the effect is often very tiny
476
Type I Errors
β€’ Type I error is false rejection of H0
β€’ Probability of making a type I error
– a – the significance value cut-off
β€’ usually 0.05 (by convention)
β€’ Always this value
β€’ Not affected by
– sample size
– type of test
477
Type II errors
β€’ Type II error is false acceptance of the
null hypothesis
– Much, much trickier
β€’ We think we have some idea
– we almost certainly don’t
β€’ Example
– I do an experiment (random sampling, all
assumptions perfectly satisfied)
– I find p = 0.05
478
– You repeat the experiment exactly
β€’ different random sample from same population
– What is probability you will find p < 0.05?
– Answer: 0.5
– Another experiment, I find p = 0.01
– Probability you find p < 0.05?
– Answer: 0.79
β€’ Very hard to work out
– not intuitive
– need to understand non-central sampling
distributions (more in a minute)
479
β€’ Probability of type II error = beta ()
– same as population regression parameter
(to be confusing)
β€’ Power = 1 – Beta
– Probability of getting a significant result
(given that there is a significant result to
be found)
480
State of the World
Research
Findings
H0 True
(no effect to
be found)
H0 false
(effect to be
found)
H0 true (we find
no effect – p >
0.05)
οƒΌ
Type II error
p=
power = 1 - 
H0 false (we find
an effect – p <
0.05)
Type I error
p=a
οƒΌ
481
β€’ Four parameters in power analysis
– a – prob. of Type I error
–  – prob. of Type II error (power = 1 – )
– Effect size – size of effect in population
–N
β€’ Know any three, can calculate the
fourth
– Look at them one at a time
482
β€’
a Probability of Type I error
– Usually set to 0.05
– Somewhat arbitrary
β€’ sometimes adjusted because of circumstances
– rarely because of power analysis
– May want to adjust it, based on power
analysis
483
β€’  – Probability of type II error
– Power (probability of finding a result)
=1–
– Standard is 80%
β€’ Some argue for 90%
– Implication that Type I error is 4 times
more serious than type II error
β€’ adjust ratio with compromise power analysis
484
β€’
Effect size in the population
– Most problematic to determine
– Three ways
1. What effect size would be useful to find?
β€’
R2 = 0.01 - no use (probably)
2. Base it on previous research
– what have other people found?
3. Use Cohen’s conventions
– small R2 = 0.02
– medium R2 = 0.13
– large R2 = 0.26
485
– Effect size usually measured as f2
– For R2
2
R
f ο€½
2
1ο€­ R
2
486
– For (standardised) slopes
2
sri
f ο€½
2
1ο€­ R
2
– Where sr2 is the contribution to the
variance accounted for by the variable of
interest
– i.e. sr2 = R2 (with variable) – R2 (without)
β€’ change in R2 in hierarchical regression
487
β€’ N – the sample size
– usually use other three parameters to
determine this
– sometimes adjust other parameters (a)
based on this
– e.g. You can have 50 participants. No
more.
488
Doing power analysis
β€’ With power analysis program
– SamplePower, Gpower (free), Nquery
– With Stata command sampsi
β€’ Which I find very confusing
β€’ But we’ll use it anyway
489
sampsi
β€’ Limited in usefulness
– A categorical, two group predictor
β€’ sampsi 0 0.5, pre(1) r01(0.5)
n1(50) sd(1)
– Find power for detecting an effect of 0.5
β€’ When there’s one other variable at baseline
β€’ Which correlates 0.5
β€’ 50 people in each group
β€’ When sd is 1.0
490
sampsi …
Method: ANCOVA
relative efficiency =
adjustment to sd =
adjusted sd1 =
1.143
0.935
0.935
Estimated power:
power =
0.762
491
GPower
β€’ Better for regression designs
492
Underpowered Studies
β€’ Research in the social sciences is often
underpowered
– Why?
– See Paper B11 – β€œthe persistence of
underpowered studies”
495
Extra Reading
β€’ Power traditionally focuses on p values
– What about CIs?
– Paper B8 – β€œObtaining regression
coefficients that are accurate, not simply
significant”
496
β€’ Exercise 8.1
497
Collinearity
498
Collinearity as Issue and
Assumption
β€’ Collinearity (multicollinearity)
– the extent to which the predictors are
(multiply) correlated
β€’ If R2 for any IV, using other IVs = 1.00
– perfect collinearity
– variable is linear sum of other variables
– regression will not proceed
– (SPSS will arbitrarily throw out a variable)
499
β€’ R2 < 1.00, but high
– other problems may arise
β€’ Four things to look at in collinearity
– meaning
– implications
– detection
– actions
500
Meaning of Collinearity
β€’ Literally β€˜co-linearity’
– lying along the same line
β€’ Perfect collinearity
– when some IVs predict another
– Total = S1 + S2 + S3 + S4
– S1 = Total – (S2 + S3 + S4)
– rare
501
β€’ Less than perfect
– when some IVs are close to predicting
other IVs
– correlations between IVs are high (usually,
but not always) οƒ  high multiple
correlations
502
Implications
β€’ Effects the stability of the parameter
estimates
– and so the standard errors of the
parameter estimates
– and so the significance and CIs
β€’ Because
– shared variance, which the regression
procedure doesn’t know where to put
503
β€’ Sex differences
– due to genetics?
– due to upbringing?
– (almost) perfect collinearity
β€’ statistically impossible to tell
504
β€’ When collinearity is less than perfect
– increases variability of estimates between
samples
– estimates are unstable
– reflected in the variances, and hence
standard errors
505
Detecting Collinearity
β€’ Look at the parameter estimates
– large standardised parameter estimates
(>0.3?), which are not significant
β€’ be suspicious
β€’ Run a series of regressions
– each IV as outcome
– all other IVs as IVs
β€’ for each IV
506
β€’ Sounds like hard work?
– SPSS does it for us!
β€’ Ask for collinearity diagnostics
– Tolerance – calculated for every IV
Tolerance ο€½ 1-R
2
– Variance Inflation Factor
β€’ sq. root of amount s.e. has been increased
1
VIF ο€½
Tolerance
507
Actions
What you can do about collinearity
β€œno quick fix” (Fox, 1991)
1. Get new data
β€’
β€’
β€’
avoids the problem
address the question in a different way
e.g. find people who have been raised as
the β€˜wrong’ gender
β€’
β€’
exist, but rare
Not a very useful suggestion
508
2. Collect more data
β€’
β€’
β€’
not different data, more data
collinearity increases standard error (se)
se decreases as N increases
β€’
get a bigger N
3. Remove / Combine variables
β€’
β€’
β€’
If an IV correlates highly with other IVs
Not telling us much new
If you have two (or more) IVs which are
very similar
β€’
e.g. 2 measures of depression, socioeconomic status, achievement, etc
509
β€’
β€’
sum them, average them, remove one
Many measures
β€’
use principal components analysis to reduce
them
3. Use stepwise regression (or some
flavour of)
β€’
β€’
See previous comments
Can be useful in theoretical vacuum
4. Ridge regression
β€’
β€’
not very useful
behaves weirdly
510
β€’ Exercise 8.2, 8.3, 8.4
511
Measurement Error
512
What is Measurement Error
β€’ In social science, it is unlikely that we
measure any variable perfectly
– measurement error represents this
imperfection
β€’ We assume that we have a true score
– T
β€’ A measure of that score
–x
513
xο€½T e
β€’ just like a regression equation
– standardise the parameters
– T is the reliability
β€’ the amount of variance in x which comes from T
β€’ but, like a regression equation
– assume that e is random and has mean of zero
– more on that later
514
Simple Effects of
Measurement Error
β€’ Lowers the measured correlation
– between two variables
β€’ Real correlation
– true scores (x* and y*)
β€’ Measured correlation
– measured scores (x and y)
515
True correlation
of x and y
rx*y*
x*
e
y*
Reliability of x
rxx
Reliability of y
ryy
x
y
Measured
correlation of x and y
rxy
e
516
β€’ Attenuation of correlation
rxy ο€½ rx * y * ο‚΄ rxx ryy
β€’ Attenuation corrected correlation
rx * y * ο€½
rxy
rxx ryy
517
β€’ Example
rxx ο€½ 0.7
ryy ο€½ 0.8
rxy ο€½ 0.3
rx* y* ο€½
rx* y*
rxy
rxx ryy
0.3
ο€½
ο€½ 0.40
0.7 ο‚΄ 0.8
518
Complex Effects of
Measurement Error
β€’ Really horribly complex
β€’ Measurement error reduces correlations
– reduces estimate of 
– reducing one estimate
β€’ increases others
– because of effects of control
– combined with effects of suppressor
variables
– exercise to examine this
519
Dealing with Measurement
Error
β€’ Attenuation correction
– very dangerous
– not recommended
β€’ Avoid in the first place
– use reliable measures
– don’t discard information
β€’ don’t categorise
β€’ Age: 10-20, 21-30, 31-40 …
520
Complications
β€’ Assume measurement error is
– additive
– linear
β€’ Additive
– e.g. weight – people may under-report / overreport at the extremes
β€’ Linear
– particularly the case when using proxy variables
521
β€’ e.g. proxy measures
– Want to know effort on childcare, count
number of children
β€’ 1st child is more effort than 19th child
– Want to know financial status, count
income
β€’ 1st £1 much greater effect on financial status
than the 1,000,000th.
522
β€’ Exercise 8.5
523
Lesson 9: Non-Linear Analysis
in Regression
524
Introduction
β€’ Non-linear effect occurs
– when the effect of one predictor
– is not consistent across the range of the IV
β€’ Assumption is violated
– expected value of residuals = 0
– no longer the case
525
Some Examples
526
Skill
A Learning Curve
Experience
527
Performance
Yerkes-Dodson Law of Arousal
Arousal
528
Suicidal
Enthusiastic
Enthusiasm Levels over a
Lesson on Regression
0
Time
3.5
529
β€’ Learning
– line changed direction once
β€’ Yerkes-Dodson
– line changed direction once
β€’ Enthusiasm
– line changed direction twice
530
Everything is Non-Linear
β€’ Every relationship we look at is nonlinear, for two reasons
– Exam results cannot keep increasing with
reading more books
β€’ Linear in the range we examine
– For small departures from linearity
β€’ Cannot detect the difference
β€’ Non-parsimonious solution
531
Non-Linear Transformations
532
Bending the Line
β€’ Non-linear regression is hard
– We cheat, and linearise the data
β€’ Do linear regression
Transformations
β€’ We need to transform the data
– rather than estimating a curved line
β€’ which would be very difficult
β€’ may not work with OLS
– we can take a straight line, and bend it
– or take a curved line, and straighten it
β€’ back to linear (OLS) regression
533
β€’ We still do linear regression
– Linear in the parameters
– Y = b1x + b2x2 + …
β€’ Can do non-linear regression
– Non-linear in the parameters
– Y = b1x + b2x2 + …
β€’ Much trickier
– Statistical theory either breaks down OR
becomes harder
534
β€’ Linear transformations
– multiply by a constant
– add a constant
– change the slope and the intercept
535
y=2x
y
y=x + 3
y=x
x
536
β€’ Linear transformations are no use
– alter the slope and intercept
– don’t alter the standardised parameter
estimate
β€’ Non-linear transformation
– will bend the slope
– quadratic transformation
y = x2
– one change of direction
537
– Cubic transformation
y = x2 + x3
– two changes of direction
538
β€’ To estimate a non-linear regression
– we don’t actually estimate anything nonlinear
– we transform the x-variable to a non-linear
version
– can estimate that straight line
– represents the curve
– we don’t bend the line, we stretch the
space around the line, and make it flat
539
Detecting Non-linearity
540
Draw a Scatterplot
β€’ Draw a scatterplot of y plotted against x
– see if it looks a bit non-linear
– e.g. Education and beginning salary
β€’ from bank data
β€’ with line of best fit
541
A Real Example
β€’ Starting salary and years of education
– From employee data.sav
542
80000
0
20000
40000
60000
Expected value
of error
(residual) is > 0
5
10
Expected 20
value
of error
beginning salary
(residual) is < 0
15
educational level (years)
Fitted values
543
Use Residual Plot
β€’ Scatterplot is only good for one variable
– use the residual plot (that we used for
heteroscedasticity)
β€’ Good for many variables
544
β€’ We want
– points to lie in a nice straight sausage
545
β€’ We don’t want
– a nasty bent sausage
546
-20000
0
20000
40000
60000
β€’ Educational level and starting salary
5000
10000
15000
20000
Linear prediction
Fitted values
25000
30000
Residuals
547
Carrying Out Non-Linear
Regression
548
Linear Transformation
β€’ Linear transformation doesn’t change
– interpretation of slope
– standardised slope
– se, t, or p of slope
– R2
β€’ Can change
– effect of a transformation
549
β€’ Actually more complex
– with some transformations can add a
constant with no effect (e.g. quadratic)
β€’ With others does have an effect
– inverse, log
β€’ Sometimes it is necessary to add a
constant
– negative numbers have no square root
– 0 has no log
550
Education and Salary
Linear Regression
β€’ Saw previously that the assumption of
expected errors = 0 was violated
β€’ Anyway …
– R2 = 0.401, p < 0.001
– salbegin = -6290 + 1727 ο‚΄ educ
– Standardised
β€’ b1 (educ) = 0.633
– Both parameters make sense
551
Non-linear Effect
β€’ Compute new variable
– quadratic
– educ2 = educ2
β€’ Add this variable to the equation
– R2 = 0.585, p < 0.001
– salbegin = 46263 + -6542 ο‚΄ educ + 310 ο‚΄ educ2
β€’ slightly curious
– Standardised
β€’ b1 (educ) = -2.4
β€’ b2 (educ2) = 3.1
– What is going on?
552
β€’ Collinearity
– is what is going on
– Correlation of educ and educ2
β€’ r = 0.990
– Regression equation becomes difficult
(impossible?) to interpret
β€’ Need hierarchical regression
– what is the change in R2
– is that change significant?
– R2 (change) = 0.184, p < 0.001
553
Cubic Effect
β€’ While we are at it, let’s look at the cubic
effect
– R2 (change) = 0.004, p = 0.045
– 19138 + 103 ο‚΄ e + -206 ο‚΄ e2 + 12 ο‚΄ e3
– Standardised:
b1(e) = 0.04
b2(e2) = -2.04
b3(e3) = 2.71
554
Fourth Power
β€’ Keep going while we are ahead?
– When do we stop?
555
Interpretation
β€’ Tricky, given that parameter estimates
are a bit nonsensical
β€’ Two methods
β€’ 1: Use R2 change
– Save predicted values
β€’ or calculate predicted values to plot line of best
fit
– Save them from equation
– Plot against IV
556
80000
60000
40000
0
20000
5
10
15
educational level (years)
Linear prediction
Linear prediction
Linear prediction
20
Linear prediction
Linear prediction
beginning salary
557
β€’ Differentiate with respect to e
β€’ We said:
s = 19138 + 103 ο‚΄ e + -206 ο‚΄ e2 + 12 ο‚΄ e3
– but first we will simplify it to quadratic
s = 46263 + -6542 ο‚΄ e + 310 ο‚΄ e2
β€’ dy/dx = -6542 + 310 x 2 x e
558
Education Slope
9
-962
10
-342
11
278
12
898
13
1518
14
2138
15
2758
16
3378
17
3998
18
4618
19
5238
20
5858
1 year of education
at the higher end of
the scale, better than
1 year at the lower
end of the scale.
MBA versus GCSE
559
β€’ Differentiate Cubic
19138 + 103 ο‚΄ e + -206 ο‚΄ e2 + 12 ο‚΄ e3
dy/dx = 103 – 206 ο‚΄ 2 ο‚΄ e + 12 ο‚΄ 3 ο‚΄ e2
β€’ Can calculate slopes for quadratic and
cubic at different values
560
Education Slope (Quad) Slope (Cub)
9
-962
-689
10
-342
-417
11
278
-73
12
898
343
13
1518
831
14
2138
1391
15
2758
2023
16
3378
2727
17
3998
3503
18
4618
4351
19
5238
5271
20
5858
6263
561
A Quick Note on
Differentiation
β€’ For y = xp
– dx/dy = pxp-1
β€’ For equations such as
y =b1x + b2xP
dy/dx = b1 + b2pxp-1
β€’ y = 3x + 4x2
– dy/dx = 3 + 4 β€’ 2x
562
β€’ y = b1x + b2x2 + b3x3
– dy/dx = b1 + b2 β€’ 2x + b3 β€’ 3 β€’ x2
β€’ y = 4x + 5x2 + 6x3
β€’ dx/dy = 4 + 5 β€’ 2 β€’ x + 6 β€’ 3 β€’ x2
β€’ Many functions are simple to
differentiate
– Not all though
563
Splines and Knots
β€’ Estimate a different slope following an
event
– Lines are splines
– Events are knots
β€’ Event might be known
– Marriage
β€’ Might be unknown
– How many years after brain injury does
recovery start
564
Lesson 10: Regression for
Counts and Categories
Dichotomous/Nominal outcomes
565
Contents
β€’ General and Generalized Linear Models
β€’ Dichotomous – logistic / probit
β€’ Counts – Poisson and negative binomial
566
GLMs and GLMs
β€’ General linear models
– Ordinary least squares regression based
models
– Identity link function
– Regression, ANOVA, correlation, etc
β€’ Generalized linear models
– More links
– More error structures
– General linear models are a subset of
generalized linear models
567
Dichotomous
β€’ Often in social sciences, we have a
dichotomous/nominal outcome
– we will look at dichotomous first, then a quick look
at multinomial
β€’ Dichotomous outcome
β€’ e.g.
–
–
–
–
guilty/not guilty
pass/fail
won/lost
Alive/dead (used in medicine)
568
Why Won’t OLS Do?
569
Example: PTSD in Veterans
β€’ How does length of deployment affect
probability of PTSD?
– Have PTSD, or don’t.
– We might be interested in severity
β€’ Army are not
β€’ If you have PTSD, you need help
– Not going back
β€’ Develop a selection procedure
– Two predictor variables
– Rank – 1 =Staff Sgt, 5 = Private,
– Deployment length (months)
570
β€’ 1st ten cases
Rank
5
1
1
4
1
1
4
1
3
4
Months
6
15
12
6
15
6
16
10
12
26
PTSD
0
0
0
0
1
0
1
1
0
1
571
β€’ outcome
– PTSD (1 = Yes, 0 = No)
β€’ Just consider score first
– Carry out regression
– Rank as predictor, PTSD as outcome
– R2 = 0.097, F = 4.1, df = 1, 48, p = 0.028.
– b0 = 0.190
– b1 = 0.110, p=0.028
β€’ Seems OK
572
β€’ Residual plot
573
β€’ Problems 1 and 2
– strange distributions of residuals
– parameter estimates may be wrong
– standard errors will certainly be wrong
574
β€’ 2nd problem – interpretation
– I have rank 2
– Pass = 0.190 + 0.110 ο‚΄ 2 = 0.41
– I have rank 8
– Pass = 0.190 + 0.110 ο‚΄ 8 = 1.07
β€’ Seems OK, but
– What does it mean?
– Cannot score 0.41 or 1.07
β€’ can only score 0 or 1
β€’ Cannot be interpreted
– need a different approach
575
A Different Approach
Logistic Regression
576
Logit Transformation
β€’ In lesson 9, transformed IVs
– now transform the outcome
β€’ Need a transformation which gives us
– graduated scores (between 0 and 1)
– No upper limit
β€’ we can’t predict someone will pass twice
– No lower limit
β€’ you can’t do worse than fail
577
Step 1: Convert to Probability
β€’ First, stop talking about values
– talk about probability
– for each value of score, calculate
probability of pass
β€’ Solves the problem of graduated scales
578
probability of
PTSD given a rank
of 1 is 0.7
Score 1 2 3 4 5
No
N
7 5 6 4 2
PTSD P
0.7 0.5 0.6 0.4 0.2
N
3 5 4 6 8
PTSD
P
0.3 0.5 0.4 0.6 0.8
probability of
PTSD given a rank
of 5 is 0.2
579
This is better
β€’ Now a score of 0.41 has a meaning
– a 0.41 probability of pass
β€’ But a score of 1.07 has no meaning
– cannot have a probability > 1 (or < 0)
– Need another transformation
580
Step 2: Convert to Odds-Ratio
Need to remove upper limit
β€’ Convert to odds
β€’ Odds, as used by betting shops
– 5:1, 1:2
β€’ Slightly different from odds in speech
– a 1 in 2 chance
– odds are 1:1 (evens)
– 50%
581
β€’ Odds ratio = (number of times it
happened) / (number of times it didn’t
happen)
p(event)
p(event )
odds ratio ο€½
ο€½
p(not event ) 1 ο€­ p(event )
582
β€’ 0.8 = 0.8/0.2 = 4
– equivalent to 4:1 (odds on)
– 4 times out of five
β€’ 0.2 = 0.2/0.8 = 0.25
– equivalent to 1:4 (4:1 against)
– 1 time out of five
583
β€’ Now we have solved the upper bound
problem
– we can interpret 1.07, 2.07, 1000000.07
β€’ But we still have the zero problem
– we cannot interpret predicted scores less
than zero
584
Step 3: The Log
β€’ Log10 of a number(x)
log( x )
10
ο€½x
β€’ log(10) = 1
β€’ log(100) = 2
β€’ log(1000) = 3
585
β€’ log(1) = 0
β€’ log(0.1) = -1
β€’ log(0.00001) = -5
586
Natural Logs and e
β€’ Don’t use log10
– Use loge
β€’ Natural log, ln
β€’ Has some desirable properties, that log10
doesn’t
–
–
–
–
For us
If y = ln(x) + c
dy/dx = 1/x
Not true for any other logarithm
587
β€’ Be careful – calculators and stats
packages are not consistent when they
use log
– Sometimes log10, sometimes loge
588
Take the natural log of the odds ratio
β€’ Goes from -ο‚₯ οƒž +ο‚₯
– can interpret any predicted value
589
Putting them all together
β€’ Logit transformation
– log-odds ratio
– not bounded at zero or one
590
Score 1
No PTSD
PTSD
N
P
N
P
Odds (No PTSD)
log(odds)No PTSD
2
3
4
7
5
6
4
0.7 0.5 0.6 0.4
3
5
4
6
0.3 0.5 0.4 0.6
5
2
0.2
8
0.8
2.33 1.00 1.50 0.67 0.25
0.85 0.00 0.41 -0.41 -1.39
591
probability
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
Probability gets closer
to zero, but never
reaches it as logit
goes down.
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5
3
Logit
592
3.5
β€’ Hooray! Problem solved, lesson over
– errrmmm… almost
β€’ Because we are now using log-odds
ratio, we can’t use OLS
– we need a new technique, called Maximum
Likelihood (ML) to estimate the parameters
593
Parameter Estimation using
ML
ML tries to find estimates of model
parameters that are most likely to give
rise to the pattern of observations in
the sample data
β€’ All gets a bit complicated
– OLS is a special case of ML
– the mean is an ML estimator
594
β€’ Don’t have closed form equations
– must be solved iteratively
– estimates parameters that are most likely
to give rise to the patterns observed in the
data
– by maximising the likelihood function (LF)
β€’ We aren’t going to worry about this
– except to note that sometimes, the
estimates do not converge
β€’ ML cannot find a solution
595
R2 in Logistic Regression
β€’ A dichotomous variable doesn’t have
variance
– If you know the mean (proportion) you
know the variance
– You can’t have R2.
β€’ There are several pseudo-R2
β€’ None are perfect
– There’s something better
596
Logistic Regression in Stata
β€’ Exercise 10.1
β€’ Two (almost) equivalent commands
– logistic ptsd rank deployment
– logit ptsd rank deployment
597
Logit
β€’ Gives output in log-odds
β€’ logit ptsd rank deployment
-----------------------------------------------------------------------------pass | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------deployment |
1.158213
.0841987
2.02
0.043
1.004404
1.335575
rank |
1.333192
.4011279
0.96
0.339
.7392395
2.404365
------------------------------------------------------------------------------
598
Logistic
β€’ Gives output in odds ratios
β€’
– No intercept
logit ptsd rank deployment
-----------------------------------------------------------------------------pass | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------deployment |
1.158213
.0841987
2.02
0.043
1.004404
1.335575
rank |
1.333192
.4011279
0.96
0.339
.7392395
2.404365
------------------------------------------------------------------------------
599
β€’ SPSS produces a classification table
– And Stata produces it if you ask
– predictions of model
– based on cut-off of 0.5 (by default)
– predicted values x actual values
β€’ DO NOT USE IT!
β€’ Will this person go to prison?
– No.
– You will be right 99.9% of the time
– Doesn’t mean you have a good model
– (Gottman and Murray – Blink)
600
Classification Tablea
Predicted
PASS
Observed
Step 1
PASS
0
Percentage
Correct
1
0
18
8
69.2
1
12
12
50.0
Overall Percentage
60.0
a. The cut value is .500
601
Model parameters
β€’B
– Change in the logged odds associated with
a change of 1 unit in IV
– just like OLS regression
– difficult to interpret
β€’ SE (B)
– Standard error
– Multiply by 1.96 to get 95% CIs
602
β€’ Constant
– i.e. score = 0
– B = 1.314
– Exp(B) = eB = e1.314 = 3.720
– OR = 3.720, p = 1 – (1 / (OR + 1))
= 1 – (1 / (3.720 + 1))
– p = 0.788
603
β€’ Score 1
– Constant b = 1.314
– Score B = -0.467
– Exp(1.314 – 0.467) = Exp(0.847)
= 2.332
– OR = 2.332
– p = 1 – (1 / (2.332 + 1))
= 0.699
604
Standard Errors and CIs
β€’ Symmetrical in B
– Non-symmetrical (sometimes very) in
exp(B)
605
β€’ The odds of failing the test are
multiplied by 0.63 (CIs = 0.408, 0.962
p = 0.033), for every additional point
on the aptitude test.
606
Hierarchical Logistic
Regression
β€’ In OLS regression
– Use R2 change
β€’ In logistic regression
– Use chi-square change
β€’ Difference in chi-square = chi-square
β€’ Difference in df = df
607
Hierarchical Logistic
Regression
β€’ Model 1: Experience
β€’ Model 2: Experience + Score
β€’ Model 1:
– Chi-square =4.83, df = 1
β€’ Model 2:
– Chi-square =5.77, df = 2
608
β€’ Difference:
– Chi-square = 5.77-4.83= 1.94,
– Df = 2 – 1 = 1
β€’ gen p = 1 - chi2(1, 1.94)
β€’ tab p
β€’ p = 0.332
β€’ P-value from SE = 0.339
β€’ Why?
609
More on Standard Errors
β€’ Because of Wald standard errors
– Wald SEs are overestimated
– Make p-value in estimates is wrong – too high
– (CIs still correct)
610
β€’ Two estimates use slightly different
information
– P-value says β€œwhat if no effect”
– CI says β€œwhat if there is this effect”
β€’ Variance depends on the hypothesised ratio of the
number of people in the two groups
β€’ Can calculate likelihood ratio based pvalues
– If you can be bothered
– Some packages provide them automatically
611
Probit Regression
β€’ Very similar to logistic
– much more complex initial transformation
(to normal distribution)
– Very similar results to logistic (multiplied by
1.7)
β€’ Swap logistic for probit in Stata
command
– Harder to interpret
β€’ Parameter doesn’t mean something – like log
odds
612
Differentiating Between Probit
and Logistic
β€’ Depends on shape of the error term
– Normal or logistic
– Graphs are very similar to each other
β€’ Could distinguish quality of fit
– Given enormous sample size
β€’ Logistic = probit x 1.7
– Actually 1.6998
β€’ Probit advantage
– Understand the distribution
β€’ Logistic advantage
– Much simpler to get back to the probability
613
3
2.8
2.6
2.4
2.2
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
1
-1
-1.2
-1.4
-1.6
-1.8
-2
-2.2
-2.4
-2.6
-2.8
-3
1.2
Normal (Probit)
Logistic
0.8
0.6
0.4
0.2
0
614
Infinite Parameters
β€’ Non-convergence can happen because
of infinite parameters
– Insoluble model
β€’ Three kinds:
β€’ Complete separation
– The groups are completely distinct
β€’ Pass group all score more than 10
β€’ Fail group all score less than 10
615
β€’ Quasi-complete separation
– Separation with some overlap
β€’ Pass group all score 10 or more
β€’ Fail group all score 10 or less
β€’ Both cases:
– No convergence
β€’ Close to this
– Curious estimates
– Curious standard errors
616
β€’ Categorical Predictors
– Can cause separation
– Especially if correlated
β€’ Need people in every cell
Male
White
Non-White
Female
White
Non-White
Below
Poverty
Line
Above
Poverty
Line
617
Logistic Regression and
Diagnosis
β€’ Logistic regression can be used for diagnostic
tests
– For every score
β€’ Calculate probability that result is positive
β€’ Calculate proportion of people with that score (or lower)
who have a positive result
β€’ Calculate c statistic
– Measure of discriminative power
– % of all possible cases, where the model gives a
higher probability to a correct case than to an
incorrect case
618
– Perfect c-statistic = 1.0
– Random c-statistic = 0.5
619
Sensitivity and Specificity
β€’ Sensitivity:
– Probability of saying someone has a
positive result –
β€’ If they do: p(pos)|pos
β€’ Specificity
– Probability of saying someone has a
negative result
β€’ If they do: p(neg)|neg
620
C-Statistic, Sensitivity and
Specificity
β€’ After logistic
– lroc
β€’ Gives c-statistic
– Better than R-squared
621
1.00
0.75
0.50
0.25
0.00
0.00
0.25
Area under ROC curve = 0.7469
0.50
1 - Specificity
0.75
1.00
More Advanced Techniques
β€’ Multinomial Logistic Regression more
than two categories in outcome
– same procedure
– one category chosen as reference group
β€’ odds of being in category other than reference
β€’ Ordinal multinomial logistic regression
– For ordinal outcome variables
623
More on Odds Ratios
β€’ Odds ratios are horrid
β€’ We use them because they have nice
distributional properties
β€’ Example:
– 40% in group 1 get PTSD
– 60% in group 2 get PTSD
– What’s the odds ratio?
– How is this confusing?
624
Alternatives to Odds Ratios
β€’ Risk difference
– 20 percentage points higher
β€’ Relative risk
– Probability is 1.5 times higher
– This is what you would think an odds ratio
meant
β€’ Can we use these in regression?
– RD – maybe. Sometimes.
– RR – yes. But we need to do something
else first
625
Final Thoughts
β€’ Logistic Regression can be extended
– dummy variables
– non-linear effects
– interactions
β€’ Same issues as OLS
– collinearity
– outliers
626
β€’ Same additional options as regress
– xi:
– cluster
– robust
627
Poisson Regression
628
Counts and the Poisson
Distribution
β€’ Von Bortkiewicz
(1898)
– Numbers of Prussian
soldiers kicked to
death by horses
120
100
80
60
0
1
2
3
4
5
109
65
22
3
1
0
40
20
0
0
1
2
3
4
5
629
β€’ The data fitted a Poisson probability distribution
– When counts of events occur, poisson distribution is
common
– E.g. papers published by researchers, police arrests,
number of murders, ship accidents
β€’ Common approach
– Log transform and treat as normal
β€’ Problems
– Censored at 0
– Integers only allowed
– Heteroscedasticity
630
The Poisson Distribution
0.7
0.6
Probability
0.5
0.5
1
4
8
0.4
0.3
0.2
0.1
0
0
1
2
3
4
5
6
7
8
9
Count
10
11
12
13
14
15
16
17
631
exp( ο€­  ) 
p ( y | x) ο€½
y!
y
632
exp(  ) 
p ( y | x) ο€½
y!
y
Excel has a Poisson
function you can
use.
β€’ Where:
– y is the count
–  is the mean of the Poisson distribution
β€’ In a Poisson distribution
– The mean = the variance (hence
heteroscedasticity issue))
–  ο€½ 2
633
Poisson Probabilities
Mean
Score
0
1
2
3
4
5
6
7
8
9
10
1
0.37
0.37
0.18
0.06
0.02
0.00
0.00
0.00
0.00
0.00
0.00
2
0.14
0.27
0.27
0.18
0.09
0.04
0.01
0.00
0.00
0.00
0.00
3
0.05
0.15
0.22
0.22
0.17
0.10
0.05
0.02
0.01
0.00
0.00
10
0.00
0.00
0.00
0.01
0.02
0.04
0.06
0.09
0.11
0.13
0.13
634
Issues with Estimation
β€’ Just as with logistic
– We can’t predict a mean below zero
β€’ Don’t predict the mean
– Predict the log of the mean
635
Poisson Regression in Stata
β€’ Adult literacy study
– Number of sessions attended
– Count variable
β€’ Poisson regression
636
poisson sessions tx
---------------------------------------------------------------------------sessions |
Coef.
Std. Err.
z
P>|z|
[95% Conf. Interval]
-----------+---------------------------------------------------------------tx | -.2359546
.06668
-3.54
0.000
-.366645
-.1052642
_cons |
1.899973
.046225
41.10
0.000
1.809374
1.990572
----------------------------------------------------------------------------
poisson sessions tx, irr
-----------------------------------------------------------------------------sessions |
IRR
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------tx |
.7898166
.052665
-3.54
0.000
.6930557
.9000867
------------------------------------------------------------------------------
637
But was it Poisson?
β€’ Look at predicted probabilities
– Compare with actual probabilities
β€’ Predicted means
– Control: exp(1.899) = 6.86
– Intervention: exp(1.899-0.236) = 5.28
β€’ Get means and SDs
638
bysort tx: sum sessions
-> tx = 0
VObs
Mean
Std. Dev.
-------------+-------------------------------------sessions |
70
6.685714
3.495516
----------------------------------------------------> tx = 1ariable |
Variable |
Obs
Mean
Std. Dev.
-------------+-------------------------------------sessions |
82
5.280488
2.709263
639
β€’ Do OK on the means
– Don’t do OK on the variances
– Variances are too high
β€’ Compare predicted probabilities with
actual probabilities
β€’ tab session tx,col nofreq
β€’ Draw graphs
– Not horrible
– Except the zeroes
640
0.25
0.20
0.15
Predicted - control
Predicted - intervention
Actual - control
Actual - intervention
0.10
0.05
0.00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Test for Goodness of Fit to
Poisson Distribution
β€’ After running Poisson
– estat gof
Goodness-of-fit chi2
Prob > chi2(150)
=
=
314.139
0.0000
β€’ Highly significant
– Poisson distribution doesn’t fit
642
Overdispersion
β€’ Problem in Poisson regression
– Too many zeroes
β€’ Causes
– c2 inflation
– Standard error deflation
β€’ Hence p-values too low
– Higher type I error rate
β€’ Two solutions
– Negative binomial regression
– Robust standard errors
643
Robust Standard Errors
poisson
sessions tx, robust
--------------------------------------------------------|
Robust
sessions |
Coef.
Std. Err.
z
P>|z|
-------------+------------------------------------------tx | -.2359546
.0840648
-2.81
0.005
_cons |
1.899973
.0622477
30.52
0.000
---------------------------------------------------------
β€’ Robust SEs are larger
644
Negative Binomial Regression
β€’ Adds a β€˜hurdle’ to account for the
zeroes
– Called alpha
β€’ nbreg sessions tx
β€’ OR
β€’ nbreg sessions tx, robust
645
Back to Categorical Outcomes
β€’ We said:
– Odds ratios are not good
β€’ We like relative risk instead
– What is the ratio of the risks?
β€’ What analysis technique do we know
that gives ratios of means
646
β€’ Poisson regression!
β€’ Wait. It won’t work. The distribution is
wrong.
β€’ Robust estimates!
647
Poisson Regression in SPSS
β€’ SPSS 15 (and above), has added it
β€’ Under generalized linear models
648
Lesson 11: Mediation and Path
Analysis
649
Introduction
β€’ Moderator
– Level of one variable influences effect of another
variable
β€’ Mediator
– One variable influences another via a third
variable
β€’ All relationships are really mediated
– are we interested in the mediators?
– can we make the process more explicit
650
β€’ In examples with bank
education
beginning
salary
β€’ Why?
– What is the process?
– Are we making assumptions about the
process?
– Should we test those assumptions?
651
job skills
expectations
beginning
salary
education
negotiating
skills
kudos
for bank
652
Direct and Indirect Influences
X may affect Y in two ways
β€’ Directly – X has a direct (causal)
influence on Y
– (or maybe mediated by other variables)
β€’ Indirectly – X affects Y via a mediating
variable - M
653
β€’ e.g. how does going to the pub effect
comprehension on a Summer school
course
– on, say, regression
not reading
books on
regression
Having fun
in pub in
evening
less
knowledge
Anything
here?
654
not reading
books on
regression
Having fun
in pub in
evening
less
knowledge
fatigue
Still
needed?
655
β€’ Mediators needed
– to cope with more sophisticated theory in
social sciences
– make explicit assumptions made about
processes
– examine direct and indirect influences
656
Detecting Mediation
657
β€œClassic Approach” 4 Steps
From Baron and Kenny (1986)
β€’ To establish that the effect of X on Y is
mediated by M
1. Show that X predicts Y
2. Show that X predicts M
3. Show that M predicts Y, controlling for X
4. If effect of X controlling for M is zero, M
is complete mediator of the relationship
β€’
(3 and 4 in same analysis)
658
Example: Book habits
Enjoy Books
οƒŸ
Buy books
οƒŸ
Read Books
659
Three Variables
β€’ Enjoy
– How much an individual enjoys books
β€’ Buy
– How many books an individual buys (in a
year)
β€’ Read
– How many books an individual reads (in a
year)
660
ENJOY
BUY
READ
ENJOY BUY
READ
1.00
0.64
0.73
0.64
1.00
0.75
0.73
0.75
1.00
661
β€’ The Theory
enjoy
buy
read
662
β€’ Step 1
1. Show that X (enjoy) predicts Y (read)
– b1 = 0.487, p < 0.001
– standardised b1 = 0.732
– OK
663
2. Show that X (enjoy) predicts M (buy)
– b1 = 0.974, p < 0.001
– standardised b1 = 0.643
– OK
664
3. Show that M (buy) predicts Y (read),
controlling for X (enjoy)
– b1 = 0.469, p < 0.001
– standardised b1 = 0.206
– OK
665
4. If effect of X controlling for M is zero,
M is complete mediator of the
relationship
– (Same as analysis for step 3.)
– b2 = 0.287, p = 0.001
– standardised b2 = 0.431
– Hmmmm…
β€’
Significant, therefore not a complete mediator
666
0.287
(step 4)
enjoy
read
buy
0.974
(from step 2)
0.206
(from step 3)
667
The Mediation Coefficient
β€’ Amount of mediation =
Step 1 – Step 4
=0.487 – 0.287
= 0.200
β€’ OR
Step 2 x Step 3
=0.974 x 0.206
= 0.200
668
SE of Mediator
enjoy
buy
a
(from step 2)
read
b
(from step 2)
β€’ sa = se(a)
β€’ sb = se(b)
669
β€’ Sobel test
– Standard error of mediation coefficient can
be calculated
se ο€½ b s + a s - s s
2 2
a
a = 0.974
sa = 0.189
2 2
b
2 2
a b
b = 0.206
sb = 0.054
670
β€’ Indirect effect = 0.200
– se = 0.056
– t =3.52, p = 0.001
β€’ Online Sobel test:
http://quantpsy.org
671
Problems with the Sobel test
β€’ Recently
– Move in methodological literature away from this
conventional approach
β€’ Problems of power:
– Several tests, all of which must be significant
β€’ Type I error rate = 0.05 * 0.05 = 0.0025
β€’ Must affect power
672
β€’ Distributional Assumption
– We assume that the sampling distribution
of the coefficient is normally distributed
β€’ Standard error is standard deviation
β€’ If:
– a (x οƒž m) is normal and not zero
– b (m οƒž y) is normal and not zero
β€’ Then:
– a×b
– Is not normally distributed
β€’ Assumption is violated
– Test is incorrect
673
β€’ Solution:
– Bootstrap
β€’ Computer intensive semi-parametric procedure
β€’ Removes distributional assumption
– Bootstrapping suggested as alternative
β€’ For Stata:
β€’ www.ats.ucla.edu/stat/stata/faq/mediat
ion_cativ.htm
β€’ For SAS, SPSS:
– www.quantpsy.org
674
Cross Sectional Bias
β€’ If everything is measured at one time
– Likely to be bias
β€’ Ideally:
– Three variables, measured on three
occasions
675
x
x
x
m
m
m
y
y
y
676
β€’ Kind of hard work
– Collecting data on three occasions
β€’ BUT: Stationarity assumption can save
us
x
x
x
m
m
m
y
y
y
677
β€’ We assume that the effect from M to Y
is stable over time
– Only need two time points
β€’ Cole and Maxwell (2003)
678
Power in Mediation
β€’ Really hard to work out
β€’ Need to run simulations
β€’ Power depends on
– Size of a
– Size of b
β€’ Fritz and Mackinnon (2007)
– Table of power for different effects
679
More Information on
Mediation
β€’ Mackinnon, Fritz and Fairchild
– Annual Review of Psychology
β€’ Mackinnon
– Introduction to statistical mediation
β€’ Iacobucci
– Mediation analysis (little green book)
β€’ Mackinnon’s website (Google: mackinnon mediation)
β€’ Facebook group
– (No, really)
680
Lesson 12: Moderators in
Regression
β€œdifferent slopes for different
folks”
681
Introduction
β€’ Moderator relationships have many
different names
– interactions (from ANOVA)
– multiplicative
– non-linear (just confusing)
– non-additive
β€’ All talking about the same thing
682
A moderated relationship occurs
β€’ when the effect of one variable
depends upon the level of another
variable
683
β€’ Hang on …
– That seems very like a nonlinear relationship
– Moderator
β€’ Effect of one variable depends on level of another
– Non-linear
β€’ Effect of one variable depends on level of itself
β€’ Where there is collinearity
– Can be hard to distinguish between them
– Paper B5
– Should (usually) compare effect sizes
684
β€’ e.g. How much it hurts when I drop a
computer on my foot depends on
– x1: how much alcohol I have drunk
– x2: how high the computer was dropped
from
– but if x1 is high enough
– x2 will have no effect
685
β€’ e.g. Likelihood of injury in a car
accident
– depends on
– x1: speed of car
– x2: if I was wearing a seatbelt
– but if x1 is low enough
– x2 will have no effect
686
30
25
Injury
20
15
10
5
0
5
15
25
35
45
Speed (mph)
Seatbelt
No Seatbelt
687
β€’ e.g. number of words (from a list) I can
remember
– depends on
– x1: type of words (abstract, e.g. β€˜justice’, or
concrete, e.g. β€˜carrot’)
– x2: Method of testing (recognition – i.e.
multiple choice, or free recall)
– but if using recognition
– x1: will not make a difference
688
β€’ We looked at three kinds of moderator
β€’ alcohol x height = pain
– continuous x continuous
β€’ speed x seatbelt = injury
– continuous x categorical
β€’ word type x test type
– categorical x categorical
β€’ We will look at them in reverse order
689
How do we know to look for
moderators?
Theoretical rationale
β€’ Often the most powerful
β€’ Many theories predict additive/linear
effects
– Fewer predict moderator effects
Presence of heteroscedasticity
β€’ Clue there may be a moderated
relationship missing
690
Two Categorical Predictors
691
β€’ 2 IVs
Data
– word type (concrete [e.g. Carrot, table], abstract
[e.g. Love, justice)
– test method (multiple choice, recall )
β€’ 20 Participants in one of four groups
–
–
–
–
Concrete, MC
Concrete, recall
Abstract, MC
Abstract, recall
β€’ 5 per group
β€’ lesson12.1-words.dta
692
MC
Mean
Concrete
SD
Mean
Abstract
SD
Mean
Total
SD
15.4
2.5
15.6
1.5
15.5
2.0
Recall
Total
15.2
15.3
3.2
2.7
7.0
11.3
1.6
4.8
11.1
13.3
4.9
4.3
693
β€’ Graph of means
20
15
10
Concrete
Abstract
5
0
MC
Recall
694
Procedure for Testing
1: Convert to dummy coding
– Already done
2: Calculate interaction term
– Multiply dummy codes together
– (Can also use xi: for this)
– Call interaction mxc
695
β€’ Interaction term (wxt)
– multiply effect coded variables together
Concrete
0
0
1
1
MC
0
1
0
1
mxc
0
0
0
1
696
3: Carry out regression
– Hierarchical
– linear effects first
– interaction effect in next block
697
β€’ b0(intercept)= 7.0
– Mean score when MC = 0 and concrete = 0
β€’ b1 (mc) = 8.6
– When concrete is zero, effect of MC
β€’ b2 (concrete) = 8.2
– When mc is zero, effect of concrete
MC
Recall
Total
Concrete Abstract Total
15.4
15.2
15.30
15.6
7
11.30
15.50
11.10
13.30
698
β€’ b3 (mc x con) = -8.4
– grand mean
β€’ Given other estimates, what’s the
predicted mean of concrete, MC?
– 7.0 + 8.6 + 8.2 = 23.8
β€’ What is it?
– 15.4
Recog
Recall
Total
Concrete Abstract Total
15.4
15.2
15.3
15.6
7.0
11.3
15.5
11.1
13.3
699
β€’ Have:
β€’ Expect:
β€’ Difference:
15.4
23.8
-8.4
700
Back to the Graph
Slope for
concrete words
15.2-15.4=-0.2
20
15
10
Concrete
Abstract
5 Difference in
slopes
0 -8.6-(-0.2) = -8.4
MC
Recall
Slope for
abstract words
7.0-15.6=-8.6
701
b associated with interaction
β€’ The difference in the slopes
OR
β€’ The change in slope, away from the
average, associated with a 1 unit
change in the moderating variable
702
β€’ Another way to look at it
Y = 7 + 8.6 ο‚΄ m + 8.2 ο‚΄ c + -8.4 ο‚΄ m ο‚΄ c
β€’ Examine concrete words group (c = 1)
– substitute values into the equation
Y(conc) = Y = 7 + 8.6 ο‚΄ m + 8.2 ο‚΄ 1 + -8.4 ο‚΄ m ο‚΄ 1
Y(conc) = Y = 7 + 8.6 ο‚΄ m + 8.2 + -8.4 ο‚΄ m
Y(conc) = Y = 7 + 8.2 + 8.6 ο‚΄ m -8.4 ο‚΄ m
Y(conc) = Y = 15.2 + 0.2 ο‚΄ m
703
Categorical x Continuous
704
Note on Dichotomisation
β€’ Very common to see people dichotomise
a variable
– Makes the analysis easier
– Very bad idea
β€’ Paper B6
705
Data
A chain of 60 supermarkets
β€’ examining the relationship between
profitability, shop size, and local
competition
β€’ 2 IVs
– shop size
– comp (local competition, 0=no, 1=yes)
β€’ outcome
– profit
706
β€’ Data, β€˜lesson 12.2.dta’
Shopsize
4
10
7
10
10
29
12
6
14
62
Comp
1
1
0
0
1
1
0
1
0
0
Profit
23
25
19
9
18
33
17
20
21
8
707
1st Analysis
Two IVs
β€’ R2=0.367, df=2, 57, p < 0.001
β€’ Unstandardised estimates
– b1 (shopsize) = 0.083 (p=0.001)
– b2 (comp) =- 5.883 (p<0.001)
β€’ Standardised estimates
– b1 (shopsize) = 0.356
– b2 (comp) = 0.448
708
β€’ Suspicions
– Presence of competition is likely to have an
effect
– Residual plot shows a little
heteroscedasticity
709
10
5
-5
0
Residuals
-10
15
20
25
Linear prediction
30
Procedure for Testing
β€’ Very similar to last time
– convert β€˜comp’ to dummy coding
β€’ (if it’s not already)
– Compute interaction term
β€’ comp (effect coded) x size
– Hierarchical regression
711
Result
β€’ Estimates
– b1 (shopsize) = 0.12, SE = 0.03
– b2 (comp) = -1.67, SE 2.50
– b3 (sxc) = -0.10, SE 0.05
712
β€’ comp now non-significant
– shows importance of hierarchical
– it obviously is important
713
Interpretation
β€’ Draw graph with lines of best fit
– graph twoway (scatter profit
shopsize if comp==1) (lfit
profit shopsize if comp==1)
(scatter profit shopsize if
comp==0) (lfit profit shopsize
if comp==0), legend(off)
714
40
30
20
10
0
0
20
40
60
80
100
shopsize
715
β€’ Substitute into equation
β€’ Effects of size
– (can ignore the constant)
β€’ Y=sizeο‚΄0.12 + compο‚΄(-1.67) + sizeο‚΄compο‚΄(-0.09)
– Competition present (comp = 1)
β€’ Y=sizeο‚΄0.12 + 1ο‚΄(-1.67) + sizeο‚΄1ο‚΄(-0.09)
β€’ Y=sizeο‚΄0.12
+ sizeο‚΄ (-0.09)
β€’ Y=sizeο‚΄0.03
716
β€’ Y=sizeο‚΄0.12 + compο‚΄(-1.67) + sizeο‚΄compο‚΄(-0.09)
– Competition present (x2 = 0)
β€’ Y=sizeο‚΄0.12 + 0
β€’ Y=sizeο‚΄0.12
ο‚΄(-1.67) + sizeο‚΄ 0 ο‚΄(-0.09)
717
Two Continuous Variables
718
Data
β€’ Bank Employees
– only using clerical staff
– 363 cases
– predicting starting salary
– previous experience
– age
– age x experience
– (exercise 6.3)
719
β€’ Correlation matrix
– only one significant
LOGSB AGESTARTPREVEXP
LOGSB
1.00
-0.09
0.08
AGESTART
-0.09
1.00
0.77
PREVEXP
0.08
0.77
1.00
720
Initial Estimates (no moderator)
β€’ (standardised)
– R2 = 0.063, p<0.001
– Age at start = -0.37, p<0.001
– Previous experience = 0.36, p<0.001
β€’ Suppressing each other
– Age and experience compensate for one
another
– Older, with no experience, bad
– Younger, with experience, good
721
The Procedure
β€’ Very similar to previous
– create multiplicative interaction term
– BUT
β€’ Center variables (subtract mean)
– Not always necessary
– Can make life easier
722
β€’ Hierarchical regression
– two linear effects first
– moderator effect in second
723
β€’ Change in R2
– 0.085, p<0.001
β€’ Estimates (standardised)
– b1 (agestart) = -0.52
– b2 (prevexp) = 0.93
– b3 (age x exp) = -0.56
724
Interpretation 1: Pick-a-Point
β€’ Graph is tricky
– can’t have two continuous variables
– Choose specific points (pick-a-point)
β€’ Graph the line of best fit of one variable at
others
– Two ways to pick a point
β€’ 1: Choose high (z = +1), medium (z = 0) and
low (z = -1)
β€’ Choose β€˜sensible’ values – age 20, 50, 80?
725
β€’ We know:
– Y = e ο‚΄ 0.94 + a ο‚΄ -0.53 + a ο‚΄ e ο‚΄ -0.58
– Where a = agestart, and e = experience
β€’ We can rewrite this as:
– Y = (e ο‚΄ 0.94) + (a ο‚΄ -0.53) + (a ο‚΄ e ο‚΄ -0.58)
– Take a out of the brackets
– Y = (e ο‚΄ 0.94) + (-0.53 + e ο‚΄ -0.58)a
β€’ Bracketed terms are simple intercept and simple
slope – intercept and slope for agestart
– 0= (e ο‚΄ 0.10)
– 1= (-0.53 + e ο‚΄ -0.58)a
– Y = 0 + 1a
726
β€’ Pick any value of e, and we know the slope
for a
– Standardised, so it’s easy
β€’ e = -1
– 0= (-1 ο‚΄ 0.94) = -0.94
– 1= (-0.53 + -1 ο‚΄ -0.58)a = -0.05a
β€’ e=0
– 0= (0 ο‚΄ 0.10) = 0
– 1= (-0.53+ 0 ο‚΄ -0.58)a = -0.53a
β€’ e=1
– 0= (1 ο‚΄ 0.10) = 0.10
– 1= (-0.53 + 1 ο‚΄ -0.58)a = -1.11a
727
Graph the Three Lines
1.5
1
e = -1
e=0
e=1
Log(salary)
0.5
0
-0.5
-1
-1.5
-1
-0.9
-0.8
-0.7
-0.6
-0.5
-0.4
-0.3
-0.2
-0.1
0
Age
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
728
Do This in Stata
β€’ The easy way
β€’ Create some pseudo cases
– Some fake people
– With sensible scores for the variables
– Regression equation β€˜stays behind’
β€’ Calculate predicted scores with
predict
– (Can be in a new dataset)
729
β€’ Then draw graph
β€’ drop if _n < 364
β€’ graph twoway (lfit pred
agestart if prevexp==0,
lcolor(red)) (lfit pred
agestart if prevexp==85,
lcolor(black)) (lfit pred
agestart if prevexp==170,
lcolor(green)) , legend(off)
731
10
9.8
9.6
9.4
20
30
40
agestart
50
β€’ (Also works in SPSS; in SAS, use Proc
Score)
733
Interpretation 2: P-Values and CIs
β€’ Second way
– Newer, rarely done
β€’ Calculate CIs of the slope
– At any point
β€’ Calculate p-value
– At any point
β€’ Give ranges of significance
734
What do you need?
β€’ The variance and covariance of the
estimates
– SPSS doesn’t provide estimates for
intercept
– Need to do it manually
β€’ In options, exclude intercept
– Create intercept – c = 1
– Use it in the regression
735
β€’ Enter information into web page:
β€’ www.people.ku.edu/~preacher/interact
/mlr2.htm
β€’ Get results
β€’ Calculations in Bauer and Curran (in
press: Multivariate Behavioral Research)
– Paper B13
736
4.1
4.2
Y
4.3
4.4
4.5
MLR 2-Way Interaction Plot
4.0
CVz1(1)
CVz1(2)
CVz1(3)
-1.0
-0.5
0.0
X
0.5
1.0
737
Areas of Significance
0.0
-0.2
-0.4
-0.6
Simple Slope
0.2
0.4
Confidence Bands
-4
-2
0
2
4
Experience
738
β€’ 2 complications
– 1: Constant differed
– 2: outcome was logged, hence non-linear
β€’ effect of 1 unit depends on where the unit is
– See paper A2
739
Finally …
740
Unlimited Moderators
β€’ Moderator effects are not limited to
– 2 variables
– linear effects
741
Three Interacting Variables
β€’ Age, Sex, Exp
β€’ Block 1
– Age, Sex, Exp
β€’ Block 2
– Age x Sex, Age x Exp, Sex x Exp
β€’ Block 3
– Age x Sex x Exp
742
β€’ Results
– All two way interactions significant
– Three way not significant
– Effect of Age depends on sex
– Effect of experience depends on sex
– Size of the age x experience interaction
does not depend on sex (phew!)
743
Moderated Non-Linear
Relationships
β€’ Enter non-linear effect
β€’ Enter non-linear effect x moderator
– if significant indicates degree of nonlinearity differs by moderator
744
745
Lesson 13: Longitudinal Models
746
Advantages of Longitudinal
Data
β€’ You get more data from the same
number of people
β€’ You can test causal relationships
– Although you can’t rule them out
β€’ You can examine change
β€’ You can control for individual
differences
747
Disadvantage of Longitudinal
Data
β€’ It’s much harder to analyze
748
Longitudinal Research
β€’ For comparing
repeated measures
– Clusters are people
β€’ Data are usually
short and fat
ID
V1
V2
V3
V4
1
2
3
4
7
2
3
6
8
4
3
2
5
7
5
749
Converting Data
β€’ Change data to tall
and thin
β€’ Use reshape in
stata
β€’ Use Data,
Restructure in
SPSS
β€’ Clusters are ID
ID
V
X
1
1
2
1
2
3
1
3
4
1
4
7
2
1
3
2
2
6
2
3
8
2
4
4
3
1
2
3
2
5
3
3
7
3
4
5
750
Predict Salary Change
β€’ Use exercise5.3-bank salary.dta
– Compare beginning salary and salary
– Would normally use paired samples t-test
β€’ Difference = $17,403, 95% CIs
$16,427.407, $18,379.555
751
Predict Salary Change
β€’ Don’t take the difference in salary and
salbegin
– Why not?
β€’ reg salary agestart salbegin
β€’ Est: -207.8, 95% CIs -267.4, -148.2
752
Restructure the Data
β€’ gen id = _n
β€’ rename salbegin sal1
β€’ rename salary sal2
β€’ reshape long sal, i(id) j(t)
β€’ replace t = t-1
753
Restructure the Data
β€’ Do it again
– With data tall and thin
β€’ Do a regression
– What do we find?
ID
Time
Cash
1
0
$18,750
1
1
$21,450
2
0
$12,000
2
1
$21,900
3
0
$13,200
3
1
$45,000
754
Results
β€’ We have violated the independence
assumption
β€’ We have the wrong answer
β€’ Simplest way to solve it:
β€’ regress sal t, cluster(id)
β€’ Assumes that ID is just an irritant
– Rather inflexible
755
However …
β€’ That has one advantage
– Missing data doesn’t mean that we exclude
the case
– If data are missing at random (or missing
completely at random) estimates will be
unbiased
756
β€’ If everyone has
– Score at time 1
– Score at time 2
β€’ Analysis is easy
β€’ If half the people have
– Score at time 1
– Score at time 2
β€’ Analysis is easy
β€’ But what if some have
– Time 1
– Time 2
– Time 1 and 2
757
β€’ If
– Missing at random
T1
β€’ MAR
T2
– Missing completely at
random
10
15
7
6
8
2
5
8
β€’ MCAR
– (Crappy names)
β€’ No problem
Interesting …
β€’ That wasn’t very interesting
– What is more interesting is when:
β€’ We have missing data
– Which we won’t talk about more (much)
β€’ We have multiple measurements of the same
people
– Which we will talk about
759
Modelling Change
β€’ Can plot and assess trajectories over
time
β€’ How do people change?
β€’ What predicts the rate of change?
760
Plotting Individuals
Salary
Person 1
T1
T2
761
Plotting Individuals
Person 3
Salary
Person 1
Person 2
T1
T2
762
0
0
100000
150000
50000
0
100000
150000
50000
0
100000
150000
50000
0
100000
150000
50000
0
100000
150000
50000
0
100000
150000
50000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
.5
Graphs by id
1
0
.5
1
0
.5
1
t
0
.5
1
0
.5
1
0
.5
1
0
50000
0
.2
.4
.6
t
.8
1
Estimation
β€’ Each individual has an intercept
– Sampled from the population of intercepts
β€’ Each individual has a slope
– Sampled from the population of slopes
β€’ Can we estimate the average of each
– And a measure of their variance?
β€’ Yes! With multilevel models
765
Multilevel Models
β€’ Can do all kinds of clever things
– We won’t worry about most of them
β€’ Used when
– Level 1 units (measures)
– Are nested within
– Level 2 units (people)
β€’ Same person measured twice
– Violated indepence
766
Levels
β€’ In regression
– Everything is at one level
β€’ In multilevel models
– We have multiple levels
β€’ Hierarchical levels (hence hierarchical linear
models)
β€’ Random effects (random effects models)
β€’ Mixed effects (mixed models)
767
Levels
β€’ Level 1 units
– First level of measurement
– Are clustered within
β€’ Level 2 units
– Second level of measurement
768
Some Equations
β€’ (This is very hard. It’s not important).
β€’ In regression
yi ο€½ b0  b1 xi1  ei
β€’ If x is time
– And we have one person
– Reference time with I
– And call it T
769
β€’ Single person equation
yi ο€½ b0  b1Ti  ei
β€’ But what if we have lots of people?
– We’ve used i for time
– We’ll use j for people
yij ο€½ b0  b1Tij  eij
β€’ But everything is fixed
– We want to have some random effects
770
β€’ Let’s make intercepts random
– Everyone has their own intercept
yij ο€½ b0 j  b1Tij  eij
β€’ Look! We added a little j
– Now it’s a multilevel model
β€’ And we need an equation for the
intercept
771
β€’ Equation for each person’s intercept
b0 j ο€½ g 00  0 j
β€’ Your intercept (b0j) is equal to:
– Mean intercept
β€’ g00
(Gamma)
– Plus residual (for that individual)
β€’ 0j
(mu)
– This is level 2 model
β€’ Level 2 residuals
β€’ i.i.d, etc
772
β€’ So now we have
yij ο€½ b0 j b1 jTij  eij
b0 j ο€½ g 00  0 j
β€’ Or
yij ο€½ (g 00  0 j )  b1Tij  eij
773
Make Time Random
β€’ Value of the time parameter can vary
– Amongst people
– Everyone can have a different effect of
time
yij ο€½ b0 j  b1 jTij  eij
774
β€’ Time is random
– Everyone has a slope parameter
btj ο€½ g t 0   tj
β€’ So:
yij ο€½ b0 j  b1Tij  eij
b0 j ο€½ g 00   0 j
b1 j ο€½ g 10  1 j
775
β€’ Or
yij ο€½ b0 j  b1 jTij  eij
b0 j ο€½ g 00   0 j
btj ο€½ g t 0  tj
yij ο€½ g t 0  1 j   g 10  1 j   eij
776
Time Invariant Covariates
β€’ Can be added at level 2
– We can predict person’s intercept
β€’ Starting point
– And rate of change
777
Employee Data
β€’ Level 1:
– Pay measures
β€’ Two of them
– Clustered within
β€’ Level 2:
– People
– Level 2 measures: age, sex, job, etc
778
Regression with Time
β€’ Do a regression analysis
– On one person
β€’ Time is the predictor
β€’ Get a regression line for that person
779
Fixed vs Random Effects
β€’ Fixed effects
– Effect is the same across all clusters
(people)
– Variation is only measurement error
β€’ Random effects
– Effect varies across people
– Additional parameter in the model
β€’ Less parsimonious
780
Fixed vs Random Effects
β€’ If an effect has variance
– It might have covariance
– With any other effects which also have
variance
β€’ More parameters
– Less parsimony
781
Covariates
β€’ Two kinds of covariates
– Time invariant
β€’ Fixed for a person
– Age when study started
– Sex
– Time variant
β€’ Can change over time
– Time
– Marital Status
782
Time Invariant
β€’ Look at effect of age
– Add age to the fixed effects
– Is that significant?
– Are random effects (still?) significant
783
Multilevel Models in Stata
β€’ Use xtmixed
– Stata 10 added xtmelogit, xtmepoisson
β€’ Continuous variables are hard enough
β€’ In SPSS, continuous variables only
784
Multilevel Models in Stata
β€’ xtmixed sal t
β€’ Does regression
β€’ Need to tell it about the people:
β€’ xtmixed sal t ||id:
785
-----------------------------------------------------------------------------sal |
Coef.
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------t |
17403.48
496.7321
35.04
0.000
16429.9
18377.06
_cons |
17016.09
610.6691
27.86
0.000
15819.2
18212.98
----------------------------------------------------------------------------------------------------------------------------------------------------------Random-effects Parameters |
Estimate
Std. Err.
[95% Conf. Interval]
-----------------------------+-----------------------------------------------id: Identity
|
sd(_cons) |
10875.87
449.592
10029.44
11793.73
-----------------------------+-----------------------------------------------sd(Residual) |
7647.093
248.6285
7174.992
8150.258
-----------------------------------------------------------------------------LR test vs. linear regression: chibar2(01) =
280.88 Prob >= chibar2 = 0.0000
786
Average
-----------------------------------------------------------------------------slope
sal |
Coef.
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------t |
17403.48
496.7321
35.04
0.000
16429.9
18377.06
_cons |
17016.09
610.6691
27.86
0.000
15819.2
18212.98
------------------------------------------------------------------------------
Average
-----------------------------------------------------------------------------intercept
Random-effects Parameters |
Estimate
Std. Err.
[95% Conf. Interval]
SD of the
-----------------------------+-----------------------------------------------id: Identity
|
slopes
sd(_cons) |
10875.87
449.592
10029.44
11793.73
-----------------------------+-----------------------------------------------sd(Residual) |
7647.093
248.6285
7174.992
8150.258
-----------------------------------------------------------------------------LR test vs. linear regression: chibar2(01) =
280.88 Prob >= chibar2 = 0.0000
SD of the
slopes
787
β€’ Gives random intercepts only
– Let’s look at them
β€’ predict rand_int
β€’ xtline rand_int , overlay
t(t) i(id) legend(off)
788
0
.2
.4
.6
t
.8
1
0
20000
40000
60000
80000
Random Slopes
β€’ Everyone has the same slope
– Maybe that’s not true
– Make slopes random
β€’ xtmixed sal t ||id: t
790
-----------------------------------------------------------------------------sal |
Coef.
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------t |
17403.48
496.7273
35.04
0.000
16429.91
18377.05
_cons |
17016.09
361.5138
47.07
0.000
16307.53
17724.64
----------------------------------------------------------------------------------------------------------------------------------------------------------Random-effects Parameters |
Estimate
Std. Err.
[95% Conf. Interval]
-----------------------------+-----------------------------------------------id: Independent
|
sd(t) |
10814.52
351.6071
10146.88
11526.09
sd(_cons) |
7870.712
255.9014
7384.801
8388.595
-----------------------------+-----------------------------------------------sd(Residual) |
.709687
.3436148
.2747476
1.833158
------------------------------------------------------------------------------
β€’ predict rand_int_slope, fitte
β€’ xtline rand_int_slope ,
overlay t(t) i(id)
legend(off)
792
0
50000
0
.2
.4
.6
t
.8
1
Structure of the Covariances
β€’ We have been forcing slope and
intercepts to be uncorrelated
β€’ Let’s correlate them
β€’ xtmixed sal t ||id: t ,
cov(un)
794
-----------------------------------------------------------------------------sal |
Coef.
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------t |
17403.48
496.7316
35.04
0.000
16429.91
18377.06
_cons |
17016.09
361.5085
47.07
0.000
16307.54
17724.63
----------------------------------------------------------------------------------------------------------------------------------------------------------Random-effects Parameters |
Estimate
Std. Err.
[95% Conf. Interval]
-----------------------------+-----------------------------------------------id: Unstructured
|
sd(t) |
10103.18
11670.32
1050.081
97205.97
sd(_cons) |
7382.783
7985.867
886.1058
61511.25
corr(t,_cons) |
.8550486
3.491476
-1
1
-----------------------------+-----------------------------------------------sd(Residual) |
2727.788
21601.34
.0004956
1.50e+10
------------------------------------------------------------------------------
Predicting Change
β€’ Does another variable moderate the
effect of time
– This means that the effect of time varies
– As a function of the slope
β€’ xi: xtmixed sal i.t*agestart
||id: t
796
-----------------------------------------------------------------------------sal |
Coef.
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------_It_1 |
25483.16
1640.544
15.53
0.000
22267.75
28698.57
agestart | -5.157022
30.85168
-0.17
0.867
-65.6252
55.31115
_ItXagest_1 | -212.5138
41.25203
-5.15
0.000
-293.3663
-131.6613
_cons |
17205.18
1226.935
14.02
0.000
14800.43
19609.93
----------------------------------------------------------------------------------------------------------------------------------------------------------Random-effects Parameters |
Estimate
Std. Err.
[95% Conf. Interval]
-----------------------------+-----------------------------------------------id: Unstructured
|
sd(t) |
9871.434
9785.792
1414.372
68896.47
sd(_cons) |
7437.632
6495.359
1342.987
41190.55
corr(t,_cons) |
.8622535
2.921366
-1
1
-----------------------------+-----------------------------------------------sd(Residual) |
2619.971
18422.9
.0027095
2.53e+09
------------------------------------------------------------------------------
Exercises
β€’ 13.1, 13.2
798
Fixed Effects Models
β€’ A second way of looking at longitudinal
data
β€’ Multilevel (mixed) models
– Assume that intercepts are random
β€’ Fixed effects models
– Assume they are fixed
– If they are fixed they can correlate
β€’ With all other predictors
799
Fixed Effects Models
β€’ Allowing intercepts to correlate
– Has the effect of controlling for ALL time
invariant predictors
– Even those you didn’t measure
– Each person is their own control
800
Fixed Effects Models
β€’ Regression asks:
– Are people who are higher on x also higher
on y?
β€’ Fixed effects asks:
– When a person is higher on x are they also
higher on y
– Effects are within people, not between
people
801
Fixed Effects in Stata
β€’ Make data long, then
– xtreg sal t agestart, i(id)
802
-----------------------------------------------------------------------------sal |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------t |
17403.48
496.7319
35.04
0.000
16427.41
18379.56
_cons |
17016.09
351.2425
48.45
0.000
16325.9
17706.28
-------------+---------------------------------------------------------------sigma_u | 12145.928
sigma_e | 7647.0911
rho | .71612838
(fraction of variance due to u_i)
-----------------------------------------------------------------------------F test that all u_i=0:
F(473, 473) =
5.05
Prob > F = 0.0000
Fixed Effects Regression
β€’ Can we look at the effect of time
invariant predictors?
β€’ xtreg sal t agestart, i(id) fe
β€’ Why not?
804
Interactions
β€’ But we can look at interactions of time
invariant predictors
β€’ xi: xtreg sal i.t*agestart,
i(id) fe
805
-----------------------------------------------------------------------------sal |
Coef.
Std. Err.
t
P>|t|
[95% Conf. Interval]
-------------+---------------------------------------------------------------_It_1 |
25483.16
1640.538
15.53
0.000
22259.48
28706.84
agestart | (dropped)
_ItXagest_1 | -212.5138
41.25188
-5.15
0.000
-293.5743
-131.4533
_cons |
17009.25
342.8103
49.62
0.000
16335.62
17682.88
-------------+---------------------------------------------------------------sigma_u |
12087.77
sigma_e | 7455.6318
rho | .72441115
(fraction of variance due to u_i)
------------------------------------------------------------------------------
Exercises
β€’ 13.3, 13.4
807
Bonus Lesson 1: Why
Regression?
A little aside, where we look at
why regression has such a curious
name.
808
Regression
The or an act of regression; reversion;
return towards the mean; return to an
earlier stage of development, as in an
adult’s or an adolescent’s behaving like
a child
(From Latin gradi, to go)
β€’ So why name a statistical technique
which is about prediction and
explanation?
809
β€’ Francis Galton
– Charles Darwin’s cousin
– Studying heritability
β€’ Tall fathers have shorter sons
β€’ Short fathers have taller sons
– β€˜Filial regression toward mediocrity’
– Regression to the mean
810
β€’ Galton thought this was biological fact
– Evolutionary basis?
β€’ Then did the analysis backward
– Tall sons have shorter fathers
– Short sons have taller fathers
β€’ Regression to the mean
– Not biological fact, statistical artefact
811
Other Examples
β€’ Secrist (1933): The Triumph of Mediocrity in
Business
β€’ Second albums often tend to not be as good
as first
β€’ Sequel to a film is not as good as the first
one
β€’ Sports Illustrated Cover Jinx
β€’ Parents think that punishing bad behaviour
works, but rewarding good behaviour doesn’t
812
β€’ Accident reduction schemes
– Always reduce accidents
β€’ Poor radiologists improve after training
β€’ Any treatment for a cold will work
– Or for most illnesses
β€’ Deaths due to methadone in Utah
– High last year
– Must take action!
813
Pair Link Diagram
β€’ An alternative to a scatterplot
x
y
814
r=1.00
x
x
x
x
x
x
x
815
r=0.00
x
x
x
x
x
816
From Regression to
Correlation
β€’ Where do we predict an individual’s
score on y will be, based on their score
on x?
– Depends on the correlation
β€’ r = 1.00 – we know exactly where they
will be
β€’ r = 0.00 – we have no idea
β€’ r = 0.50 – we have some idea
817
r=1.00
Starts here
Will end up
here
x
y
818
r=0.00
Starts here
Could end
anywhere here
x
y
819
r=0.50
Probably
end
somewhere
here
Starts here
x
y
820
Galton Squeeze Diagram
β€’ Don’t show individuals
– Show groups of individuals, from the same
(or similar) starting point
– Shows regression to the mean
821
r=0.00
Ends here
Group starts
here
x
Group starts
here
y
822
r=0.50
x
y
823
r=1.00
x
y
824
1 unit
r units
x
y
β€’ Correlation is amount of regression that
doesn’t occur
825
β€’ No regression
β€’ r=1.00
x
y
826
β€’ Some
regression
β€’ r=0.50
x
y
827
r=0.00
β€’ Lots
(maximum)
regression
β€’ r=0.00
x
y
828
Formula
zˆ y  rxy z x
829
Conclusion
β€’ Regression towards mean is statistical necessity
regression = perfection – correlation
β€’ Very non-intuitive
β€’ Interest in regression and correlation
– From examining the extent of regression towards
mean
– By Pearson – worked with Galton
– Stuck with curious name
β€’ See also Paper B3
830
β€’ Correcting for regression to the mean
– Possible
– Makes lots of tricky assumptions
β€’ To appear to do well in your job / life
– Do something after someone has failed
– You probably can’t do worse
– Hospital / school / department / class /
study / experiment
β€’ If it fails, volunteer to do it
831
Bonus Lesson 2: Other Kinds
of Regression
832
Introduction
β€’ We’ve covered a few kinds of
regression
– There are many more, for specific types of
outcomes
833
Beta Regression
β€’ Used when the outcome variable is beta
distributed
β€’ Rates and proportions
– Bounded by zero and 1
– Uniform, or strange shaped distributions
834
Cox Proportional Hazards
Regression
β€’ Type of survival model
β€’ Used for time to an event
– When the event might not occur
β€’ Developed for medical research
835
Cox Proportional Hazards
Regression
β€’ E.g. How long does it take for a car to
break down
– The car crashes, and is scrapped
– We’ll never know – but we want to know
the information
– Discarding the data point would lead to
bias
836
Competing Risks Survival
β€’ Time to multiple events
– Several things are trying to kill you
– Which one succeeds
837
Data Mining Techniques
β€’ Avoid problems with stepwise
regression
– Used as alternatives to logistic
β€’ Boosted regression (Stata command:
boost)
– Semi-parametric alternative to logistic
regression
β€’ Least Angle Regression (LARS)
838
β€’ Classification trees
839
Seemingly Unrelated
Regression
β€’ Used for multiple outcomes
– With correlated error terms
β€’ Some say it should be seemingly related
β€’ Stata command: sureg
840
Instrumental Variables
Regression
β€’ Used for mediator models
– Although economists don’t call them that.
β€’ Use ivregress in Stata
841
Quantile Regression
β€’ Why do we always try to predict the
mean?
β€’ What about predicting the median? The
25th percentile?
β€’ That’s quantile regression
842
Non-Parametric Regression
β€’ (Might also include LARS/Lasso/Boost)
β€’ Don’t force any functional form on the
relationship
β€’ LO(W)ESS – locally weighted scatterplot
smoothing
– Will find any relationship
843
Robust Regression
β€’ (Careful, not sandwich estimators)
β€’ Trimmed of outliers, estimated with
bootstrap
β€’ Lots of publications by Wilcox
844
Censored Regression
β€’ Tobit regression
– When a measure is censored
– E.g. unemployed people work 0 hours.
845