GENERALIZED LINEAR MODELS
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
GENERALIZED LINEAR MODELS
OVERVIEW
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
OVERVIEW GENERAL LINEAR MODELS
yi 0 1 x1i
k xki i
2
i ~ i.i.d . N (0, )
var( yi )
2
Actually, proc glm
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
OVERVIEW GENERALIZED LINEAR MODELS
g ( E ( yi )) 0 1 x1i … k xki X
•
•
•
The distributon of the observatons can come from the
exponental family of distributons.
The variance of the response variable is a specifed
functon of its mean.
X is ft to a functon of E(y) (called a link functon)
suggested by the distributon of the observatons:
g(E(y)) = g() = X
Link functin
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
OVERVIEW LOGIT LINK FUNCTION FOR BINARY RESPONSE
p
logit( p ) log
1
p
Logit (pi)
pi
Logit
Transform
Predictor
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
Predictor
OVERVIEW LOG LINK FUNCTION FOR COUNT DATA
Count
Log(count)
Log
Transform
Predictor
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
Predictor
OVERVIEW EXAMPLES OF GENERALIZED LINEAR MODELS
*Models often use the LOG link in practice.
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
POISSON REGRESSION
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
POISSON REGRESSION PROPERTIES AND EXAMPLES
• is one type of generalized linear model
• assumes that the response variable follows a
Poisson distributon conditonal on the values of
the predictor variables
• can be used to model the number of
occurrences of an event of interest or the rate of
occurrence of an event of interest as a functon
of some predictor variables
• is most appropriate for rare events
• Response dist. should have small mean (<10 or even
<5 and ideally ~1)
• If no, gamma and lognormal could be beter choice
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
Examples include
• number of ear infections in
infants
• number of equipment failures
• colony counts for bacteria or
viruses
• counts of a rare disease in a
population
• number of fatal crashes at an
intersection
• homicide rates in a given state
• rate of insurance claims
• number of infected areas per
unit volume of a tree
• response rates to a marketing
campaign
POISSON REGRESSION POISSON VERSUS NORMAL DISTRIBUTION
Poisson distributon
• is skewed to the right for rare events
• is for nonnegatve integer values
• has only one parameter (the mean)
• has a variance that is equal to the mean
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
Normal distributon
• is symmetric
• can be for negatve as well as positve real values
• has two unrelated parameters (mean and variance)
POISSON REGRESSION MODEL
log( ) 0 1 X 1 2 X 2 ... k X k
e
( 0 1 X1 2 X 2 ... k X k )
e e
0
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
1 X1
e
2 X 2
e
k X k
POISSON REGRESSION PARAMETER ESTIMATES
ˆ
e
multiplicative effect on
̂
for a one-unit change in X.
Example 1, if
ˆ1
e
1.20, then a one-unit increase in X1 yields
a 20% increase in the estimated mean.
Example 2, if
e
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
ˆ2
0.80, then a one-unit increase in X2 yields
a 20% decrease in the estimated mean.
POISSON REGRESSION ПРИМЕР: ДАННЫЕ
Number if Self-Diagnised Ear Infectins
Age in Years
Frequent ir Occasiinal
Ocean Swimmer
Typical Swimming
Licatin
Gender
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
POISSON REGRESSION CATEGORICAL
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
Male
Gender
Female
nonBeach
Typical Swimming
Licatin
Beach
Occasional
Freq
Frequent ir Occasiinal
Ocean Swimmer
POISSON REGRESSION INTERVAL
Age in Years
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
POISSON REGRESSION ПРИМЕР
proc genmod data=sasuser.earinfection;
class Swimmer (param=ref ref='Freq')
Location (param=ref ref='Beach')
Gender (param=ref ref='Male');
model infections = swimmer location gender age age*age
/ dist=poisson link=log type3;
run;
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
POISSON REGRESSION ПРИМЕР: PROC GENMOD OUTPUT
Scale = 1*
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
POISSON REGRESSION OVERDISPERSION
• Poisson regression models assume the
variance is equal to the mean.
• Count data ofen exhibit variability exceeding
the mean.
• Overdispersion leads to underestmates of the
standard errors of parameter estmates.
WHAT TO DO
•
•
Use the negatve binomial
distributon [NOW]
Apply a multplicatve adjustment
factor (PSCALE or DSCALE opton in
the MODEL statement) [HW]
• Overdispersion results in overestmates of the
test statstc and liberal p-values.
• Subject heterogeneity due to an under-specifed model
• Outliers in the data
• Positve correlaton between the responses in clustered data
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
NEGATIVE BINOMIAL REGRESSION
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
NEGATIVE BINOMIAL
DISTRIBUTION AND MODEL
REGRESSION
The negatve binomial distributon
• is the distributon for count data that permits the variance to exceed
the mean
• enables the model to have greater fexibility in modeling the
relatonship between the mean and the variance of the response
variable than the Poisson model
Response
Variable
Distribution
Link
Function
Count
Negative
Binomial
Natural Log
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
Variance
Function
k
2
NEGATIVE BINOMIAL
DISPERSION PARAMETER K
REGRESSION
• The dispersion parameter k is not allowed to vary over observatons.
• The limitng case when the parameter k is equal to 0 corresponds to a
Poisson regression model.
• When the parameter is greater than 0, overdispersion is evident and
the standard errors will increase. The fted values are similar, but the
larger standard errors refect the overdispersion uncaptured with the
Poisson model.
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
NEGATIVE BINOMIAL
ПРИМЕР
REGRESSION
proc genmod data=sasuser.earinfection;
class Swimmer (param=ref ref='Freq')
Location (param=ref ref='Beach')
Gender (param=ref ref='Male');
model infections = swimmer location gender age age*age
/ dist=negbin link=log type3;
run;
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
NEGATIVE BINOMIAL
ПРИМЕР: PROC GENMOD OUTPUT
REGRESSION
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
POISSON REGRESSION FOR RATES
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
POISSON REGRESSION:
RATES DATA: DEFINITION & EXAMPLES
RATES
• When events occur over tme, space, or
some other index of exposure, it is more
relevant to model the rate at which they
occur rather than the number of events.
• Rates provide the necessary
standardizaton to make the outcomes
comparable.
• You use the OFFSET= opton in the
MODEL statement in PROC GENMOD.
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
• How crime rates are related to the
city’s unemployment rate
• How melanoma incidence rates are
related to demographic variables
• How the rate of loan defaults is
related to region of the country
• How response rates to marketing
campaigns relate to known
characteristics of the recipients
POISSON REGRESSION:
RATES DATA: OFFSET
RATES
log 0 1 x1 … k xk
T
log( ) log(T ) 0 1 x1 … k xk
OFFSET = Variable
T * e
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
( 0 1 x1 … k xk )
•
Log(T) is called the ofset variable
that has a coefcient equal to 1.
•
The ofset variable makes the
fted rate proportonal to the
index of exposure.
•
For example, using the log of the
populaton as an ofset variable is
the same as modeling the mean
number of events proportonal to
populaton size.
POISSON REGRESSION:
SKIN CANCER IN TEXAS AND MINNESOTA
RATES
City: Minneapolis-St. Paul
Dallas-Fort Worth
Incidence if
ninmelanima
skin cancer
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
Age_ 15-24
Group: 25-34
35-44
45-54
55-64
65-74
75-84
85+
POISSON REGRESSION:
ПРИМЕР
RATES
proc genmod data=sasuser.skin;
class City (param=ref ref='MSP')
Age (param=ref ref='85+');
model cases = city age
/ offset=log_pop dist=poisson link=log type3;
run;
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
ZERO-INFLATED POISSON MODEL
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
ZIP PURPOSE
•
In some setngs, the incidence of zero counts will be much greater
than expected for the Poisson distributon.
•
Poisson regression models will exhibit overdispersion when they are
ft to data with an excess number of zeros.
•
Zero-infated Poisson (ZIP) models might be a beter ft to the data.
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
ZIP MODEL
•
The populaton that can be modeled with the zero-infated Poisson distributon
is considered to consist of two types of responses.
•
The frst type gives Poisson distributed counts, which can produce the zero
outcome or some other positve outcome.
•
The second type always gives a zero count.
•
Therefore, the relevant distributon is a mixture of a Poisson distributon and a
distributon that is constant at zero.
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
ZIP COMPONENTS
g (i ) xi
MODEL statement
h(i ) zi
ZEROMODEL statement
proc genmod data=sasuser.roots;
class bap photoperiod;
model roots = photoperiod | bap
/ dist=zip link=log type3;
zeromodel photoperiod;
run;
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
ZIP ПРИМЕР: ДАННЫЕ
photoperiod
(hour)
8
16
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
concentration (M)
2.2
4.4
8.8
17.6
Number of
roots
Number of
roots
Number of
roots
Number of
roots
Number of
roots
Number of
roots
Number of
roots
Number of
roots
8 hours
16 hours
ZIP ПРИМЕР
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
ZIP ПРИМЕР: РЕЗУЛЬТАТЫ
dist=zinb
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
GAMMA REGRESSION
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
GAMMA DISTRIBUTION
•
•
•
is a skewed distributon for positve values
has a variance that is proportonal to the squared mean
has lighter tails than a lognormal distributon
gamma
Var(y) [E(y)]2
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
DISTRIBUTIONS COMPARISON
Distribution
Variance
Normal (truncated)
constant*
Poisson
E(Y)
Gamma
(E(Y))2
Lognormal
(E(Y))2
100x
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
GAMMA REGRESSION ПРИМЕР
proc univariate data=car;
var price;
histogram / gamma (alpha=est sigma=est theta=est color=blue w=2)
vaxis=0 to 14 by 2 midpoints=8 to 50 by 2;
run;
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
GAMMA REGRESSION REG AND GENMOD RESULTS: RESIDUAL
proc genmod data=car;
model price = hwympg hwympg2 horsepower
/ dist=gamma link=log /*identity*/ obstats id=model;
run;
PROC REG
PROC GENMOD, link=lig
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
PROC GENMOD, link=identty
SUMMARY
•
•
Problem:
• nonconstant variance
PROBLEM fir OLS
Approaches:
Transform the dependent variable Price (log).
Fit a gamma regression model with the log link functon.
Fit a gamma regression model with the identty link functon.
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
?
СТРАХОВАНИЕ
CASE STUDY
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
GENMOD СТРАХОВАНИЕ
• Frequency - how ofen claims are made
• Severity
• A typical way to model severity (claim amount) is
by using a gamma distributon with a log link
functon
• Pure premium - it is the porton of the company’s
expected cost that is “purely” atributed to loss
• does not include the general expense of doing
business
• Tweedie distributon
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
GLM СТРАХОВАНИЕ: FREQUENCY & PURE PREMIUM
• ZIP
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
• Tweedie distributon –
• PROC SEVERITY SAS/ETS
СПАСИБО!
Copy right © 2013, SAS I nst it ute I nc . All rights reserved.
sas.com