Public
Edited
Oct 16, 2023
Insert cell
Insert cell
Insert cell
Insert cell
linearRegression = d3.regressionLinear()
.x(d => d.x)
.y(d => d.y)
.domain([-1.7, 16]);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
quadraticRegression = d3.regressionQuad()
.x(d => d.x)
.y(d => d.y)
.domain([-4, 4]);
Insert cell
Insert cell
lineGenerator = d3.line()
.x(d => xScale(d[0]))
.y(d => yScale(d[1]));
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const pr = polynomialRegression(dataPolynomial);
return d3.range(...xScalePolynomial.domain()).map(x => [x, pr.predict(x), dataPolynomial.find(d => d.x >= x)]);
}
Insert cell
polynomialRegression = d3.regressionPoly()
.x(d => d.x)
.y(d => d.y)
.order(3);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dataExponential.map(d => ({ x: 2**d.x, y: d.y }));
Insert cell
Insert cell
Insert cell
d3.regressionExp()( [[0.75,0.0008322048187316205],[0.5,0.002950193881990022],[0.25,0.013783049583435358],[0.125,0.04848795175552207],[0.0625,0.14894719541065593],[0.03125,0.4342218506336344],[0.015625,1.1765973861516719],[0.0078125,3.1163323602081308],[0.00390625,7.376351052224644],[0.001953125,14.473160939529752],[0.0009765625,33.616200305708034],[0.00048828125,65.89583139608975],[0.000244140625,195.2348298878895],[0.0001220703125,384.9595503351178],[0.00006103515625,666.0828711250322],[0.000030517578125,2138.1863559873227],[0.0000152587890625,4245.4559120226995]].map(v => [1-v[0], v[1]]))
Insert cell
exponentialRegression = d3.regressionExp()
.x(d => d.x)
.y(d => d.y);
Insert cell
Insert cell
{
const slope = 1;
const reg = exponentialRegression(dataExponential);
return Math.log(slope * 1/(reg.a*reg.b))/reg.b
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
logarithmicRegression = d3.regressionLog()
.x(d => d.x)
.y(d => d.y)
.domain([.81, 35]);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
powerRegression = d3.regressionPow()
.x(d => d.rank)
.y(d => d.sales);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
arcStatsMeta2 ={
const max = _.maxBy(arcStatsMeta, "coordCounts").coordCounts;
const minDelta = 5000;
const last = arcStatsMeta.at(-1);
return arcStatsMeta.filter(m => m == last || m.coordCounts > last.coordCounts * 1);
}
Insert cell
arcStatsMeta3 = arcStatsMeta.map(m => ({ value: Math.log2(m.value), coordCounts: m.coordCounts }));
Insert cell
Insert cell
import { arcStats, arcStatsMeta } from "053fea843f886be5"
Insert cell
Insert cell
loessRegression = d3.regressionLoess()
.x(d => d.year)
.y(d => d.temperature)
.bandwidth(bandwidth);
Insert cell
Insert cell
Insert cell
Insert cell
function getXScale(data, field) {
return d3.scaleLinear()
.domain([_.minBy(data, field)[field], _.maxBy(data, field)[field]])
.range([0, innerWidth]);
}
Insert cell
function getYScale(data, field) {
return d3.scaleLinear()
.domain([_.minBy(data, field)[field], _.maxBy(data, field)[field]])
.range([innerHeight, 0]);
}
Insert cell
yScaleLoess.range()
Insert cell
function getXAxis(xScale) {
return d3.axisBottom(xScale)
.tickSize(innerHeight + 10)
.tickValues(d3.range(...xScale.domain()));
}
Insert cell
function getYAxis(yScale) {
return d3.axisLeft(yScale)
.tickSize(innerWidth + 10);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more