Generalized Additive Models

Similar documents
CH9.Generalized Additive Model

SAS/STAT 13.1 User s Guide. The GAM Procedure

SAS/STAT 12.3 User s Guide. The GAM Procedure (Chapter)

Lecture 24: Generalized Additive Models Stat 704: Data Analysis I, Fall 2010

Stat 8053, Fall 2013: Additive Models

9.2 User s Guide SAS/STAT. The GAM Procedure. (Book Excerpt) SAS Documentation

Generalized Additive Model

Statistics & Analysis. Fitting Generalized Additive Models with the GAM Procedure in SAS 9.2

Generalized Additive Models

Chapter 10: Extensions to the GLM

Generalized additive models I

Non-Linear Regression. Business Analytics Practice Winter Term 2015/16 Stefan Feuerriegel

STAT 705 Introduction to generalized additive models

Nina Zumel and John Mount Win-Vector LLC

Applied Statistics : Practical 9

Goals of the Lecture. SOC6078 Advanced Statistics: 9. Generalized Additive Models. Limitations of the Multiple Nonparametric Models (2)

This is called a linear basis expansion, and h m is the mth basis function For example if X is one-dimensional: f (X) = β 0 + β 1 X + β 2 X 2, or

CHAPTER 12 Additive Models

Statistics & Analysis. A Comparison of PDLREG and GAM Procedures in Measuring Dynamic Effects

GAMs semi-parametric GLMs. Simon Wood Mathematical Sciences, University of Bath, U.K.

Poisson Regression and Model Checking

Nonparametric Regression

SAS/STAT. Software: Changes and Enhancements, Release 8.2

Moving Beyond Linearity

Smoothing non-stationary noise of the Nigerian Stock Exchange All-Share Index data using variable coefficient functions

Using Multivariate Adaptive Regression Splines (MARS ) to enhance Generalised Linear Models. Inna Kolyshkina PriceWaterhouseCoopers

Lecture 17: Smoothing splines, Local Regression, and GAMs

Regression Lab 1. The data set cholesterol.txt available on your thumb drive contains the following variables:

Solution to Series 7

Lecture 7: Splines and Generalized Additive Models

Predictive Checking. Readings GH Chapter 6-8. February 8, 2017

Organizing data in R. Fitting Mixed-Effects Models Using the lme4 Package in R. R packages. Accessing documentation. The Dyestuff data set

Stat 500 lab notes c Philip M. Dixon, Week 10: Autocorrelated errors

Nonlinearity and Generalized Additive Models Lecture 2

Package gplm. August 29, 2016

Stat 5100 Handout #14.a SAS: Logistic Regression

STENO Introductory R-Workshop: Loading a Data Set Tommi Suvitaival, Steno Diabetes Center June 11, 2015

run ld50 /* Plot the onserved proportions and the fitted curve */ DATA SETR1 SET SETR1 PROB=X1/(X1+X2) /* Use this to create graphs in Windows */ gopt

Repeated Measures Part 4: Blood Flow data

Splines and penalized regression

Binary Regression in S-Plus

Lecture 16: High-dimensional regression, non-linear regression

An introduction to SPSS

Discussion Notes 3 Stepwise Regression and Model Selection

Using the SemiPar Package

Discriminant analysis in R QMMA

Multiple Linear Regression: Global tests and Multiple Testing

NONPARAMETRIC REGRESSION SPLINES FOR GENERALIZED LINEAR MODELS IN THE PRESENCE OF MEASUREMENT ERROR

1 The SAS System 23:01 Friday, November 9, 2012

Salary 9 mo : 9 month salary for faculty member for 2004

Moving Beyond Linearity

Nonparametric Regression

Orange Juice data. Emanuele Taufer. 4/12/2018 Orange Juice data (1)

SAS/STAT 14.3 User s Guide The GAMPL Procedure

ITSx: Policy Analysis Using Interrupted Time Series

Stat 4510/7510 Homework 4

Model Inference and Averaging. Baging, Stacking, Random Forest, Boosting

A Knitr Demo. Charles J. Geyer. February 8, 2017

Regression Analysis and Linear Regression Models

Regression Model Building for Large, Complex Data with SAS Viya Procedures

Stat 5303 (Oehlert): Response Surfaces 1

Splines. Patrick Breheny. November 20. Introduction Regression splines (parametric) Smoothing splines (nonparametric)

