Least-Squares Fit
Scatter plot with a least-squares line the learner manipulates: drag data points or a candidate line and watch residuals, RSS, R^2 and the ANOVA split respond; drag x0 to read confidence and prediction bands; drag one point to see leverage, standardized residual and Cook's distance with and without it; recentre a polynomial or interaction model and watch only the lower-order coefficients change.
Used in: Introduction to Statistics
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| mode | string | fit | View: 'fit' (drag data, line refits), 'line' (drag a candidate line vs the least-squares minimum), 'anova' (SST = SSR + SSE for a highlighted point), 'bands' (CI and prediction bands at a draggable x0), 'influence' (fit with and without one point; leverage, standardized residual, Cook's D), 'polynomial' (polynomial fit with a draggable centring origin), 'interaction' (conditional slopes of y = b0 + b1 x1 + b2 x2 + b3 x1 x2). |
| points | [number, number][] | [[1,2],[2,3],[3,5],[4,4],[5,6]] | Data as [x, y] pairs. Defaults per mode: influence adds the point (10, 6); polynomial uses [[1,3],[2,5],[3,6],[4,6],[5,5],[6,3]]. Ignored in 'interaction' mode. |
| presets | (string | {label: string, points: [number, number][]})[] | [] | Extra data sets offered in a 'Data set' dropdown (after `points`, if given). Built-in names: study-hours, linear, parabola, random-cloud (uses `seed`), high-leverage-off-trend, high-leverage-on-trend, outlier-at-centre. |
| title | string | per mode | Title bar text. |
| xLabel | string | $x$ | x-axis title ($...$ TeX allowed); '$x_1$' in interaction mode. |
| yLabel | string | $y$ | y-axis title ($...$ TeX allowed). |
| xRange | [number, number] | data extent padded | Visible x window (also the drag bounds). In 'bands' mode the default widens to include x0. |
| yRange | [number, number] | data extent padded | Visible y window (also the drag bounds); in 'bands' mode the default includes the bands. |
| editable | boolean | true | Whether data points can be dragged (and, in fit/anova modes, added by clicking the plot). |
| readouts | string[] | per mode | Rows of the readout panel, in order. fit/anova: n, slope, intercept, r, r2, sse, rss, sst, ssr, s, F, t, t2, p, df, residualSum, xbar, ybar. line: candidate, intercept, slope, rss, minRss, excess, residualSum, lsSlope, lsIntercept, s. bands: x0, yhat, ci, ciHalfWidth, pi, piHalfWidth, ratio, seMean, sePred, v0, tStar, floor, s, n, xbar, coverage. influence: point, leverage, leverageCutoff, residual, residualSdFactor, residualSd, standardized, cooks, slopeWith, slopeWithout, interceptWith, interceptWithout, s, sWithout, r2, n. polynomial: sse, r2, origin, xbar, fittedAtOrigin, slopeAtOrigin, corrRaw, corrCentered, seTop. interaction: conditionalSlope, b1, b3, a0, a1, a2, a3. |
| showResiduals | boolean | true | fit and line modes: start with the vertical residual segments shown (learner can toggle). |
| showSquares | boolean | false | fit and line modes: start with each squared residual drawn as a square (learner can toggle). |
| showTable | boolean | false | Show the mode's table: per-point fitted values and residuals (fit), the ANOVA table (anova), or per-point h, e, r, D (influence). |
| showMean | boolean | false | fit mode: mark the centroid (x-bar, y-bar), which the least-squares line always passes through. |
| line | [number, number] | {intercept, slope} | [y-bar, 0] | line mode: the learner's starting candidate line as [intercept, slope]. |
| showLeastSquares | boolean | false | line mode: start with the least-squares line revealed (learner can toggle). |
| showRssSurface | boolean | false | line mode: add a contour plot of RSS over (intercept, slope) with the candidate as a draggable point. |
| level | number | 0.95 | bands mode: starting confidence level (0.5 to 0.999); the learner can slide it. |
| x0 | number | middle of the data | bands mode: starting position of the draggable target x0. |
| bands | string[] | ["mean", "prediction"] | bands mode: which bands to draw, any of 'mean' (confidence band for the mean response) and 'prediction' (prediction band for a new response). |
| shadeOutsideData | boolean | false | bands mode: grey out the x range outside the data and label it extrapolation. |
| replicateMax | number | 0 | bands mode: if > 1, a 'copies of each x' slider from 1 to this value replicates the design with s held fixed (n grows, the CI shrinks, the PI does not). |
| simulate | boolean | false | bands mode: add a 'Draw new sample' button that regenerates y from the initial fitted line plus normal noise (sd = initial s), refits, and counts how often the CI covers the true mean and the PI covers a new response at x0. |
| seed | number | string | 1 | Seed for the 'random-cloud' preset and for simulate draws. |
| dragIndex | number | last point | influence mode: 0-based index of the initially selected point (the fit without it is drawn dashed). |
| cutoffs | number[] | [2, 3] | influence mode: |standardized residual| cutoffs for 'large' and 'extreme' flags. |
| degree | number | 2 | polynomial mode: starting degree 1, 2 or 3 (learner can switch). |
| origin | number | 'mean' | 'mean' (polynomial), 0 (interaction) | polynomial mode: starting centring origin c for the predictor; interaction mode: starting centring constant m for x2. |
| coefficients | [number, number, number, number] | [10, 2, 1, 0.5] | interaction mode: fitted coefficients [b0, b1, b2, b3] of y = b0 + b1 x1 + b2 x2 + b3 x1 x2. |
| x2 | number | 0 | interaction mode: starting value of x2 at which the conditional slope of x1 is read. |
| x2Values | number[] | [0, 2, 4] | interaction mode: x2 values drawn as reference lines. |
| x1Range | [number, number] | [0, 10] | interaction mode: x1 window. |
| controls | string[] | all controls shown | Registry ids of the readouts and panels this lecture shows (see `controls` in this file); unlisted ones stay hidden, e.g. the correlation and R^2 rows before those are taught, or the prediction band before regression prediction intervals. Computed by component_scopes.py fit-nodes; omit to show everything. |
PreviousNext