Contents: | Purpose / Requirements / Usage / Details |
BY 0.01
value in the first DATA step to see how well (or how poorly) this
method works when there are more (or fewer) x values in the input
data set for this curve.
Under certain conditions, as in this example, a cubic spline as fit by PROC EXPAND offers a good approximation of the underlying function. In this case, the exact derivative values computed from the spline are close approximations to the actual derivative values of the underlying function.
Likewise, it's true that if the spline poorly approximates the underlying function, then the exact derivatives of the spline will poorly approximate the actual function derivatives. So the quality of the derivative approximation depends on how closely the cubic smoothing spline approximates the underlying function.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
**** Generate some data ;
data one;
do x=-2 to 2 by 0.01;
y=(x-2)*(x-1.5)*(x-1)*(x-.5)*x*(x+.5)*(x+1)*(x+1.5)*(x+2);
output;
end;
run;
**** Plot Y vs X ;
proc gplot data=one;
title 'Original Series';
plot y*x;
run;
proc sort data=one;
by x;
run;
**** Compute the first derivative of the fitted spline ;
proc expand data=one outest=two out=three ;
convert y=slope/observed=(beginning,derivative);
id x;
run;
**** Clip the slope when abs(slope)>20 so that the graph appears clearly ;
data four;
set three;
deriv1=slope;
if slope >20 then deriv1=20;
if slope <-20 then deriv1=-20;
run;
**** Create the graph of Y vs X and DERIV1 vs X ;
proc gplot data=four;
title 'Series and First Derivative';
title2 'DERIV1 is clipped at -20/20';
plot (y deriv1)*x/overlay;
run;
**** Compute the second derivative ;
proc expand data=four out=five;
convert slope=deriv/observed=(beginning,derivative);
id x;
run;
**** Clip the values of the second derivative ;
data six;
set five;
deriv2=deriv;
if deriv >25 then deriv2=25;
if deriv <-25 then deriv2=-25;
run;
proc gplot data=six(firstobs=2);
title 'Series, First Derivative and Second Derivative';
title2 'DERIV1 is clipped at -20/20';
title3 'DERIV2 is clipped at -25/25';
plot (y deriv1 deriv2)*x / overlay;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> EXPAND Analytics ==> Missing Value Imputation Analytics ==> Time Series Analysis Analytics ==> Transformations Analytics ==> Financial Data Access and Manipulation |
Date Modified: | 2022-01-07 14:05:33 |
Date Created: | 2005-01-13 15:03:15 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/ETS | All | n/a | n/a |