STAT Statistical Learning. Predictive Modeling. Statistical Learning. Overview. Predictive Modeling. Classification Methods.

Last time... Bias-Variance decomposition. This week

Regression on the trees data with R

THIS IS NOT REPRESNTATIVE OF CURRENT CLASS MATERIAL. STOR 455 Midterm 1 September 28, 2010

Package robustgam. February 20, 2015

Logistic Regression. (Dichotomous predicted variable) Tim Frasier

Minitab 17 commands Prepared by Jeffrey S. Simonoff

Outline. Topic 16 - Other Remedies. Ridge Regression. Ridge Regression. Ridge Regression. Robust Regression. Regression Trees. Piecewise Linear Model

Nonparametric Regression and Generalized Additive Models Part I

Paper CC-016. METHODOLOGY Suppose the data structure with m missing values for the row indices i=n-m+1,,n can be re-expressed by

EXST 7014, Lab 1: Review of R Programming Basics and Simple Linear Regression

Nonparametric Approaches to Regression

The theory of the linear model 41. Theorem 2.5. Under the strong assumptions A3 and A5 and the hypothesis that

Economics Nonparametric Econometrics

Statistics Lab #7 ANOVA Part 2 & ANCOVA

Chapter 1 Changes and Enhancements to SAS/STAT Software in Versions 7 and 8

Package robustgam. January 7, 2013

GAMs, GAMMs and other penalized GLMs using mgcv in R. Simon Wood Mathematical Sciences, University of Bath, U.K.

Machine Learning: Practice Midterm, Spring 2018

Lasso.jl Documentation

SAS/STAT 12.3 User s Guide. The TPSPLINE Procedure (Chapter)

Generalized additive models II

Predictive Analytics: Demystifying Current and Emerging Methodologies. Tom Kolde, FCAS, MAAA Linda Brobeck, FCAS, MAAA

Unit 5 Logistic Regression Practice Problems

Non-linear Modelling Solutions to Exercises

Chapter 6: Linear Model Selection and Regularization

Generalized Additive and Generalized Linear Modeling for Children Diseases

book 2014/5/6 15:21 page v #3 List of figures List of tables Preface to the second edition Preface to the first edition

Package FWDselect. December 19, 2015

NCSS Statistical Software

22s:152 Applied Linear Regression

A toolbox of smooths. Simon Wood Mathematical Sciences, University of Bath, U.K.

Nonparametric Risk Attribution for Factor Models of Portfolios. October 3, 2017 Kellie Ottoboni

Modelling Proportions and Count Data

SAS/STAT 14.1 User s Guide. The LOESS Procedure

Random Forest A. Fornaser

Machine Learning / Jan 27, 2010

Modelling Proportions and Count Data

Transcription:

Generalized Additive Models Statistics 135 Autumn 2005 Copyright c 2005 by Mark E. Irwin

Generalized Additive Models GAMs are one approach to non-parametric regression in the multiple predictor setting. The additive linear model is of the form E[Y X 1,..., X p ] = β 0 + β 1 X 1 +... + β p X p The generalized additive model in contrast is of the form µ(x) = E[Y X 1,..., X p ] = α + f 1 (X 1 ) +... + f p (X p ) As last time, the f j s are unspecified smooth nonparametric functions. The approach that is taken to fitting is to fit each function using a scatterplot smoother such as Generalized Additive Models 1

Cubic smoothing spline (available in S and SAS) LOESS (available in S and SAS) Kernel smoother (currently not available, but could be added to S in theory) Thin-plate splines, which allow for interactions between two predictor variables (available in R and SAS) When the data is fit, each scatterplot smoother is fit simultaneously using a backfitting algorithm. In R there are two libraries for fitting GAMS, gam which matches the S-Plus procedures and mgcv. mgcv takes a different approach to picking the amount of smoothness and the only one that will handle thin-plate splines. In the following examples, gam will be used, since it is consistent with S-Plus and the output from SAS, which will be focused on. Generalized Additive Models 2

In both packages, actually more general models can be fit. As mentioned, interactions can be added with the use of thin-plate splines. In addition, the semiparametric model can be fit. It has the form E[Y X, Z 1,..., Z q ] = Xβ + f 1 (Z 1 ) +... + f q (X q ) In this case, a parametric form is assumed for variables in the vector X. This may contain interactions between the Xs and categorical factors. Nonparametric relationships are assumed for Z 1,..., Z q, which in theory could have some of them be contained in X, though usually they are not. Both S and SAScan handle this extension. The final extension to this model, at least that I wish to discuss, is the extension to other distributions. So as in generalized linear models, the distribution of Y X can be specified. In addition a link function g(µ(x)) can be specified (at least in theory). Thus, for example, we could have the additive logistic model where Generalized Additive Models 3

