Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const regression = d3.regressionLinear()
</script>
```


## Demos
- [Angular](https://stackblitz.com/edit/angular-ivy-dksajy?file=src/app/app.component.ts)

- [Standalone NodeJS](/examples/linear.js)

## API Reference
- [Linear](#regressionLinear)
- [Exponential](#regressionExp)
Expand Down Expand Up @@ -229,4 +235,4 @@ See [<em>linear</em>.y()](#linear_y).

<a name="loess_bandwidth" href="#loess_bandwidth">#</a> <i>loess</i>.<b>bandwidth</b>([<i>bandwidth</i>]) · [Source](https://github.com/harrystevens/d3-regression/blob/master/src/loess.js#L77 "Source")

If <em>bandwidth</em> is specified, sets the LOESS regression's bandwidth, or smoothing parameter, to the specific number between 0 and 1. The bandwidth represents the share of the total data points that are used to calculate each local fit. Higher bandwidths produce smoother lines, and vice versa. If <em>bandwidth</em> is not specified, returns a copy of the regression generator’s current bandwidth, which defaults to .3.
If <em>bandwidth</em> is specified, sets the LOESS regression's bandwidth, or smoothing parameter, to the specific number between 0 and 1. The bandwidth represents the share of the total data points that are used to calculate each local fit. Higher bandwidths produce smoother lines, and vice versa. If <em>bandwidth</em> is not specified, returns a copy of the regression generator’s current bandwidth, which defaults to .3.
33 changes: 33 additions & 0 deletions examples/linear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

// Run with node linear.js
var d3 = require('d3-regression');

data2 = [{ x: 8, y: 3 }, { x: 2, y: 10 }, { x: 11, y: 3 }, { x: 6, y: 6 }, { x: 5, y: 8 }, { x: 4, y: 12 }, { x: 12, y: 1 }, { x: 9, y: 4 }, { x: 6, y: 9 }, { x: 1, y: 14 }]

data3 = [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 2, y: 3 }]

data = [
{ x: 0, y: 3.3 },
{ x: 1, y: 3.5 },
{ x: 2, y: 3.8 },
{ x: 3, y: 4.1 },
{ x: 4, y: 4.4 },
{ x: 5, y: 4.7 },
{ x: 6, y: 4.9 },
{ x: 7, y: 5.2 },
{ x: 8, y: 5.4 },
{ x: 9, y: 5.6 }
]


linearRegression = d3.regressionLinear()
.x(d => d.x)
.y(d => d.y)
.domain([-1.7, 16]);

// Select your data sourse
const regressionLine = linearRegression(data3);

console.log(regressionLine);

console.log(regressionLine.predict(1));