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

Nonparametric Tweedie Model

The GAMMOD Procedure

Fit Statistics
Penalized Log Likelihood-1178.69507
Roughness Penalty0
Effective Degrees of Freedom7.00000
Effective Degrees of Freedom for Error993.00000
AIC (smaller is better)2371.39014
AICC (smaller is better)2371.50305
BIC (smaller is better)2405.74443


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

Parameter Estimates
ParameterDFEstimateStandard
Error
Chi-SquarePr > ChiSq
Intercept10.4418320.06733443.0565<.0001
x11-0.0437250.0649650.45300.5009
x210.2022420.0642169.91880.0016
x31-0.2539200.06662514.52500.0001
x41-0.0610980.0660400.85590.3549
Dispersion10.4160010.016987  
Power11.5245810.048675  


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

The GAMMOD Procedure

Fit Statistics
Penalized Log Likelihood-1157.17502
Roughness Penalty2.62230
Effective Degrees of Freedom14.11920
Effective Degrees of Freedom for Error983.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

Parameter Estimates
ParameterDFEstimateStandard
Error
Chi-SquarePr > ChiSq
Intercept10.3568250.018329379.0079<.0001
Dispersion10.4004590.518084  
Power11.5017711.514451  


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

Estimates for Smoothing Components
ComponentEffective
DF
Smoothing
Parameter
Roughness
Penalty
Number of
Parameters
Rank of
Penalty
Matrix
Number of
Knots
Spline(x1)2.109690.95600.56599101000
Spline(x2)2.383400.56040.38149101000
Spline(x3)5.626080.01451.67509101000
Spline(x4)1.000021330783.662E-69101000


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

Tests for Smoothing Components
ComponentEffective
DF
Effective
DF for Test
F ValuePr > F
Spline(x1)2.1096934.760.0027
Spline(x2)2.38340313.64<.0001
Spline(x3)5.62608749.02<.0001
Spline(x4)1.0000210.880.3484


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

Smoothing Component Panel


Last updated: December 21, 2018