@compstats/core 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/LICENSE +21 -0
  3. package/README.md +310 -0
  4. package/dist/3d.d.ts +33 -0
  5. package/dist/3d.d.ts.map +1 -0
  6. package/dist/3d.js +1984 -0
  7. package/dist/3d.js.map +22 -0
  8. package/dist/core/arith.d.ts +133 -0
  9. package/dist/core/arith.d.ts.map +1 -0
  10. package/dist/core/frame.d.ts +98 -0
  11. package/dist/core/frame.d.ts.map +1 -0
  12. package/dist/core/histogram.d.ts +68 -0
  13. package/dist/core/histogram.d.ts.map +1 -0
  14. package/dist/core/kde.d.ts +106 -0
  15. package/dist/core/kde.d.ts.map +1 -0
  16. package/dist/core/logit.d.ts +109 -0
  17. package/dist/core/logit.d.ts.map +1 -0
  18. package/dist/core/matrix.d.ts +135 -0
  19. package/dist/core/matrix.d.ts.map +1 -0
  20. package/dist/core/moderation.d.ts +127 -0
  21. package/dist/core/moderation.d.ts.map +1 -0
  22. package/dist/core/ols.d.ts +76 -0
  23. package/dist/core/ols.d.ts.map +1 -0
  24. package/dist/core/pca.d.ts +99 -0
  25. package/dist/core/pca.d.ts.map +1 -0
  26. package/dist/core/precision.d.ts +10 -0
  27. package/dist/core/precision.d.ts.map +1 -0
  28. package/dist/core/pretty.d.ts +51 -0
  29. package/dist/core/pretty.d.ts.map +1 -0
  30. package/dist/core/regression.d.ts +68 -0
  31. package/dist/core/regression.d.ts.map +1 -0
  32. package/dist/core/rng.d.ts +206 -0
  33. package/dist/core/rng.d.ts.map +1 -0
  34. package/dist/core/sampling.d.ts +157 -0
  35. package/dist/core/sampling.d.ts.map +1 -0
  36. package/dist/core/special.d.ts +92 -0
  37. package/dist/core/special.d.ts.map +1 -0
  38. package/dist/core/tdist.d.ts +53 -0
  39. package/dist/core/tdist.d.ts.map +1 -0
  40. package/dist/core/ttest.d.ts +146 -0
  41. package/dist/core/ttest.d.ts.map +1 -0
  42. package/dist/data/moderationData.d.ts +40 -0
  43. package/dist/data/moderationData.d.ts.map +1 -0
  44. package/dist/data/pcaDegenerate.d.ts +18 -0
  45. package/dist/data/pcaDegenerate.d.ts.map +1 -0
  46. package/dist/index.d.ts +66 -0
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +4195 -0
  49. package/dist/index.js.map +47 -0
  50. package/dist/interactive/controls.d.ts +97 -0
  51. package/dist/interactive/controls.d.ts.map +1 -0
  52. package/dist/interactive/logit.d.ts +57 -0
  53. package/dist/interactive/logit.d.ts.map +1 -0
  54. package/dist/interactive/matrixInverse.d.ts +86 -0
  55. package/dist/interactive/matrixInverse.d.ts.map +1 -0
  56. package/dist/interactive/moderation3d.d.ts +103 -0
  57. package/dist/interactive/moderation3d.d.ts.map +1 -0
  58. package/dist/interactive/pca.d.ts +90 -0
  59. package/dist/interactive/pca.d.ts.map +1 -0
  60. package/dist/interactive/regression.d.ts +57 -0
  61. package/dist/interactive/regression.d.ts.map +1 -0
  62. package/dist/interactive/sampling.d.ts +78 -0
  63. package/dist/interactive/sampling.d.ts.map +1 -0
  64. package/dist/interactive/scatter3d.d.ts +124 -0
  65. package/dist/interactive/scatter3d.d.ts.map +1 -0
  66. package/dist/interactive/tTest.d.ts +69 -0
  67. package/dist/interactive/tTest.d.ts.map +1 -0
  68. package/dist/interactive/target.d.ts +132 -0
  69. package/dist/interactive/target.d.ts.map +1 -0
  70. package/dist/plot/axes.d.ts +128 -0
  71. package/dist/plot/axes.d.ts.map +1 -0
  72. package/dist/plot/draw.d.ts +46 -0
  73. package/dist/plot/draw.d.ts.map +1 -0
  74. package/dist/plot/format.d.ts +33 -0
  75. package/dist/plot/format.d.ts.map +1 -0
  76. package/dist/plot/logit.d.ts +68 -0
  77. package/dist/plot/logit.d.ts.map +1 -0
  78. package/dist/plot/matrixInverse.d.ts +62 -0
  79. package/dist/plot/matrixInverse.d.ts.map +1 -0
  80. package/dist/plot/moderation3d.d.ts +135 -0
  81. package/dist/plot/moderation3d.d.ts.map +1 -0
  82. package/dist/plot/pca.d.ts +79 -0
  83. package/dist/plot/pca.d.ts.map +1 -0
  84. package/dist/plot/plotly.d.ts +209 -0
  85. package/dist/plot/plotly.d.ts.map +1 -0
  86. package/dist/plot/regression.d.ts +52 -0
  87. package/dist/plot/regression.d.ts.map +1 -0
  88. package/dist/plot/sampleCi.d.ts +82 -0
  89. package/dist/plot/sampleCi.d.ts.map +1 -0
  90. package/dist/plot/sampling.d.ts +159 -0
  91. package/dist/plot/sampling.d.ts.map +1 -0
  92. package/dist/plot/scatter3d.d.ts +164 -0
  93. package/dist/plot/scatter3d.d.ts.map +1 -0
  94. package/dist/plot/tTest.d.ts +49 -0
  95. package/dist/plot/tTest.d.ts.map +1 -0
  96. package/dist/plot/target.d.ts +55 -0
  97. package/dist/plot/target.d.ts.map +1 -0
  98. package/package.json +71 -0
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The matrix inverse plot: a matrix and its inverse, each as a parallelogram
3
+ * with an arrow along each column.
4
+ *
5
+ * This is the drawing half of `plot_matrix_inverse()` in
6
+ * `../compstatslib/R/matrix_inverse_plot.R`. Every number it draws comes from
7
+ * `invertMatrix` in `src/core/matrix.ts`; this module computes no arithmetic
8
+ * of its own. The picture teaches one thing: the area of each parallelogram is
9
+ * the determinant of the matrix that spans it, so a matrix that stretches
10
+ * space has an inverse that squeezes it, and the two areas are reciprocal.
11
+ *
12
+ * Three things here differ from the other plots in this port.
13
+ *
14
+ * **A matrix with no inverse leaves the canvas untouched.** `solve(A)` is the
15
+ * second line of the R function and `plot(NA, ...)` is the fourth, so R stops
16
+ * with an error before it opens a window. Traced on a null device, the
17
+ * singular case makes no graphics call at all. This function does the same and
18
+ * returns the report, which names the reason. A caller that redraws while a
19
+ * control moves has to clear its own surface, because this function will not.
20
+ *
21
+ * **The window does not hold its aspect.** The R call passes no `asp`, unlike
22
+ * `plot_pca()`, so a square in the data is a square on screen only on a square
23
+ * plot area. Measured in R, `par("usr")` reads -3.24 3.24 -3.24 3.24 on a 10
24
+ * by 5 inch device and the same on a 5 by 5 inch one. The parallelograms shear
25
+ * with the surface, and that is R's picture.
26
+ *
27
+ * **The arrowhead is a physical size.** R asks for `length = 0.25`, measured
28
+ * in inches, so the head does not shrink with a short vector. A vector short
29
+ * enough loses its arrow altogether: see `MIN_ARROW_PIXELS` in `draw.ts`.
30
+ */
31
+ import type { Matrix2, MatrixInversion } from "../core/matrix";
32
+ import type { Scale } from "./axes";
33
+ import type { PlotTarget } from "./target";
34
+ /**
35
+ * Build the scale that `plotMatrixInverse` draws through.
36
+ *
37
+ * The window is R's fixed -3 to 3 on both axes. The two axes are scaled
38
+ * separately, as R scales them: a wide surface makes a wide picture. Unlike R,
39
+ * the limits are the literal ones — R pads a range by 4% first, and this port
40
+ * drops that padding everywhere.
41
+ *
42
+ * @param width The pixel width of the surface.
43
+ * @param height The pixel height of the surface.
44
+ * @returns The map between world values and pixels.
45
+ */
46
+ export declare function matrixInverseScale(width: number, height: number): Scale;
47
+ /**
48
+ * Draw the matrix and its inverse.
49
+ *
50
+ * A matrix with no inverse draws nothing — not the axes, not the background.
51
+ * See the note on this module: R stops before it draws, and the report this
52
+ * function returns says why.
53
+ *
54
+ * @param target A canvas, or a context and a size. See `./target.ts`.
55
+ * @param matrix The matrix, as two columns. See `Matrix2`.
56
+ * @returns The determinant, the inverse, and the singularity, exactly as
57
+ * `invertMatrix` reports them. R returns nothing, but a browser caller needs
58
+ * the numbers it has just drawn — and needs the reason when nothing was
59
+ * drawn.
60
+ */
61
+ export declare function plotMatrixInverse(target: PlotTarget, matrix: Matrix2): MatrixInversion;
62
+ //# sourceMappingURL=matrixInverse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrixInverse.d.ts","sourceRoot":"","sources":["../../src/plot/matrixInverse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG5C,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,UAAU,CAAC;AAwBtD;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK,CAEvE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,OAAO,GACd,eAAe,CA6BjB"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The moderation surface: a fitted regression drawn as a height field over
3
+ * the IV and the moderator.
4
+ *
5
+ * This is the drawing half of `plot_moderation_3d()` of
6
+ * `../compstatslib/R/moderation_3d_plot.R`. Every number comes from
7
+ * `moderationSurface` in `src/core/moderation.ts`; this module computes no
8
+ * statistics of its own. The grid values are pinned in
9
+ * `.claude/plans/moderation-fixtures.md` section 3.
10
+ *
11
+ * Three decisions are worth stating.
12
+ *
13
+ * **The engine is Plotly, not lattice.** R draws this surface with
14
+ * `lattice::wireframe(drape = TRUE, colorkey = FALSE)`, which colors the mesh
15
+ * by height and hides the key. A Plotly surface is colored by height already,
16
+ * so the port sets `showscale: false` and keeps the rest. The colors
17
+ * themselves are Plotly's, not lattice's: a browser has no lattice palette,
18
+ * and the teaching point of the picture is the twist of the surface, not its
19
+ * hue.
20
+ *
21
+ * **The rotation arguments become a camera, approximately.** Lattice takes
22
+ * `screen = list(z = z_rot, x = x_rot)`, two rotations of the data. Plotly
23
+ * takes a camera position. `cameraFromRotations` maps one onto the other, and
24
+ * says how.
25
+ *
26
+ * **The vertical axis carries the outcome.** With the bundled data the
27
+ * moderator is named `z` and it is drawn on a horizontal axis, while the
28
+ * outcome `y` stands up. R's help makes the same point, twice.
29
+ */
30
+ import type { ModerationOptions, ModerationSurface } from "../core/moderation";
31
+ import type { DataFrame } from "../core/frame";
32
+ import type { EyeCamera, PlotlyHTMLElement, PlotlyLayout, PlotlyLike, SurfaceTrace } from "./plotly";
33
+ /** How to look at the surface. */
34
+ export interface Moderation3dViewOptions {
35
+ /**
36
+ * The turn about the vertical axis, in degrees. R's `z_rot`, 40 by default.
37
+ * 0 lays the IV across the screen; 270 lays the moderator across it.
38
+ */
39
+ readonly zRot?: number;
40
+ /**
41
+ * The tilt, in degrees. R's `x_rot`, −70 by default. −90 looks along the
42
+ * floor of the plot, and the view rises towards 0.
43
+ */
44
+ readonly xRot?: number;
45
+ /**
46
+ * The values the vertical axis spans, as `[low, high]`. The range of the
47
+ * data together with the range of the surface by default, which is R's own
48
+ * rule and what `moderationSurface` reports as `zlim`.
49
+ */
50
+ readonly zlim?: readonly [number, number];
51
+ }
52
+ /** The options of `plotModeration3d`: the model, the view, and the engine. */
53
+ export interface PlotModeration3dOptions extends ModerationOptions, Moderation3dViewOptions {
54
+ /**
55
+ * The Plotly engine. `loadPlotly()` by default, which fetches the library on
56
+ * first use.
57
+ */
58
+ readonly plotly?: PlotlyLike;
59
+ }
60
+ /** What a surface and a set of view options draw. */
61
+ export interface Moderation3dSpec {
62
+ /** The one height field. */
63
+ readonly traces: readonly SurfaceTrace[];
64
+ readonly layout: PlotlyLayout;
65
+ /**
66
+ * What R says in its `message()` when predictors are held off the axes.
67
+ * Null when every predictor of the model is drawn.
68
+ */
69
+ readonly note: string | null;
70
+ }
71
+ /** A drawn surface: its specification, its fit, its element, and its engine. */
72
+ export interface Moderation3dHandle extends Moderation3dSpec {
73
+ /** The element Plotly drew into, with its event emitter attached. */
74
+ readonly element: PlotlyHTMLElement;
75
+ /** The engine that drew, ready for the next redraw and for teardown. */
76
+ readonly plotly: PlotlyLike;
77
+ /** The fit and the grid behind the picture. */
78
+ readonly surface: ModerationSurface;
79
+ }
80
+ /**
81
+ * Place the camera for a pair of lattice rotations.
82
+ *
83
+ * This is a visual approximation, not an equivalence: lattice rotates the data
84
+ * and Plotly moves the camera, and the two pictures agree in direction, not
85
+ * pixel for pixel. The mapping is
86
+ *
87
+ * ```text
88
+ * azimuth = -90 - zRot degrees
89
+ * elevation = 90 + xRot degrees
90
+ * eye = distance * (cos elevation * cos azimuth,
91
+ * cos elevation * sin azimuth,
92
+ * sin elevation)
93
+ * ```
94
+ *
95
+ * Both anchors of R's own help hold under it. At `zRot = 0` the camera stands
96
+ * on the moderator axis, so the IV runs across the screen and the IV slope
97
+ * plane faces the viewer; at `zRot = 270` the camera stands on the IV axis and
98
+ * the moderator plane faces it. The tilt reads the same way as lattice's: at
99
+ * `xRot = -90` the camera is level with the floor of the plot, and R's default
100
+ * −70 lifts it 20 degrees above it.
101
+ *
102
+ * @param zRot The turn about the vertical axis, in degrees.
103
+ * @param xRot The tilt, in degrees.
104
+ * @returns The camera, as Plotly's `scene.camera`.
105
+ * @throws RangeError If either angle is not a finite number, which would
106
+ * place the camera nowhere.
107
+ */
108
+ export declare function cameraFromRotations(zRot: number, xRot: number): EyeCamera;
109
+ /**
110
+ * Build the trace and the layout of a moderation surface.
111
+ *
112
+ * @param surface The fit and the grid, from `moderationSurface`.
113
+ * @param model The columns the surface was fitted over. Their names title the
114
+ * axes, and the controls decide whether there is a note.
115
+ * @param view How to look at the surface.
116
+ * @returns The trace, the layout, and the note about held predictors.
117
+ * @throws RangeError If a rotation is not finite, if a given vertical range is
118
+ * not two finite numbers, or if any height of the surface is not finite —
119
+ * a non-finite height would crash the WebGL engine for the whole page.
120
+ */
121
+ export declare function moderation3dSpec(surface: ModerationSurface, model: ModerationOptions, view?: Moderation3dViewOptions): Moderation3dSpec;
122
+ /**
123
+ * Fit the model and draw its surface.
124
+ *
125
+ * @param target The element to draw into. Plotly fills it.
126
+ * @param data The frame holding every column the model names.
127
+ * @param options The model, the view, and the engine.
128
+ * @returns The drawn plot: its element, its specification, its engine, and the
129
+ * surface behind it.
130
+ * @throws RangeError Everything `moderationSurface` and `moderation3dSpec`
131
+ * throw, as a rejected promise. Nothing reaches the engine until the model
132
+ * is fitted and the view is settled.
133
+ */
134
+ export declare function plotModeration3d(target: HTMLElement, data: DataFrame, options: PlotModeration3dOptions): Promise<Moderation3dHandle>;
135
+ //# sourceMappingURL=moderation3d.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moderation3d.d.ts","sourceRoot":"","sources":["../../src/plot/moderation3d.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,OAAO,KAAK,EACV,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,YAAY,EAEb,MAAM,UAAU,CAAC;AAiBlB,kCAAkC;AAClC,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAED,8EAA8E;AAC9E,MAAM,WAAW,uBACf,SAAQ,iBAAiB,EACvB,uBAAuB;IACzB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;CAC9B;AAED,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,4BAA4B;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,gFAAgF;AAChF,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IACpC,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAczE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,iBAAiB,EACxB,IAAI,GAAE,uBAA4B,GACjC,gBAAgB,CAqDlB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAQ7B"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The PCA plot: the points, and an arrow along each principal component.
3
+ *
4
+ * This is the drawing half of `plot_pca()` in `../compstatslib/R/pca_plot.R`.
5
+ * Every number it draws comes from `principalComponents` in
6
+ * `src/core/pca.ts`; this module computes no statistics of its own.
7
+ *
8
+ * Two things here differ from every earlier plot in this port.
9
+ *
10
+ * **The window keeps equal units on both axes.** R's call passes `asp = 1`,
11
+ * which makes a right angle on the data look like a right angle on screen —
12
+ * the whole point of a picture about perpendicular components. R holds the
13
+ * limits it was given on whichever axis constrains the fit and widens the
14
+ * other about its middle; `pcaScale` does the same. Measured from R on a null
15
+ * device with `xlim = ylim = c(-50, 50)`: a 10 by 5 inch device reports
16
+ * `par("usr")` of `-149.696 149.696 -54 54`, and a 5 by 10 inch device
17
+ * reports `-54 54 -117.191 117.191`.
18
+ *
19
+ * **Mean-centering is not a statistical option.** It moves the arrows'
20
+ * anchor and nothing else. The components are the same either way, because
21
+ * R's `prcomp` centers internally whatever it is handed (fixture F7 shows the
22
+ * two runs agreeing bit for bit), and the points on screen are the raw ones —
23
+ * R plots `points`, not `mc_points`.
24
+ */
25
+ import type { PcaResult } from "../core/pca";
26
+ import type { Point } from "../core/regression";
27
+ import type { Scale } from "./axes";
28
+ import type { PlotTarget } from "./target";
29
+ /** R's `plot_pca()` arguments, less the points. */
30
+ export interface PlotPcaOptions {
31
+ /**
32
+ * Anchor the arrows on the middle of the data. True by default, as in R.
33
+ *
34
+ * False anchors them on the origin instead. Nothing else changes: not the
35
+ * components, not the points, only where the arrows are drawn.
36
+ */
37
+ readonly meancenter?: boolean;
38
+ /** The x limits, R's `xlim`. Both default to R's `c(-50, 50)`. */
39
+ readonly xlim?: readonly [number, number];
40
+ /** The y limits, R's `ylim`. */
41
+ readonly ylim?: readonly [number, number];
42
+ }
43
+ /**
44
+ * Build the scale that `plotPca` draws through, with equal units per pixel.
45
+ *
46
+ * The interactive layer needs this to turn a click into a world coordinate.
47
+ * It reads the scale from here so the window rule stays in one place.
48
+ *
49
+ * Both requested ranges are honoured or widened, never narrowed: the axis
50
+ * that needs the most world per pixel keeps its limits, and the other grows
51
+ * about its middle until the two agree. Unlike R, the constraining axis keeps
52
+ * the literal limits it was given — R would pad them by 4% first, and this
53
+ * port drops that padding everywhere.
54
+ *
55
+ * @param width The pixel width of the surface.
56
+ * @param height The pixel height of the surface.
57
+ * @param options The limits. A reversed pair reads as the range it spans, not
58
+ * as a flipped axis.
59
+ * @returns The map between world values and pixels.
60
+ */
61
+ export declare function pcaScale(width: number, height: number, options?: PlotPcaOptions): Scale;
62
+ /**
63
+ * Draw the points and the arrows along their principal components.
64
+ *
65
+ * R guards this drawing at three sizes, and so does this. With no points it
66
+ * draws an empty pair of axes. Below three points it draws the points alone:
67
+ * two points always lie on a line, so the second component would be an arrow
68
+ * of no length and the first would say only what the eye already sees. The
69
+ * core will answer for one or two points; this asks it only from three, which
70
+ * is R's own `nrow(points) >= 3`.
71
+ *
72
+ * @param target A canvas, or a context and a size. See `./target.ts`.
73
+ * @param points The observations, in world coordinates.
74
+ * @param options The anchor and the window.
75
+ * @returns The components drawn, or null below three points. R returns the
76
+ * same `prcomp` result, invisibly, and NULL at the same two guards.
77
+ */
78
+ export declare function plotPca(target: PlotTarget, points: readonly Point[], options?: PlotPcaOptions): PcaResult | null;
79
+ //# sourceMappingURL=pca.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pca.d.ts","sourceRoot":"","sources":["../../src/plot/pca.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG5C,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtD,mDAAmD;AACnD,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,kEAAkE;IAClE,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,gCAAgC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAaD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,cAAmB,GAC3B,KAAK,CAuBP;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,SAAS,KAAK,EAAE,EACxB,OAAO,GAAE,cAAmB,GAC3B,SAAS,GAAG,IAAI,CA+BlB"}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * The seam between this library and Plotly.js.
3
+ *
4
+ * The two 3D plots of the R package are drawn by Plotly (`plot_scatter3d()`)
5
+ * and by lattice (`plot_moderation_3d()`). In a browser there is one sensible
6
+ * engine for both, and the R package already chose it for the scatterplot, so
7
+ * both 3D plots of this port draw through Plotly.
8
+ *
9
+ * Plotly is four megabytes of code. Three rules keep that weight off everyone
10
+ * who does not draw in three dimensions.
11
+ *
12
+ * 1. **The 2D entry never names it.** The 3D plots live behind their own entry
13
+ * point, `src/3d.ts`, which the package exports as `compstatslib/3d`.
14
+ * 2. **The 3D entry does not carry it either.** `loadPlotly()` reaches the
15
+ * library through a dynamic `import`, which a bundler keeps in a chunk of
16
+ * its own and a browser fetches only when a plot is drawn.
17
+ * 3. **The engine is an argument.** Both plot functions take a `plotly`
18
+ * option. The tests pass a recorder (`test/recording-plotly.ts`) and never
19
+ * load Plotly at all: happy-dom has no WebGL, and the work this port does
20
+ * is the trace and the layout it builds, not the picture Plotly makes.
21
+ *
22
+ * `PlotlyLike` lists the exact calls the port makes, in the manner of
23
+ * `Context2D` in `./target.ts`. The real library satisfies it, and so does
24
+ * any object with those two methods.
25
+ *
26
+ * The trace and layout types below are equally narrow. They describe the
27
+ * fields this port sets, not the several hundred Plotly accepts.
28
+ */
29
+ /** A point in three dimensions, as Plotly writes one. */
30
+ export interface Vector3 {
31
+ readonly x: number;
32
+ readonly y: number;
33
+ readonly z: number;
34
+ }
35
+ /**
36
+ * Where the camera stands, where it looks, and which way is up. Plotly's
37
+ * `scene.camera`. Every part is optional: Plotly supplies its own.
38
+ */
39
+ export interface PlotlyCamera {
40
+ readonly eye?: Vector3;
41
+ readonly center?: Vector3;
42
+ readonly up?: Vector3;
43
+ }
44
+ /**
45
+ * A camera whose position is known. `cameraFromRotations` returns one, so a
46
+ * caller can read the eye without asking whether it is there.
47
+ */
48
+ export interface EyeCamera extends PlotlyCamera {
49
+ readonly eye: Vector3;
50
+ }
51
+ /** How the markers of a 3D scatterplot are drawn. */
52
+ export interface Scatter3dMarker {
53
+ /** R's `opacity`, in (0, 1]. */
54
+ readonly opacity: number;
55
+ /** R's `size`, in pixels. */
56
+ readonly size: number;
57
+ /** One value per point, when a numeric column drives the color. */
58
+ readonly color?: readonly number[];
59
+ /** The scale those values are read through. */
60
+ readonly colorscale?: string;
61
+ /** Whether the scale is drawn beside the plot as a color bar. */
62
+ readonly showscale?: boolean;
63
+ }
64
+ /** A cloud of points. */
65
+ export interface Scatter3dTrace {
66
+ readonly type: "scatter3d";
67
+ readonly mode: "markers";
68
+ readonly x: readonly number[];
69
+ readonly y: readonly number[];
70
+ readonly z: readonly number[];
71
+ readonly marker: Scatter3dMarker;
72
+ /** The level this trace holds, when a categorical column splits the data. */
73
+ readonly name?: string;
74
+ /** Whether the level is listed in the legend. */
75
+ readonly showlegend?: boolean;
76
+ }
77
+ /**
78
+ * A height field.
79
+ *
80
+ * `z[j][i]` is the height above `x[i]` and `y[j]` — the row index runs along
81
+ * `y`, which is why the moderation plot writes the moderator into the rows.
82
+ */
83
+ export interface SurfaceTrace {
84
+ readonly type: "surface";
85
+ readonly x: readonly number[];
86
+ readonly y: readonly number[];
87
+ readonly z: readonly (readonly number[])[];
88
+ /** Whether the height scale is drawn beside the plot. */
89
+ readonly showscale: boolean;
90
+ }
91
+ /** Anything this port draws. */
92
+ export type PlotlyTrace = Scatter3dTrace | SurfaceTrace;
93
+ /** One axis of a 3D scene. */
94
+ export interface PlotlyAxis {
95
+ /**
96
+ * The axis label, in Plotly's object form. Plotly v2 silently drops a
97
+ * bare-string title, so the type refuses the shorthand that would compile
98
+ * and then show nothing.
99
+ */
100
+ readonly title: {
101
+ readonly text: string;
102
+ };
103
+ /**
104
+ * The values the axis spans, as `[low, high]`. Plotly fits the data when
105
+ * the range is absent.
106
+ */
107
+ readonly range?: readonly [number, number];
108
+ }
109
+ /** The 3D scene: three axes, the shape of the box, and the camera. */
110
+ export interface PlotlyScene {
111
+ /** `"manual"` reads the ratio below. The others are Plotly's own rules. */
112
+ readonly aspectmode?: "auto" | "cube" | "data" | "manual";
113
+ readonly aspectratio?: Vector3;
114
+ readonly xaxis: PlotlyAxis;
115
+ readonly yaxis: PlotlyAxis;
116
+ readonly zaxis: PlotlyAxis;
117
+ /**
118
+ * A name for the view. Plotly keeps the rotation and the zoom across a
119
+ * redraw while this string does not change, which is how a slider can
120
+ * rebuild the plot without throwing away the angle the user chose.
121
+ */
122
+ readonly uirevision?: string;
123
+ readonly camera?: PlotlyCamera;
124
+ }
125
+ /** The layout of a 3D plot. */
126
+ export interface PlotlyLayout {
127
+ readonly uirevision: string;
128
+ readonly scene: PlotlyScene;
129
+ }
130
+ /** The behavior of the plot, as opposed to its content. */
131
+ export interface PlotlyConfig {
132
+ /** Whether the plot follows the size of the element that holds it. */
133
+ readonly responsive?: boolean;
134
+ }
135
+ /**
136
+ * What Plotly reports after the user moves the plot.
137
+ *
138
+ * The camera arrives under the key `scene.camera`, which is a path, not a
139
+ * nested object. The other keys depend on what moved.
140
+ */
141
+ export interface PlotlyRelayoutEvent {
142
+ readonly "scene.camera"?: PlotlyCamera;
143
+ readonly [key: string]: unknown;
144
+ }
145
+ /**
146
+ * A change pushed at a plot that is already drawn.
147
+ *
148
+ * Plotly's `relayout` takes the layout attribute by its path, so the camera
149
+ * arrives under the same `scene.camera` key it is reported under.
150
+ */
151
+ export interface PlotlyRelayoutUpdate {
152
+ readonly "scene.camera"?: PlotlyCamera;
153
+ }
154
+ /**
155
+ * The element Plotly hands back after it has drawn.
156
+ *
157
+ * Plotly adds an event emitter to that element, which is the only way to learn
158
+ * that the user rotated the plot.
159
+ */
160
+ export interface PlotlyHTMLElement extends HTMLElement {
161
+ on(event: "plotly_relayout", handler: (event: PlotlyRelayoutEvent) => void): void;
162
+ removeAllListeners(event: string): void;
163
+ }
164
+ /**
165
+ * The part of Plotly this library calls.
166
+ *
167
+ * `react` both draws and updates: on an empty element it builds the plot, and
168
+ * on one that already holds a plot it changes only what differs.
169
+ *
170
+ * `relayout` exists for one case that `react` cannot serve. The layouts of
171
+ * this port carry a constant `uirevision`, which is what keeps a user's own
172
+ * rotation across a redraw; Plotly honours that literally, so once the user
173
+ * has dragged the plot, a `react` carrying a different `scene.camera` is
174
+ * ignored. The rotation sliders of the moderation surface would then move
175
+ * nothing. `relayout` is an instruction rather than a preference, so it moves
176
+ * the camera whatever the user did before, and it is called only when a
177
+ * slider asks for a view the plot is not already at.
178
+ */
179
+ export interface PlotlyLike {
180
+ react(element: HTMLElement, data: readonly PlotlyTrace[], layout: PlotlyLayout, config?: PlotlyConfig): Promise<PlotlyHTMLElement>;
181
+ /** Change one part of the layout of a plot that is already drawn. */
182
+ relayout(element: HTMLElement, update: PlotlyRelayoutUpdate): Promise<PlotlyHTMLElement>;
183
+ /** Remove the plot, and everything it attached to the element. */
184
+ purge(element: HTMLElement): void;
185
+ }
186
+ /**
187
+ * Whether two cameras stand at the same view.
188
+ *
189
+ * The interactive components write a camera the user dragged to back into the
190
+ * live layout, and the `relayout` that does so fires `plotly_relayout` again
191
+ * with the same camera as a fresh object. Comparing by value is what lets the
192
+ * capture handlers recognize that echo and stop, so this must never be
193
+ * replaced with a reference comparison.
194
+ *
195
+ * @param a One camera, or nothing.
196
+ * @param b The other, or nothing.
197
+ * @returns True when both are absent, or both present with equal parts.
198
+ */
199
+ export declare function sameCamera(a: PlotlyCamera | undefined, b: PlotlyCamera | undefined): boolean;
200
+ /**
201
+ * Load Plotly.js.
202
+ *
203
+ * The library is fetched once. Every later call gets the same promise, so two
204
+ * plots on one page load one copy.
205
+ *
206
+ * @returns The library, narrowed to the calls this port makes.
207
+ */
208
+ export declare function loadPlotly(): Promise<PlotlyLike>;
209
+ //# sourceMappingURL=plotly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plotly.d.ts","sourceRoot":"","sources":["../../src/plot/plotly.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,yDAAyD;AACzD,MAAM,WAAW,OA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AU,CAAC,CAMhD"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The regression plot: points, the mean crosshair, the fitted line, and a
3
+ * block of statistics.
4
+ *
5
+ * This is the drawing half of `plot_regression()` in
6
+ * `../compstatslib/R/regression_plot.R`. Every number it draws comes from
7
+ * `linearRegression` in `src/core/regression.ts`; this module computes no
8
+ * statistics of its own.
9
+ */
10
+ import type { Point, RegressionFit } from "../core/regression";
11
+ import type { Scale } from "./axes";
12
+ import type { PlotTarget } from "./target";
13
+ /** What to show, and where. The toggles default to true, as in R. */
14
+ export interface PlotRegressionOptions {
15
+ /** Draw the mean crosshair and the fitted line. */
16
+ readonly regression?: boolean;
17
+ /** List the statistics at the top left. Needs `regression`. */
18
+ readonly stats?: boolean;
19
+ /** The x limits, R's `xlim`. Both default to R's `c(-5, 50)`. */
20
+ readonly xlim?: readonly [number, number];
21
+ /** The y limits, R's `ylim`. */
22
+ readonly ylim?: readonly [number, number];
23
+ }
24
+ /**
25
+ * Build the scale that `plotRegression` draws through.
26
+ *
27
+ * The interactive layer needs this to turn a click into a world coordinate.
28
+ * It reads the scale from here so that the world window stays defined in one
29
+ * place. Nothing outside this module may restate it.
30
+ *
31
+ * @param width The pixel width of the surface.
32
+ * @param height The pixel height of the surface.
33
+ * @param options The limits. A reversed pair reads as the range it spans, not
34
+ * as a flipped axis. Omitted limits keep the R teaching window.
35
+ * @returns The map between world values and pixels.
36
+ */
37
+ export declare function regressionScale(width: number, height: number, options?: PlotRegressionOptions): Scale;
38
+ /**
39
+ * Draw the points and their regression.
40
+ *
41
+ * With no points, the function draws empty axes. With one point, it draws the
42
+ * point alone, because a single point has no line to fit. R stops at the same
43
+ * two places.
44
+ *
45
+ * @param target A canvas, or a context and a size. See `./target.ts`.
46
+ * @param points The observations, in world coordinates.
47
+ * @param options What to show.
48
+ * @returns The fit that the plot drew, or null if there are no points. R
49
+ * returns the points instead, which the caller already holds.
50
+ */
51
+ export declare function plotRegression(target: PlotTarget, points: readonly Point[], options?: PlotRegressionOptions): RegressionFit | null;
52
+ //# sourceMappingURL=regression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regression.d.ts","sourceRoot":"","sources":["../../src/plot/regression.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAG/D,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG5C,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtD,qEAAqE;AACrE,MAAM,WAAW,qBAAqB;IACpC,mDAAmD;IACnD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,+DAA+D;IAC/D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,iEAAiE;IACjE,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,gCAAgC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3C;AAaD;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,qBAA0B,GAClC,KAAK,CAOP;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,SAAS,KAAK,EAAE,EACxB,OAAO,GAAE,qBAA0B,GAClC,aAAa,GAAG,IAAI,CA2BtB"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * One row per sample, each showing what that sample says about the mean it
3
+ * came from — the drawing half of `plot_sample_ci()` in
4
+ * `../compstatslib/R/sample_ci_plot.R`.
5
+ *
6
+ * The population is simulated, so its mean is known and drawn as a vertical
7
+ * line. Each sample gets a row: a wide 99% interval, a 95% interval over it,
8
+ * and a diamond at the sample mean. Rows whose intervals miss the true mean
9
+ * are drawn again in coral over the blue, which is the whole lesson of the
10
+ * picture — at 95% confidence, about one row in twenty should miss.
11
+ *
12
+ * Drawing order is faithful to R and is not incidental. R draws every row in
13
+ * the good colors, then draws the missing ones again on top, then the mean
14
+ * line last:
15
+ *
16
+ * ```r
17
+ * segments_ci(..., good = TRUE) # every row, skyblue
18
+ * segments_ci(...[bad], bad, good = FALSE) # the misses again, coral
19
+ * abline(v = mean(population_data))
20
+ * ```
21
+ *
22
+ * Within one of those calls R works in three vectorised passes — every 99%
23
+ * span, then every 95% span, then every point — rather than finishing a row
24
+ * at a time. This does the same, so overlapping neighbours stack as they do
25
+ * in R.
26
+ *
27
+ * The statistics all come from `simulateSampleCi` in `src/core/sampling.ts`;
28
+ * this module computes none of its own.
29
+ */
30
+ import type { Rng } from "../core/rng";
31
+ import type { SampleCiOptions, SampleCiSimulation } from "../core/sampling";
32
+ import type { Scale } from "./axes";
33
+ import type { PlotTarget } from "./target";
34
+ /** What to draw. R's `plot_sample_ci()` arguments, plus the generator. */
35
+ export interface PlotSampleCiOptions extends SampleCiOptions {
36
+ /**
37
+ * Where the randomness comes from.
38
+ *
39
+ * One call draws one picture, so unlike the sampling plot there is nothing
40
+ * to carry between calls and the default is harmless. It is still built the
41
+ * same way — a stream seeded once from `Math.random()` — so a page that
42
+ * says nothing about seeds gets a fresh picture each time, and
43
+ * `seededRng(42)` repeats one exactly.
44
+ */
45
+ readonly rng?: Rng;
46
+ }
47
+ /**
48
+ * Build the scale the plot draws through.
49
+ *
50
+ * The window is R's: half a standard deviation of the population each side of
51
+ * its mean, which is deliberately too narrow to hold every interval — the
52
+ * ones that run off the edge are the interesting ones. Rows count upward from
53
+ * one, so the first sample sits at the foot of the panel.
54
+ *
55
+ * A population with no spread leaves the width undefined. R stops there, on
56
+ * a non-finite `xlim`. This opens a unit window around the mean instead, so
57
+ * the frame and its axes still draw.
58
+ *
59
+ * @param width The pixel width of the surface.
60
+ * @param height The pixel height of the surface.
61
+ * @param simulation What `simulateSampleCi` returned.
62
+ * @returns The map between world values and pixels.
63
+ */
64
+ export declare function sampleCiScale(width: number, height: number, simulation: SampleCiSimulation): Scale;
65
+ /**
66
+ * Simulate a population, sample it, and draw what each sample says.
67
+ *
68
+ * A sample too small to have a spread gives an interval of NaN, which R would
69
+ * report as NA. Such a row is left undrawn rather than turned into a shape at
70
+ * a meaningless coordinate; the row still appears in the returned simulation,
71
+ * where the caller can see the NaN for what it is.
72
+ *
73
+ * @param target A canvas, or a context and a size. See `./target.ts`.
74
+ * @param options The sizes, the population's distribution, and the generator.
75
+ * @returns The simulation drawn — the population's mean and spread, and every
76
+ * sample's interval — so a caller need not run it again to read it.
77
+ * @throws RangeError If the sample size is larger than the population, or a
78
+ * count is negative or fractional. Both come from the core, which is where
79
+ * R's own refusals live.
80
+ */
81
+ export declare function plotSampleCi(target: PlotTarget, options?: PlotSampleCiOptions): SampleCiSimulation;
82
+ //# sourceMappingURL=sampleCi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampleCi.d.ts","sourceRoot":"","sources":["../../src/plot/sampleCi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGvC,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAEnB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAGpC,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtD,0EAA0E;AAC1E,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;;;;;;;OAQG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC;CACpB;AAmCD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,kBAAkB,GAC7B,KAAK,CAcP;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,mBAAwB,GAChC,kBAAkB,CAqCpB"}