( ) µ(x) log 1 µ(x) and Y X is binomially distributed. = α + f 1 (X 1 ) +... + f p (X p ) So the most general form of the generalized additive model has g(µ(x)) = E[Y X 1,..., X p ] = α + f 1 (X 1 ) +... + f p (X p ) for some link function g( ). The implementation in SAS only allows for the canonical link to be used. In S, I believe that any link function available in glm can be used in gam, which is the function used for describing GAMs. Generalized Additive Models 4

Example: New York Ozone Concentration A dataset with 111 observations taken from an environmental study that measured the four variables for 111 consecutive days. ozone: surface concentration of ozone in New York, in parts per million radiation: solar radiation temperature: observed temperature, in degrees Fahrenheit wind: wind speed, in miles per hour Generalized Additive Models 5

0 50 150 250 5 10 15 20 ozone 1 2 3 4 5 0 100 200 300 radiation temperature 60 70 80 90 5 10 15 20 wind 1 2 3 4 5 60 70 80 90 Generalized Additive Models 6

Lets fit this data with SAS. The general form of the PROC GAM is PROC GAM < option > ; CLASS variables ; MODEL dependent = < PARAM(effects) > smoothing effects < /options > ; SCORE data=sas-data-set out=sas-data-set ; OUTPUT <out=sas-data-set> keyword <...keyword> ; BY variables ; ID variables ; FREQ variable ; Generalized Additive Models 7

Most of the options are as we have discussed before. The two important ones are MODEL dependent = < PARAM(effects) > smoothing effects </options >: Describes the model. possibilities Model terms can be added by the following PARAM(x): Adds a linear term in x to the model SPLINE(x): Fits smoothing spline with the variable x. Degree of smoothness can be controlled by DF (default = 4). LOESS(x): Fits local regression with variable x. Degree of smoothness can be controlled by DF (default = 4). SPLINE2(x,y): Fits bivariate thin-plate smoothing spline in x and y. Degree of smoothness can be controlled by DF (default = 4). At least one model term must be defined, though any combination of these is fine. Generalized Additive Models 8

There are two important options for the MODEL statement. They are METHOD = GCV: Chooses smoothing parameters by generalized cross validation. If DF is set for a variable, that choice overrides the GCV. DIST = : Specifies the conditional distribution of the response variable. The choices are GAUSSIAN (default), BINARY, BINOMIAL, GAMMA, IGAUSSIAN, and POISSON. As mentioned before, only the canonical link can be used in each case. SCORE data=sas-data-set out=sas-data-set: Allow for fits to be generated for levels of the predictor variables of interest and stored in SAS dataset. Generalized Additive Models 9

Lets look at the fits of the New York ozone data, generated by the code ods html; ods graphics on; PROC GAM DATA = air PLOTS(CLM COMMONAXES); MODEL Ozone = SPLINE(Radiation) SPLINE(Wind) SPLINE(Temperature); OUTPUT OUT = air_spline PREDICTED RESIDUAL; RUN; ods graphics off; ods html close; Note that the ODS graphics system is an experimental graphics system in SAS which allows for generation of the plots that follow. It also generates text output in a number of forms. The example done generates output compatible with web sites (html). This was done as I wanted to get the graphics in gif format so I could convert them to postscript. Generalized Additive Models 10

The GAM Procedure Dependent Variable: ozone Smoothing Model Component(s): spline(radiation) spline(wind) spline(temperature) Summary of Input Data Set Number of Observations 111 Number of Missing Observations 0 Distribution Gaussian Link Function Identity Iteration Summary and Fit Statistics Final Number of Backfitting Iterations 7 Final Backfitting Criterion 5.4325795E-9 The Deviance of the Final Estimate 19.942887908 The local score algorithm converged. Generalized Additive Models 11

