Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
Locally-weighted polynomial regression via the LOWESS algorithm.
License
stdlib-js/stats-lowess
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!
Locally-weighted polynomial regression via the LOWESS algorithm.
npm install @stdlib/stats-lowess
Alternatively,
- To load the package in a website via a
scripttag without installation and bundlers, use theES Module available on theesmbranch (seeREADME). - If you are using Deno, visit the
denobranch (seeREADME for usage intructions). - For use in Observable, or in browser/node environments, use theUniversal Module Definition (UMD) build available on the
umdbranch (seeREADME).
Thebranches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
varlowess=require('@stdlib/stats-lowess');
Forinput arrays and/ortyped arraysx andy, the function returns an object holding the ordered input valuesx and smoothed values fory.
varx=[4,4,7,7,8,9,10,10,10,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,16,16,17,17,17,18,18,18,18,19,19,19,20,20,20,20,20,22,23,24,24,24,24,25];vary=[2,10,4,22,16,10,18,26,34,17,28,14,20,24,28,26,34,34,46,26,36,60,80,20,26,54,32,40,32,40,50,42,56,76,84,36,46,68,32,48,52,56,64,66,54,70,92,93,120,85];varout=lowess(x,y);/* returns { 'x': [ 4, 4, 7, 7, ..., 24, 24, 24, 25 ], 'y': [ ~4.857, ~4.857, ~13.1037, ~13.1037, ..., ~79.102, ~79.102, ~79.102, ~84.825 ] }*/
The function accepts the followingoptions:
- f: positive
numberspecifying the smoothing span, i.e., the proportion of points which influence smoothing at each value. Larger values correspond to more smoothing. Default:2/3. - nsteps:
numberof iterations in the robust fit (fewer iterations translates to faster function execution). If set to zero, the nonrobust fit is returned. Default:3. - delta: nonnegative
numberwhich may be used to reduce the number of computations. Default: 1/100th of the range ofx. - sorted:
booleanindicating if the input arrayxis sorted. Default:false.
By default, smoothing at each value is determined by2/3 of all other points. To choose a different smoothing span, set thef option.
varx=[4,4,7,7,8,9,10,10,10,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,16,16,17,17,17,18,18,18,18,19,19,19,20,20,20,20,20,22,23,24,24,24,24,25];vary=[2,10,4,22,16,10,18,26,34,17,28,14,20,24,28,26,34,34,46,26,36,60,80,20,26,54,32,40,32,40,50,42,56,76,84,36,46,68,32,48,52,56,64,66,54,70,92,93,120,85];varout=lowess(x,y,{'f':0.2});/* returns { 'x': [ 4, 4, 7, ..., 24, 24, 25 ], 'y': [ ~6.03, ~6.03, ~12.68, ..., ~82.575, ~82.575, ~93.028 ] }*/
By default, three iterations of locally weighted regression fits are calculated after the initial fit. To set a different number of iterations for the robust fit, set thensteps option.
varx=[4,4,7,7,8,9,10,10,10,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,16,16,17,17,17,18,18,18,18,19,19,19,20,20,20,20,20,22,23,24,24,24,24,25];vary=[2,10,4,22,16,10,18,26,34,17,28,14,20,24,28,26,34,34,46,26,36,60,80,20,26,54,32,40,32,40,50,42,56,76,84,36,46,68,32,48,52,56,64,66,54,70,92,93,120,85];varout=lowess(x,y,{'nsteps':20});/* returns { 'x': [ 4, ..., 25 ], 'y': [ ~4.857, ..., ~84.825 ] }*/
To save computations, set thedelta option. For cases where one has a large number of (x,y)-pairs, carrying out regression calculations for all points is not likely to be necessary. By default,delta is set to 1/100th of the range of the values inx. In this case, if the values inx were uniformly scattered over the entire range, the locally weighted regression would be calculated at approximately 100 points. On the other hand, for small data sets with less than 100 observations, one can safely set the option to zero so calculations are made for each data point.
varx=[4,4,7,7,8,9,10,10,10,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,16,16,17,17,17,18,18,18,18,19,19,19,20,20,20,20,20,22,23,24,24,24,24,25];vary=[2,10,4,22,16,10,18,26,34,17,28,14,20,24,28,26,34,34,46,26,36,60,80,20,26,54,32,40,32,40,50,42,56,76,84,36,46,68,32,48,52,56,64,66,54,70,92,93,120,85];varout=lowess(x,y,{'delta':0.0});/* returns { 'x': [ 4, ..., 25 ], 'y': [ ~4.857, ..., ~84.825 ] }*/
If the elements ofx are sorted in ascending order, set thesorted option totrue.
varx=[4,4,7,7,8,9,10,10,10,11,11,12,12,12,12,13,13,13,13,14,14,14,14,15,15,15,16,16,17,17,17,18,18,18,18,19,19,19,20,20,20,20,20,22,23,24,24,24,24,25];vary=[2,10,4,22,16,10,18,26,34,17,28,14,20,24,28,26,34,34,46,26,36,60,80,20,26,54,32,40,32,40,50,42,56,76,84,36,46,68,32,48,52,56,64,66,54,70,92,93,120,85];varout=lowess(x,y,{'sorted':true});/* returns { 'x': [ 4, ..., 25 ], 'y': [ ~4.857, ..., ~84.825 ] }*/
varrandn=require('@stdlib/random-base-randn');varFloat64Array=require('@stdlib/array-float64');varplot=require('@stdlib/plot-ctor');varlowess=require('@stdlib/stats-lowess');varx;vary;vari;// Create some data...x=newFloat64Array(100);y=newFloat64Array(x.length);for(i=0;i<x.length;i++){x[i]=i;y[i]=(0.5*i)+(10.0*randn());}varopts={'delta':0};varout=lowess(x,y,opts);varh=plot([x,out.x],[y,out.y]);h.lineStyle=['none','-'];h.symbols=['closed-circle','none'];h.view('stdout');
- Cleveland, William S. 1979. "Robust Locally and Smoothing Weighted Regression Scatterplots."Journal of the American Statistical Association 74 (368): 829–36. doi:10.1080/01621459.1979.10481038.
- Cleveland, William S. 1981. "Lowess: A program for smoothing scatterplots by robust locally weighted regression."American Statistician 35 (1): 54–55. doi:10.2307/2683591.
This package is part ofstdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to developstdlib, see the main projectrepository.
SeeLICENSE.
Copyright © 2016-2026. The StdlibAuthors.
About
Locally-weighted polynomial regression via the LOWESS algorithm.
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.