The exact area, given by the definite integral, is calculated directly for the polynomial curve in order to assess the precision of the approximations.
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.
%let lower=-2;
%let upper=1;
%let interval=0.2;
* Generate some data according to a high order polynomial;
data kvm;
do x=&lower to &upper by &interval;
y=15+(x-2)*(x-1.5)*(x-1)*(x-.5)*x*(x+.5)*(x+1)*(x+1.5)*(x+2);
output;
end;
run;
proc sort;
by x;
run;
/* PROC EXPAND will include a contribution for the last interval. For
an accurate approximation to the integral, this last contribution
must be negligible. To do this, append an additional x value which
is extremely close to the last x value. The two Y values will be
identical, but the result is that the last interval is extremely short
making any contribution to the integral approximation negligible.
*/
data one;
set kvm end=eof;
output;
if eof then do;
x=x+(1e-10);
output;
end;
run;
proc print data=one;
title 'Original Series';
run;
proc gplot data=one;
title 'Original Series';
plot y*x;
run;
****************** Compute area by spline method *********************;
proc expand data=one out=three method=spline ;
convert y=total/observed=(beginning,total) transformout=(sum);
id x;
run;
proc sort data=three;
by descending total;
run;
proc print data=three(obs=1) noobs label;
title 'Approximate Integral Using Spline method';
var total;
label total="Spline Area";
run;
******************* Compute area by trapezoid rule *********************;
proc expand data=one out=three method=join;
convert y=total/observed=(beginning,total) transformout=(sum);
id x;
run;
proc sort data=three;
by descending total;
run;
proc print data=three(obs=1) noobs label;
title 'Approximate Integral Using Trapezoid Rule';
var total;
label total="Trapezoid Area";
run;
************************ Compute exact area ***************************;
/* Since these data were generated using a high order polynomial, it's
easy to directly compute the definite integral. Then we can compare
the exact area to the approximations to assess their precision.
*/
data four;
set one;
x3= x*x*x;
x5= x*x*x*x*x;
x7= x*x*x*x*x*x*x;
x9= x*x*x*x*x*x*x*x*x;
run;
proc autoreg data=four outest=five noprint;
title 'Calculate polynomial coefficients';
model y=x x3 x5 x7 x9;
run;
data six;
set five;
title 'direct integration of polynomial';
val=&upper;
eval=intercept*val+x*(val**2)/2+x3/4*(val**4)+x5/6*(val**6)
+x7/8*(val**8)+x9/10*(val**10);
temp=eval;
val=&lower;
eval=intercept*val+x*(val**2)/2+x3/4*(val**4)+x5/6*(val**6)
+x7/8*(val**8)+x9/10*(val**10);
integral=temp-eval;
keep integral;
run;
proc print noobs label;
title 'Exact area under the curve';
var integral;
label integral="Exact Area";
run;
title;
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.
Original Series Obs x y 1 -2.00000 15.0000 2 -1.80000 24.0707 3 -1.60000 17.5738 4 -1.40000 13.6404 5 -1.20000 13.6971 6 -1.00000 15.0000 7 -0.80000 15.6076 8 -0.60000 15.2906 9 -0.40000 14.7573 10 -0.20000 14.6471 11 -0.00000 15.0000 12 0.20000 15.3529 13 0.40000 15.2427 14 0.60000 14.7094 15 0.80000 14.3924 16 1.00000 15.0000 17 1.00000 15.0000 Approximate Integral Using Spline method Spline Area 47.2012 Approximate Integral Using Trapezoid Rule Trapezoid Area 46.7964 Exact area under the curve Exact Area 47.2781
Type: | Sample |
Topic: | Analytics ==> Regression Analytics ==> Transformations SAS Reference ==> Procedures ==> EXPAND |
Date Modified: | 2022-01-07 14:06:24 |
Date Created: | 2005-01-13 15:02:56 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/ETS | z/OS | ||
z/OS 64-bit | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 10 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |