@numero-uno-jpn/rstats 0.14.0 → 0.15.1

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 (49) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.ja.md +7 -7
  3. package/README.md +7 -7
  4. package/dist/chunks/{chunk-7PSGKKOP.js → chunk-3QTVXDUM.js} +2 -2
  5. package/dist/chunks/{chunk-A76XBA3D.js → chunk-4ILI2FSB.js} +1 -1
  6. package/dist/chunks/{chunk-RZIWVCHO.js → chunk-5OSQ76OO.js} +2 -2
  7. package/dist/chunks/{chunk-7T74KLE5.js → chunk-5SQFDLNG.js} +2 -2
  8. package/dist/chunks/{chunk-ACE64PMM.js → chunk-5XQZNKHZ.js} +2 -2
  9. package/dist/chunks/chunk-5YMP4WAJ.js +2 -0
  10. package/dist/chunks/{chunk-ZUESNU7W.js → chunk-735NNFAS.js} +2 -2
  11. package/dist/chunks/{chunk-WM33ADZV.js → chunk-7J4HW6VF.js} +2 -2
  12. package/dist/chunks/{chunk-6JRESWVF.js → chunk-BDJPSEA7.js} +2 -2
  13. package/dist/chunks/{chunk-7CPM3M6Q.js → chunk-GEJCBCMP.js} +2 -2
  14. package/dist/chunks/{chunk-SZ357HRC.js → chunk-H4CHJMFU.js} +1 -1
  15. package/dist/chunks/{chunk-Q4JF4QHS.js → chunk-IQOVOHZG.js} +2 -2
  16. package/dist/chunks/chunk-KO6QQPC6.js +2 -0
  17. package/dist/chunks/{chunk-FBDZ6B2G.js → chunk-LY2T6DA6.js} +2 -2
  18. package/dist/chunks/chunk-OLPTFKIZ.js +3 -0
  19. package/dist/chunks/{chunk-YTV3RFCA.js → chunk-SAZAEPZC.js} +1 -1
  20. package/dist/chunks/{chunk-DWNGNTS6.js → chunk-TYFGVCVQ.js} +2 -2
  21. package/dist/chunks/{chunk-XCAMWVNO.js → chunk-UWBYDIOH.js} +1 -1
  22. package/dist/chunks/{chunk-IGSR4GIF.js → chunk-UZHY5DWN.js} +2 -2
  23. package/dist/chunks/{chunk-NTETWLP3.js → chunk-VOIJKNL2.js} +1 -1
  24. package/dist/chunks/{chunk-IBJ7RI44.js → chunk-Z3C3G5XI.js} +2 -2
  25. package/dist/descriptive.js +2 -2
  26. package/dist/distributions/nchisq.js +123 -25
  27. package/dist/distributions/signrank.js +73 -20
  28. package/dist/distributions.js +2 -2
  29. package/dist/linalg.js +2 -2
  30. package/dist/mixed.js +4 -4
  31. package/dist/models/glm.js +4 -2
  32. package/dist/models/glmFamily.js +16 -4
  33. package/dist/models/lmer.d.ts +28 -5
  34. package/dist/models/lmer.js +129 -20
  35. package/dist/models/lmerAnova.d.ts +8 -3
  36. package/dist/models/lmerAnova.js +10 -4
  37. package/dist/models/lmerHypotheses.d.ts +4 -3
  38. package/dist/models/lmerHypotheses.js +9 -7
  39. package/dist/models/lmerTest.d.ts +13 -7
  40. package/dist/models/lmerTest.js +16 -11
  41. package/dist/models/mixedStructure.js +30 -14
  42. package/dist/numerics.js +2 -2
  43. package/dist/rstats.js +13 -13
  44. package/dist/special.js +2 -2
  45. package/dist/tests.js +7 -7
  46. package/package.json +1 -1
  47. package/dist/chunks/chunk-DCGBYO44.js +0 -2
  48. package/dist/chunks/chunk-SD7ML5PE.js +0 -2
  49. package/dist/chunks/chunk-YQLEXH2Y.js +0 -3
@@ -4,8 +4,10 @@
4
4
  //
5
5
  // Written for rStats.js (no ported code) from oracle/lmer-behaviour.md (stage 1a) and the notation of D. Bates,
6
6
  // M. Mächler, B. Bolker, S. Walker (2015), "Fitting Linear Mixed-Effects Models Using lme4", Journal of Statistical
7
- // Software 67(1). The fixed-effects part is coded as in lm (src/models/modelMatrix.ts); each random-effects term's
8
- // left-hand side is a model matrix with treatment contrasts; its grouping expression is expanded as a right-hand side
7
+ // Software 67(1). The fixed-effects part is the formula without the random-effects terms, coded as lm codes it
8
+ // (src/models/modelMatrix.ts; the order of its own variables names the interaction columns: `y ~ (z | g) + x * z` has
9
+ // `x:z`), on the model frame of the whole formula; each random-effects term's left-hand side is a model matrix with
10
+ // treatment contrasts (a term without columns is an error); its grouping expression is expanded as a right-hand side
9
11
  // into grouping factors (`a/b` gives `b:a` and `a`); `||` splits a term into one term per column group. The terms are
10
12
  // then ordered by their number of levels (decreasing, when not already non-increasing; ties reversed). Z is
11
13
  // level-major within each term, and Λ_θ is block diagonal with one lower-triangular block per level of each term,
