fit

fitNode

A least-squares fit through the observations of the scatter named in of:, and no others — a graph may carry two fits over two scatters. model chooses the family and degree the polynomial degree; giving degree a parameter rather than a number puts the degree under the reader's control through that parameter's slider. Publishes derived slope, intercept and r2.

Only withxyplane

#Attributes

ofRequiredImplicit
Also written: through, dataThe scatter to fit, by its id — fit(of: #readings). The fit is taken through that mark's observations alone, so two scatters in one graph carry two independent fits. To fit part of a sample, draw that part as its own scatter and name it here.Can be written as shorthand: fit:value
model
polynomiallinear
Model family: polynomial or linear.
Defaultpolynomial
degreeAnimatable
Polynomial degree — a number, or an expression of parameters (degree: d) when the reader should drive it through a parameter slider.
Default1
colourAnimatable
neutralredorangeyellowgreentealbluepurplepinkgreywhiteblack
Also written: colorCurve colour.
Defaultteal
widthAnimatable
Stroke width.
Default2
hiddenAnimatable
Declared but not drawn. Animatable — hidden: true !cue.to{false}(at: 2) reveals it — and unlike a cue, a hidden element still frames the plot, so the axes do not jump when it appears.
Defaultfalse
Also written: lockedKeeps the reader from editing this element on an editable: graph. Nothing at all on a graph that is not editable.
Defaultfalse

#Derived attributes

Computed while the element renders — read one with #id.name in attribute position or {{#id.name}} in prose, never set.

slopeDerived
The x¹ coefficient of the current fit — live under the reader-draggable degree.
interceptDerived
The constant term of the current fit.
r2Derived
The coefficient of determination of the current fit against the observations it was taken through.

#Allowed in

#Examples

fit(of: #readings; model: polynomial; degree: d; colour: teal)
scatter#all(x: #trial.dose; y: #trial.response)
scatter#typical(x: #clean.dose; y: #clean.response)

fit#with-outlier(of: #all; degree: 1; colour: grey)
fit#without(of: #typical; degree: 1; colour: blue)