The GAMMOD Procedure
Example 6.3 Nonparametric Tweedie Regression
This example illustrates how you can use the GAMMOD procedure to fit a nonparametric regression model with spline effects for a response variable that has a Tweedie distribution.
You can view this model as a generalized linear model because the Tweedie distribution belongs to the exponential family. The Tweedie distribution is particularly useful for modeling response variables that are continuous for positive values and take the value 0 with a positive probability. For example, in the insurance industry the Tweedie distribution is often assumed for claims, which are positive for customers who have filed claims and are 0 for other customers. You can use the Tweedie distribution to model such response variables without special transformations.
The GENSELECT procedure can fit Tweedie regression models that incorporate linear effects for the covariates. However, as demonstrated in this example, the assumption of linearity can be too restrictive, and you might want to use the GAMMOD procedure to explore the nonlinear dependency structures in the data.
The following DATA step simulates a response variable Y by using a Tweedie distribution and four continuous predictors. Each continuous predictor is sampled independently from the uniform distribution . The linear predictor for the true model is formed by applying additive nonlinear transformations to , , and :
The predictor is a nuisance parameter that does not enter the model. The parameters for the Tweedie distribution are and , and the link function is , where the expected value is and the variance is . The power parameter p controls the variance of the distribution. When p is between 1 and 2, as in this example, a Tweedie random variable can be generated from a compound Poisson distribution (Smyth 1996).
title 'Nonparametric Tweedie Model';
%let phi=0.4;
%let power=1.5;
data mycas.one;
do i=1 to 1000;
/* Sample the predictors */
x1=ranuni(1);
x2=ranuni(1);
x3=ranuni(1);
x4=ranuni(1);
/* Apply nonlinear transformations to predictors */
f1=2*sin(3.14159265*x1);
f2=exp(2*x2)*0.8;
f3=0.2*x3**11*(10*(1-x3))**6+10*(10*x3)**3*(1-x3)**10;
xb=f1+f2+f3;
xb=xb/20;
mu=exp(xb);
/* Compute parameters of compound Poisson distribution */
lambda=mu**(2-&power)/(&phi*(2-&power));
alpha=(2-&power)/(&power-1);
gamma=&phi*(&power-1)*(mu**(&power-1));
/* Simulate the response */
rpoi=ranpoi(1,lambda);
if rpoi=0 then y=0;
else do;
y=0;
do j=1 to rpoi;
y=y+rangam(1,alpha);
end;
y=y*gamma;
end;
output;
end;
run;
You can use PROC GENSELECT to fit a parametric model for Y by using the following statements:
proc genselect data=mycas.one; model y=x1 x2 x3 x4/dist=tweedie; run;
Equivalently, you can also use PROC GAMMOD to fit a parametric linear model by using the PARAM option in the MODEL statement, as shown in the following statements.
proc gammod data=mycas.one seed=1234; model y=param(x1 x2 x3 x4)/dist=tweedie; run;
The “Fit Statistics” table in Output 6.3.1 shows the summary statistics for the fitted parametric Tweedie model.
Output 6.3.1: Fit Statistics
The “Parameter Estimates” table in Output 6.3.2 shows the estimates for regression parameters in addition to dispersion and power parameters ( and p).
Output 6.3.2: Parameter Estimates
If you are uncertain about the relationship between the linked mean for the fitted Tweedie model and the covariates, you can add spline terms to the model to explore possible nonlinear dependence. The following statements fit a nonparametric Tweedie model and produce a plot of fitted smoothing components.
proc gammod data=mycas.one seed=1234 plots; model y=spline(x1) spline(x2) spline(x3) spline(x4)/dist=tweedie; run;
The “Fit Statistics” table in Output 6.3.3 shows the summary statistics for the fitted nonparametric Tweedie model. Compared to the parametric model, the nonparametric model has more effective degrees of freedom, but smaller AIC and AICC values. The penalized likelihood value is larger for the nonparametric model. These statistics indicate that the nonparametric model provides a better fit.
Output 6.3.3: Fit Statistics
| Nonparametric Tweedie Model |
| Fit Statistics | |
|---|---|
| Penalized Log Likelihood | -1157.17502 |
| Roughness Penalty | 2.62230 |
| Effective Degrees of Freedom | 14.11920 |
| Effective Degrees of Freedom for Error | 983.62098 |
| AIC (smaller is better) | 2339.96615 |
| AICC (smaller is better) | 2340.39965 |
| BIC (smaller is better) | 2409.25974 |
| GCV (smaller is better) | 0.39845 |
The “Regression Parameter Estimates” table in Output 6.3.4 lists the estimate for the intercept, in addition to the estimates for the dispersion and power parameters for the Tweedie model. Both variance parameters are close to the true values.
Output 6.3.4: Regression Parameter Estimates
The “Estimates for Smoothing Components” table in Output 6.3.5 shows the fitted information for the spline terms in the model. The degrees of freedom value and the roughness penalty value suggest some moderate nonlinear relationship between the linked mean and the three covariates , , and . The spline term for the nuisance parameter has a linear form.
Output 6.3.5: Estimates for Smoothing Components
The “Tests for Smoothing Components” table in Output 6.3.6 shows the approximate Wald test for the four spline terms. The spline term for the nuisance predictor is not significant.
Output 6.3.6: Tests for Smoothing Components
Output 6.3.7 displays the “Smoothing Component Panel” for all the spline terms used in the model. For , , and , the fitted curves are reasonably smooth and close to the true functions. For , the spline plot shows a strictly linear fit, with 95% Bayesian confidence bands covering the horizontal line at 0. This reinforces the conclusion that does not contribute to the model and can be removed from further analysis.
Output 6.3.7: Smoothing Component Panel
