(function(l,v){typeof exports=="object"&&typeof module<"u"?v(exports):typeof define=="function"&&define.amd?define(["exports"],v):(l=typeof globalThis<"u"?globalThis:l||self,v(l.Psychometric={}))})(this,function(l){"use strict";function v(t){if(t.length===0)return 0;var e=t[0],r=0,a;if(typeof e!="number")return Number.NaN;for(var n=1;n=Math.abs(t[n])?r+=e-a+t[n]:r+=t[n]-a+e,e=a}return e+r}function u(t){if(t.length===0)throw new Error("mean requires at least one data point");return v(t)/t.length}function E(t,e){var r=u(t),a=0,n,o;for(o=0;oh.map((c,f)=>({val:c,index:f})).sort((c,f)=>c.val-f.val).map((c,f)=>({...c,rank:f+1})).sort((c,f)=>c.index-f.index).map(c=>c.rank),o=r??(t?n(t):void 0),i=a??(e?n(e):void 0);if(!o||!i)throw new Error("Insufficient data to calculate Spearman correlation coefficient.");const d=o.reduce((h,c,f)=>h+(c-i[f])**2,0),s=o.length;return 1-6*d/(s*(s**2-1))}function M(t,e,r,a,n){if((!t||!e)&&(r===void 0||a===void 0||n===void 0))throw new Error("Either provide binary and continuous arrays, or provide mean1, mean0, and overallSD.");const o=(t==null?void 0:t.length)??(e==null?void 0:e.length)??0,i=t?t.filter(f=>f===1).length:void 0,d=o-(i??0),s=r??(t&&e?u(e.filter((f,g)=>t[g]===1)):void 0),h=a??(t&&e?u(e.filter((f,g)=>t[g]===0)):void 0),c=n??(e?m(e):void 0);if(s===void 0||h===void 0||c===void 0||i===void 0||d===void 0)throw new Error("Insufficient data to calculate point-biserial correlation coefficient.");return(s-h)/c*Math.sqrt(i*d/o**2)}function q(t,e,r,a,n){if(n){if(n.length!==2||n[0].length!==2||n[1].length!==2)throw new Error("Table must be a 2x2 array.");[t,e]=n[0],[r,a]=n[1]}if(t===void 0||e===void 0||r===void 0||a===void 0)throw new Error("Insufficient data to calculate phi coefficient. Provide a, b, c, and d, or a 2x2 table.");const o=t*a-e*r,i=Math.sqrt((t+e)*(t+r)*(e+a)*(r+a));if(i===0)throw new Error("Denominator is zero, cannot calculate phi coefficient.");return o/i}function p(t,e,r=1.96,a){const n=a??(t!==void 0&&e!==void 0?t/Math.sqrt(e):void 0);if(n===void 0)throw new Error("Insufficient data to calculate margin of error. Provide either stdDev and sampleSize, or a pre-calculated standardError.");return r*n}function S(t,e,r,a=1.96,n){const o=n??(e!==void 0&&r!==void 0?p(e,r,a):void 0);if(o===void 0)throw new Error("Insufficient data to calculate confidence interval. Provide either stdDev, sampleSize, and zScore or a pre-calculated moe.");return{lower:t-o,upper:t+o}}function y(t,e,r,a){if(!r&&(!t||!e))throw new Error("Provide either observed and predicted arrays or a pre-calculated rss with the number of observations.");if(t&&e&&t.length!==e.length)throw new Error("Observed and predicted arrays must be of the same length.");const n=r??(t&&e?t.reduce((i,d,s)=>i+(d-e[s])**2,0):void 0),o=a??(t==null?void 0:t.length);if(n===void 0||o===void 0)throw new Error("Insufficient data to calculate standard error of estimate. Provide complete data or calculated values.");return Math.sqrt(n/(o-2))}function I(t,e,r){const a=e??(t?m(t):void 0),n=r??(t==null?void 0:t.length);if(a===void 0||n===void 0||n===0)throw new Error("Insufficient data to calculate standard error. Provide either values or both stdDev and n.");return a/Math.sqrt(n)}function P(t,e,r){if(!r)throw new Error("A correlation function must be provided.");if(t.length!==e.length)throw new Error("Both forms must have the same number of scores.");return r(t,e)}function D(t){const e=t.length;t[0].length;const r=t.map(o=>w(o)),a=w(t[0].map((o,i)=>u(t.map(d=>d[i])))),n=r.reduce((o,i)=>o+i,0);return e/(e-1)*(1-n/a)}function O(t,e){if(!e)throw new Error("A correlation function must be provided.");const r=t.filter((n,o)=>o%2===0),a=t.filter((n,o)=>o%2!==0);return e(r,a)}function V(t,e,r){if(!r)throw new Error("A correlation function must be provided.");if(t.length!==e.length)throw new Error("Both test administrations must have the same number of scores.");return r(t,e)}function N(t,e,r){if(!r)throw new Error("A correlation function must be provided.");if(t.length!==e.length)throw new Error("Both forms must have the same number of scores.");return r(t,e)}function k(t,e){if(!e)throw new Error("A correlation function must be provided.");const r=t.length;let a=0,n=0;for(let o=0;oo+i,0)/t.length,a=e.reduce((o,i)=>o+i,0)/e.length,n=r-a;return{averageConvergent:r,averageDiscriminant:a,constructValidityIndex:n}}function _(t,e,r){if(t.length!==e.length)throw new Error("Scores arrays must be of the same length.");return r(t,e)}l.alternateFormsReliability=P,l.confidenceInterval=S,l.constructValidity=A,l.criterionRelatedValidity=_,l.cronbachsAlpha=D,l.interRaterReliability=k,l.marginOfError=p,l.parallelFormsReliability=N,l.pearsonCorrelationCoefficient=C,l.phiCoefficient=q,l.pointBiserialCorrelation=M,l.spearmanRankCorrelationCoefficient=b,l.splitHalfReliability=O,l.standardErrorMean=I,l.standardErrorOfEstimate=y,l.testRetestReliability=V,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});