Regression Model Analysis Parameter Estimates Parameter Standard Parameter Estimate Error t Value Pr > t Intercept 0.15594 0.49095 0.32 0.7514 Linear(radiation) 0.00235 0.00049382 4.76 <.0001 Linear(wind) -0.07317 0.01393-5.25 <.0001 Linear(temperature) 0.04351 0.00540 8.06 <.0001 Smoothing Model Analysis Fit Summary for Smoothing Components Num Smoothing Unique Component Parameter DF GCV Obs Spline(radiation) 0.999893 3.000000 0.182513 93 Spline(wind) 0.991577 3.000000 0.206527 28 Spline(temperature) 0.997312 3.000000 0.157737 39 Generalized Additive Models 12

Smoothing Model Analysis Analysis of Deviance Sum of Source DF Squares Chi-Square Pr > ChiSq Spline(radiation) 3.00000 1.380892 6.7858 0.0790 Spline(wind) 3.00000 2.998911 14.7367 0.0021 Spline(temperature) 3.00000 2.864131 14.0744 0.0028 Generalized Additive Models 13

Generalized Additive Models 14

The graphic shows the spline fits of the three effects after the linear trend has been removed. This model can also be fit in R will the following code library(gam) # only needs to be run once per session # fit linear model for comparison air.lm <- lm(log(ozone) ~ radiation + wind + temperature, data=air) # fit additive model air.gam <- gam(log(ozone) ~ s(radiation) + s(wind) + s(temperature), data=air) summary(air.gam) anova(air.lm,air.gam) The s function fits a cubic spline for the desired variable. It also takes a df argument with 4 as a default. The output Generalized Additive Models 15

> summary(air.gam) Call: gam(formula = log(ozone) ~ s(radiation) + s(wind) + s(temperature), data = air) Deviance Residuals: Min 1Q Median 3Q Max -0.61526-0.08185-0.01468 0.10474 0.33293 (Dispersion Parameter for gaussian family taken to be 0.0248) Null Deviance: 9.1633 on 110 degrees of freedom Residual Deviance: 2.4334 on 98 degrees of freedom AIC: -81.0436 Number of Local Scoring Iterations: 2 Generalized Additive Models 16

DF for Terms and F-values for Nonparametric Effects Df Npar Df Npar F Pr(F) (Intercept) 1 s(radiation) 1 3 2.8496 0.04135 * s(wind) 1 3 3.4753 0.01893 * s(temperature) 1 3 2.9350 0.03717 * --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05. 0.1 1 > anova(air.lm,air.gam) Analysis of Variance Table Model 1: log(ozone) ~ radiation + wind + temperature Model 2: log(ozone) ~ s(radiation) + s(wind) + s(temperature) Res.Df RSS Df Sum of Sq F Pr(>F) 1 107 3.07416 2 98 2.43337 9 0.64079 2.8674 0.004797 ** Generalized Additive Models 17

s(radiation) 0.4 0.2 0.0 0.2 0.4 s(wind) 0.4 0.2 0.0 0.2 0.4 s(temperature) 0.4 0.2 0.0 0.2 0.4 0 50 100 200 300 radiation 5 10 15 20 wind 60 70 80 90 temperature par(mfrow = c(1,3), pty="s") plot(air.gam, se=t, ylim=c(-0.45,0.4)) The S plots of the fits don t remove the linear trend. Generalized Additive Models 18

Another example run in SAS is PROC GAM DATA = air PLOTS(CLM COMMONAXES); MODEL Ozone = SPLINE2(Radiation,Wind) LOESS(Temperature, DF=5); which gives output Iteration Summary and Fit Statistics Final Number of Backfitting Iterations 10 Final Backfitting Criterion 2.4527292E-9 The Deviance of the Final Estimate 22.048500672 The local score algorithm converged. Generalized Additive Models 19

Regression Model Analysis Parameter Estimates Parameter Standard Parameter Estimate Error t Value Pr > t Intercept 3.24778 0.04435 73.23 <.0001 Smoothing Model Analysis Fit Summary for Smoothing Components Num Smoothing Unique Component Parameter DF GCV Obs Spline2(radiation wind) 43.311111 4.000000 0.217817 110 Loess(temperature) 0.301802 5.020171 0.002044 111 Generalized Additive Models 20

Smoothing Model Analysis Analysis of Deviance Sum of Source DF Squares Chi-Square Pr > ChiSq Spline2(radiation wind) 4.00000 9.024662 41.3320 <.0001 Loess(temperature) 5.02017 18.765081 85.9421 <.0001 The following graphic suggests that there probably isn t an interaction since the change in colour is roughly the same for each level of wind. If there was an interaction, I would expect to see a diagonal pattern in the second graph. Generalized Additive Models 21

Generalized Additive Models 22