The UCM Procedure

Example 42.6 Using Splines to Incorporate Nonlinear Effects

(View the complete code for this example.)

The data in this example are created to mirror the electricity demand and temperature data recorded at a utility company in the midwest region of the United States. The data set (not shown), utility, has three variables: load, temp, and date. The load column contains the daily electricity demand, the temp column has the average daily temperature readings, and the date column records the observation date.

The following statements produce a plot, shown in Output 42.6.1, of electricity load versus temperature. Clearly the relationship is smooth but nonlinear: the load generally increases when the temperatures are away from the comfortable sixties.

proc sgplot data=utility;
    loess x=temp y=load / smooth=0.4;
run;

Output 42.6.1: Load versus Temperature Plot

Load versus Temperature Plot


The time series plot of the load (not shown) also shows that, apart from a day-of-the-week seasonal effect, there are no additional easily identifiable patterns in the series. The series has no apparent upward or downward trend. The following statements fit a UCM to the series that takes into account these observations. The particular choice of the model is a result of a little modeling exercise that compared a small number of competing models. The chosen model is adequate but by no means the best possible. The temperature effect is modeled by a deterministic three-degree spline with knots at 30, 40, 50, 60, and 75. The knot locations and the degree were chosen by visual inspection of the plot (Output 42.6.1). An autoreg component is used in place of the simple irregular component, which improved the residual analysis. The last 60 days of data are withheld for out-of-sample forecast evaluation (note the BACK= option in both the ESTIMATE and FORECAST statements). The OUTLIER statement is used to increase the number of outliers reported to 10. Since no CHECKBREAK option is used in the LEVEL statement, only the additive outliers are searched. In this example the use of the EXTRADIFFUSE= option in the ESTIMATE and FORECAST statements is useful for discarding some early one-step-ahead forecasts and residuals with large variance.

proc ucm data=utility;
   id date interval=day;
   model load;
   autoreg;
   level plot=smooth;
   splinereg temp knots=30 40 50 65 75 degree=3
      variance=0 noest;
   season length=7 var=0 noest;
   estimate plot=panel back=60
      extradiffuse=50;
   outlier maxnum=10;
   forecast back=60 lead=60
      extradiffuse=50;
run;

The parameter estimates are given in Output 42.6.2, and the residual goodness-of-fit statistics are shown in Output 42.6.3. The residual diagnostic plots are shown in Output 42.6.4. The ACF and PACF plots appear satisfactory, but the normality plots, particularly the Q-Q plot, show possible violations. It appears that, at least in part, this nonnormal behavior of the residuals might be attributable to the outliers in the series. The outlier summary table, Output 42.6.5, shows the most likely outlying observations. Notice that most of these outliers are holidays, like July 4th, when the electricity load is lower than usual for that day of the week.

Output 42.6.2: Electricity Load: Parameter Estimates

The UCM Procedure

Final Estimates of the Free Parameters
ComponentParameterEstimateApprox
Std Error
t ValueApprox
Pr > |t|
LevelError Variance0.211850.050254.22<.0001
AutoRegDamping Factor0.575220.0346616.60<.0001
AutoRegError Variance2.210570.2047810.79<.0001
tempSpline Coefficient_14.725021.939972.440.0149
tempSpline Coefficient_22.191161.712431.280.2007
tempSpline Coefficient_3-7.144921.56805-4.56<.0001
tempSpline Coefficient_4-11.399501.45098-7.86<.0001
tempSpline Coefficient_5-16.380551.36977-11.96<.0001
tempSpline Coefficient_6-18.760751.28898-14.55<.0001
tempSpline Coefficient_7-8.046281.09017-7.38<.0001
tempSpline Coefficient_8-2.305251.25102-1.840.0654


Output 42.6.3: Electricity Load: goodness-of-fit

Fit Statistics Based on Residuals
Mean Squared Error2.90945
Root Mean Squared Error1.70571
Mean Absolute Percentage Error2.92586
Maximum Percent Error14.96281
R-Square0.92739
Adjusted R-Square0.92721
Random Walk R-Square0.69618
Amemiya's Adjusted R-Square0.92684
Number of non-missing residuals used for computing the fit statistics = 791


Output 42.6.4: Electricity Load: Residual Diagnostics

Electricity Load: Residual Diagnostics


Output 42.6.5: Additive Outliers in the Electricity Load Series

ObsTimeEstimateStdErrChiSqDFProbChiSq
128104JUL2002-7.999081.341748635.541<.0001
91604JUL2001-6.557781.33843124.011<.0001
32925NOV1999-5.850471.337973519.121<.0001
97703SEP2001-5.672541.338913817.951<.0001
134102SEP2002-5.496311.33784316.881<.0001
69323NOV2000-5.279681.337436815.581<.0001
91503JUL20015.065571.337527314.3410.0002
105722NOV2001-5.015501.338618414.0410.0002
55104JUL2000-4.899651.338155713.4110.0003
87928MAY2001-4.761351.337534912.6710.0004


The plot of the load forecasts for the withheld data is shown in Output 42.6.6.

Output 42.6.6: Electricity Load: Forecast Evaluation of the Withheld Data

Electricity Load: Forecast Evaluation of the Withheld Data


Last updated: May 22, 2025