|
|
|
||||
|
Stat Computing > SAS > FAQ
|
Help the Stat Consulting Group by
giving a gift
| ||||
|
Loading
|
|||||
Proc transreg performs transformation regression in which both the outcome and predictor(s) can be transformed and splines can be fit. Splines are piecewise polynomials that can be used to estimate relationships that are difficult to fit with a single function.
In this page, we will walk through an example proc transreg with the spline option and explore its defaults. The bspline, spline, and pspline options, when similarly specified, yield the same results. Their differences lie in the number and type of transformed variables generated for estimation. For more information on the other options available, see the SAS Online Documentation.
We can begin by creating a dataset with an outcome Y and a predictor X. This example data is generated in the SAS examples for proc transreg.
data a; x=-0.000001; do i=0 to 199; if mod(i,50)=0 then do; c=((x/2)-5)**2; if i=150 then c=c+5; y=c; end; x=x+0.1; y=y-sin(x-c); output; end; run; proc gplot data = a; plot y*x; run;
Clearly, there is not a single, continuous function relating Y to X. The relationship does not appear random, but it does appear to change with X. Thus it makes sense to try to fit this with splines. Before running the proc transreg, we can see that our data contains four variables:
proc print data = a (obs = 5); run; Obs X I C Y 1 0.10000 0 25.0000 24.7694 2 0.20000 1 25.0000 24.4427 3 0.30000 2 25.0000 24.0234 4 0.40000 3 25.0000 23.5155 5 0.50000 4 25.0000 22.9241
In the proc transreg command, we indicate in the model line that we wish to predict variable y without transformation with identity(y). If we wished to model a transformed version of y (the log or rank of y, for example), we would indicate the transformation here. To predict y, we indicate that we wish to use a B-spline transformation with spline(x) (NOTE: There is also a bspline option that indicates you wish to expand each predictor to a B-spline basis). We also opted to output a dataset, a2, containing predicted values from the model.
proc transreg data=a;
model identity(y) = spline(x);
output out = a2 predicted;
run;
The TRANSREG Procedure
TRANSREG MORALS Algorithm Iteration History for Identity(Y)
Iteration Average Maximum Criterion
Number Change Change R-Square Change Note
-------------------------------------------------------------------------
1 0.71380 3.62827 0.10061
2 0.00000 0.00000 0.46884 0.36824 Converged
We can see in the outcome above that the model converged in the second iteration and has an R-squared value of 0.47. Let's look at the dataset output by proc transreg.
proc print data = a2 (obs = 5); run; Obs _TYPE_ _NAME_ Y TY PY Intercept X TIntercept TX 1 SCORE ROW1 24.7694 24.7694 24.1144 1 0.10000 1 21.1001 2 SCORE ROW2 24.4427 24.4427 23.4722 1 0.20000 1 20.5123 3 SCORE ROW3 24.0234 24.0234 22.8424 1 0.30000 1 19.9357 4 SCORE ROW4 23.5155 23.5155 22.2249 1 0.40000 1 19.3704 5 SCORE ROW5 22.9241 22.9241 21.6195 1 0.50000 1 18.8162
In addition to adding the predicted values, py, to the dataset, we can see that there are two new variables, ty and tx. The ty variable is the "transformed" values of y (since our transformation was the identity, these values are the same as y). The tx variable represents the transformation of x that yields the best linear fit when we predict y with tx. Though it is not made obvious in the procedure's output or the generated dataset, proc transreg fits a degree-3 polynomial with zero knots by default for the spline option.
We can plot the predicted values to see how closely they match the original data.
legend label=none value=('y' 'predicted y') position=(bottom left inside) mode=share down = 2; proc gplot data = a2; plot (y py)*x / overlay legend = legend; run;
If we were to regress y on tx, our model would have the same R-Squared value as that shown in the proc transreg output.
proc reg data = a2; model y = tx; run;
The REG Procedure
Model: MODEL1
Dependent Variable: Y
Number of Observations Read 200
Number of Observations Used 200
Analysis of Variance
Sum of Mean
Source DF Squares Square F Value Pr > F
Model 1 7955.26078 7955.26078 174.77 <.0001
Error 198 9012.65604 45.51846
Corrected Total 199 16968
Root MSE 6.74674 R-Square 0.4688
Dependent Mean 12.04335 Adj R-Sq 0.4662
Coeff Var 56.02042
Parameter Estimates
Parameter Standard
Variable Label DF Estimate Error t Value Pr > |t|
Intercept Intercept 1 1.06482 0.95772 1.11 0.2676
TX X Transformation 1 1.09239 0.08263 13.22 <.0001
Note that the default settings for bspline, spline, and pspline yield identical fitted values.
UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services