Examples / LOWESS.RPF |
LOWESS.RPF provides an example of the use of NPREG, doing LOWESS and kernel fits. It is taken from the NIST Engineering Statistics Handbook.
http://www.itl.nist.gov/div898/handbook/pmd/section1/dep/dep144.htm
npreg(method=lowess,frac=.33) y x / xv yv
scatter(style=dots,overlay=line,ovsame,header="LOWESS Fit, Frac=.33") 2
# x y
# xv yv
does a LOWESS fit, with a moderately "loose" choice for the fraction of data points used. NPREG produces XV and YV as the X and Y series for showing the fit. With the default options, the "X" series for the fit (XV) will be 100 points spread across the original range of X. The SCATTER shows the original data as the DOT, and the LOWESS fit as LINE. (The OVSAME option is used to ensure that both the graph styles use the same scale).
npreg(method=nadaraya,grid=input) y x / xv yn
scatter(style=dots,overlay=line,ovsame,header="Kernel Fit, Default Bandwidth") 2
# x y
# xv yn
npreg(method=nadaraya,grid=input,bandwidth=2.0) y x / xv yx
scatter(style=dots,overlay=line,ovsame,header="Kernel Fit, Smaller Bandwidth") 2
# x y
# xv yx
does Nadaraya-Watson kernel fits, using the same XV series as the X coordinates as from the first NPREG (GRID=INPUT option). The first uses the default bandwidth (which is data dependent) while the second uses a specific (smaller) bandwidth (with the X series running from roughly 0 to 20, a bandwidth of 2 is fairly small; the default here is roughly 4).
Full Program
data(unit=input,org=columns) 1 21 seq x y
1 0.5578196 18.63654
2 2.0217271 103.49646
3 2.5773252 150.35391
4 3.4140288 190.51031
5 4.3014084 208.70115
6 4.7448394 213.71135
7 5.1073781 228.49353
8 6.5411662 233.55387
9 6.7216176 234.55054
10 7.2600583 223.89225
11 8.1335874 227.68339
12 9.1224379 223.91982
13 11.9296663 168.01999
14 12.3797674 164.95750
15 13.2728619 152.61107
16 14.2767453 160.78742
17 15.3731026 168.55567
18 15.6476637 152.42658
19 18.5605355 221.70702
20 18.5866354 222.69040
21 18.7572812 243.18828
npreg(method=lowess,frac=.33) y x / xv yv
scatter(style=dots,overlay=line,ovsame,header="LOWESS Fit, Frac=.33") 2
# x y
# xv yv
*
npreg(method=nadaraya,grid=input) y x / xv yn
scatter(style=dots,overlay=line,ovsame,header="Kernel Fit, Default Bandwidth") 2
# x y
# xv yn
npreg(method=nadaraya,grid=input,bandwidth=2.0) y x / xv yx
scatter(style=dots,overlay=line,ovsame,header="Kernel Fit, Smaller Bandwidth") 2
# x y
# xv yx
Graphs
Copyright © 2025 Thomas A. Doan