@@ -92,19 +94,21 @@ export function mixedModelStructure(formula, data, options = {}) {
92
94
  const { fixed, bars } = splitBarTerms(parsed.rhs);
93
95
  if (typeof data !== "object" || data === null)
94
96
  throw new TypeError("data must be an object of columns");
95
- // the fixed-effects part (its terms collect the variables of the whole formula, so that every model matrix below
96
- // uses the same rows)
97
+ // the fixed-effects part: the formula without the random-effects terms, `response ~ fixed part`, as lm codes it (the
98
+ // order of its variables names the interaction columns); its model frame has the variables of the whole formula too,
99
+ // so that every model matrix below uses the same rows
97
100
  const frameOptions = {
98
101
  ...(options.levels === undefined ? {} : { levels: options.levels }),
99
102
  dropUnusedLevels: true,
100
103
  };
101
104
  // (if nothing is left of the right-hand side, the fixed part is `1`)
102
105
  const fixedRhs = fixed ?? { type: "num", value: 1, text: "1" };
106
+ const fixedFormula = { response: parsed.response, rhs: fixedRhs };
107
+ // the variables of the whole formula (in the model frame, those of the fixed part come first, in its order)
108
+ const allVariables = termsOf(parsed, Object.keys(data), fixedRhs).variables;
103
109
  // (a contrast is for a variable of the fixed-effects part: a grouping variable alone counts as absent)
104
- const contrastOptions = options.contrasts === undefined
105
- ? {}
106
- : { contrasts: options.contrasts, contrastVariables: termsOf({ response: parsed.response, rhs: fixedRhs }, Object.keys(data)).variables };
107
- const fixedDesign = design(parsed, data, { ...frameOptions, ...contrastOptions }, fixedRhs);
110
+ const contrastOptions = options.contrasts === undefined ? {} : { contrasts: options.contrasts };
111
+ const fixedDesign = design(fixedFormula, data, { ...frameOptions, ...contrastOptions, extraVariables: allVariables }, fixedRhs);
108
112
  const { frame } = fixedDesign;
109
113
  const n = frame.rows.length;
110
114
  if (n === 0)
@@ -112,24 +116,28 @@ export function mixedModelStructure(formula, data, options = {}) {
112
116
  // (the model frame's errors, above, come before this check)
113
117
  if (bars.length === 0)
114
118
  throw new Error("No random effects terms specified in formula");
115
- const variables = fixedDesign.terms.variables;
119
+ const variables = [...fixedDesign.terms.variables, ...allVariables.filter((v) => !fixedDesign.terms.variables.includes(v))];
116
120
  // (lhs || group) split into one term per term of lhs, then each term expanded by its grouping factors
117
121
  const expanded = [];
118
- for (const bar of bars) {
122
+ /** The first bar term (in the formula's order) without columns */
123
+ let noColumns;
124
+ bars.forEach((bar, barIndex) => {
119
125
  let lhsList = [bar.lhs];
120
126
  if (bar.double) {
121
127
  const lhsTerms = termsOf(parsed, Object.keys(data), bar.lhs);
122
128
  lhsList = lhsTerms.intercept ? [{ type: "num", value: 1, text: "1" }] : [];
123
129
  for (const t of lhsTerms.terms) {
124
- const term = t.map((v) => ({ type: "var", name: variables[v] })).reduce((l, r) => ({ type: "binary", op: ":", left: l, right: r }));
130
+ const term = t.map((v) => ({ type: "var", name: lhsTerms.variables[v] })).reduce((l, r) => ({ type: "binary", op: ":", left: l, right: r }));
125
131
  lhsList.push({ type: "binary", op: "+", left: { type: "num", value: 0, text: "0" }, right: term });
126
132
  }
133
+ if (lhsList.length === 0)
134
+ noColumns ??= barIndex;
127
135
  }
128
136
  const factors = groupingFactorsOf(bar.group);
129
137
  for (const lhs of lhsList)
130
138
  for (const groupVariables of factors)
131
- expanded.push({ lhs, groupVariables });
132
- }
139
+ expanded.push({ lhs, groupVariables, bar: barIndex });
140
+ });
133
141
  // the grouping factors (levels present, ordered by the levels of the first variable, then the second, ...)
134
142
  const factorCache = new Map();
135
143
  const factorOf = (vs) => {
@@ -187,6 +195,8 @@ export function mixedModelStructure(formula, data, options = {}) {
187
195
  // the left-hand side: treatment contrasts whatever the options say
188
196
  const lhsDesign = design(parsed, data, frameOptions, t.lhs);
189
197
  const nc = lhsDesign.colNames.length;
198
+ if (nc === 0 && (noColumns === undefined || t.bar < noColumns))
199
+ noColumns = t.bar;
190
200
  const nLevels = t.factor.levels.length;
191
201
  terms.push({
192
202
  label: `${deparseFormula(t.lhs)} | ${t.name}`,
@@ -200,7 +210,11 @@ export function mixedModelStructure(formula, data, options = {}) {
200
210
  zOffset += nLevels * nc;
201
211
  thetaOffset += (nc * (nc + 1)) / 2;
202
212
  }
203
- // checks
213
+ // checks: a term without columns (its bar term as written), then the grouping factors and the numbers of effects
214
+ if (noColumns !== undefined) {
215
+ const bar = bars[noColumns];
216
+ throw new Error(`lmer: the random-effects term '${deparseFormula(bar.lhs)} ${bar.double ? "||" : "|"} ${deparseFormula(bar.group)}' has no columns`);
217
+ }
204
218
  if (groups.some((g) => g.levels.length < 2))
205
219
  throw new RangeError("grouping factors must have > 1 sampled level");
206
220
  const tooMany = groups.filter((g) => g.levels.length >= n).map((g) => g.name);
@@ -286,6 +300,8 @@ export function mixedModelStructure(formula, data, options = {}) {
286
300
  sds.push(sd);
287
301
  }
288
302
  const limit = Math.log(1000);
303
+ // (a constant column other than 0/1 has sd 0, so log(0) = -Infinity and the warning is given: lme4's check includes
304
+ // such columns too, so this is intended)
289
305
  const badScale = sds.some((a, i) => Math.abs(Math.log(a)) > limit || sds.some((b, k) => k !== i && Math.abs(Math.log(a / b)) > limit));
290
306
  if (badScale) {
291
307
  warnings.push("Some predictor variables are on very different scales: consider rescaling. \nYou may also use (g)lmerControl(autoscale = TRUE) to improve numerical stability.");
package/dist/numerics.js CHANGED
@@ -1,2 +1,2 @@
1
- /*! rStats.js 0.14.0 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
- import{a as $,b as T,c as D,d as F,e as O}from"./chunks/chunk-ACE64PMM.js";import"./chunks/chunk-NTETWLP3.js";import{a as k,f as j}from"./chunks/chunk-Q4JF4QHS.js";import"./chunks/chunk-A76XBA3D.js";import{f as S}from"./chunks/chunk-WM33ADZV.js";import"./chunks/chunk-SZ357HRC.js";import"./chunks/chunk-XCAMWVNO.js";function M(o,l,t="mean"){if(o.length!==l.length)throw new RangeError("'x' and 'y' lengths differ");let n=[];for(let r=0;r<o.length;r++)!Number.isNaN(o[r])&&!Number.isNaN(l[r])&&n.push(r);n.sort((r,s)=>o[r]-o[s]);let e=typeof t=="function"?t:t==="min"?r=>Math.min(...r):t==="max"?r=>Math.max(...r):S,a=[],f=[];for(let r=0;r<n.length;){let s=o[n[r]],c=r+1;for(;c<n.length&&o[n[c]]===s;)c++;a.push(s),f.push(c-r===1?l[n[r]]:e(n.slice(r,c).map(i=>l[i]))),r=c}return{x:a,y:f}}function X(o,l,t,n){let e=(n-o[t])/(o[t+1]-o[t]);return l[t]+(l[t+1]-l[t])*e}function J(o,l,t){let n=(e,a)=>e===0?0:e*a;return n(1-t,o[l])+n(t,o[l+1])}function P(o,l,t={}){let{method:n="linear",n:e=50,f:a=0,rule:f=1,ties:r="mean"}=t,s=M(o,l,r),c=s.x.length;if(c<=1&&n==="linear")throw new RangeError("need at least two non-NA values to interpolate");if(c===0)throw new RangeError("zero non-NA points");if(n==="constant"&&!(a>=0&&a<=1))throw new RangeError("approx(): invalid f value");let[i,p]=typeof f=="number"?[f,f]:f,d=t.yleft??(i===1?NaN:s.y[0]),h=t.yright??(p===1?NaN:s.y[c-1]),m;if(t.xout!==void 0)m=Array.from(t.xout);else{if(e<=0)throw new RangeError("'approx' requires n >= 1");m=k(s.x[0],s.x[c-1],e)}let g=s.x,u=s.y,w=j(m,g),y=m.map((b,A)=>{let R=w[A];if(Number.isNaN(R))return NaN;if(R===0)return d;let E=R-1;return b===g[E]?u[E]:R===c?h:n==="linear"?X(g,u,E,b):J(u,E,a)});return{x:m,y}}function v(o,l){let t=o.length,n=new Array(t).fill(0),e=new Array(t).fill(0),a=new Array(t).fill(0);if(t<2)return{b:n,c:e,d:a};if(t<3)return n[0]=(l[1]-l[0])/(o[1]-o[0]),n[1]=n[0],{b:n,c:e,d:a};let f=t-1;a[0]=o[1]-o[0],e[1]=(l[1]-l[0])/a[0];for(let r=1;r<f;r++)a[r]=o[r+1]-o[r],n[r]=2*(a[r-1]+a[r]),e[r+1]=(l[r+1]-l[r])/a[r],e[r]=e[r+1]-e[r];n[0]=-a[0],n[f]=-a[t-2],e[0]=0,e[f]=0,t>3&&(e[0]=e[2]/(o[3]-o[1])-e[1]/(o[2]-o[0]),e[f]=e[t-2]/(o[f]-o[t-3])-e[t-3]/(o[t-2]-o[t-4]),e[0]=e[0]*a[0]*a[0]/(o[3]-o[0]),e[f]=-e[f]*a[t-2]*a[t-2]/(o[f]-o[t-4]));for(let r=1;r<t;r++){let s=a[r-1]/n[r-1];n[r]=n[r]-s*a[r-1],e[r]=e[r]-s*e[r-1]}e[f]=e[f]/n[f];for(let r=t-2;r>=0;r--)e[r]=(e[r]-a[r]*e[r+1])/n[r];n[f]=(l[f]-l[t-2])/a[t-2]+a[t-2]*(e[t-2]+2*e[f]);for(let r=0;r<f;r++)n[r]=(l[r+1]-l[r])/a[r]-a[r]*(e[r+1]+2*e[r]),a[r]=(e[r+1]-e[r])/a[r],e[r]=3*e[r];return e[f]=3*e[f],a[f]=a[t-2],{b:n,c:e,d:a}}function z(o,l,t){let n=o.length,e=new Array(n).fill(0),a=new Array(n).fill(0),f=new Array(n).fill(0);for(let r=0;r<n-1;r++){let s=o[r+1]-o[r];e[r]=(l[r+1]-l[r])/s-s*(t[r+1]+2*t[r]),a[r]=3*t[r],f[r]=(t[r+1]-t[r])/s}return{b:e,c:a,d:f}}function Y(o,l){let t=o.length;if(t<3)return v(o,l);let n=Array.from({length:t-1},(c,i)=>o[i+1]-o[i]),e=n.map((c,i)=>(l[i+1]-l[i])/c),a=new Array(t).fill(0),f=new Array(t).fill(0);for(let c=1;c<t-1;c++)a[c]=2*(n[c-1]+n[c]),f[c]=e[c]-e[c-1];for(let c=2;c<t-1;c++){let i=n[c-1]/a[c-1];a[c]=a[c]-i*n[c-1],f[c]=f[c]-i*f[c-1]}let r=new Array(t).fill(0);r[t-2]=f[t-2]/a[t-2];for(let c=t-3;c>=1;c--)r[c]=(f[c]-n[c]*r[c+1])/a[c];let s=z(o,l,r);return s.b[t-1]=e[t-2]+n[t-2]*r[t-2],s}function B(o,l){let t=o.length;if(l[0]!==l[t-1])throw new RangeError("periodic spline needs y[1] == y[n]");if(t<3)return{b:new Array(t).fill(0),c:new Array(t).fill(0),d:new Array(t).fill(0)};let n=t-1,e=Array.from({length:n},(u,w)=>o[w+1]-o[w]),a=e.map((u,w)=>(l[w+1]-l[w])/u),f=u=>u===0?n-1:u-1,r=Array.from({length:n},(u,w)=>2*(e[f(w)]+e[w])),s=Array.from({length:n},(u,w)=>a[w]-a[f(w)]),c=e.slice(),i=new Array(n).fill(0);i[0]=e[n-1],i[n-2]=i[n-2]+e[n-2];let p=i[0],d=r[n-1],h=s[n-1];for(let u=0;u<n-1;u++){if(u+1<n-1){let y=e[u]/r[u];r[u+1]=r[u+1]-y*c[u],i[u+1]=i[u+1]-y*i[u],s[u+1]=s[u+1]-y*s[u]}let w=p/r[u];d-=w*i[u],h-=w*s[u],u+1<n-1&&(p=(u+1===n-2?e[n-2]:0)-w*c[u])}let m=new Array(t).fill(0);m[n-1]=h/d;for(let u=n-2;u>=0;u--){let w=s[u]-i[u]*m[n-1]-(u<n-2?c[u]*m[u+1]:0);m[u]=w/r[u]}m[t-1]=m[0];let g=z(o,l,m);return g.b[t-1]=g.b[0],g.c[t-1]=g.c[0],g.d[t-1]=g.d[0],g}function G(o,l){let t=o.length,{b:n,c:e,d:a}=v(o,l);if(t<2)return{b:n,c:e,d:a};let f=Array.from({length:t-1},(s,c)=>(l[c+1]-l[c])/(o[c+1]-o[c]));for(let s=0;s<t;s++){let c=f[s===0?0:s-1],i=f[s===t-1?t-2:s],p=Math.min(Math.abs(c),Math.abs(i)),d=c*i>0?i>0:n[s]>=0;n[s]=d?Math.min(Math.max(0,n[s]),3*p):Math.max(Math.min(0,n[s]),-3*p)}for(let s=0;s<t-1;s++){let c=o[s+1]-o[s],i=(l[s+1]-l[s])/c;e[s]=(3*i-2*n[s]-n[s+1])/c,a[s]=(n[s]+n[s+1]-2*i)/(c*c)}let r=o[t-1]-o[t-2];return e[t-1]=(n[t-2]+2*n[t-1]-3*(l[t-1]-l[t-2])/r)/r,a[t-1]=a[t-2],{b:n,c:e,d:a}}function q(o,l,t,n){let e=M(o,l,n),a=e.x.length;if(a===0)throw new RangeError("zero non-NA points");t==="periodic"&&e.y[a-1]!==e.y[0]&&(e.y[a-1]=e.y[0]),t==="hyman"&&K(e.y);let f=t==="fmm"?v(e.x,e.y):t==="natural"?Y(e.x,e.y):t==="periodic"?B(e.x,e.y):t==="hyman"?G(e.x,e.y):(()=>{throw new RangeError(`invalid spline method '${String(t)}'`)})();return{method:t,...e,...f}}function K(o){let l=!0,t=!0;for(let n=1;n<o.length;n++){let e=o[n]-o[n-1];e>=0||(l=!1),e<=0||(t=!1)}if(!l&&!t)throw new RangeError("'y' must be increasing or decreasing")}function C(o){let l=Math.trunc(o);if(!(l>=0&&l<=3))throw new RangeError("'deriv' must be between 0 and 3");return l}function H(o,l,t){let n=C(t),{x:e,y:a,b:f,c:r,d:s,method:c}=o,i=e.length,p=c==="natural",d=e[i-1]-e[0],h=0;return Array.from(l,m=>{let g=m;if(c==="periodic"&&i>1){let y=(g-e[0])%d;y<0&&(y+=d),g=e[0]+y}if(p&&n>0&&g<=e[0])return n===1?f[0]:0;if(!(e[h]<=g&&(h===i-1||g<=e[h+1]))){let y=0,b=i;for(;b-y>1;){let A=y+b>>1;e[A]<=g?y=A:b=A}h=y}let u=g-e[h],w=p&&g<e[0]?0:s[h];switch(n){case 0:return a[h]+u*(f[h]+u*(r[h]+u*w));case 1:return f[h]+u*(2*r[h]+u*(3*w));case 2:return 2*r[h]+u*(6*w);default:return 6*w}})}function Q(o,l,t={}){let{method:n="fmm",ties:e="mean"}=t,a=q(o,l,n,e),f;if(t.xout!==void 0)f=Array.from(t.xout);else{let r=a.x.length,s=t.n??3*r;if(s<=0)throw new RangeError("'spline' requires n >= 1");f=k(t.xmin??a.x[0],t.xmax??a.x[r-1],s)}return{x:f,y:H(a,f,0)}}function U(o,l,t={}){let{method:n="fmm",ties:e="mean"}=t;if(n==="monoH.FC"){let f=M(o,l,e);if(f.x.length===0)throw new RangeError("zero non-NA points");let r=V(f.x,f.y);return(s,c=0)=>I(f.x,f.y,r,s,c)}let a=q(o,l,n,e);return(f,r=0)=>H(a,f,r)}function V(o,l){let t=o.length;if(t<2)throw new RangeError("length(m) must be at least two");let n=Array.from({length:t-1},(a,f)=>(l[f+1]-l[f])/(o[f+1]-o[f])),e=Array.from({length:t},(a,f)=>f===0?n[0]:f===t-1?n[t-2]:(n[f-1]+n[f])/2);for(let a=0;a<t-1;a++){let f=n[a];if(f===0){e[a]=0,e[a+1]=0;continue}let r=e[a]/f,s=e[a+1]/f,c=2*r+s-3,i=r+2*s-3;if(c>0&&i>0&&r*(c+i)<c*c){let p=3*f/Math.sqrt(r*r+s*s);e[a]=p*r,e[a+1]=p*s}}return e}function I(o,l,t,n,e){let a=C(e),f=o.length;return Array.from(n,r=>{if(Number.isNaN(r))return NaN;let s=0,c=f;for(;s<c;){let A=s+c>>1;o[A]<=r?s=A+1:c=A}let i=s;if(i===0||i===f){let A=i===0?0:f-1;return a===0?l[A]+t[A]*(r-o[A]):a===1?t[A]:0}let p=o[i-1],d=o[i]-p,h=(r-p)/d,m=h-1,g=l[i-1],u=l[i],w=t[i-1],y=t[i],b=(u-g)/d;switch(a){case 0:{let A=h*h*(3-2*h);return g*(1-A)+d*w*(h*m*m)+u*A+d*y*(h*h*m)}case 1:return b*(-6*h*m)+w*(m*(3*h-1))+y*(h*(3*h-2));case 2:return(b*(6-12*h)+w*(6*h-4)+y*(6*h-2))/d;default:return(-12*b+6*w+6*y)/(d*d)}})}function W(o,l,t){let n=o.length;if(l.length!==n||t.length!==n)throw new RangeError("'x', 'y' and 'm' must have the same length");let e=Array.from({length:n},(s,c)=>c).sort((s,c)=>o[s]-o[c]),a=e.map(s=>o[s]),f=e.map(s=>l[s]),r=e.map(s=>t[s]);for(let s=1;s<n;s++)if(!(a[s]-a[s-1]>0))throw new RangeError("'x' must be *strictly* increasing (non - NA)");return(s,c=0)=>I(a,f,r,s,c)}function Z(o,l,t){let n=Array.from(o),e=Array.from(l),a=n.length;if(e.length!==a)throw new RangeError("'xi' and 'yi' must have the same length");let f=Array.from(t),r=Math.min(...n),s=Math.max(...n);if(f.some(i=>i<r||i>s))throw new RangeError("Some interpolation points outside the nodes.");let c=n.map((i,p)=>{let d=1;for(let h=0;h<a;h++)h!==p&&(d*=i-n[h]);return 1/d});return f.map(i=>{let p=0,d=0,h=n.lastIndexOf(i);if(h>=0)return e[h];for(let m=0;m<a;m++){let g=i-n[m],u=c[m]/g;p+=u*e[m],d+=u}return p/d})}function tt(o,l,t,n){let e=Array.from(o),a=Array.from(l),f=Array.from(t),r=e.length;if(a.length!==r||f.length!==r)throw new RangeError("'xi', 'yi' and 'di' must have the same length");let s=e.flatMap(h=>[h,h]),c=2*r,i=a.flatMap(h=>[h,h]),p=[i[0]],d=i.slice();for(let h=1;h<c;h++){let m=[];for(let g=0;g<c-h;g++)h===1&&s[g+1]===s[g]?m.push(f[g>>1]):m.push((d[g+1]-d[g])/(s[g+h]-s[g]));p.push(m[0]),d=m}return Array.from(n,h=>{let m=p[c-1];for(let g=c-2;g>=0;g--)m=m*(h-s[g])+p[g];return m})}function nt(o,l,t,n=[],e={}){let a=e.method??"rk4";if(a!=="euler"&&a!=="rk2"&&a!=="rk4")throw new RangeError(`unknown method '${String(a)}'`);let f=[...n],r=o.length,s=(d,h)=>{let m=Array.from(t(d,h,f));if(m.length!==r)throw new RangeError(`The number of derivatives returned by func() (${m.length}) must equal the length of the initial conditions vector (${r})`);return m},c=(d,h,m)=>d.map((g,u)=>g+h*m[u]),i=[...o],p=[];if(l.length===0)return p;p.push([l[0],...i]);for(let d=1;d<l.length;d++){let h=l[d-1],m=l[d]-h,g=s(h,i);if(a==="euler")i=c(i,m,g);else if(a==="rk2"){let u=s(h+m,c(i,m,g));i=i.map((w,y)=>w+m*(.5*g[y]+.5*u[y]))}else{let u=s(h+m/2,c(i,m/2,g)),w=s(h+m/2,c(i,m/2,u)),y=s(h+m,c(i,m,w));i=i.map((b,A)=>b+m/6*(g[A]+2*u[A]+2*w[A]+y[A]))}p.push([l[d],...i])}return p}function _(o,l,t){let n=l.eps??1e-4,e=l.d??t,a=l.zeroTol??Math.sqrt(Number.EPSILON/7e-7),f=l.r??4;if(!(Number.isInteger(f)&&f>=1))throw new RangeError("'r' must be a positive integer");return{eps:n,r:f,h0:o.map(r=>Math.abs(e*r)+(Math.abs(r)<a?n:0))}}function x(o){let l=[...o];for(let t=1;t<l.length;t++){let n=4**t;for(let e=0;e<l.length-t;e++)l[e]=(l[e+1]*n-l[e])/(n-1)}return l[0]}function N(o,l,t){let n=[...o];return n[l]=n[l]+t,n}function L(o){let l=o.method??"Richardson";if(l!=="Richardson"&&l!=="simple")throw new RangeError(`unknown method "${String(l)}" (expected "Richardson" or "simple")`);return l}function rt(o,l,t={}){let n=[...l],e=n.length;if(L(t)==="simple"){let s=t.eps??1e-4,c=o([...n]);return n.map((i,p)=>(o(N(n,p,s))-c)/s)}let{r:a,h0:f}=_(n,t,1e-4),r=[];for(let s=0;s<e;s++){let c=[],i=f[s];for(let p=0;p<a;p++){if(p>0&&Math.abs(c[p-1])<1e-20?c.push(0):c.push((o(N(n,s,i))-o(N(n,s,-i)))/(2*i)),Number.isNaN(c[p]))throw new RangeError(`func returned NaN at step ${i} from x`);i/=2}r.push(x(c))}return r}function et(o,l,t={}){let n=[...l],e=n.length,a=Array.from(o([...n])),f=a.map(()=>new Array(e).fill(NaN));if(L(t)==="simple"){let c=t.eps??1e-4;for(let i=0;i<e;i++){let p=o(N(n,i,c));a.forEach((d,h)=>f[h][i]=(p[h]-d)/c)}return f}let{r,h0:s}=_(n,t,1e-4);for(let c=0;c<e;c++){let i=a.map(()=>[]),p=s[c];for(let d=0;d<r;d++){let h=o(N(n,c,p)),m=o(N(n,c,-p));a.forEach((g,u)=>i[u].push((h[u]-m[u])/(2*p))),p/=2}a.forEach((d,h)=>f[h][c]=x(i[h]))}return f}function ot(o,l,t={}){if((t.method??"Richardson")!=="Richardson")throw new RangeError('hessian supports only method "Richardson"');let n=[...l],e=n.length,{r:a,h0:f}=_(n,t,.1),r=o([...n]),s=[];for(let i=0;i<e;i++){let p=[],d=f[i];for(let h=0;h<a;h++)p.push((o(N(n,i,d))-2*r+o(N(n,i,-d)))/d**2),d/=2;s.push(x(p))}let c=n.map(()=>new Array(e).fill(NaN));for(let i=0;i<e;i++){c[i][i]=s[i];for(let p=0;p<i;p++){let d=[],h=f[i],m=f[p];for(let g=0;g<a;g++){let u=N(N(n,i,h),p,m),w=N(N(n,i,-h),p,-m);d.push((o(u)-2*r+o(w)-s[i]*h**2-s[p]*m**2)/(2*h*m)),h/=2,m/=2}c[i][p]=c[p][i]=x(d)}}return c}export{P as approx,Z as barylag,rt as grad,tt as hermiteInterp,ot as hessian,$ as integrate,et as jacobian,nt as ode,O as optim,F as optimHess,T as optimize,Q as spline,U as splinefun,W as splinefunH,D as uniroot};
1
+ /*! rStats.js 0.15.1 | MIT License | includes code ported from SciPy, Boost.Math, statsmodels, LAPACK and others: see THIRD_PARTY_NOTICES.md at https://github.com/numero-uno-jpn/rStats.js */
2
+ import{a as $,b as T,c as D,d as F,e as O}from"./chunks/chunk-5XQZNKHZ.js";import"./chunks/chunk-VOIJKNL2.js";import{a as k,f as j}from"./chunks/chunk-IQOVOHZG.js";import"./chunks/chunk-4ILI2FSB.js";import{f as S}from"./chunks/chunk-7J4HW6VF.js";import"./chunks/chunk-H4CHJMFU.js";import"./chunks/chunk-UWBYDIOH.js";function M(o,l,t="mean"){if(o.length!==l.length)throw new RangeError("'x' and 'y' lengths differ");let n=[];for(let r=0;r<o.length;r++)!Number.isNaN(o[r])&&!Number.isNaN(l[r])&&n.push(r);n.sort((r,s)=>o[r]-o[s]);let e=typeof t=="function"?t:t==="min"?r=>Math.min(...r):t==="max"?r=>Math.max(...r):S,a=[],f=[];for(let r=0;r<n.length;){let s=o[n[r]],c=r+1;for(;c<n.length&&o[n[c]]===s;)c++;a.push(s),f.push(c-r===1?l[n[r]]:e(n.slice(r,c).map(i=>l[i]))),r=c}return{x:a,y:f}}function X(o,l,t,n){let e=(n-o[t])/(o[t+1]-o[t]);return l[t]+(l[t+1]-l[t])*e}function J(o,l,t){let n=(e,a)=>e===0?0:e*a;return n(1-t,o[l])+n(t,o[l+1])}function P(o,l,t={}){let{method:n="linear",n:e=50,f:a=0,rule:f=1,ties:r="mean"}=t,s=M(o,l,r),c=s.x.length;if(c<=1&&n==="linear")throw new RangeError("need at least two non-NA values to interpolate");if(c===0)throw new RangeError("zero non-NA points");if(n==="constant"&&!(a>=0&&a<=1))throw new RangeError("approx(): invalid f value");let[i,p]=typeof f=="number"?[f,f]:f,d=t.yleft??(i===1?NaN:s.y[0]),h=t.yright??(p===1?NaN:s.y[c-1]),m;if(t.xout!==void 0)m=Array.from(t.xout);else{if(e<=0)throw new RangeError("'approx' requires n >= 1");m=k(s.x[0],s.x[c-1],e)}let g=s.x,u=s.y,w=j(m,g),y=m.map((b,A)=>{let R=w[A];if(Number.isNaN(R))return NaN;if(R===0)return d;let E=R-1;return b===g[E]?u[E]:R===c?h:n==="linear"?X(g,u,E,b):J(u,E,a)});return{x:m,y}}function v(o,l){let t=o.length,n=new Array(t).fill(0),e=new Array(t).fill(0),a=new Array(t).fill(0);if(t<2)return{b:n,c:e,d:a};if(t<3)return n[0]=(l[1]-l[0])/(o[1]-o[0]),n[1]=n[0],{b:n,c:e,d:a};let f=t-1;a[0]=o[1]-o[0],e[1]=(l[1]-l[0])/a[0];for(let r=1;r<f;r++)a[r]=o[r+1]-o[r],n[r]=2*(a[r-1]+a[r]),e[r+1]=(l[r+1]-l[r])/a[r],e[r]=e[r+1]-e[r];n[0]=-a[0],n[f]=-a[t-2],e[0]=0,e[f]=0,t>3&&(e[0]=e[2]/(o[3]-o[1])-e[1]/(o[2]-o[0]),e[f]=e[t-2]/(o[f]-o[t-3])-e[t-3]/(o[t-2]-o[t-4]),e[0]=e[0]*a[0]*a[0]/(o[3]-o[0]),e[f]=-e[f]*a[t-2]*a[t-2]/(o[f]-o[t-4]));for(let r=1;r<t;r++){let s=a[r-1]/n[r-1];n[r]=n[r]-s*a[r-1],e[r]=e[r]-s*e[r-1]}e[f]=e[f]/n[f];for(let r=t-2;r>=0;r--)e[r]=(e[r]-a[r]*e[r+1])/n[r];n[f]=(l[f]-l[t-2])/a[t-2]+a[t-2]*(e[t-2]+2*e[f]);for(let r=0;r<f;r++)n[r]=(l[r+1]-l[r])/a[r]-a[r]*(e[r+1]+2*e[r]),a[r]=(e[r+1]-e[r])/a[r],e[r]=3*e[r];return e[f]=3*e[f],a[f]=a[t-2],{b:n,c:e,d:a}}function z(o,l,t){let n=o.length,e=new Array(n).fill(0),a=new Array(n).fill(0),f=new Array(n).fill(0);for(let r=0;r<n-1;r++){let s=o[r+1]-o[r];e[r]=(l[r+1]-l[r])/s-s*(t[r+1]+2*t[r]),a[r]=3*t[r],f[r]=(t[r+1]-t[r])/s}return{b:e,c:a,d:f}}function Y(o,l){let t=o.length;if(t<3)return v(o,l);let n=Array.from({length:t-1},(c,i)=>o[i+1]-o[i]),e=n.map((c,i)=>(l[i+1]-l[i])/c),a=new Array(t).fill(0),f=new Array(t).fill(0);for(let c=1;c<t-1;c++)a[c]=2*(n[c-1]+n[c]),f[c]=e[c]-e[c-1];for(let c=2;c<t-1;c++){let i=n[c-1]/a[c-1];a[c]=a[c]-i*n[c-1],f[c]=f[c]-i*f[c-1]}let r=new Array(t).fill(0);r[t-2]=f[t-2]/a[t-2];for(let c=t-3;c>=1;c--)r[c]=(f[c]-n[c]*r[c+1])/a[c];let s=z(o,l,r);return s.b[t-1]=e[t-2]+n[t-2]*r[t-2],s}function B(o,l){let t=o.length;if(l[0]!==l[t-1])throw new RangeError("periodic spline needs y[1] == y[n]");if(t<3)return{b:new Array(t).fill(0),c:new Array(t).fill(0),d:new Array(t).fill(0)};let n=t-1,e=Array.from({length:n},(u,w)=>o[w+1]-o[w]),a=e.map((u,w)=>(l[w+1]-l[w])/u),f=u=>u===0?n-1:u-1,r=Array.from({length:n},(u,w)=>2*(e[f(w)]+e[w])),s=Array.from({length:n},(u,w)=>a[w]-a[f(w)]),c=e.slice(),i=new Array(n).fill(0);i[0]=e[n-1],i[n-2]=i[n-2]+e[n-2];let p=i[0],d=r[n-1],h=s[n-1];for(let u=0;u<n-1;u++){if(u+1<n-1){let y=e[u]/r[u];r[u+1]=r[u+1]-y*c[u],i[u+1]=i[u+1]-y*i[u],s[u+1]=s[u+1]-y*s[u]}let w=p/r[u];d-=w*i[u],h-=w*s[u],u+1<n-1&&(p=(u+1===n-2?e[n-2]:0)-w*c[u])}let m=new Array(t).fill(0);m[n-1]=h/d;for(let u=n-2;u>=0;u--){let w=s[u]-i[u]*m[n-1]-(u<n-2?c[u]*m[u+1]:0);m[u]=w/r[u]}m[t-1]=m[0];let g=z(o,l,m);return g.b[t-1]=g.b[0],g.c[t-1]=g.c[0],g.d[t-1]=g.d[0],g}function G(o,l){let t=o.length,{b:n,c:e,d:a}=v(o,l);if(t<2)return{b:n,c:e,d:a};let f=Array.from({length:t-1},(s,c)=>(l[c+1]-l[c])/(o[c+1]-o[c]));for(let s=0;s<t;s++){let c=f[s===0?0:s-1],i=f[s===t-1?t-2:s],p=Math.min(Math.abs(c),Math.abs(i)),d=c*i>0?i>0:n[s]>=0;n[s]=d?Math.min(Math.max(0,n[s]),3*p):Math.max(Math.min(0,n[s]),-3*p)}for(let s=0;s<t-1;s++){let c=o[s+1]-o[s],i=(l[s+1]-l[s])/c;e[s]=(3*i-2*n[s]-n[s+1])/c,a[s]=(n[s]+n[s+1]-2*i)/(c*c)}let r=o[t-1]-o[t-2];return e[t-1]=(n[t-2]+2*n[t-1]-3*(l[t-1]-l[t-2])/r)/r,a[t-1]=a[t-2],{b:n,c:e,d:a}}function q(o,l,t,n){let e=M(o,l,n),a=e.x.length;if(a===0)throw new RangeError("zero non-NA points");t==="periodic"&&e.y[a-1]!==e.y[0]&&(e.y[a-1]=e.y[0]),t==="hyman"&&K(e.y);let f=t==="fmm"?v(e.x,e.y):t==="natural"?Y(e.x,e.y):t==="periodic"?B(e.x,e.y):t==="hyman"?G(e.x,e.y):(()=>{throw new RangeError(`invalid spline method '${String(t)}'`)})();return{method:t,...e,...f}}function K(o){let l=!0,t=!0;for(let n=1;n<o.length;n++){let e=o[n]-o[n-1];e>=0||(l=!1),e<=0||(t=!1)}if(!l&&!t)throw new RangeError("'y' must be increasing or decreasing")}function C(o){let l=Math.trunc(o);if(!(l>=0&&l<=3))throw new RangeError("'deriv' must be between 0 and 3");return l}function H(o,l,t){let n=C(t),{x:e,y:a,b:f,c:r,d:s,method:c}=o,i=e.length,p=c==="natural",d=e[i-1]-e[0],h=0;return Array.from(l,m=>{let g=m;if(c==="periodic"&&i>1){let y=(g-e[0])%d;y<0&&(y+=d),g=e[0]+y}if(p&&n>0&&g<=e[0])return n===1?f[0]:0;if(!(e[h]<=g&&(h===i-1||g<=e[h+1]))){let y=0,b=i;for(;b-y>1;){let A=y+b>>1;e[A]<=g?y=A:b=A}h=y}let u=g-e[h],w=p&&g<e[0]?0:s[h];switch(n){case 0:return a[h]+u*(f[h]+u*(r[h]+u*w));case 1:return f[h]+u*(2*r[h]+u*(3*w));case 2:return 2*r[h]+u*(6*w);default:return 6*w}})}function Q(o,l,t={}){let{method:n="fmm",ties:e="mean"}=t,a=q(o,l,n,e),f;if(t.xout!==void 0)f=Array.from(t.xout);else{let r=a.x.length,s=t.n??3*r;if(s<=0)throw new RangeError("'spline' requires n >= 1");f=k(t.xmin??a.x[0],t.xmax??a.x[r-1],s)}return{x:f,y:H(a,f,0)}}function U(o,l,t={}){let{method:n="fmm",ties:e="mean"}=t;if(n==="monoH.FC"){let f=M(o,l,e);if(f.x.length===0)throw new RangeError("zero non-NA points");let r=V(f.x,f.y);return(s,c=0)=>I(f.x,f.y,r,s,c)}let a=q(o,l,n,e);return(f,r=0)=>H(a,f,r)}function V(o,l){let t=o.length;if(t<2)throw new RangeError("length(m) must be at least two");let n=Array.from({length:t-1},(a,f)=>(l[f+1]-l[f])/(o[f+1]-o[f])),e=Array.from({length:t},(a,f)=>f===0?n[0]:f===t-1?n[t-2]:(n[f-1]+n[f])/2);for(let a=0;a<t-1;a++){let f=n[a];if(f===0){e[a]=0,e[a+1]=0;continue}let r=e[a]/f,s=e[a+1]/f,c=2*r+s-3,i=r+2*s-3;if(c>0&&i>0&&r*(c+i)<c*c){let p=3*f/Math.sqrt(r*r+s*s);e[a]=p*r,e[a+1]=p*s}}return e}function I(o,l,t,n,e){let a=C(e),f=o.length;return Array.from(n,r=>{if(Number.isNaN(r))return NaN;let s=0,c=f;for(;s<c;){let A=s+c>>1;o[A]<=r?s=A+1:c=A}let i=s;if(i===0||i===f){let A=i===0?0:f-1;return a===0?l[A]+t[A]*(r-o[A]):a===1?t[A]:0}let p=o[i-1],d=o[i]-p,h=(r-p)/d,m=h-1,g=l[i-1],u=l[i],w=t[i-1],y=t[i],b=(u-g)/d;switch(a){case 0:{let A=h*h*(3-2*h);return g*(1-A)+d*w*(h*m*m)+u*A+d*y*(h*h*m)}case 1:return b*(-6*h*m)+w*(m*(3*h-1))+y*(h*(3*h-2));case 2:return(b*(6-12*h)+w*(6*h-4)+y*(6*h-2))/d;default:return(-12*b+6*w+6*y)/(d*d)}})}function W(o,l,t){let n=o.length;if(l.length!==n||t.length!==n)throw new RangeError("'x', 'y' and 'm' must have the same length");let e=Array.from({length:n},(s,c)=>c).sort((s,c)=>o[s]-o[c]),a=e.map(s=>o[s]),f=e.map(s=>l[s]),r=e.map(s=>t[s]);for(let s=1;s<n;s++)if(!(a[s]-a[s-1]>0))throw new RangeError("'x' must be *strictly* increasing (non - NA)");return(s,c=0)=>I(a,f,r,s,c)}function Z(o,l,t){let n=Array.from(o),e=Array.from(l),a=n.length;if(e.length!==a)throw new RangeError("'xi' and 'yi' must have the same length");let f=Array.from(t),r=Math.min(...n),s=Math.max(...n);if(f.some(i=>i<r||i>s))throw new RangeError("Some interpolation points outside the nodes.");let c=n.map((i,p)=>{let d=1;for(let h=0;h<a;h++)h!==p&&(d*=i-n[h]);return 1/d});return f.map(i=>{let p=0,d=0,h=n.lastIndexOf(i);if(h>=0)return e[h];for(let m=0;m<a;m++){let g=i-n[m],u=c[m]/g;p+=u*e[m],d+=u}return p/d})}function tt(o,l,t,n){let e=Array.from(o),a=Array.from(l),f=Array.from(t),r=e.length;if(a.length!==r||f.length!==r)throw new RangeError("'xi', 'yi' and 'di' must have the same length");let s=e.flatMap(h=>[h,h]),c=2*r,i=a.flatMap(h=>[h,h]),p=[i[0]],d=i.slice();for(let h=1;h<c;h++){let m=[];for(let g=0;g<c-h;g++)h===1&&s[g+1]===s[g]?m.push(f[g>>1]):m.push((d[g+1]-d[g])/(s[g+h]-s[g]));p.push(m[0]),d=m}return Array.from(n,h=>{let m=p[c-1];for(let g=c-2;g>=0;g--)m=m*(h-s[g])+p[g];return m})}function nt(o,l,t,n=[],e={}){let a=e.method??"rk4";if(a!=="euler"&&a!=="rk2"&&a!=="rk4")throw new RangeError(`unknown method '${String(a)}'`);let f=[...n],r=o.length,s=(d,h)=>{let m=Array.from(t(d,h,f));if(m.length!==r)throw new RangeError(`The number of derivatives returned by func() (${m.length}) must equal the length of the initial conditions vector (${r})`);return m},c=(d,h,m)=>d.map((g,u)=>g+h*m[u]),i=[...o],p=[];if(l.length===0)return p;p.push([l[0],...i]);for(let d=1;d<l.length;d++){let h=l[d-1],m=l[d]-h,g=s(h,i);if(a==="euler")i=c(i,m,g);else if(a==="rk2"){let u=s(h+m,c(i,m,g));i=i.map((w,y)=>w+m*(.5*g[y]+.5*u[y]))}else{let u=s(h+m/2,c(i,m/2,g)),w=s(h+m/2,c(i,m/2,u)),y=s(h+m,c(i,m,w));i=i.map((b,A)=>b+m/6*(g[A]+2*u[A]+2*w[A]+y[A]))}p.push([l[d],...i])}return p}function _(o,l,t){let n=l.eps??1e-4,e=l.d??t,a=l.zeroTol??Math.sqrt(Number.EPSILON/7e-7),f=l.r??4;if(!(Number.isInteger(f)&&f>=1))throw new RangeError("'r' must be a positive integer");return{eps:n,r:f,h0:o.map(r=>Math.abs(e*r)+(Math.abs(r)<a?n:0))}}function x(o){let l=[...o];for(let t=1;t<l.length;t++){let n=4**t;for(let e=0;e<l.length-t;e++)l[e]=(l[e+1]*n-l[e])/(n-1)}return l[0]}function N(o,l,t){let n=[...o];return n[l]=n[l]+t,n}function L(o){let l=o.method??"Richardson";if(l!=="Richardson"&&l!=="simple")throw new RangeError(`unknown method "${String(l)}" (expected "Richardson" or "simple")`);return l}function rt(o,l,t={}){let n=[...l],e=n.length;if(L(t)==="simple"){let s=t.eps??1e-4,c=o([...n]);return n.map((i,p)=>(o(N(n,p,s))-c)/s)}let{r:a,h0:f}=_(n,t,1e-4),r=[];for(let s=0;s<e;s++){let c=[],i=f[s];for(let p=0;p<a;p++){if(p>0&&Math.abs(c[p-1])<1e-20?c.push(0):c.push((o(N(n,s,i))-o(N(n,s,-i)))/(2*i)),Number.isNaN(c[p]))throw new RangeError(`func returned NaN at step ${i} from x`);i/=2}r.push(x(c))}return r}function et(o,l,t={}){let n=[...l],e=n.length,a=Array.from(o([...n])),f=a.map(()=>new Array(e).fill(NaN));if(L(t)==="simple"){let c=t.eps??1e-4;for(let i=0;i<e;i++){let p=o(N(n,i,c));a.forEach((d,h)=>f[h][i]=(p[h]-d)/c)}return f}let{r,h0:s}=_(n,t,1e-4);for(let c=0;c<e;c++){let i=a.map(()=>[]),p=s[c];for(let d=0;d<r;d++){let h=o(N(n,c,p)),m=o(N(n,c,-p));a.forEach((g,u)=>i[u].push((h[u]-m[u])/(2*p))),p/=2}a.forEach((d,h)=>f[h][c]=x(i[h]))}return f}function ot(o,l,t={}){if((t.method??"Richardson")!=="Richardson")throw new RangeError('hessian supports only method "Richardson"');let n=[...l],e=n.length,{r:a,h0:f}=_(n,t,.1),r=o([...n]),s=[];for(let i=0;i<e;i++){let p=[],d=f[i];for(let h=0;h<a;h++)p.push((o(N(n,i,d))-2*r+o(N(n,i,-d)))/d**2),d/=2;s.push(x(p))}let c=n.map(()=>new Array(e).fill(NaN));for(let i=0;i<e;i++){c[i][i]=s[i];for(let p=0;p<i;p++){let d=[],h=f[i],m=f[p];for(let g=0;g<a;g++){let u=N(N(n,i,h),p,m),w=N(N(n,i,-h),p,-m);d.push((o(u)-2*r+o(w)-s[i]*h**2-s[p]*m**2)/(2*h*m)),h/=2,m/=2}c[i][p]=c[p][i]=x(d)}}return c}export{P as approx,Z as barylag,rt as grad,tt as hermiteInterp,ot as hessian,$ as integrate,et as jacobian,nt as ode,O as optim,F as optimHess,T as optimize,Q as spline,U as splinefun,W as splinefunH,D as uniroot};