datly 0.0.1 ā 0.0.2
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.
- package/dist/datly.cjs +1 -0
- package/dist/datly.mjs +1 -0
- package/dist/datly.umd.js +1 -1
- package/dist/datly.umd.js.map +1 -0
- package/package.json +24 -11
- package/src/core/dataLoader.js +407 -0
- package/src/core/utils.js +306 -0
- package/src/core/validator.js +205 -0
- package/src/dataviz/index.js +1566 -0
- package/src/descriptive/centralTendency.js +208 -0
- package/src/descriptive/dispersion.js +273 -0
- package/src/descriptive/position.js +268 -0
- package/src/descriptive/shape.js +336 -0
- package/src/index.js +480 -0
- package/src/inferential/confidenceIntervals.js +561 -0
- package/src/inferential/hypothesisTesting.js +527 -0
- package/src/inferential/normalityTests.js +587 -0
- package/src/insights/autoAnalyser.js +685 -0
- package/src/insights/interpreter.js +543 -0
- package/src/insights/patternDetector.js +897 -0
- package/src/insights/reportGenerator.js +1072 -0
- package/src/ml/ClassificationMetrics.js +336 -0
- package/src/ml/DecisionTree.js +412 -0
- package/src/ml/KNearestNeighbors.js +317 -0
- package/src/ml/LinearRegression.js +179 -0
- package/src/ml/LogisticRegression.js +396 -0
- package/src/ml/MachineLearning.js +490 -0
- package/src/ml/NaiveBayes.js +296 -0
- package/src/ml/RandomForest.js +323 -0
- package/src/ml/SupportVectorMachine.js +299 -0
- package/src/ml/baseModel.js +106 -0
- package/src/multivariate/correlation.js +653 -0
- package/src/multivariate/regression.js +660 -0
package/dist/datly.mjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function e(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(){return n=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},n.apply(null,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,i(t,e)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function a(t,e){try{var n=t()}catch(t){return e(t)}return n&&n.then?n.then(void 0,e):n}var o=function(){try{return s?u?Promise.resolve(u):(l||(l=import("fs").then(function(t){return u=t.default||t}).catch(function(){return null})),Promise.resolve(l)):Promise.resolve(null)}catch(t){return Promise.reject(t)}},s="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node,u=null,l=null,c=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.loadCSV=function(t,e){void 0===e&&(e={});try{var r=this,i=n({},{delimiter:",",header:!0,skipEmptyLines:!0,encoding:"utf8"},e);return Promise.resolve(a(function(){function e(){function e(){function e(t){if(!n)throw new Error("No file system available. Use fetch, fs module, or pass CSV text directly to parseCSV()");return r.parseCSV(n,i)}var a=function(){if(!n&&"undefined"!=typeof fetch)return Promise.resolve(fetch(t)).then(function(t){if(!t.ok)throw new Error("HTTP error! status: "+t.status);return Promise.resolve(t.text()).then(function(t){n=t})})}();return a&&a.then?a.then(e):e()}var a=function(){if(!n&&"undefined"!=typeof window&&window.fs){var e=function(t){n=t};return window.fs.readFileSync?e(window.fs.readFileSync(t,{encoding:i.encoding})):Promise.resolve(window.fs.readFile(t,{encoding:i.encoding})).then(e)}}();return a&&a.then?a.then(e):e()}var n,a=function(){if(s)return Promise.resolve(o()).then(function(e){e&&(n=e.readFileSync(t,{encoding:i.encoding}))})}();return a&&a.then?a.then(e):e()},function(t){throw new Error("Failed to load CSV: "+t.message)}))}catch(t){return Promise.reject(t)}},e.loadJSON=function(t,e){void 0===e&&(e={});try{var r=this,i=n({},{validateTypes:!0,autoInferHeaders:!0},e);return Promise.resolve(a(function(){function e(t){return r.parseJSON(n,i)}var n,a=function(){if("string"==typeof t&&!t.trim().startsWith("{")&&!t.trim().startsWith("[")){var e,r=function(){function r(){function r(t){if(!e)throw new Error("No file system available");n=JSON.parse(e)}var i=function(){if(!e&&"undefined"!=typeof fetch)return Promise.resolve(fetch(t)).then(function(t){if(!t.ok)throw new Error("HTTP error! status: "+t.status);return Promise.resolve(t.text()).then(function(t){e=t})})}();return i&&i.then?i.then(r):r()}var i=function(){if(!e&&"undefined"!=typeof window&&window.fs){var n=function(t){e=t};return window.fs.readFileSync?n(window.fs.readFileSync(t,{encoding:"utf8"})):Promise.resolve(window.fs.readFile(t,{encoding:"utf8"})).then(n)}}();return i&&i.then?i.then(r):r()},i=function(){if(s)return Promise.resolve(o()).then(function(n){n&&(e=n.readFileSync(t,{encoding:"utf8"}))})}();return i&&i.then?i.then(r):r()}if("string"==typeof t)n=JSON.parse(t);else{if("object"!=typeof t)throw new Error("Invalid JSON input: must be string, file path, or object");n=t}}();return a&&a.then?a.then(e):e()},function(t){throw new Error("Failed to load JSON: "+t.message)}))}catch(t){return Promise.reject(t)}},e.parseJSON=function(t,e){if(!t)throw new Error("JSON data is empty or null");if(Array.isArray(t))return this.parseJSONArray(t,e);if(t.headers&&t.data)return this.parseStructuredJSON(t,e);if("object"==typeof t)return this.parseJSONObject(t,e);throw new Error("Unsupported JSON format")},e.parseJSONArray=function(t,e){var n=this;if(0===t.length)throw new Error("JSON array is empty");var r,i=t[0];if("object"!=typeof i||null===i)throw new Error("JSON array must contain objects");if(e.autoInferHeaders){var a=new Set;t.forEach(function(t){"object"==typeof t&&null!==t&&Object.keys(t).forEach(function(t){return a.add(t)})}),r=Array.from(a)}else r=Object.keys(i);var o=t.map(function(t,i){if("object"!=typeof t||null===t)return console.warn("Row "+i+" is not an object, skipping"),null;var a={};return r.forEach(function(r){var i=t[r];e.validateTypes&&(i=n.inferType(i)),a[r]=i}),a}).filter(function(t){return null!==t});return{headers:r,data:o,length:o.length,columns:r.length,source:"json_array"}},e.parseStructuredJSON=function(t,e){var n=this,r=t.headers,i=t.data;if(!Array.isArray(r))throw new Error("Headers must be an array");if(!Array.isArray(i))throw new Error("Data must be an array");if(0===r.length)throw new Error("Headers array is empty");var a=i.map(function(t,i){if(Array.isArray(t)){var a={};return r.forEach(function(r,i){var o=i<t.length?t[i]:null;e.validateTypes&&(o=n.inferType(o)),a[r]=o}),a}if("object"==typeof t&&null!==t){var o={};return r.forEach(function(r){var i=t[r];e.validateTypes&&(i=n.inferType(i)),o[r]=i}),o}return console.warn("Row "+i+" has invalid format, skipping"),null}).filter(function(t){return null!==t});return{headers:r,data:a,length:a.length,columns:r.length,source:"structured_json"}},e.parseJSONObject=function(t,e){var n=this,r=Object.entries(t);if(0===r.length)throw new Error("JSON object is empty");var i=r.map(function(t){var r=t[1];return{key:t[0],value:e.validateTypes?n.inferType(r):r}});return{headers:["key","value"],data:i,length:i.length,columns:2,source:"json_object"}},e.parseCSV=function(t,e){var n=this,r=t.split("\n").filter(function(t){return!e.skipEmptyLines||""!==t.trim()});if(0===r.length)throw new Error("CSV file is empty");for(var i=e.header?r[0].split(e.delimiter).map(function(t){return t.trim().replace(/['"]/g,"")}):Array.from({length:r[0].split(e.delimiter).length},function(t,e){return"col_"+e}),a=[],o=function(){var t=r[s].split(e.delimiter);if(t.length===i.length){var o={};i.forEach(function(e,r){var i=t[r].trim().replace(/['"]/g,"");o[e]=n.inferType(i)}),a.push(o)}},s=e.header?1:0;s<r.length;s++)o();return{headers:i,data:a,length:a.length,columns:i.length}},e.inferType=function(t){return""===t||"null"===t||"NULL"===t||"NaN"===t?null:"true"===t||"TRUE"===t||"false"!==t&&"FALSE"!==t&&(/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d*\.\d+$/.test(t)?parseFloat(t):t)},e.cleanData=function(t){var e=n({},t,{data:t.data.filter(function(t){return Object.values(t).some(function(t){return null!=t})})});return e.length=e.data.length,e},e.getDataInfo=function(t){var e={rows:t.length,columns:t.columns,headers:t.headers,types:{},nullCounts:{},uniqueCounts:{}};return t.headers.forEach(function(n){var r=t.data.map(function(t){return t[n]}),i=r.filter(function(t){return null!=t}),a=[].concat(new Set(i.map(function(t){return typeof t})));e.types[n]=1===a.length?a[0]:"mixed",e.nullCounts[n]=r.length-i.length,e.uniqueCounts[n]=new Set(i).size}),e},e.getColumn=function(t,e){if(!t.headers.includes(e))throw new Error("Column '"+e+"' not found");return t.data.map(function(t){return t[e]}).filter(function(t){return null!=t&&!isNaN(t)})},e.getColumns=function(t,e){var n=this,r={};return e.forEach(function(e){r[e]=n.getColumn(t,e)}),r},e.filterRows=function(t,e){return n({},t,{data:t.data.filter(e),length:t.data.filter(e).length})},e.sortBy=function(t,e,r){return void 0===r&&(r="asc"),n({},t,{data:[].concat(t.data).sort(function(t,n){var i=t[e],a=n[e];return null==i?1:null==a?-1:"string"==typeof i&&"string"==typeof a?"asc"===r?i.localeCompare(a):a.localeCompare(i):"asc"===r?i-a:a-i})})},t}(),f=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.validateData=function(t){var e=[],n=[];return t&&"object"==typeof t?(t.data&&Array.isArray(t.data)||e.push("Dataset must contain a data array"),t.headers&&Array.isArray(t.headers)||e.push("Dataset must contain a headers array"),t.data&&0===t.data.length&&n.push("Dataset is empty"),t.data&&t.headers&&(new Set(t.headers).size!==t.headers.length&&e.push("Duplicate column headers found"),t.data.forEach(function(e,r){var i=Object.keys(e),a=t.headers.filter(function(t){return!i.includes(t)}),o=i.filter(function(e){return!t.headers.includes(e)});a.length>0&&n.push("Row "+r+": Missing columns: "+a.join(", ")),o.length>0&&n.push("Row "+r+": Extra columns: "+o.join(", "))})),{valid:0===e.length,errors:e,warnings:n}):(e.push("Dataset must be an object"),{valid:!1,errors:e,warnings:n})},e.validateNumericColumn=function(t){if(!Array.isArray(t))throw new Error("Column must be an array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("Column contains no valid numeric values");return{valid:!0,validCount:e.length,invalidCount:t.length-e.length,cleanData:e}},e.validateSampleSize=function(t,e){if(void 0===e&&(e=2),!Array.isArray(t))throw new Error("Sample must be an array");if(t.length<e)throw new Error("Sample size ("+t.length+") must be at least "+e);return!0},e.validateConfidenceLevel=function(t){if("number"!=typeof t||t<=0||t>=1)throw new Error("Confidence level must be a number between 0 and 1");return!0},e.validateCorrelationInputs=function(t,e){if(this.validateNumericColumn(t),this.validateNumericColumn(e),t.length!==e.length)throw new Error("Columns must have the same length");if(t.length<3)throw new Error("Need at least 3 paired observations for correlation");return!0},e.validateRegressionInputs=function(t,e){if(this.validateNumericColumn(t),this.validateNumericColumn(e),t.length!==e.length)throw new Error("X and Y arrays must have the same length");if(t.length<3)throw new Error("Need at least 3 data points for regression");if(0===this.calculateVariance(t))throw new Error("X values must have non-zero variance");return!0},e.calculateVariance=function(t){var e=t.reduce(function(t,e){return t+e},0)/t.length;return t.reduce(function(t,n){return t+Math.pow(n-e,2)},0)/(t.length-1)},e.validateGroupsForANOVA=function(t){var e=this;if(!Array.isArray(t)||t.length<2)throw new Error("ANOVA requires at least 2 groups");return t.forEach(function(t,n){if(!Array.isArray(t))throw new Error("Group "+n+" must be an array");e.validateSampleSize(t,2),e.validateNumericColumn(t)}),!0},e.validateContingencyTable=function(t,e){if(!Array.isArray(t)||!Array.isArray(e))throw new Error("Both columns must be arrays");if(t.length!==e.length)throw new Error("Columns must have the same length");if(t.length<5)throw new Error("Need at least 5 observations for chi-square test");return!0},e.isInteger=function(t){return"number"==typeof t&&Number.isInteger(t)},e.isPositive=function(t){return"number"==typeof t&&t>0},e.isInRange=function(t,e,n){return"number"==typeof t&&t>=e&&t<=n},e.hasMinimumObservations=function(t,e){return Array.isArray(t)&&t.length>=e},e.checkForConstantValues=function(t){return 1===new Set(t).size},e.validateHypothesisTestInputs=function(t,e,n){if(this.validateSampleSize(t,2),("two-sample"===n||"paired"===n)&&(this.validateSampleSize(e,2),"paired"===n&&t.length!==e.length))throw new Error("Paired samples must have the same length");return this.validateNumericColumn(t),e&&this.validateNumericColumn(e),!0},t}(),h=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.detectOutliers=function(t,e){void 0===e&&(e="iqr");var n=[].concat(t).sort(function(t,e){return t-e}),r=[],i=[];switch(e){case"iqr":var a=this.quantile(n,.25),o=this.quantile(n,.75),s=o-a,u=a-1.5*s,l=o+1.5*s;t.forEach(function(t,e){(t<u||t>l)&&(r.push(t),i.push(e))});break;case"zscore":var c=this.mean(t),f=this.standardDeviation(t);t.forEach(function(t,e){Math.abs((t-c)/f)>3&&(r.push(t),i.push(e))});break;case"modified_zscore":var h=this.median(t),d=t.map(function(t){return Math.abs(t-h)}),p=this.median(d);t.forEach(function(t,e){Math.abs(.6745*(t-h)/p)>3.5&&(r.push(t),i.push(e))});break;default:throw new Error("Unknown outlier detection method: "+e)}return{outliers:r,indices:i,count:r.length,percentage:r.length/t.length*100}},e.frequencyTable=function(t){var e={},n=t.length;return t.forEach(function(t){var n=null==t?"null":String(t);e[n]=(e[n]||0)+1}),Object.entries(e).map(function(t){var e=t[0],r=t[1];return{value:"null"===e?null:e,frequency:r,relativeFrequency:r/n,percentage:r/n*100}}).sort(function(t,e){return e.frequency-t.frequency})},e.groupBy=function(t,e,n){var r=this,i={};t.data.forEach(function(t){var n=t[e];i[n]||(i[n]=[]),i[n].push(t)});var a={};return Object.entries(i).forEach(function(t){var e=t[0],i=t[1];a[e]={count:i.length,data:i},n&&"object"==typeof n&&Object.entries(n).forEach(function(t){var n=t[0],o=t[1],s=i.map(function(t){return t[n]}).filter(function(t){return"number"==typeof t&&!isNaN(t)});s.length>0&&(a[e][o+"_"+n]=r.applyAggregation(s,o))})}),a},e.applyAggregation=function(t,e){switch(e){case"mean":return this.mean(t);case"median":return this.median(t);case"sum":return t.reduce(function(t,e){return t+e},0);case"min":return Math.min.apply(Math,t);case"max":return Math.max.apply(Math,t);case"std":return this.standardDeviation(t);case"var":return this.variance(t);case"count":return t.length;default:throw new Error("Unknown aggregation function: "+e)}},e.sample=function(t,e,r){if(void 0===r&&(r="random"),e>=t.length)return n({},t);var i;switch(r){case"random":i=this.randomSample(t.length,e).map(function(e){return t.data[e]});break;case"systematic":var a=Math.floor(t.length/e);i=[];for(var o=0;o<e;o++)i.push(t.data[o*a]);break;case"first":i=t.data.slice(0,e);break;case"last":i=t.data.slice(-e);break;default:throw new Error("Unknown sampling method: "+r)}return n({},t,{data:i,length:i.length})},e.randomSample=function(t,e){for(var n=Array.from({length:t},function(t,e){return e}),r=[],i=0;i<e;i++){var a=Math.floor(Math.random()*n.length);r.push(n.splice(a,1)[0])}return r},e.bootstrap=function(t,e,n){void 0===n&&(n=1e3);for(var r=[],i=0;i<n;i++){for(var a=[],o=0;o<t.length;o++){var s=Math.floor(Math.random()*t.length);a.push(t[s])}var u=this.applyStatistic(a,e);r.push(u)}return{bootstrapStats:r.sort(function(t,e){return t-e}),mean:this.mean(r),standardError:this.standardDeviation(r),confidenceInterval:{lower:this.quantile(r,.025),upper:this.quantile(r,.975)}}},e.applyStatistic=function(t,e){switch(e){case"mean":return this.mean(t);case"median":return this.median(t);case"std":return this.standardDeviation(t);case"var":return this.variance(t);default:if("function"==typeof e)return e(t);throw new Error("Unknown statistic: "+e)}},e.contingencyTable=function(t,e){var n=[].concat(new Set(t)),r=[].concat(new Set(e)),i={},a={row:{},col:{},grand:0};n.forEach(function(t){i[t]={},a.row[t]=0}),r.forEach(function(t){a.col[t]=0});for(var o=0;o<t.length;o++){var s=t[o],u=e[o];i[s][u]||(i[s][u]=0),i[s][u]++,a.row[s]++,a.col[u]++,a.grand++}return n.forEach(function(t){r.forEach(function(e){i[t][e]||(i[t][e]=0)})}),{table:i,totals:a,rows:n,columns:r}},e.mean=function(t){return t.reduce(function(t,e){return t+e},0)/t.length},e.median=function(t){var e=[].concat(t).sort(function(t,e){return t-e}),n=Math.floor(e.length/2);return e.length%2==0?(e[n-1]+e[n])/2:e[n]},e.quantile=function(t,e){var n=[].concat(t).sort(function(t,e){return t-e}),r=(n.length-1)*e,i=Math.floor(r),a=Math.ceil(r),o=r%1;return i===a?n[i]:n[i]*(1-o)+n[a]*o},e.standardDeviation=function(t){return Math.sqrt(this.variance(t))},e.variance=function(t){var e=this.mean(t);return t.reduce(function(t,n){return t+Math.pow(n-e,2)},0)/(t.length-1)},e.round=function(t,e){return void 0===e&&(e=4),Math.round(t*Math.pow(10,e))/Math.pow(10,e)},e.formatNumber=function(t,e){return void 0===e&&(e=4),"number"!=typeof t?t:this.round(t,e)},t}(),d=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.mean=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");return e.reduce(function(t,e){return t+e},0)/e.length},e.median=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=e.sort(function(t,e){return t-e}),r=Math.floor(n.length/2);return n.length%2==0?(n[r-1]+n[r])/2:n[r]},e.mode=function(t){var e=this;if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var n={},r=0;t.forEach(function(t){var e=null==t?"null":String(t);n[e]=(n[e]||0)+1,r=Math.max(r,n[e])});var i=Object.entries(n).filter(function(t){return t[1]===r}).map(function(t){var n=t[0];return"null"===n?null:e.parseValue(n)});return{values:i,frequency:r,isMultimodal:i.length>1,isUniform:1===r&&Object.keys(n).length===t.length}},e.parseValue=function(t){return/^-?\d+$/.test(t)?parseInt(t,10):/^-?\d*\.\d+$/.test(t)?parseFloat(t):"true"===t||"false"!==t&&t},e.geometricMean=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)&&t>0});if(0===e.length)throw new Error("Geometric mean requires positive numeric values");var n=e.reduce(function(t,e){return t+Math.log(e)},0);return Math.exp(n/e.length)},e.harmonicMean=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)&&t>0});if(0===e.length)throw new Error("Harmonic mean requires positive numeric values");var n=e.reduce(function(t,e){return t+1/e},0);return e.length/n},e.trimmedMean=function(t,e){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");if("number"!=typeof e||e<0||e>=50)throw new Error("Percentage must be between 0 and 50");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===n.length)throw new Error("No valid numeric values found");var r=n.sort(function(t,e){return t-e}),i=Math.floor(e/100*r.length),a=r.slice(i,r.length-i);if(0===a.length)throw new Error("Too much trimming - no values remain");return a.reduce(function(t,e){return t+e},0)/a.length},e.quadraticMean=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=e.reduce(function(t,e){return t+e*e},0);return Math.sqrt(n/e.length)},e.weightedMean=function(t,e){if(!Array.isArray(t)||!Array.isArray(e))throw new Error("Values and weights must be arrays");if(t.length!==e.length)throw new Error("Values and weights must have the same length");if(0===t.length)throw new Error("Arrays must not be empty");for(var n=[],r=0;r<t.length;r++)"number"==typeof t[r]&&"number"==typeof e[r]&&!isNaN(t[r])&&!isNaN(e[r])&&isFinite(t[r])&&isFinite(e[r])&&e[r]>=0&&n.push({value:t[r],weight:e[r]});if(0===n.length)throw new Error("No valid value-weight pairs found");var i=n.reduce(function(t,e){return t+e.weight},0);if(0===i)throw new Error("Total weight cannot be zero");return n.reduce(function(t,e){return t+e.value*e.weight},0)/i},e.midrange=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");return(Math.min.apply(Math,e)+Math.max.apply(Math,e))/2},t}(),p=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.variance=function(t,e){if(void 0===e&&(e=!0),!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===n.length)throw new Error("No valid numeric values found");if(e&&n.length<2)throw new Error("Sample variance requires at least 2 values");var r=n.reduce(function(t,e){return t+e},0)/n.length;return n.reduce(function(t,e){return t+Math.pow(e-r,2)},0)/(e?n.length-1:n.length)},e.standardDeviation=function(t,e){return void 0===e&&(e=!0),Math.sqrt(this.variance(t,e))},e.range=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=Math.min.apply(Math,e),r=Math.max.apply(Math,e);return{range:r-n,min:n,max:r}},e.interquartileRange=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=e.sort(function(t,e){return t-e}),r=this.quantile(n,.25),i=this.quantile(n,.75);return{iqr:i-r,q1:r,q3:i}},e.quantile=function(t,e){var n=(t.length-1)*e,r=Math.floor(n),i=Math.ceil(n),a=n%1;return r===i?t[r]:t[r]*(1-a)+t[i]*a},e.coefficientOfVariation=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=e.reduce(function(t,e){return t+e},0)/e.length;if(0===n)throw new Error("Cannot calculate coefficient of variation when mean is zero");var r=this.standardDeviation(t);return{cv:r/Math.abs(n),cvPercent:r/Math.abs(n)*100}},e.meanAbsoluteDeviation=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=e.reduce(function(t,e){return t+e},0)/e.length;return{mad:e.reduce(function(t,e){return t+Math.abs(e-n)},0)/e.length,mean:n}},e.medianAbsoluteDeviation=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=e.sort(function(t,e){return t-e}),r=this.quantile(n,.5),i=e.map(function(t){return Math.abs(t-r)}).sort(function(t,e){return t-e});return{mad:this.quantile(i,.5),median:r}},e.standardError=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");return this.standardDeviation(t)/Math.sqrt(e.length)},e.quartileCoefficient=function(t){var e=this.interquartileRange(t),n=e.q1,r=e.q3;if(n+r===0)throw new Error("Cannot calculate quartile coefficient when Q1 + Q3 = 0");return(r-n)/(r+n)},e.percentileRange=function(t,e,n){if(e>=n)throw new Error("Lower percentile must be less than upper percentile");if(e<0||n>100)throw new Error("Percentiles must be between 0 and 100");var r=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===r.length)throw new Error("No valid numeric values found");var i=r.sort(function(t,e){return t-e}),a=this.quantile(i,e/100),o=this.quantile(i,n/100);return{range:o-a,lowerValue:a,upperValue:o,lowerPercentile:e,upperPercentile:n}},e.giniCoefficient=function(t){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)&&t>=0});if(0===e.length)throw new Error("Gini coefficient requires non-negative numeric values");var n=e.sort(function(t,e){return t-e}),r=n.length,i=n.reduce(function(t,e){return t+e},0)/r;if(0===i)return 0;for(var a=0,o=0;o<r;o++)for(var s=0;s<r;s++)a+=Math.abs(n[o]-n[s]);return a/(2*r*r*i)},e.robustScale=function(t){var e=this.interquartileRange(t),n=this.quantile(t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}).sort(function(t,e){return t-e}),.5);return{scaledValues:t.map(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)?0!==e.iqr?(t-n)/e.iqr:0:null}),median:n,iqr:e.iqr}},t}(),m=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.quantile=function(t,e){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");if("number"!=typeof e||e<0||e>1)throw new Error("Quantile must be between 0 and 1");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===n.length)throw new Error("No valid numeric values found");var r=n.sort(function(t,e){return t-e}),i=(r.length-1)*e,a=Math.floor(i),o=Math.ceil(i),s=i%1;return a===o?r[a]:r[a]*(1-s)+r[o]*s},e.percentile=function(t,e){if("number"!=typeof e||e<0||e>100)throw new Error("Percentile must be between 0 and 100");return this.quantile(t,e/100)},e.quartiles=function(t){return{q1:this.quantile(t,.25),q2:this.quantile(t,.5),q3:this.quantile(t,.75),iqr:this.quantile(t,.75)-this.quantile(t,.25)}},e.quintiles=function(t){return{q1:this.quantile(t,.2),q2:this.quantile(t,.4),q3:this.quantile(t,.6),q4:this.quantile(t,.8)}},e.deciles=function(t){for(var e={},n=1;n<=9;n++)e["d"+n]=this.quantile(t,n/10);return e},e.percentileRank=function(t,e){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");if("number"!=typeof e||!isFinite(e))throw new Error("Value must be a finite number");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===n.length)throw new Error("No valid numeric values found");return(n.filter(function(t){return t<e}).length+.5*n.filter(function(t){return t===e}).length)/n.length*100},e.zScore=function(t,e){if(!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");if("number"!=typeof e||!isFinite(e))throw new Error("Value must be a finite number");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===n.length)throw new Error("No valid numeric values found");var r=n.reduce(function(t,e){return t+e},0)/n.length,i=n.reduce(function(t,e){return t+Math.pow(e-r,2)},0)/(n.length-1),a=Math.sqrt(i);if(0===a)throw new Error("Cannot calculate z-score when standard deviation is zero");return(e-r)/a},e.boxplotStats=function(t){var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=e.sort(function(t,e){return t-e}),r=this.quantile(n,.25),i=this.quantile(n,.5),a=this.quantile(n,.75),o=a-r,s=r-1.5*o,u=a+1.5*o,l=n.filter(function(t){return t<s||t>u}),c=n.filter(function(t){return t>=s&&t<=u});return{min:Math.min.apply(Math,c),q1:r,median:i,q3:a,max:Math.max.apply(Math,c),iqr:o,lowerFence:s,upperFence:u,outliers:l,outlierCount:l.length}},e.fiveNumberSummary=function(t){var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");return{minimum:Math.min.apply(Math,e),q1:this.quantile(e,.25),median:this.quantile(e,.5),q3:this.quantile(e,.75),maximum:Math.max.apply(Math,e)}},e.rank=function(t,e){if(void 0===e&&(e="average"),!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var n=[];if(t.forEach(function(t,e){"number"==typeof t&&!isNaN(t)&&isFinite(t)&&n.push({value:t,originalIndex:e})}),0===n.length)throw new Error("No valid numeric values found");n.sort(function(t,e){return t.value-e.value});for(var r=new Array(t.length).fill(null),i=1,a=function(t){for(var a,s=n[t].value,u=[t];t+1<n.length&&n[t+1].value===s;)t++,u.push(t);switch(e){case"average":a=(i+i+u.length-1)/2;break;case"min":a=i;break;case"max":a=i+u.length-1;break;case"first":return u.forEach(function(t,e){r[n[t].originalIndex]=i+e}),i+=u.length,o=t,1;default:throw new Error("Unknown ranking method. Use: average, min, max, or first")}u.forEach(function(t){r[n[t].originalIndex]=a}),i+=u.length,o=t},o=0;o<n.length;o++)a(o);return r},e.normalizedRank=function(t){var e=this.rank(t),n=e.filter(function(t){return null!==t}),r=Math.max.apply(Math,n);return e.map(function(t){return null!==t?(t-1)/(r-1):null})},e.standardizedValues=function(t){var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===e.length)throw new Error("No valid numeric values found");var n=e.reduce(function(t,e){return t+e},0)/e.length,r=e.reduce(function(t,e){return t+Math.pow(e-n,2)},0)/(e.length-1),i=Math.sqrt(r);return t.map(0===i?function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)?0:null}:function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)?(t-n)/i:null})},t}(),g=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.skewness=function(t,e){if(void 0===e&&(e=!0),!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<3)throw new Error("Skewness calculation requires at least 3 values");var r=n.length,i=n.reduce(function(t,e){return t+e},0)/r,a=n.reduce(function(t,e){return t+Math.pow(e-i,2)},0)/(r-1),o=Math.sqrt(a);if(0===o)return 0;var s=n.reduce(function(t,e){return t+Math.pow((e-i)/o,3)},0);return e?s/r:r/((r-1)*(r-2))*s},e.kurtosis=function(t,e,n){if(void 0===e&&(e=!0),void 0===n&&(n=!0),!Array.isArray(t)||0===t.length)throw new Error("Column must be a non-empty array");var r=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(r.length<4)throw new Error("Kurtosis calculation requires at least 4 values");var i=r.length,a=r.reduce(function(t,e){return t+e},0)/i,o=r.reduce(function(t,e){return t+Math.pow(e-a,2)},0)/(i-1),s=Math.sqrt(o);if(0===s)return n?-3:0;var u,l=r.reduce(function(t,e){return t+Math.pow((e-a)/s,4)},0);return u=e?l/i:i*(i+1)/((i-1)*(i-2)*(i-3))*l-3*Math.pow(i-1,2)/((i-2)*(i-3)),n?u-3:u},e.isNormalDistribution=function(t,e){void 0===e&&(e=.05);var n=this.shapiroWilkTest(t),r=this.jarqueBeraTest(t);return{shapiroWilk:{statistic:n.statistic,pValue:n.pValue,isNormal:n.pValue>e},jarqueBera:{statistic:r.statistic,pValue:r.pValue,isNormal:r.pValue>e},skewness:this.skewness(t,!1),kurtosis:this.kurtosis(t,!1,!0),isNormalByTests:n.pValue>e&&r.pValue>e}},e.shapiroWilkTest=function(t){var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(e.length<3||e.length>5e3)throw new Error("Shapiro-Wilk test requires between 3 and 5000 observations");for(var n=e.length,r=[].concat(e).sort(function(t,e){return t-e}),i=r.reduce(function(t,e){return t+e},0)/n,a=r.reduce(function(t,e){return t+Math.pow(e-i,2)},0),o=0,s=0;s<Math.floor(n/2);s++)o+=this.shapiroWilkCoefficient(s+1,n)*(r[n-1-s]-r[s]);var u=o*o/a,l=this.shapiroWilkPValue(u,n);return{statistic:u,pValue:l,isNormal:l>.05}},e.shapiroWilkCoefficient=function(t,e){return e<=10&&t<=e?[0,.7071,.7071,.6872,.6646,.6431,.6233,.6052,.5888,.5739,.5601][t]||.5:.5+1*this.normalInverse((t-.375)/(e+.25))},e.normalInverse=function(t){if(t<=0||t>=1)throw new Error("p must be between 0 and 1");if(t>.5)return-this.normalInverse(1-t);var e=Math.sqrt(-2*Math.log(t));return(((((2.506628277459239*e-30.66479806614716)*e+138.357751867269)*e-275.9285104469687)*e+220.9460984245205)*e-39.69683028665376)/((((-13.28068155288572*e+66.80131188771972)*e-155.6989798598866)*e+161.5858368580409)*e-54.47609879822406)*e+1},e.shapiroWilkPValue=function(t,e){if(e<3)return 1;if(t>=1)return 1;if(t<=0)return 0;var n,r=Math.log(t);return n=e<=11?-(.459*e-2.273)*r:(r-(-1.5861-.31082*Math.log(e)-.083751*Math.pow(Math.log(e),2)+.0038915*Math.pow(Math.log(e),3)))/Math.exp(-.4803-.082676*Math.log(e)+.0030302*Math.pow(Math.log(e),2)),1-this.standardNormalCDF(n)},e.jarqueBeraTest=function(t){var e=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(e.length<4)throw new Error("Jarque-Bera test requires at least 4 observations");var n=e.length,r=this.skewness(t,!1),i=this.kurtosis(t,!1,!0),a=n/6*(Math.pow(r,2)+Math.pow(i,2)/4),o=1-this.chiSquareCDF(a,2);return{statistic:a,pValue:o,skewness:r,kurtosis:i,isNormal:o>.05}},e.standardNormalCDF=function(t){return.5*(1+this.erf(t/Math.sqrt(2)))},e.erf=function(t){var e=t<0?-1:1,n=1/(1+.3275911*(t=Math.abs(t)));return e*(1-((((1.061405429*n-1.453152027)*n+1.421413741)*n-.284496736)*n+.254829592)*n*Math.exp(-t*t))},e.chiSquareCDF=function(t,e){return t<=0?0:this.incompleteGamma(e/2,t/2)/this.gamma(e/2)},e.incompleteGamma=function(t,e){if(e<=0)return 0;if(t<=0)return 1;for(var n=1,r=1,i=1;i<100&&(n+=r*=e/(t+i-1),!(Math.abs(r)<1e-12));i++);return Math.pow(e,t)*Math.exp(-e)*n},e.gamma=function(t){if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*this.gamma(1-t));t-=1;var e=1,n=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];e=n[0];for(var r=1;r<n.length;r++)e+=n[r]/(t+r);var i=t+n.length-1.5;return Math.sqrt(2*Math.PI)*Math.pow(i,t+.5)*Math.exp(-i)*e},e.momentCoefficient=function(t,e){if("number"!=typeof e||e<1)throw new Error("Moment must be a positive integer");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===n.length)throw new Error("No valid numeric values found");var r=n.reduce(function(t,e){return t+e},0)/n.length;return n.reduce(function(t,n){return t+Math.pow(n-r,e)},0)/n.length},e.pearsonSkewness=function(t,e){void 0===e&&(e=1);var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===n.length)throw new Error("No valid numeric values found");var r=n.reduce(function(t,e){return t+e},0)/n.length,i=n.reduce(function(t,e){return t+Math.pow(e-r,2)},0)/(n.length-1),a=Math.sqrt(i);if(0===a)return 0;if(1===e){var o=[].concat(n).sort(function(t,e){return t-e}),s=o.length%2==0?(o[o.length/2-1]+o[o.length/2])/2:o[Math.floor(o.length/2)];return(r-s)/a}if(2===e)return 3*(r-this.median(n))/a;throw new Error("Mode must be 1 or 2")},e.median=function(t){var e=[].concat(t).sort(function(t,e){return t-e}),n=Math.floor(e.length/2);return e.length%2==0?(e[n-1]+e[n])/2:e[n]},t}(),v=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.tTest=function(t,e,n,r){void 0===n&&(n="two-sample"),void 0===r&&(r=.05);var i=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(i.length<2)throw new Error("Sample 1 must have at least 2 valid values");switch(n){case"one-sample":return this.oneSampleTTest(i,e,r);case"two-sample":var a=e.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(a.length<2)throw new Error("Sample 2 must have at least 2 valid values");return this.twoSampleTTest(i,a,r);case"paired":if(t.length!==e.length)throw new Error("Paired samples must have the same length");return this.pairedTTest(i,e,r);default:throw new Error("Unknown t-test type. Use: one-sample, two-sample, or paired")}},e.oneSampleTTest=function(t,e,n){void 0===n&&(n=.05);var r=t.length,i=t.reduce(function(t,e){return t+e},0)/r,a=t.reduce(function(t,e){return t+Math.pow(e-i,2)},0)/(r-1),o=Math.sqrt(a/r);if(0===o)throw new Error("Cannot perform t-test when standard error is zero");var s=(i-e)/o,u=r-1,l=2*(1-this.tCDF(Math.abs(s),u));return{type:"one-sample",statistic:s,pValue:l,degreesOfFreedom:u,sampleMean:i,hypothesizedMean:e,standardError:o,criticalValue:this.tInverse(1-n/2,u),significant:l<n,alpha:n}},e.twoSampleTTest=function(t,e,n,r){void 0===n&&(n=.05),void 0===r&&(r=!1);var i,a,o,s=t.length,u=e.length,l=t.reduce(function(t,e){return t+e},0)/s,c=e.reduce(function(t,e){return t+e},0)/u,f=t.reduce(function(t,e){return t+Math.pow(e-l,2)},0)/(s-1),h=e.reduce(function(t,e){return t+Math.pow(e-c,2)},0)/(u-1);if(r?(o=Math.sqrt(((s-1)*f+(u-1)*h)/(s+u-2)*(1/s+1/u)),a=s+u-2):(o=Math.sqrt(f/s+h/u),a=Math.pow(f/s+h/u,2)/(Math.pow(f/s,2)/(s-1)+Math.pow(h/u,2)/(u-1))),0===o)throw new Error("Cannot perform t-test when standard error is zero");i=(l-c)/o;var d=2*(1-this.tCDF(Math.abs(i),a));return{type:"two-sample",statistic:i,pValue:d,degreesOfFreedom:a,sample1Mean:l,sample2Mean:c,meanDifference:l-c,standardError:o,equalVariances:r,criticalValue:this.tInverse(1-n/2,a),significant:d<n,alpha:n}},e.pairedTTest=function(t,e,n){if(void 0===n&&(n=.05),t.length!==e.length)throw new Error("Paired samples must have equal length");for(var r=[],i=0;i<t.length;i++)"number"==typeof t[i]&&"number"==typeof e[i]&&!isNaN(t[i])&&!isNaN(e[i])&&isFinite(t[i])&&isFinite(e[i])&&r.push(t[i]-e[i]);if(r.length<2)throw new Error("Need at least 2 valid paired observations");return this.oneSampleTTest(r,0,n)},e.zTest=function(t,e,n,r){void 0===r&&(r=.05);var i=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===i.length)throw new Error("No valid numeric values found");if(n<=0)throw new Error("Population standard deviation must be positive");var a=i.length,o=i.reduce(function(t,e){return t+e},0)/a,s=n/Math.sqrt(a),u=(o-e)/s,l=2*(1-this.normalCDF(Math.abs(u)));return{type:"z-test",statistic:u,pValue:l,sampleMean:o,populationMean:e,populationStd:n,sampleSize:a,standardError:s,criticalValue:this.normalInverse(1-r/2),significant:l<r,alpha:r}},e.anovaTest=function(t,e){if(void 0===e&&(e=.05),!Array.isArray(t)||t.length<2)throw new Error("ANOVA requires at least 2 groups");var n=t.map(function(t){return t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)})});n.forEach(function(t,e){if(t.length<2)throw new Error("Group "+(e+1)+" must have at least 2 valid values")});var r=n.length,i=n.map(function(t){return t.reduce(function(t,e){return t+e},0)/t.length}),a=n.map(function(t){return t.length}),o=a.reduce(function(t,e){return t+e},0),s=n.flat().reduce(function(t,e){return t+e},0)/o,u=n.reduce(function(t,e,n){return t+a[n]*Math.pow(i[n]-s,2)},0),l=n.reduce(function(t,e,n){var r=i[n];return t+e.reduce(function(t,e){return t+Math.pow(e-r,2)},0)},0),c=r-1,f=o-r,h=u/c,d=l/f;if(0===d)throw new Error("Cannot perform ANOVA when within-group variance is zero");var p=h/d,m=1-this.fCDF(p,c,f);return{type:"one-way-anova",statistic:p,pValue:m,dfBetween:c,dfWithin:f,sumOfSquaresBetween:u,sumOfSquaresWithin:l,meanSquareBetween:h,meanSquareWithin:d,groupMeans:i,grandMean:s,significant:m<e,alpha:e}},e.chiSquareTest=function(t,e,n){if(void 0===n&&(n=.05),t.length!==e.length)throw new Error("Columns must have the same length");var r=this.createContingencyTable(t,e),i=r.table,a=r.totals,o=r.rows,s=r.columns,u=0,l={};o.forEach(function(t){l[t]={},s.forEach(function(e){var n=a.row[t]*a.col[e]/a.grand;l[t][e]=n,n<5&&console.warn("Warning: Expected frequency ("+n.toFixed(2)+") is less than 5"),u+=Math.pow(i[t][e]-n,2)/n})});var c=(o.length-1)*(s.length-1),f=1-this.chiSquareCDF(u,c);return{type:"chi-square-independence",statistic:u,pValue:f,degreesOfFreedom:c,observed:i,expected:l,significant:f<n,alpha:n,cramersV:this.cramersV(u,a.grand,Math.min(o.length,s.length))}},e.createContingencyTable=function(t,e){var n=[].concat(new Set(t)),r=[].concat(new Set(e)),i={},a={row:{},col:{},grand:0};n.forEach(function(t){i[t]={},a.row[t]=0}),r.forEach(function(t){a.col[t]=0});for(var o=0;o<t.length;o++){var s=t[o],u=e[o];i[s][u]||(i[s][u]=0),i[s][u]++,a.row[s]++,a.col[u]++,a.grand++}return n.forEach(function(t){r.forEach(function(e){i[t][e]||(i[t][e]=0)})}),{table:i,totals:a,rows:n,columns:r}},e.cramersV=function(t,e,n){return Math.sqrt(t/(e*(n-1)))},e.mannWhitneyTest=function(t,e,n){void 0===n&&(n=.05);var r=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}),i=e.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===r.length||0===i.length)throw new Error("Both samples must contain valid numeric values");var a=r.length,o=i.length,s=[].concat(r.map(function(t){return{value:t,group:1}}),i.map(function(t){return{value:t,group:2}}));s.sort(function(t,e){return t.value-e.value});for(var u=1,l=function(t){for(var e=[s[t]];t+1<s.length&&s[t+1].value===s[t].value;)t++,e.push(s[t]);var n=(u+u+e.length-1)/2;e.forEach(function(t){return t.rank=n}),u+=e.length,c=t},c=0;c<s.length;c++)l(c);var f=s.filter(function(t){return 1===t.group}).reduce(function(t,e){return t+e.rank},0)-a*(a+1)/2,h=a*o-f,d=Math.min(f,h),p=(d-a*o/2)/Math.sqrt(a*o*(a+o+1)/12),m=2*(1-this.normalCDF(Math.abs(p)));return{type:"mann-whitney-u",statistic:d,u1:f,u2:h,zStatistic:p,pValue:m,sample1Size:a,sample2Size:o,significant:m<n,alpha:n}},e.tCDF=function(t,e){return 1-.5*this.incompleteBeta(e/2,.5,e/(t*t+e))},e.tInverse=function(t,e){if(t<=0||t>=1)return NaN;var n=this.normalInverse(t);return n+n/4/e+(5*n*n*n+16*n)/96/(e*e)+(3*n*n*n*n*n+19*n*n*n+17*n)/384/(e*e*e)},e.normalCDF=function(t){return.5*(1+this.erf(t/Math.sqrt(2)))},e.normalInverse=function(t){if(t<=0||t>=1)throw new Error("p must be between 0 and 1");var e=[-39.69683028665376,220.9460984245205,-275.9285104469687,138.357751867269,-30.66479806614716,2.506628277459239],n=[-54.47609879822406,161.5858368580409,-155.6989798598866,66.80131188771972,-13.28068155288572,1];if(t>.5)return-this.normalInverse(1-t);for(var r=Math.sqrt(-2*Math.log(t)),i=e[5],a=n[5],o=4;o>=0;o--)i=i*r+e[o],a=a*r+n[o];return i/a},e.fCDF=function(t,e,n){return 1-this.incompleteBeta(n/2,e/2,n/(n+e*t))},e.chiSquareCDF=function(t,e){return t<=0?0:this.incompleteGamma(e/2,t/2)/this.gamma(e/2)},e.erf=function(t){var e=t<0?-1:1,n=1/(1+.3275911*(t=Math.abs(t)));return e*(1-((((1.061405429*n-1.453152027)*n+1.421413741)*n-.284496736)*n+.254829592)*n*Math.exp(-t*t))},e.incompleteBeta=function(t,e,n){if(n<=0)return 0;if(n>=1)return 1;var r=Math.exp(this.logGamma(t+e)-this.logGamma(t)-this.logGamma(e)+t*Math.log(n)+e*Math.log(1-n));return n<(t+1)/(t+e+2)?r*this.continuedFractionBeta(t,e,n)/t:1-r*this.continuedFractionBeta(e,t,1-n)/e},e.continuedFractionBeta=function(t,e,n){var r=t+e,i=t+1,a=t-1,o=1,s=1-r*n/i;Math.abs(s)<1e-30&&(s=1e-30);for(var u=s=1/s,l=1;l<=100;l++){var c=2*l,f=l*(e-l)*n/((a+c)*(t+c));s=1+f*s,Math.abs(s)<1e-30&&(s=1e-30),o=1+f/o,Math.abs(o)<1e-30&&(o=1e-30),u*=(s=1/s)*o,s=1+(f=-(t+l)*(r+l)*n/((t+c)*(i+c)))*s,Math.abs(s)<1e-30&&(s=1e-30),o=1+f/o,Math.abs(o)<1e-30&&(o=1e-30);var h=(s=1/s)*o;if(u*=h,Math.abs(h-1)<1e-12)break}return u},e.logGamma=function(t){var e=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],n=1.000000000190015,r=t,i=t,a=t+5.5;a-=(t+.5)*Math.log(a);for(var o=0;o<6;o++)n+=e[o]/++i;return-a+Math.log(2.5066282746310007*n/r)},e.incompleteGamma=function(t,e){if(e<=0)return 0;for(var n=1,r=1,i=1;i<100&&(n+=r*=e/(t+i-1),!(Math.abs(r)<1e-12));i++);return Math.pow(e,t)*Math.exp(-e)*n},e.gamma=function(t){return Math.exp(this.logGamma(t))},t}(),y=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.mean=function(t,e){if(void 0===e&&(e=.95),e<=0||e>=1)throw new Error("Confidence level must be between 0 and 1");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<2)throw new Error("Need at least 2 valid observations");var r=n.length,i=n.reduce(function(t,e){return t+e},0)/r,a=n.reduce(function(t,e){return t+Math.pow(e-i,2)},0)/(r-1),o=Math.sqrt(a/r),s=this.tInverse(1-(1-e)/2,r-1)*o;return{mean:i,standardError:o,marginOfError:s,lowerBound:i-s,upperBound:i+s,confidence:e,degreesOfFreedom:r-1,sampleSize:r}},e.meanKnownVariance=function(t,e,n){if(void 0===n&&(n=.95),n<=0||n>=1)throw new Error("Confidence level must be between 0 and 1");if(e<=0)throw new Error("Population standard deviation must be positive");var r=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===r.length)throw new Error("No valid numeric values found");var i=r.length,a=r.reduce(function(t,e){return t+e},0)/i,o=e/Math.sqrt(i),s=this.normalInverse(1-(1-n)/2)*o;return{mean:a,standardError:o,marginOfError:s,lowerBound:a-s,upperBound:a+s,confidence:n,sampleSize:i,populationStd:e}},e.proportion=function(t,e,n){if(void 0===n&&(n=.95),!Number.isInteger(t)||!Number.isInteger(e))throw new Error("Successes and total must be integers");if(t<0||e<=0||t>e)throw new Error("Invalid values: 0 ⤠successes ⤠total, total > 0");if(n<=0||n>=1)throw new Error("Confidence level must be between 0 and 1");var r=t/e,i=this.normalInverse(1-(1-n)/2);(e*r<5||e*(1-r)<5)&&console.warn("Warning: Normal approximation may not be accurate. Consider using Wilson score interval.");var a=Math.sqrt(r*(1-r)/e),o=i*a,s={proportion:r,standardError:a,marginOfError:o,lowerBound:Math.max(0,r-o),upperBound:Math.min(1,r+o),confidence:n,sampleSize:e,successes:t},u=this.wilsonScoreInterval(t,e,n);return{normal:s,wilson:u,recommended:e*r>=5&&e*(1-r)>=5?s:u}},e.wilsonScoreInterval=function(t,e,n){void 0===n&&(n=.95);var r=t/e,i=this.normalInverse(1-(1-n)/2),a=i*i,o=1+a/e,s=(r+a/(2*e))/o,u=i*Math.sqrt(r*(1-r)/e+a/(4*e*e))/o;return{proportion:r,center:s,halfWidth:u,lowerBound:s-u,upperBound:s+u,confidence:n,sampleSize:e,successes:t}},e.variance=function(t,e){if(void 0===e&&(e=.95),e<=0||e>=1)throw new Error("Confidence level must be between 0 and 1");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<2)throw new Error("Need at least 2 valid observations");var r=n.length,i=n.reduce(function(t,e){return t+e},0)/r,a=n.reduce(function(t,e){return t+Math.pow(e-i,2)},0)/(r-1),o=1-e,s=r-1,u=this.chiSquareInverse(o/2,s);return{sampleVariance:a,lowerBound:s*a/this.chiSquareInverse(1-o/2,s),upperBound:s*a/u,confidence:e,degreesOfFreedom:s,sampleSize:r}},e.standardDeviation=function(t,e){void 0===e&&(e=.95);var n=this.variance(t,e);return{sampleStandardDeviation:Math.sqrt(n.sampleVariance),lowerBound:Math.sqrt(n.lowerBound),upperBound:Math.sqrt(n.upperBound),confidence:e,degreesOfFreedom:n.degreesOfFreedom,sampleSize:n.sampleSize}},e.meanDifference=function(t,e,n,r){if(void 0===n&&(n=.95),void 0===r&&(r=!1),n<=0||n>=1)throw new Error("Confidence level must be between 0 and 1");var i=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}),a=e.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(i.length<2||a.length<2)throw new Error("Both samples must have at least 2 valid observations");var o,s,u=i.length,l=a.length,c=i.reduce(function(t,e){return t+e},0)/u,f=a.reduce(function(t,e){return t+e},0)/l,h=c-f,d=i.reduce(function(t,e){return t+Math.pow(e-c,2)},0)/(u-1),p=a.reduce(function(t,e){return t+Math.pow(e-f,2)},0)/(l-1);r?(o=Math.sqrt(((u-1)*d+(l-1)*p)/(u+l-2)*(1/u+1/l)),s=u+l-2):(o=Math.sqrt(d/u+p/l),s=Math.pow(d/u+p/l,2)/(Math.pow(d/u,2)/(u-1)+Math.pow(p/l,2)/(l-1)));var m=this.tInverse(1-(1-n)/2,s)*o;return{meanDifference:h,sample1Mean:c,sample2Mean:f,standardError:o,marginOfError:m,lowerBound:h-m,upperBound:h+m,confidence:n,degreesOfFreedom:s,equalVariances:r}},e.pairedMeanDifference=function(t,e,n){if(void 0===n&&(n=.95),t.length!==e.length)throw new Error("Paired samples must have equal length");for(var r=[],i=0;i<t.length;i++)"number"==typeof t[i]&&"number"==typeof e[i]&&!isNaN(t[i])&&!isNaN(e[i])&&isFinite(t[i])&&isFinite(e[i])&&r.push(t[i]-e[i]);if(r.length<2)throw new Error("Need at least 2 valid paired observations");return this.mean(r,n)},e.correlation=function(t,e,n,r){if(void 0===n&&(n=.95),void 0===r&&(r="pearson"),n<=0||n>=1)throw new Error("Confidence level must be between 0 and 1");if(t.length!==e.length)throw new Error("x and y must have the same length");for(var i=[],a=0;a<t.length;a++)"number"==typeof t[a]&&"number"==typeof e[a]&&!isNaN(t[a])&&!isNaN(e[a])&&isFinite(t[a])&&isFinite(e[a])&&i.push({x:t[a],y:e[a]});if(i.length<3)throw new Error("Need at least 3 valid paired observations");var o,s=i.length;if("pearson"!==r)throw new Error("Only Pearson correlation is supported for confidence intervals");var u=i.map(function(t){return t.x}),l=i.map(function(t){return t.y});if(o=this.pearsonCorrelation(u,l),Math.abs(o)>=1)throw new Error("Cannot calculate confidence interval for perfect correlation");var c=.5*Math.log((1+o)/(1-o)),f=1/Math.sqrt(s-3),h=this.normalInverse(1-(1-n)/2)*f,d=c-h,p=c+h;return{correlation:o,fisherZ:c,standardError:f,lowerBound:(Math.exp(2*d)-1)/(Math.exp(2*d)+1),upperBound:(Math.exp(2*p)-1)/(Math.exp(2*p)+1),confidence:n,sampleSize:s}},e.pearsonCorrelation=function(t,e){for(var n=t.length,r=t.reduce(function(t,e){return t+e},0)/n,i=e.reduce(function(t,e){return t+e},0)/n,a=0,o=0,s=0,u=0;u<n;u++){var l=t[u]-r,c=e[u]-i;a+=l*c,o+=l*l,s+=c*c}var f=Math.sqrt(o*s);return 0===f?0:a/f},e.median=function(t,e){if(void 0===e&&(e=.95),e<=0||e>=1)throw new Error("Confidence level must be between 0 and 1");var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<3)throw new Error("Need at least 3 valid observations for median CI");var r=[].concat(n).sort(function(t,e){return t-e}),i=r.length,a=this.normalInverse(1-(1-e)/2),o=Math.floor(i/2-a*Math.sqrt(i)/2),s=Math.ceil(i/2+a*Math.sqrt(i)/2),u=Math.max(0,o-1),l=Math.min(i-1,s-1);return{median:i%2==0?(r[i/2-1]+r[i/2])/2:r[Math.floor(i/2)],lowerBound:r[u],upperBound:r[l],confidence:e,sampleSize:i,lowerIndex:u+1,upperIndex:l+1}},e.bootstrapCI=function(t,e,n,r){if(void 0===n&&(n=.95),void 0===r&&(r=1e3),n<=0||n>=1)throw new Error("Confidence level must be between 0 and 1");var i=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(0===i.length)throw new Error("No valid numeric values found");for(var a=[],o=0;o<r;o++){for(var s=[],u=0;u<i.length;u++){var l=Math.floor(Math.random()*i.length);s.push(i[l])}var c=this.calculateStatistic(s,e);a.push(c)}a.sort(function(t,e){return t-e});var f=1-n,h=Math.floor(f/2*r),d=Math.floor((1-f/2)*r)-1,p=this.calculateStatistic(i,e),m=a.reduce(function(t,e){return t+e},0)/a.length;return{originalStatistic:p,bootstrapMean:m,bias:m-p,standardError:this.calculateStandardDeviation(a),lowerBound:a[h],upperBound:a[d],confidence:n,iterations:r}},e.calculateStatistic=function(t,e){switch(e){case"mean":return t.reduce(function(t,e){return t+e},0)/t.length;case"median":var n=[].concat(t).sort(function(t,e){return t-e}),r=Math.floor(n.length/2);return n.length%2==0?(n[r-1]+n[r])/2:n[r];case"std":return this.calculateStandardDeviation(t);case"var":return this.calculateVariance(t);default:if("function"==typeof e)return e(t);throw new Error("Unknown statistic: "+e)}},e.calculateStandardDeviation=function(t){var e=t.reduce(function(t,e){return t+e},0)/t.length,n=t.reduce(function(t,n){return t+Math.pow(n-e,2)},0)/(t.length-1);return Math.sqrt(n)},e.calculateVariance=function(t){var e=t.reduce(function(t,e){return t+e},0)/t.length;return t.reduce(function(t,n){return t+Math.pow(n-e,2)},0)/(t.length-1)},e.normalInverse=function(t){if(t<=0||t>=1)throw new Error("p must be between 0 and 1");var e=[-39.69683028665376,220.9460984245205,-275.9285104469687,138.357751867269,-30.66479806614716,2.506628277459239],n=[-54.47609879822406,161.5858368580409,-155.6989798598866,66.80131188771972,-13.28068155288572,1];if(t>.5)return-this.normalInverse(1-t);for(var r=Math.sqrt(-2*Math.log(t)),i=e[5],a=n[5],o=4;o>=0;o--)i=i*r+e[o],a=a*r+n[o];return i/a},e.tInverse=function(t,e){if(t<=0||t>=1)return NaN;var n=this.normalInverse(t);return n+n/4/e+(5*n*n*n+16*n)/96/(e*e)+(3*n*n*n*n*n+19*n*n*n+17*n)/384/(e*e*e)},e.chiSquareInverse=function(t,e){if(t<=0||t>=1)throw new Error("p must be between 0 and 1");if(e<=0)throw new Error("Degrees of freedom must be positive");for(var n=e,r=0;r<100;r++){var i=this.chiSquareCDF(n,e)-t,a=this.chiSquarePDF(n,e);if(Math.abs(i)<1e-12)break;if(0===a)break;(n-=i/a)<=0&&(n=e/2)}return Math.max(0,n)},e.chiSquareCDF=function(t,e){return t<=0?0:this.incompleteGamma(e/2,t/2)/this.gamma(e/2)},e.chiSquarePDF=function(t,e){return t<=0?0:Math.pow(t,e/2-1)*Math.exp(-t/2)/(Math.pow(2,e/2)*this.gamma(e/2))},e.incompleteGamma=function(t,e){if(e<=0)return 0;for(var n=1,r=1,i=1;i<100&&(n+=r*=e/(t+i-1),!(Math.abs(r)<1e-12));i++);return Math.pow(e,t)*Math.exp(-e)*n},e.gamma=function(t){var e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*this.gamma(1-t));t-=1;for(var n=e[0],r=1;r<e.length;r++)n+=e[r]/(t+r);var i=t+e.length-1.5;return Math.sqrt(2*Math.PI)*Math.pow(i,t+.5)*Math.exp(-i)*n},t}(),b=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.shapiroWilk=function(t,e){void 0===e&&(e=.05);var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<3||n.length>5e3)throw new Error("Shapiro-Wilk test requires between 3 and 5000 observations");var r=n.length,i=[].concat(n).sort(function(t,e){return t-e}),a=i.reduce(function(t,e){return t+e},0)/r,o=i.reduce(function(t,e){return t+Math.pow(e-a,2)},0);if(0===o)return{statistic:NaN,pValue:NaN,isNormal:!1,error:"All values are identical"};for(var s=0,u=0;u<Math.floor(r/2);u++)s+=this.shapiroWilkCoefficient(u+1,r)*(i[r-1-u]-i[u]);var l=s*s/o,c=this.shapiroWilkPValue(l,r);return{statistic:l,pValue:c,isNormal:c>e,alpha:e,sampleSize:r,interpretation:this.interpretNormalityResult(c,e,"Shapiro-Wilk")}},e.shapiroWilkCoefficient=function(t,e){return e<=10&&t<=e?[0,.7071,.7071,.6872,.6646,.6431,.6233,.6052,.5888,.5739,.5601][t]||.5:.5+1*this.normalInverse((t-.375)/(e+.25))},e.shapiroWilkPValue=function(t,e){if(e<3)return 1;if(t>=1)return 1;if(t<=0)return 0;var n,r=Math.log(t);return n=e<=11?-(.459*e-2.273)*r:(r-(-1.5861-.31082*Math.log(e)-.083751*Math.pow(Math.log(e),2)+.0038915*Math.pow(Math.log(e),3)))/Math.exp(-.4803-.082676*Math.log(e)+.0030302*Math.pow(Math.log(e),2)),1-this.standardNormalCDF(n)},e.kolmogorovSmirnov=function(t,e){void 0===e&&(e=.05);var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<5)throw new Error("Kolmogorov-Smirnov test requires at least 5 observations");var r=n.length,i=[].concat(n).sort(function(t,e){return t-e}),a=i.reduce(function(t,e){return t+e},0)/r,o=i.reduce(function(t,e){return t+Math.pow(e-a,2)},0)/(r-1),s=Math.sqrt(o);if(0===s)return{statistic:NaN,pValue:NaN,isNormal:!1,error:"All values are identical"};for(var u=0,l=0;l<r;l++){var c=(l+1)/r,f=this.standardNormalCDF((i[l]-a)/s),h=Math.abs(c-f),d=Math.abs(l/r-f);u=Math.max(u,h,d)}var p=u*Math.sqrt(r),m=this.kolmogorovSmirnovPValue(p);return{statistic:u,pValue:m,isNormal:m>e,alpha:e,sampleSize:r,lambda:p,interpretation:this.interpretNormalityResult(m,e,"Kolmogorov-Smirnov")}},e.kolmogorovSmirnovPValue=function(t){if(t<=0)return 1;if(t>7)return 0;for(var e=0,n=1;n<=100;n++){var r=2*Math.pow(-1,n-1)*Math.exp(-2*n*n*t*t);if(e+=r,Math.abs(r)<1e-12)break}return Math.min(1,Math.max(0,e))},e.andersonDarling=function(t,e){void 0===e&&(e=.05);var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<8)throw new Error("Anderson-Darling test requires at least 8 observations");var r=n.length,i=[].concat(n).sort(function(t,e){return t-e}),a=i.reduce(function(t,e){return t+e},0)/r,o=i.reduce(function(t,e){return t+Math.pow(e-a,2)},0)/(r-1),s=Math.sqrt(o);if(0===s)return{statistic:NaN,pValue:NaN,isNormal:!1,error:"All values are identical"};for(var u=0,l=0;l<r;l++){var c=(i[l]-a)/s,f=this.standardNormalCDF(c),h=this.standardNormalCDF(-c);f>0&&h>0&&(u+=(2*l+1)*(Math.log(f)+Math.log(h)))}var d=-r-1/r*u,p=d*(1+.75/r+2.25/(r*r)),m=this.andersonDarlingPValue(p);return{statistic:d,adjustedStatistic:p,pValue:m,isNormal:m>e,alpha:e,sampleSize:r,interpretation:this.interpretNormalityResult(m,e,"Anderson-Darling")}},e.andersonDarlingPValue=function(t){return t<=.2?1-Math.exp(-1.2337141/t)*(2.00012+(.247105-(.0649821-(.0347962-(.011672-.00168691*t)*t)*t)*t)*t):t<=.34?1-Math.exp(-.9177603-1.25156*t)*(1.38033+(.421981-.668119*t)*t):t<.6?Math.exp(.731-3.009*t+4.86*t*t):t<10?Math.exp(1.0776-(2.30695-(.43424-(.082433-(.008056-3146e-7*t)*t)*t)*t)*t):0},e.jarqueBera=function(t,e){void 0===e&&(e=.05);var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<4)throw new Error("Jarque-Bera test requires at least 4 observations");var r=n.length,i=this.calculateSkewness(n),a=this.calculateKurtosis(n,!0),o=r/6*(Math.pow(i,2)+Math.pow(a,2)/4),s=1-this.chiSquareCDF(o,2);return{statistic:o,pValue:s,isNormal:s>e,alpha:e,sampleSize:r,skewness:i,excessKurtosis:a,interpretation:this.interpretNormalityResult(s,e,"Jarque-Bera")}},e.dagoTest=function(t,e){void 0===e&&(e=.05);var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<20)throw new Error("D'Agostino test requires at least 20 observations");var r=n.length,i=this.calculateSkewness(n),a=this.calculateKurtosis(n,!0),o=this.skewnessZScore(i,r),s=this.kurtosisZScore(a,r),u=o*o+s*s,l=1-this.chiSquareCDF(u,2);return{statistic:u,pValue:l,isNormal:l>e,alpha:e,sampleSize:r,skewness:i,excessKurtosis:a,skewnessZ:o,kurtosisZ:s,interpretation:this.interpretNormalityResult(l,e,"D'Agostino K-squared")}},e.skewnessZScore=function(t,e){var n=t*Math.sqrt((e+1)*(e+3)/(6*(e-2))),r=-1+Math.sqrt(2*(3*(e*e+27*e-70)*(e+1)*(e+3)/((e-2)*(e+5)*(e+7)*(e+9))-1)),i=1/Math.sqrt(.5*Math.log(r)),a=Math.sqrt(2/(r-1));return i*Math.log(n/a+Math.sqrt(Math.pow(n/a,2)+1))},e.kurtosisZScore=function(t,e){var n=(t-3*(e-1)/(e+1))/Math.sqrt(24*e*(e-2)*(e-3)/((e+1)*(e+1)*(e+3)*(e+5))),r=6*(e*e-5*e+2)/((e+7)*(e+9))*Math.sqrt(6*(e+3)*(e+5)/(e*(e-2)*(e-3))),i=6+8/r*(2/r+Math.sqrt(1+4/Math.pow(r,2)));return Math.sqrt(9*i/2)*((1-2/i)/(1+n*Math.sqrt(2/(i-4)))-1)},e.lillieforsTest=function(t,e){void 0===e&&(e=.05);var n=t.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});if(n.length<4||n.length>1e3)throw new Error("Lilliefors test requires between 4 and 1000 observations");var r=n.length,i=[].concat(n).sort(function(t,e){return t-e}),a=i.reduce(function(t,e){return t+e},0)/r,o=i.reduce(function(t,e){return t+Math.pow(e-a,2)},0)/(r-1),s=Math.sqrt(o);if(0===s)return{statistic:NaN,pValue:NaN,isNormal:!1,error:"All values are identical"};for(var u=0,l=0;l<r;l++){var c=(l+1)/r,f=this.standardNormalCDF((i[l]-a)/s),h=Math.abs(c-f),d=Math.abs(l/r-f);u=Math.max(u,h,d)}var p=this.lillieforsPValue(u,r);return{statistic:u,pValue:p,isNormal:p>e,alpha:e,sampleSize:r,interpretation:this.interpretNormalityResult(p,e,"Lilliefors")}},e.lillieforsPValue=function(t,e){var n,r={4:.381,5:.337,6:.319,7:.3,8:.285,9:.271,10:.258,11:.249,12:.242,13:.234,14:.227,15:.22,16:.213,17:.206,18:.2,19:.195,20:.19,25:.173,30:.161,40:.144,50:.131,100:.096};if(r[e])n=r[e];else if(e>100)n=.886/Math.sqrt(e);else{var i=Object.keys(r).map(Number).sort(function(t,e){return t-e}),a=i.filter(function(t){return t<=e}).pop(),o=i.filter(function(t){return t>=e})[0];n=a===o?r[a]:r[a]+(e-a)/(o-a)*(r[o]-r[a])}return t>n?.01:t<.8*n?.2:.05},e.batchNormalityTest=function(t,e){void 0===e&&(e=.05);var n={};try{n.shapiroWilk=this.shapiroWilk(t,e)}catch(t){n.shapiroWilk={error:t.message}}try{n.jarqueBera=this.jarqueBera(t,e)}catch(t){n.jarqueBera={error:t.message}}try{n.andersonDarling=this.andersonDarling(t,e)}catch(t){n.andersonDarling={error:t.message}}try{n.kolmogorovSmirnov=this.kolmogorovSmirnov(t,e)}catch(t){n.kolmogorovSmirnov={error:t.message}}try{t.length>=20&&(n.dagostino=this.dagoTest(t,e))}catch(t){n.dagostino={error:t.message}}var r=Object.entries(n).filter(function(t){var e=t[1];return!e.error&&void 0!==e.pValue}),i=r.filter(function(t){return t[1].isNormal}).length,a=r.length;return{individualTests:n,summary:{testsRun:a,testsPassingNormality:i,consensusNormal:i>=Math.ceil(a/2),strongNormalEvidence:i===a,strongNonNormalEvidence:0===i},recommendation:this.getNormalityRecommendation(n,a,i)}},e.getNormalityRecommendation=function(t,e,n){if(0===e)return"Unable to assess normality - insufficient data or all tests failed";var r=n/e;return 1===r?"Strong evidence for normality - all tests indicate normal distribution":r>=.75?"Good evidence for normality - most tests indicate normal distribution":r>=.5?"Mixed evidence - consider visual inspection and domain knowledge":r>0?"Evidence against normality - most tests indicate non-normal distribution":"Strong evidence against normality - all tests indicate non-normal distribution"},e.calculateSkewness=function(t,e){void 0===e&&(e=!1);var n=t.length,r=t.reduce(function(t,e){return t+e},0)/n,i=t.reduce(function(t,e){return t+Math.pow(e-r,2)},0)/(n-1),a=Math.sqrt(i);if(0===a)return 0;var o=t.reduce(function(t,e){return t+Math.pow((e-r)/a,3)},0);return e?o/n:n/((n-1)*(n-2))*o},e.calculateKurtosis=function(t,e,n){void 0===e&&(e=!0),void 0===n&&(n=!1);var r=t.length,i=t.reduce(function(t,e){return t+e},0)/r,a=t.reduce(function(t,e){return t+Math.pow(e-i,2)},0)/(r-1),o=Math.sqrt(a);if(0===o)return e?-3:0;var s,u=t.reduce(function(t,e){return t+Math.pow((e-i)/o,4)},0);return s=n?u/r:r*(r+1)/((r-1)*(r-2)*(r-3))*u-3*Math.pow(r-1,2)/((r-2)*(r-3)),e?s-3:s},e.interpretNormalityResult=function(t,e,n){return t>e?n+" test: Fail to reject null hypothesis (p-value = "+t.toFixed(4)+" > α = "+e+"). Data appears to be normally distributed.":n+" test: Reject null hypothesis (p-value = "+t.toFixed(4)+" ⤠α = "+e+"). Data appears to be non-normally distributed."},e.standardNormalCDF=function(t){return.5*(1+this.erf(t/Math.sqrt(2)))},e.erf=function(t){var e=t<0?-1:1,n=1/(1+.3275911*(t=Math.abs(t)));return e*(1-((((1.061405429*n-1.453152027)*n+1.421413741)*n-.284496736)*n+.254829592)*n*Math.exp(-t*t))},e.normalInverse=function(t){if(t<=0||t>=1)throw new Error("p must be between 0 and 1");var e=[-39.69683028665376,220.9460984245205,-275.9285104469687,138.357751867269,-30.66479806614716,2.506628277459239],n=[-54.47609879822406,161.5858368580409,-155.6989798598866,66.80131188771972,-13.28068155288572,1];if(t>.5)return-this.normalInverse(1-t);for(var r=Math.sqrt(-2*Math.log(t)),i=e[5],a=n[5],o=4;o>=0;o--)i=i*r+e[o],a=a*r+n[o];return i/a},e.chiSquareCDF=function(t,e){return t<=0?0:this.incompleteGamma(e/2,t/2)/this.gamma(e/2)},e.incompleteGamma=function(t,e){if(e<=0)return 0;for(var n=1,r=1,i=1;i<100&&(n+=r*=e/(t+i-1),!(Math.abs(r)<1e-12));i++);return Math.pow(e,t)*Math.exp(-e)*n},e.gamma=function(t){var e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*this.gamma(1-t));t-=1;for(var n=e[0],r=1;r<e.length;r++)n+=e[r]/(t+r);var i=t+e.length-1.5;return Math.sqrt(2*Math.PI)*Math.pow(i,t+.5)*Math.exp(-i)*n},t}(),w=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.pearson=function(t,e){if(!Array.isArray(t)||!Array.isArray(e))throw new Error("Both inputs must be arrays");if(t.length!==e.length)throw new Error("Arrays must have the same length");for(var n=[],r=0;r<t.length;r++)"number"==typeof t[r]&&"number"==typeof e[r]&&!isNaN(t[r])&&!isNaN(e[r])&&isFinite(t[r])&&isFinite(e[r])&&n.push({x:t[r],y:e[r]});if(n.length<3)throw new Error("Need at least 3 valid paired observations");for(var i=n.length,a=n.map(function(t){return t.x}),o=n.map(function(t){return t.y}),s=a.reduce(function(t,e){return t+e},0)/i,u=o.reduce(function(t,e){return t+e},0)/i,l=0,c=0,f=0,h=0;h<i;h++){var d=a[h]-s,p=o[h]-u;l+=d*p,c+=d*d,f+=p*p}var m=Math.sqrt(c*f);if(0===m)return{correlation:0,pValue:1,tStatistic:0,degreesOfFreedom:i-2,significant:!1,confidenceInterval:{lower:0,upper:0},sampleSize:i};var g=l/m,v=g*Math.sqrt((i-2)/(1-g*g)),y=2*(1-this.tCDF(Math.abs(v),i-2));return{correlation:g,pValue:y,tStatistic:v,degreesOfFreedom:i-2,significant:y<.05,confidenceInterval:this.pearsonConfidenceInterval(g,i),sampleSize:i,interpretation:this.interpretCorrelation(g,y)}},e.spearman=function(t,e){if(!Array.isArray(t)||!Array.isArray(e))throw new Error("Both inputs must be arrays");if(t.length!==e.length)throw new Error("Arrays must have the same length");for(var n=[],r=0;r<t.length;r++)"number"==typeof t[r]&&"number"==typeof e[r]&&!isNaN(t[r])&&!isNaN(e[r])&&isFinite(t[r])&&isFinite(e[r])&&n.push({x:t[r],y:e[r],originalIndex:r});if(n.length<3)throw new Error("Need at least 3 valid paired observations");var i=n.length,a=this.calculateRanks(n.map(function(t){return t.x})),o=this.calculateRanks(n.map(function(t){return t.y})),s=this.pearsonFromArrays(a,o),u=s*Math.sqrt((i-2)/(1-s*s)),l=2*(1-this.tCDF(Math.abs(u),i-2));return{correlation:s,pValue:l,tStatistic:u,degreesOfFreedom:i-2,significant:l<.05,sampleSize:i,xRanks:a,yRanks:o,interpretation:this.interpretCorrelation(s,l,"Spearman")}},e.kendall=function(t,e){if(!Array.isArray(t)||!Array.isArray(e))throw new Error("Both inputs must be arrays");if(t.length!==e.length)throw new Error("Arrays must have the same length");for(var n=[],r=0;r<t.length;r++)"number"==typeof t[r]&&"number"==typeof e[r]&&!isNaN(t[r])&&!isNaN(e[r])&&isFinite(t[r])&&isFinite(e[r])&&n.push({x:t[r],y:e[r]});if(n.length<3)throw new Error("Need at least 3 valid paired observations");for(var i=n.length,a=0,o=0,s=0,u=0,l=0,c=0;c<i;c++)for(var f=c+1;f<i;f++){var h=n[c].x-n[f].x,d=n[c].y-n[f].y;0===h&&0===d?l++:0===h?s++:0===d?u++:h*d>0?a++:o++}var p=i*(i-1)/2,m=(a-o)/Math.sqrt((p-s)*(p-u)),g=m/Math.sqrt(2*(2*i+5)/(9*i*(i-1))),v=2*(1-this.normalCDF(Math.abs(g)));return{correlation:m,pValue:v,zStatistic:g,concordantPairs:a,discordantPairs:o,tiesX:s,tiesY:u,tiesXY:l,significant:v<.05,sampleSize:i,interpretation:this.interpretCorrelation(m,v,"Kendall")}},e.matrix=function(t,e){var n=this;if(void 0===e&&(e="pearson"),!t||!t.headers||!t.data)throw new Error("Invalid dataset format");var r=t.headers.filter(function(e){return t.data.map(function(t){return t[e]}).filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}).length>0});if(r.length<2)throw new Error("Need at least 2 numeric columns for correlation matrix");var i={},a={},o={};return r.forEach(function(s){i[s]={},a[s]={},o[s]={},r.forEach(function(r){if(s===r)i[s][r]=1,a[s][r]=0,o[s][r]=t.data.length;else{var u=t.data.map(function(t){return t[s]}),l=t.data.map(function(t){return t[r]});try{var c;switch(e){case"pearson":c=n.pearson(u,l);break;case"spearman":c=n.spearman(u,l);break;case"kendall":c=n.kendall(u,l);break;default:throw new Error("Unknown correlation method: "+e)}i[s][r]=c.correlation,a[s][r]=c.pValue,o[s][r]=c.sampleSize}catch(t){i[s][r]=NaN,a[s][r]=NaN,o[s][r]=0}}})}),{correlations:i,pValues:a,sampleSizes:o,columns:r,method:e,strongCorrelations:this.findStrongCorrelations(i,a),summary:this.summarizeCorrelationMatrix(i,a,r)}},e.covariance=function(t,e,n){if(void 0===n&&(n=!0),!Array.isArray(t)||!Array.isArray(e))throw new Error("Both inputs must be arrays");if(t.length!==e.length)throw new Error("Arrays must have the same length");for(var r=[],i=0;i<t.length;i++)"number"==typeof t[i]&&"number"==typeof e[i]&&!isNaN(t[i])&&!isNaN(e[i])&&isFinite(t[i])&&isFinite(e[i])&&r.push({x:t[i],y:e[i]});if(r.length<2)throw new Error("Need at least 2 valid paired observations");var a=r.length,o=r.map(function(t){return t.x}),s=r.map(function(t){return t.y}),u=o.reduce(function(t,e){return t+e},0)/a,l=s.reduce(function(t,e){return t+e},0)/a,c=o.reduce(function(t,e,n){return t+(e-u)*(s[n]-l)},0)/(n?a-1:a);return{covariance:c,meanX:u,meanY:l,sampleSize:a,sample:n}},e.covarianceMatrix=function(t,e){var n=this;if(void 0===e&&(e=!0),!t||!t.headers||!t.data)throw new Error("Invalid dataset format");var r=t.headers.filter(function(e){return t.data.map(function(t){return t[e]}).filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}).length>0});if(r.length<2)throw new Error("Need at least 2 numeric columns for covariance matrix");var i={};return r.forEach(function(a){i[a]={},r.forEach(function(r){var o=t.data.map(function(t){return t[a]}),s=t.data.map(function(t){return t[r]}),u=n.covariance(o,s,e);i[a][r]=u.covariance})}),{covariance:i,columns:r,sample:e}},e.partialCorrelation=function(t,e,n){var r=this.pearson(t,e),i=this.pearson(t,n),a=this.pearson(e,n),o=r.correlation-i.correlation*a.correlation,s=Math.sqrt((1-Math.pow(i.correlation,2))*(1-Math.pow(a.correlation,2)));if(0===s)return{correlation:0,pValue:1,significant:!1};var u=o/s,l=Math.min(r.sampleSize,i.sampleSize,a.sampleSize),c=l-3,f=u*Math.sqrt(c/(1-Math.pow(u,2))),h=2*(1-this.tCDF(Math.abs(f),c));return{correlation:u,pValue:h,tStatistic:f,degreesOfFreedom:c,significant:h<.05,sampleSize:l,controllingFor:"third variable"}},e.calculateRanks=function(t){var e=t.map(function(t,e){return{value:t,index:e}});e.sort(function(t,e){return t.value-e.value});for(var n=new Array(t.length),r=1,i=function(t){for(var i=[e[t]];t+1<e.length&&e[t+1].value===e[t].value;)t++,i.push(e[t]);var o=(r+r+i.length-1)/2;i.forEach(function(t){n[t.index]=o}),r+=i.length,a=t},a=0;a<e.length;a++)i(a);return n},e.pearsonFromArrays=function(t,e){for(var n=t.length,r=t.reduce(function(t,e){return t+e},0)/n,i=e.reduce(function(t,e){return t+e},0)/n,a=0,o=0,s=0,u=0;u<n;u++){var l=t[u]-r,c=e[u]-i;a+=l*c,o+=l*l,s+=c*c}var f=Math.sqrt(o*s);return 0===f?0:a/f},e.pearsonConfidenceInterval=function(t,e,n){if(void 0===n&&(n=.95),Math.abs(t)>=1)return{lower:t,upper:t};var r=.5*Math.log((1+t)/(1-t)),i=1/Math.sqrt(e-3),a=this.normalInverse(1-(1-n)/2)*i,o=r-a,s=r+a;return{lower:(Math.exp(2*o)-1)/(Math.exp(2*o)+1),upper:(Math.exp(2*s)-1)/(Math.exp(2*s)+1)}},e.findStrongCorrelations=function(t,e,n){void 0===n&&(n=.7);for(var r=[],i=Object.keys(t),a=0;a<i.length;a++)for(var o=a+1;o<i.length;o++){var s=i[a],u=i[o],l=t[s][u],c=e[s][u];Math.abs(l)>=n&&c<.05&&r.push({variable1:s,variable2:u,correlation:l,pValue:c,strength:this.getCorrelationStrength(Math.abs(l))})}return r.sort(function(t,e){return Math.abs(e.correlation)-Math.abs(t.correlation)})},e.summarizeCorrelationMatrix=function(t,e,n){for(var r=0,i=0,a=0,o=0,s=0,u=0,l=0;l<n.length;l++)for(var c=l+1;c<n.length;c++){var f=n[l],h=n[c],d=t[f][h],p=e[f][h];isNaN(d)||(r++,p<.05&&i++,d>.7&&a++,d<-.7&&o++,s=Math.max(s,d),u=Math.min(u,d))}return{totalPairs:r,significantPairs:i,strongPositiveCorrelations:a,strongNegativeCorrelations:o,maxCorrelation:s,minCorrelation:u,averageAbsoluteCorrelation:this.calculateAverageAbsoluteCorrelation(t,n)}},e.calculateAverageAbsoluteCorrelation=function(t,e){for(var n=0,r=0,i=0;i<e.length;i++)for(var a=i+1;a<e.length;a++){var o=t[e[i]][e[a]];isNaN(o)||(n+=Math.abs(o),r++)}return r>0?n/r:0},e.getCorrelationStrength=function(t){return t>=.9?"Very Strong":t>=.7?"Strong":t>=.5?"Moderate":t>=.3?"Weak":"Very Weak"},e.interpretCorrelation=function(t,e,n){void 0===n&&(n="Pearson");var r=e<.05?"significant":"not significant";return n+" correlation: "+this.getCorrelationStrength(Math.abs(t))+" "+(t>0?"positive":"negative")+" relationship (r = "+t.toFixed(4)+", p = "+e.toFixed(4)+", "+r+")"},e.tCDF=function(t,e){return 1-.5*this.incompleteBeta(e/2,.5,e/(t*t+e))},e.normalCDF=function(t){return.5*(1+this.erf(t/Math.sqrt(2)))},e.normalInverse=function(t){if(t<=0||t>=1)throw new Error("p must be between 0 and 1");var e=[-39.69683028665376,220.9460984245205,-275.9285104469687,138.357751867269,-30.66479806614716,2.506628277459239],n=[-54.47609879822406,161.5858368580409,-155.6989798598866,66.80131188771972,-13.28068155288572,1];if(t>.5)return-this.normalInverse(1-t);for(var r=Math.sqrt(-2*Math.log(t)),i=e[5],a=n[5],o=4;o>=0;o--)i=i*r+e[o],a=a*r+n[o];return i/a},e.erf=function(t){var e=t<0?-1:1,n=1/(1+.3275911*(t=Math.abs(t)));return e*(1-((((1.061405429*n-1.453152027)*n+1.421413741)*n-.284496736)*n+.254829592)*n*Math.exp(-t*t))},e.incompleteBeta=function(t,e,n){if(n<=0)return 0;if(n>=1)return 1;var r=Math.exp(this.logGamma(t+e)-this.logGamma(t)-this.logGamma(e)+t*Math.log(n)+e*Math.log(1-n));return n<(t+1)/(t+e+2)?r*this.continuedFractionBeta(t,e,n)/t:1-r*this.continuedFractionBeta(e,t,1-n)/e},e.continuedFractionBeta=function(t,e,n){var r=t+e,i=t+1,a=t-1,o=1,s=1-r*n/i;Math.abs(s)<1e-30&&(s=1e-30);for(var u=s=1/s,l=1;l<=100;l++){var c=2*l,f=l*(e-l)*n/((a+c)*(t+c));s=1+f*s,Math.abs(s)<1e-30&&(s=1e-30),o=1+f/o,Math.abs(o)<1e-30&&(o=1e-30),u*=(s=1/s)*o,s=1+(f=-(t+l)*(r+l)*n/((t+c)*(i+c)))*s,Math.abs(s)<1e-30&&(s=1e-30),o=1+f/o,Math.abs(o)<1e-30&&(o=1e-30);var h=(s=1/s)*o;if(u*=h,Math.abs(h-1)<1e-12)break}return u},e.logGamma=function(t){var e=[76.18009172947146,-86.50532032941678,24.01409824083091,-1.231739572450155,.001208650973866179,-5395239384953e-18],n=1.000000000190015,r=t,i=t,a=t+5.5;a-=(t+.5)*Math.log(a);for(var o=0;o<6;o++)n+=e[o]/++i;return-a+Math.log(2.5066282746310007*n/r)},t}(),M=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.linear=function(t,e){if(!Array.isArray(t)||!Array.isArray(e))throw new Error("Both inputs must be arrays");if(t.length!==e.length)throw new Error("Arrays must have the same length");for(var n=[],r=0;r<t.length;r++)"number"==typeof t[r]&&"number"==typeof e[r]&&!isNaN(t[r])&&!isNaN(e[r])&&isFinite(t[r])&&isFinite(e[r])&&n.push({x:t[r],y:e[r]});if(n.length<3)throw new Error("Need at least 3 valid paired observations");for(var i=n.length,a=n.map(function(t){return t.x}),o=n.map(function(t){return t.y}),s=a.reduce(function(t,e){return t+e},0)/i,u=o.reduce(function(t,e){return t+e},0)/i,l=0,c=0,f=0;f<i;f++){var h=a[f]-s;l+=h*(o[f]-u),c+=h*h}if(0===c)throw new Error("Cannot perform regression: X values have zero variance");var d=l/c,p=u-d*s,m=a.map(function(t){return p+d*t}),g=o.map(function(t,e){return t-m[e]}),v=g.reduce(function(t,e){return t+e*e},0),y=o.reduce(function(t,e){return t+Math.pow(e-u,2)},0),b=y-v,w=0===y?1:b/y,M=1-v/(i-2)/(y/(i-1)),x=v/(i-2),S=Math.sqrt(x),N=Math.sqrt(x/c),E=Math.sqrt(x*(1/i+s*s/c)),A=d/N,C=p/E,q=i-2,k=2*(1-this.tCDF(Math.abs(A),q)),_=2*(1-this.tCDF(Math.abs(C),q)),F=b/1/(v/q),T=1-this.fCDF(F,1,q);return{slope:d,intercept:p,rSquared:w,adjustedRSquared:M,correlation:Math.sqrt(w)*Math.sign(d),standardErrorSlope:N,standardErrorIntercept:E,tStatSlope:A,tStatIntercept:C,pValueSlope:k,pValueIntercept:_,fStatistic:F,pValueModel:T,degreesOfFreedom:q,mse:x,rmse:S,residuals:g,predicted:m,sampleSize:i,equation:"y = "+p.toFixed(4)+" + "+d.toFixed(4)+"x",residualAnalysis:this.analyzeResiduals(g,m)}},e.multiple=function(t,e,n){var r=this;if(!t||!t.data||!Array.isArray(t.data))throw new Error("Invalid dataset format");if(!t.headers.includes(e))throw new Error("Dependent variable '"+e+"' not found in dataset");var i=n.filter(function(e){return!t.headers.includes(e)});if(i.length>0)throw new Error("Independent variables not found: "+i.join(", "));var a=t.data.filter(function(t){return[e].concat(n).every(function(e){var n=t[e];return"number"==typeof n&&!isNaN(n)&&isFinite(n)})});if(a.length<n.length+2)throw new Error("Need at least "+(n.length+2)+" valid observations");var o=a.length,s=n.length,u=a.map(function(t){return t[e]}),l=a.map(function(t){return[1].concat(n.map(function(e){return t[e]}))}),c=this.transpose(l),f=this.matrixMultiply(c,l),h=this.matrixInverse(f),d=this.matrixVectorMultiply(c,u),p=this.matrixVectorMultiply(h,d),m=l.map(function(t){return p.reduce(function(e,n,r){return e+n*t[r]},0)}),g=u.map(function(t,e){return t-m[e]}),v=u.reduce(function(t,e){return t+e},0)/o,y=g.reduce(function(t,e){return t+e*e},0),b=u.reduce(function(t,e){return t+Math.pow(e-v,2)},0),w=b-y,M=0===b?1:w/b,x=1-y/(o-s-1)/(b/(o-1)),S=y/(o-s-1),N=Math.sqrt(S),E=p.map(function(t,e){return Math.sqrt(S*h[e][e])}),A=p.map(function(t,e){return t/E[e]}),C=A.map(function(t){return 2*(1-r.tCDF(Math.abs(t),o-s-1))}),q=w/s/(y/(o-s-1)),k=1-this.fCDF(q,s,o-s-1),_=p.map(function(t,e){return{variable:0===e?"Intercept":n[e-1],coefficient:t,standardError:E[e],tStatistic:A[e],pValue:C[e],significant:C[e]<.05}});return{coefficients:_,intercept:p[0],rSquared:M,adjustedRSquared:x,fStatistic:q,pValueModel:k,mse:S,rmse:N,residuals:g,predicted:m,sampleSize:o,degreesOfFreedom:o-s-1,dependentVariable:e,independentVariables:n,equation:this.buildEquation(_),residualAnalysis:this.analyzeResiduals(g,m)}},e.polynomial=function(t,e,n){var r=this;if(void 0===n&&(n=2),!Array.isArray(t)||!Array.isArray(e))throw new Error("Both inputs must be arrays");if(t.length!==e.length)throw new Error("Arrays must have the same length");if(n<1||n>10)throw new Error("Degree must be between 1 and 10");for(var i=[],a=0;a<t.length;a++)"number"==typeof t[a]&&"number"==typeof e[a]&&!isNaN(t[a])&&!isNaN(e[a])&&isFinite(t[a])&&isFinite(e[a])&&i.push({x:t[a],y:e[a]});var o=i.length;if(o<n+2)throw new Error("Need at least "+(n+2)+" valid observations for degree "+n+" polynomial");var s=i.map(function(t){return t.x}),u=i.map(function(t){return t.y}),l=s.map(function(t){for(var e=[1],r=1;r<=n;r++)e.push(Math.pow(t,r));return e}),c=this.transpose(l),f=this.matrixMultiply(c,l),h=this.matrixInverse(f),d=this.matrixVectorMultiply(c,u),p=this.matrixVectorMultiply(h,d),m=l.map(function(t){return p.reduce(function(e,n,r){return e+n*t[r]},0)}),g=u.map(function(t,e){return t-m[e]}),v=u.reduce(function(t,e){return t+e},0)/o,y=g.reduce(function(t,e){return t+e*e},0),b=u.reduce(function(t,e){return t+Math.pow(e-v,2)},0),w=0===b?1:(b-y)/b,M=1-y/(o-n-1)/(b/(o-1)),x=y/(o-n-1),S=Math.sqrt(x),N=p.map(function(t,e){return Math.sqrt(x*h[e][e])}),E=p.map(function(t,e){return t/N[e]}),A=E.map(function(t){return 2*(1-r.tCDF(Math.abs(t),o-n-1))});return{coefficients:p,degree:n,rSquared:w,adjustedRSquared:M,mse:x,rmse:S,residuals:g,predicted:m,sampleSize:o,equation:this.buildPolynomialEquation(p),residualAnalysis:this.analyzeResiduals(g,m),standardErrors:N,tStatistics:E,pValues:A}},e.logistic=function(t,e,n,r){var i=this;if(void 0===n&&(n=100),void 0===r&&(r=1e-6),!Array.isArray(t)||!Array.isArray(e))throw new Error("Both inputs must be arrays");for(var a=[],o=0;o<t.length;o++)"number"!=typeof t[o]||"number"!=typeof e[o]||isNaN(t[o])||isNaN(e[o])||!isFinite(t[o])||!isFinite(e[o])||0!==e[o]&&1!==e[o]||a.push({x:t[o],y:e[o]});if(a.length<10)throw new Error("Need at least 10 valid observations for logistic regression");for(var s=a.map(function(t){return t.x}),u=a.map(function(t){return t.y}),l=a.length,c=0,f=0,h=0;h<n;h++){for(var d=s.map(function(t){return i.sigmoid(c+f*t)}),p=d.map(function(t){return t*(1-t)}),m=0,g=0,v=0,y=0,b=0,w=0;w<l;w++){var M=u[w]-d[w];m+=M,g+=M*s[w],v+=p[w],y+=p[w]*s[w],b+=p[w]*s[w]*s[w]}var x=v*b-y*y;if(Math.abs(x)<1e-10)throw new Error("Information matrix is singular");var S=(b*m-y*g)/x,N=(v*g-y*m)/x;if(c+=S,f+=N,Math.abs(S)<r&&Math.abs(N)<r)break}var E=s.map(function(t){return i.sigmoid(c+f*t)}),A=E.map(function(t){return t>=.5?1:0}),C=u.reduce(function(t,e,n){var r=E[n];return t+e*Math.log(r+1e-15)+(1-e)*Math.log(1-r+1e-15)},0),q=1-C/this.calculateNullLogLikelihood(u),k=A.reduce(function(t,e,n){return t+(e===u[n]?1:0)},0)/l;return{intercept:c,slope:f,probabilities:E,predicted:A,logLikelihood:C,mcFaddenR2:q,accuracy:k,sampleSize:l,equation:"p = 1 / (1 + exp(-("+c.toFixed(4)+" + "+f.toFixed(4)+"x)))",confusionMatrix:this.calculateConfusionMatrix(u,A)}},e.predict=function(t,e){if(!t||"object"!=typeof t)throw new Error("Invalid model object");if(t.coefficients&&Array.isArray(t.coefficients)){if(Array.isArray(e[0]))return e.map(function(e){var n=[1].concat(e);return t.coefficients.reduce(function(t,e,r){return t+e.coefficient*n[r]},0)});var n=[1].concat(e);return t.coefficients.reduce(function(t,e,r){return t+e.coefficient*n[r]},0)}if(void 0!==t.slope&&void 0!==t.intercept)return Array.isArray(e)?e.map(function(e){return t.intercept+t.slope*e}):t.intercept+t.slope*e;if(t.coefficients&&void 0!==t.degree){if(Array.isArray(e))return e.map(function(e){for(var n=t.coefficients[0],r=1;r<=t.degree;r++)n+=t.coefficients[r]*Math.pow(e,r);return n});for(var r=t.coefficients[0],i=1;i<=t.degree;i++)r+=t.coefficients[i]*Math.pow(e,i);return r}throw new Error("Unknown model type")},e.analyzeResiduals=function(t,e){var n=t.length,r=t.reduce(function(t,e){return t+e},0)/n,i=Math.sqrt(t.reduce(function(t,e){return t+Math.pow(e-r,2)},0)/(n-1)),a=t.map(function(t){return t/i}),o=a.map(function(t,e){return{index:e,value:t}}).filter(function(t){return Math.abs(t.value)>2}),s=this.calculateDurbinWatson(t);return{mean:r,standardDeviation:i,standardizedResiduals:a,outliers:o,durbinWatson:s,normalityTest:this.testResidualNormality(t)}},e.calculateDurbinWatson=function(t){for(var e=0,n=0,r=1;r<t.length;r++)e+=Math.pow(t[r]-t[r-1],2);for(var i=0;i<t.length;i++)n+=Math.pow(t[i],2);return e/n},e.testResidualNormality=function(t){var e=t.length,n=t.reduce(function(t,e){return t+e},0)/e,r=t.reduce(function(t,e){return t+Math.pow(e-n,2)},0)/(e-1),i=Math.sqrt(r);if(0===i)return{isNormal:!0,pValue:1};var a=t.reduce(function(t,e){return t+Math.pow((e-n)/i,3)},0)/e,o=t.reduce(function(t,e){return t+Math.pow((e-n)/i,4)},0)/e-3,s=e/6*(Math.pow(a,2)+Math.pow(o,2)/4),u=1-this.chiSquareCDF(s,2);return{jarqueBeraStatistic:s,pValue:u,isNormal:u>.05,skewness:a,kurtosis:o}},e.buildEquation=function(t){return"y = "+t.map(function(t){return"Intercept"===t.variable?t.coefficient.toFixed(4):(t.coefficient>=0?"+":"")+t.coefficient.toFixed(4)+"*"+t.variable}).join(" ")},e.buildPolynomialEquation=function(t){return"y = "+t.map(function(t,e){return 0===e?t.toFixed(4):1===e?(t>=0?"+":"")+t.toFixed(4)+"*x":(t>=0?"+":"")+t.toFixed(4)+"*x^"+e}).join(" ")},e.sigmoid=function(t){return 1/(1+Math.exp(-Math.max(-500,Math.min(500,t))))},e.calculateNullLogLikelihood=function(t){var e=t.reduce(function(t,e){return t+e},0)/t.length;return t.reduce(function(t,n){return t+n*Math.log(e+1e-15)+(1-n)*Math.log(1-e+1e-15)},0)},e.calculateConfusionMatrix=function(t,e){for(var n=0,r=0,i=0,a=0,o=0;o<t.length;o++)1===t[o]&&1===e[o]?n++:0===t[o]&&1===e[o]?r++:0===t[o]&&0===e[o]?i++:1===t[o]&&0===e[o]&&a++;var s=n+r>0?n/(n+r):0,u=n+a>0?n/(n+a):0;return{truePositive:n,falsePositive:r,trueNegative:i,falseNegative:a,precision:s,recall:u,specificity:i+r>0?i/(i+r):0,f1Score:s+u>0?s*u*2/(s+u):0}},e.matrixMultiply=function(t,e){for(var n=t.length,r=t[0].length,i=e[0].length,a=Array(n).fill().map(function(){return Array(i).fill(0)}),o=0;o<n;o++)for(var s=0;s<i;s++)for(var u=0;u<r;u++)a[o][s]+=t[o][u]*e[u][s];return a},e.matrixVectorMultiply=function(t,e){return t.map(function(t){return t.reduce(function(t,n,r){return t+n*e[r]},0)})},e.transpose=function(t){return t[0].map(function(e,n){return t.map(function(t){return t[n]})})},e.matrixInverse=function(t){for(var e=t.length,n=Array(e).fill().map(function(t,n){return Array(e).fill().map(function(t,e){return n===e?1:0})}),r=t.map(function(t,e){return[].concat(t,n[e])}),i=0;i<e;i++){for(var a=i,o=i+1;o<e;o++)Math.abs(r[o][i])>Math.abs(r[a][i])&&(a=o);var s=[r[a],r[i]];r[i]=s[0],r[a]=s[1];var u=r[i][i];if(Math.abs(u)<1e-10)throw new Error("Matrix is singular and cannot be inverted");for(var l=0;l<2*e;l++)r[i][l]/=u;for(var c=0;c<e;c++)if(c!==i)for(var f=r[c][i],h=0;h<2*e;h++)r[c][h]-=f*r[i][h]}return r.map(function(t){return t.slice(e)})},e.tCDF=function(t,e){return e<=0?.5:1-.5*this.incompleteBeta(e/2,.5,e/(t*t+e))},e.fCDF=function(t,e,n){return t<=0?0:1-this.incompleteBeta(n/2,e/2,n/(n+e*t))},e.chiSquareCDF=function(t,e){return t<=0?0:this.incompleteGamma(e/2,t/2)/this.gamma(e/2)},e.incompleteBeta=function(t,e,n){if(n<=0)return 0;if(n>=1)return 1;for(var r=0,i=1,a=0;a<100&&(a>0&&(i*=n*(t+a-1)/a),r+=i/(t+a),!(Math.abs(i)<1e-10));a++);return r*Math.pow(n,t)*Math.pow(1-n,e)},e.incompleteGamma=function(t,e){if(e<=0)return 0;for(var n=1,r=1,i=1;i<100&&(n+=r*=e/(t+i-1),!(Math.abs(r)<1e-12));i++);return Math.pow(e,t)*Math.exp(-e)*n},e.gamma=function(t){if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*this.gamma(1-t));t-=1;for(var e=.9999999999998099,n=[676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7],r=0;r<n.length;r++)e+=n[r]/(t+r+1);var i=t+n.length-.5;return Math.sqrt(2*Math.PI)*Math.pow(i,t+.5)*Math.exp(-i)*e},t}(),x=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.summary=function(t){if(!t||!t.data||!t.headers)throw new Error("Invalid dataset format");var e=this.getBasicInfo(t),n=this.analyzeColumns(t),r=this.assessDataQuality(t),i=this.analyzeDistributions(t),a=this.analyzeRelationships(t),o=this.generateKeyInsights(t,n,a);return{title:"Statistical Summary Report",generatedAt:(new Date).toISOString(),basicInfo:e,columnAnalysis:n,dataQuality:r,distributions:i,relationships:a,keyInsights:o,recommendations:this.generateRecommendations(r,n,a)}},e.getBasicInfo=function(t){return{totalRows:t.length,totalColumns:t.columns,headers:t.headers,memoryFootprint:this.estimateMemoryFootprint(t),dataTypes:this.getDataTypes(t)}},e.analyzeColumns=function(t){var e=this,r={};return t.headers.forEach(function(i){var a=t.data.map(function(t){return t[i]}),o=e.inferColumnType(a);r[i]=n({type:o,totalCount:a.length,validCount:e.getValidCount(a),nullCount:e.getNullCount(a),uniqueCount:e.getUniqueCount(a),nullPercentage:e.getNullPercentage(a)},e.getTypeSpecificAnalysis(a,o))}),r},e.getTypeSpecificAnalysis=function(t,e){var n=t.filter(function(t){return null!=t});if("numeric"===e){var r=n.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});return 0===r.length?{}:{min:Math.min.apply(Math,r),max:Math.max.apply(Math,r),mean:this.calculateMean(r),median:this.calculateMedian(r),standardDeviation:this.calculateStandardDeviation(r),variance:this.calculateVariance(r),skewness:this.calculateSkewness(r),kurtosis:this.calculateKurtosis(r),quartiles:this.calculateQuartiles(r),outliers:this.detectOutliers(r),distribution:this.classifyDistribution(r)}}if("categorical"===e){var i=this.calculateFrequencyTable(n);return{categories:i,mostFrequent:this.getMostFrequent(i),leastFrequent:this.getLeastFrequent(i),entropy:this.calculateEntropy(i),concentration:this.calculateConcentration(i)}}if("datetime"===e){var a=n.filter(function(t){return!isNaN(new Date(t).getTime())});if(0===a.length)return{};var o=a.map(function(t){return new Date(t).getTime()});return{earliest:new Date(Math.min.apply(Math,o)).toISOString(),latest:new Date(Math.max.apply(Math,o)).toISOString(),span:Math.max.apply(Math,o)-Math.min.apply(Math,o),frequency:this.analyzeDateFrequency(a)}}return{}},e.assessDataQuality=function(t){var e,n=[],r=this.assessCompleteness(t),i=this.assessConsistency(t),a=this.assessUniqueness(t),o=this.assessValidity(t);return e=(r+i+a+o)/4,r<80&&n.push({type:"completeness",severity:r<50?"high":"medium",description:(100-r).toFixed(1)+"% of data is missing"}),i<80&&n.push({type:"consistency",severity:i<50?"high":"medium",description:"Data consistency issues detected"}),{overallScore:e,completenessScore:r,consistencyScore:i,uniquenessScore:a,validityScore:o,issues:n,recommendation:this.getQualityRecommendation(e)}},e.analyzeDistributions=function(t){var e=this,n={};return t.headers.forEach(function(r){var i=t.data.map(function(t){return t[r]}).filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)});i.length>5&&(n[r]={type:e.classifyDistribution(i),normalityTest:e.testNormality(i),histogram:e.createHistogram(i),descriptiveStats:e.getDescriptiveStats(i)})}),n},e.analyzeRelationships=function(t){var e=this,n=t.headers.filter(function(e){var n=t.data.map(function(t){return t[e]});return n.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}).length>.5*n.length});if(n.length<2)return{correlations:{},strongRelationships:[]};for(var r={},i=[],a=function(a){r[n[a]]={};for(var o=function(o){if(a===o)r[n[a]][n[o]]=1;else{var s=t.data.map(function(t){return t[n[a]]}),u=t.data.map(function(t){return t[n[o]]}),l=e.calculatePearsonCorrelation(s,u);r[n[a]][n[o]]=l,Math.abs(l)>.7&&a<o&&i.push({variable1:n[a],variable2:n[o],correlation:l,strength:e.getCorrelationStrength(Math.abs(l)),direction:l>0?"positive":"negative"})}},s=0;s<n.length;s++)o(s)},o=0;o<n.length;o++)a(o);return{correlations:r,strongRelationships:i,averageCorrelation:this.calculateAverageCorrelation(r,n)}},e.generateKeyInsights=function(t,e,n){var r=[];return r.push.apply(r,this.generateDataVolumeInsights(t)),r.push.apply(r,this.generateColumnInsights(e)),r.push.apply(r,this.generateRelationshipInsights(n)),r.push.apply(r,this.generateDistributionInsights(e)),r.push.apply(r,this.generateQualityInsights(t,e)),r.sort(function(t,e){return e.importance-t.importance}).slice(0,10)},e.generateDataVolumeInsights=function(t){var e=[];return t.length>1e4?e.push({type:"volume",title:"Large Dataset Detected",description:"Dataset contains "+t.length.toLocaleString()+" rows, which is suitable for robust statistical analysis.",importance:7,actionable:!1}):t.length<30&&e.push({type:"volume",title:"Small Sample Size Warning",description:"Dataset has only "+t.length+" rows. Statistical tests may lack power.",importance:8,actionable:!0,recommendation:"Consider collecting more data for reliable statistical inference."}),t.columns>50&&e.push({type:"dimensionality",title:"High-Dimensional Dataset",description:"Dataset has "+t.columns+" columns, which may benefit from dimensionality reduction.",importance:6,actionable:!0,recommendation:"Consider feature selection or PCA to reduce dimensionality."}),e},e.generateColumnInsights=function(t){var e=[],n=Object.keys(t),r=n.filter(function(e){return t[e].nullPercentage>25});r.length>0&&e.push({type:"data_quality",title:"High Missing Data Detected",description:"Columns "+r.join(", ")+" have >25% missing values.",importance:9,actionable:!0,recommendation:"Consider imputation strategies or removing these columns."});var i=n.filter(function(e){var n=t[e];return n.skewness&&Math.abs(n.skewness)>2});i.length>0&&e.push({type:"distribution",title:"Highly Skewed Variables Found",description:"Columns "+i.join(", ")+" show extreme skewness.",importance:7,actionable:!0,recommendation:"Consider log transformation or other normalization techniques."});var a=n.filter(function(e){return 1===t[e].uniqueCount});return a.length>0&&e.push({type:"data_quality",title:"Constant Variables Detected",description:"Columns "+a.join(", ")+" have no variation.",importance:8,actionable:!0,recommendation:"Remove these columns as they provide no information."}),e},e.generateRelationshipInsights=function(t){var e=[];if(t.strongRelationships.length>0){var n=t.strongRelationships[0];e.push({type:"correlation",title:"Strong Correlation Found",description:n.variable1+" and "+n.variable2+" have a "+n.strength.toLowerCase()+" "+n.direction+" correlation (r = "+n.correlation.toFixed(3)+").",importance:8,actionable:!0,recommendation:"Investigate this relationship further with regression analysis."})}return t.strongRelationships.filter(function(t){return Math.abs(t.correlation)>.9}).length>0&&e.push({type:"multicollinearity",title:"Potential Multicollinearity Detected",description:"Very high correlations found between some variables.",importance:7,actionable:!0,recommendation:"Consider removing redundant variables before modeling."}),t.averageCorrelation>.5&&e.push({type:"correlation",title:"Generally High Inter-Variable Correlations",description:"Average correlation is "+t.averageCorrelation.toFixed(3)+", indicating related variables.",importance:6,actionable:!1}),e},e.generateDistributionInsights=function(t){var e=[],n=Object.keys(t).filter(function(e){return"numeric"===t[e].type}),r=n.filter(function(e){var n=t[e];return"normal"===n.distribution||Math.abs(n.skewness||0)<.5&&Math.abs(n.kurtosis||0)<.5});r.length>.7*n.length&&e.push({type:"distribution",title:"Most Variables Normally Distributed",description:r.length+" out of "+n.length+" numeric variables appear normally distributed.",importance:6,actionable:!1});var i=n.filter(function(e){var n=t[e];return n.outliers&&n.outliers.count>0});if(i.length>0){var a=i.reduce(function(e,n){return e+t[n].outliers.count},0);e.push({type:"outliers",title:"Outliers Detected",description:"Found "+a+" outliers across "+i.length+" variables.",importance:7,actionable:!0,recommendation:"Investigate outliers to determine if they represent errors or genuine extreme values."})}return e},e.generateQualityInsights=function(t,e){var n=[],r=Object.keys(e),i=this.countDuplicateRows(t);i>0&&n.push({type:"data_quality",title:"Duplicate Rows Found",description:"Dataset contains "+i+" duplicate rows.",importance:8,actionable:!0,recommendation:"Remove duplicate rows to avoid bias in analysis."});var a=r.reduce(function(t,n){return t+e[n].nullCount},0)/(t.length*t.columns)*100;return a>10&&n.push({type:"data_quality",title:"Significant Missing Data",description:a.toFixed(1)+"% of all data points are missing.",importance:9,actionable:!0,recommendation:"Develop a comprehensive missing data strategy."}),n},e.generateRecommendations=function(t,e,n){var r=[];return t.overallScore<70&&r.push({priority:"high",category:"data_cleaning",title:"Improve Data Quality",description:"Address missing values, outliers, and inconsistencies before analysis.",steps:["Handle missing values through imputation or removal","Investigate and address outliers","Standardize data formats and categories","Validate data integrity"]}),n.strongRelationships.length>0&&r.push({priority:"medium",category:"analysis",title:"Explore Strong Relationships",description:"Investigate detected correlations with deeper analysis.",steps:["Perform regression analysis on highly correlated variables","Create visualizations to understand relationships","Test for causality where appropriate"]}),Object.keys(e).filter(function(t){return"numeric"===e[t].type}).length>2&&r.push({priority:"low",category:"modeling",title:"Consider Advanced Analytics",description:"Dataset is suitable for machine learning approaches.",steps:["Perform feature selection","Try different modeling approaches","Validate models with cross-validation","Interpret model results"]}),r},e.inferColumnType=function(t){var e=t.filter(function(t){return null!=t});if(0===e.length)return"unknown";var n=e.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}).length,r=e.filter(function(t){if("string"==typeof t){var e=new Date(t);return!isNaN(e.getTime())}return!1}).length;return n/e.length>.8?"numeric":r/e.length>.8?"datetime":"categorical"},e.getValidCount=function(t){return t.filter(function(t){return null!=t}).length},e.getNullCount=function(t){return t.filter(function(t){return null==t}).length},e.getUniqueCount=function(t){var e=t.filter(function(t){return null!=t});return new Set(e).size},e.getNullPercentage=function(t){return this.getNullCount(t)/t.length*100},e.calculateMean=function(t){return t.reduce(function(t,e){return t+e},0)/t.length},e.calculateMedian=function(t){var e=[].concat(t).sort(function(t,e){return t-e}),n=Math.floor(e.length/2);return e.length%2==0?(e[n-1]+e[n])/2:e[n]},e.calculateStandardDeviation=function(t){var e=this.calculateMean(t),n=t.reduce(function(t,n){return t+Math.pow(n-e,2)},0)/(t.length-1);return Math.sqrt(n)},e.calculateVariance=function(t){var e=this.calculateMean(t);return t.reduce(function(t,n){return t+Math.pow(n-e,2)},0)/(t.length-1)},e.calculateSkewness=function(t){var e=t.length,n=this.calculateMean(t),r=this.calculateStandardDeviation(t);return 0===r?0:e/((e-1)*(e-2))*t.reduce(function(t,e){return t+Math.pow((e-n)/r,3)},0)},e.calculateKurtosis=function(t){var e=t.length,n=this.calculateMean(t),r=this.calculateStandardDeviation(t);return 0===r?-3:e*(e+1)/((e-1)*(e-2)*(e-3))*t.reduce(function(t,e){return t+Math.pow((e-n)/r,4)},0)-3*Math.pow(e-1,2)/((e-2)*(e-3))},e.calculateQuartiles=function(t){var e=[].concat(t).sort(function(t,e){return t-e}),n=e.length,r=Math.floor(.25*n),i=Math.floor(.5*n),a=Math.floor(.75*n);return{q1:e[r],q2:e[i],q3:e[a],iqr:e[a]-e[r]}},e.detectOutliers=function(t){var e=this.calculateQuartiles(t),n=e.q1-1.5*e.iqr,r=e.q3+1.5*e.iqr,i=t.filter(function(t){return t<n||t>r});return{count:i.length,percentage:i.length/t.length*100,values:i,lowerBound:n,upperBound:r}},e.classifyDistribution=function(t){var e=this.calculateSkewness(t),n=this.calculateKurtosis(t);return Math.abs(e)<.5&&Math.abs(n)<.5?"normal":e>1?"right_skewed":e<-1?"left_skewed":n>1?"heavy_tailed":n<-1?"light_tailed":"unknown"},e.calculateFrequencyTable=function(t){var e={};t.forEach(function(t){var n=String(t);e[n]=(e[n]||0)+1});var n=t.length;return Object.entries(e).map(function(t){var e=t[1];return{value:t[0],count:e,percentage:e/n*100}}).sort(function(t,e){return e.count-t.count})},e.getMostFrequent=function(t){return t[0]||null},e.getLeastFrequent=function(t){return t[t.length-1]||null},e.calculateEntropy=function(t){var e=t.reduce(function(t,e){return t+e.count},0);return t.reduce(function(t,n){var r=n.count/e;return t-r*Math.log2(r)},0)},e.calculateConcentration=function(t){var e=t.reduce(function(t,e){return t+e.count},0),n=t[0];return n?n.count/e*100:0},e.analyzeDateFrequency=function(t){var e=t.map(function(t){return new Date(t).getTime()}),n=e.sort(function(t,e){return t-e});if(n.length<2)return"insufficient_data";for(var r=[],i=1;i<n.length;i++)r.push(n[i]-n[i-1]);var a=r.reduce(function(t,e){return t+e},0)/r.length;return a<864e5?"sub_daily":a<6048e5?"daily":a<2592e6?"weekly":a<31536e6?"monthly":"yearly"},e.assessCompleteness=function(t){var e=t.length*t.columns,n=0;return t.data.forEach(function(e){t.headers.forEach(function(t){null!=e[t]&&n++})}),n/e*100},e.assessConsistency=function(t){var e=100;return t.headers.forEach(function(n){var r=t.data.map(function(t){return t[n]});new Set(r.filter(function(t){return null!=t}).map(function(t){return typeof t})).size>1&&(e-=10)}),Math.max(0,e)},e.assessUniqueness=function(t){var e=this.countDuplicateRows(t);return Math.max(0,100-e/t.length*100)},e.assessValidity=function(t){var e=100,n=0,r=0;return t.data.forEach(function(e){t.headers.forEach(function(t){var i=e[t];null!=i&&(n++,"number"!=typeof i||isFinite(i)||r++)})}),n>0&&(e=Math.max(0,100-r/n*100)),e},e.getQualityRecommendation=function(t){return t>=90?"Excellent data quality - ready for analysis":t>=80?"Good data quality - minor cleaning recommended":t>=70?"Fair data quality - significant cleaning needed":t>=60?"Poor data quality - extensive preprocessing required":"Very poor data quality - major data work needed before analysis"},e.testNormality=function(t){if(t.length<8)return{test:"insufficient_data"};this.calculateMean(t),this.calculateStandardDeviation(t);var e=this.calculateSkewness(t),n=this.calculateKurtosis(t),r=t.length/6*(Math.pow(e,2)+Math.pow(n,2)/4),i=1-this.chiSquareCDF(r,2);return{test:"jarque_bera",statistic:r,pValue:i,isNormal:i>.05,skewness:e,kurtosis:n}},e.createHistogram=function(t,e){void 0===e&&(e=10);var n=Math.min.apply(Math,t),r=(Math.max.apply(Math,t)-n)/e,i=Array(e).fill(0);return t.forEach(function(t){var a=Math.floor((t-n)/r);a===e&&(a=e-1),i[a]++}),i.map(function(e,i){return{binStart:n+i*r,binEnd:n+(i+1)*r,count:e,percentage:e/t.length*100}})},e.getDescriptiveStats=function(t){return{count:t.length,mean:this.calculateMean(t),median:this.calculateMedian(t),min:Math.min.apply(Math,t),max:Math.max.apply(Math,t),std:this.calculateStandardDeviation(t),var:this.calculateVariance(t),skewness:this.calculateSkewness(t),kurtosis:this.calculateKurtosis(t)}},e.calculatePearsonCorrelation=function(t,e){for(var n=[],r=0;r<t.length;r++)"number"==typeof t[r]&&"number"==typeof e[r]&&!isNaN(t[r])&&!isNaN(e[r])&&isFinite(t[r])&&isFinite(e[r])&&n.push({x:t[r],y:e[r]});if(n.length<3)return 0;for(var i=n.length,a=n.map(function(t){return t.x}),o=n.map(function(t){return t.y}),s=a.reduce(function(t,e){return t+e},0)/i,u=o.reduce(function(t,e){return t+e},0)/i,l=0,c=0,f=0,h=0;h<i;h++){var d=a[h]-s,p=o[h]-u;l+=d*p,c+=d*d,f+=p*p}var m=Math.sqrt(c*f);return 0===m?0:l/m},e.getCorrelationStrength=function(t){return t>=.9?"Very Strong":t>=.7?"Strong":t>=.5?"Moderate":t>=.3?"Weak":"Very Weak"},e.calculateAverageCorrelation=function(t,e){for(var n=0,r=0,i=0;i<e.length;i++)for(var a=i+1;a<e.length;a++){var o=t[e[i]][e[a]];isNaN(o)||(n+=Math.abs(o),r++)}return r>0?n/r:0},e.countDuplicateRows=function(t){var e=new Set,n=0;return t.data.forEach(function(t){var r=JSON.stringify(t);e.has(r)?n++:e.add(r)}),n},e.getDataTypes=function(t){var e={};return t.headers.forEach(function(n){var r=t.data.map(function(t){return t[n]}).filter(function(t){return null!=t});if(0!==r.length){var i=new Set(r.map(function(t){return typeof t}));e[n]=1===i.size?Array.from(i)[0]:"mixed"}else e[n]="empty"}),e},e.estimateMemoryFootprint=function(t){var e=0;t.data.forEach(function(n){t.headers.forEach(function(t){var r=n[t];e+="string"==typeof r?2*r.length:"number"==typeof r?8:"boolean"==typeof r?1:8})});var n=e/1024,r=n/1024;return r>=1?r.toFixed(2)+" MB":n>=1?n.toFixed(2)+" KB":e+" bytes"},e.chiSquareCDF=function(t,e){return t<=0?0:this.incompleteGamma(e/2,t/2)/this.gamma(e/2)},e.incompleteGamma=function(t,e){if(e<=0)return 0;for(var n=1,r=1,i=1;i<100&&(n+=r*=e/(t+i-1),!(Math.abs(r)<1e-12));i++);return Math.pow(e,t)*Math.exp(-e)*n},e.gamma=function(t){var e=[.9999999999998099,676.5203681218851,-1259.1392167224028,771.3234287776531,-176.6150291621406,12.507343278686905,-.13857109526572012,9984369578019572e-21,1.5056327351493116e-7];if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*this.gamma(1-t));t-=1;for(var n=e[0],r=1;r<e.length;r++)n+=e[r]/(t+r);var i=t+e.length-1.5;return Math.sqrt(2*Math.PI)*Math.pow(i,t+.5)*Math.exp(-i)*n},e.generateTextReport=function(t){var e="";return e+="STATISTICAL SUMMARY REPORT\n",e+="Generated: "+new Date(t.generatedAt).toLocaleString()+"\n",e+="=".repeat(50)+"\n\n",e+="BASIC INFORMATION\n",e+="-".repeat(20)+"\n",e+="Rows: "+t.basicInfo.totalRows.toLocaleString()+"\n",e+="Columns: "+t.basicInfo.totalColumns+"\n",e+="Memory: "+t.basicInfo.memoryFootprint+"\n\n",e+="DATA QUALITY\n",e+="-".repeat(20)+"\n",e+="Overall Score: "+t.dataQuality.overallScore.toFixed(1)+"/100\n",e+="Completeness: "+t.dataQuality.completenessScore.toFixed(1)+"%\n",e+="Consistency: "+t.dataQuality.consistencyScore.toFixed(1)+"%\n",e+=t.dataQuality.recommendation+"\n\n",t.keyInsights.length>0&&(e+="KEY INSIGHTS\n",e+="-".repeat(20)+"\n",t.keyInsights.slice(0,5).forEach(function(t,n){e+=n+1+". "+t.title+"\n",e+=" "+t.description+"\n",t.recommendation&&(e+=" ā "+t.recommendation+"\n"),e+="\n"})),t.relationships.strongRelationships.length>0&&(e+="STRONG RELATIONSHIPS\n",e+="-".repeat(20)+"\n",t.relationships.strongRelationships.slice(0,3).forEach(function(t){e+=t.variable1+" ā "+t.variable2+": "+t.correlation.toFixed(3)+" ("+t.strength+")\n"}),e+="\n"),t.recommendations.length>0&&(e+="RECOMMENDATIONS\n",e+="-".repeat(20)+"\n",t.recommendations.forEach(function(t,n){e+=n+1+". ["+t.priority.toUpperCase()+"] "+t.title+"\n",e+=" "+t.description+"\n",t.steps.forEach(function(t){e+=" ⢠"+t+"\n"}),e+="\n"})),e},e.exportSummary=function(t,e){switch(void 0===e&&(e="json"),e){case"json":return JSON.stringify(t,null,2);case"text":return this.generateTextReport(t);case"csv":return this.generateCSVReport(t);default:throw new Error("Unsupported export format: "+e)}},e.generateCSVReport=function(t){var e="Metric,Value\n";return e+="Total Rows,"+t.basicInfo.totalRows+"\n",e+="Total Columns,"+t.basicInfo.totalColumns+"\n",e+="Overall Quality Score,"+t.dataQuality.overallScore.toFixed(1)+"\n",e+="Completeness Score,"+t.dataQuality.completenessScore.toFixed(1)+"\n",e+="Consistency Score,"+t.dataQuality.consistencyScore.toFixed(1)+"\n",e+="Strong Relationships,"+t.relationships.strongRelationships.length+"\n",e+="Key Insights,"+t.keyInsights.length+"\n",t.relationships.strongRelationships.length>0&&(e+="\nVariable 1,Variable 2,Correlation,Strength\n",t.relationships.strongRelationships.forEach(function(t){e+=t.variable1+","+t.variable2+","+t.correlation.toFixed(4)+","+t.strength+"\n"})),e},t}(),S=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.analyze=function(t){if(!t||!t.data||!t.headers)throw new Error("Invalid dataset format");var e={trends:this.detectTrends(t),seasonality:this.detectSeasonality(t),outliers:this.detectOutliers(t),correlations:this.detectCorrelationPatterns(t),distributions:this.detectDistributionPatterns(t),clustering:this.detectSimpleClusters(t),temporal:this.detectTemporalPatterns(t)};return{timestamp:(new Date).toISOString(),datasetSize:t.length,patterns:e,summary:this.generateSummary(e),insights:this.generateInsights(e)}},e.detectTrends=function(t){var e=this,n=this.getNumericColumns(t),r=[];return n.forEach(function(n){var i=e.getColumnValues(t,n);if(!(i.length<5)){var a=i.map(function(t,e){return{x:e,y:t}}),o=e.calculateTrend(a);Math.abs(o.slope)>.01&&o.rSquared>.3&&r.push({column:n,direction:o.slope>0?"increasing":"decreasing",slope:o.slope,rSquared:o.rSquared,strength:e.classifyTrendStrength(o.rSquared),significance:o.pValue<.05})}}),r},e.detectSeasonality=function(t){var e=this,n=this.getDateColumns(t),r=this.getNumericColumns(t),i=[];return 0===n.length||n.forEach(function(n){r.forEach(function(r){var a=e.createTimeSeries(t,n,r);if(!(a.length<12)){var o=e.analyzeSeasonalPattern(a);o.strength>.3&&i.push({dateColumn:n,valueColumn:r,strength:o.strength,period:o.period,peaks:o.peaks,pattern:o.type})}})}),i},e.detectOutliers=function(t){var e=this,n=this.getNumericColumns(t),r=[];return n.forEach(function(n){var i=e.getColumnValues(t,n);if(!(i.length<10)){var a=e.findOutliers(i);a.count>0&&r.push({column:n,count:a.count,percentage:a.percentage,method:"IQR",outlierValues:a.values.slice(0,5),severity:e.classifyOutlierSeverity(a.percentage)})}}),r},e.detectCorrelationPatterns=function(t){var e=this.getNumericColumns(t);if(e.length<2)return{strongCorrelations:[],clusters:[]};var n=this.buildCorrelationMatrix(t,e);return{strongCorrelations:this.findStrongCorrelations(n),clusters:this.findCorrelationClusters(n),avgCorrelation:this.calculateAverageCorrelation(n)}},e.detectDistributionPatterns=function(t){var e=this,n=this.getNumericColumns(t),r=[];return n.forEach(function(n){var i=e.getColumnValues(t,n);if(!(i.length<20)){var a=e.analyzeDistribution(i);r.push({column:n,type:a.type,skewness:a.skewness,kurtosis:a.kurtosis,isNormal:Math.abs(a.skewness)<1&&Math.abs(a.kurtosis)<1,transformation:e.suggestTransformation(a)})}}),r},e.detectSimpleClusters=function(t){var e=this.getNumericColumns(t);if(e.length<2)return[];for(var n=[],r=0;r<e.length;r++)for(var i=r+1;i<e.length;i++){var a=e[r],o=e[i],s=this.getTwoColumnData(t,a,o);if(!(s.length<10)){var u=this.performSimpleKMeans(s,3);u.quality>.5&&n.push({variables:[a,o],clusters:u.centers,quality:u.quality,interpretation:this.interpretClusterQuality(u.quality)})}}return n},e.detectTemporalPatterns=function(t){var e=this,n=this.getDateColumns(t),r=[];return n.forEach(function(n){var i=e.getColumnValues(t,n).map(function(t){return new Date(t)}).filter(function(t){return!isNaN(t.getTime())}).sort(function(t,e){return t-e});if(!(i.length<5)){var a=e.calculateIntervals(i),o=e.determineFrequency(a),s=e.findGaps(i,o);r.push({column:n,frequency:o,totalSpan:i[i.length-1]-i[0],avgInterval:a.reduce(function(t,e){return t+e},0)/a.length,gaps:s.length,pattern:s.length>.1*i.length?"irregular":"regular"})}}),r},e.getNumericColumns=function(t){return t.headers.filter(function(e){var n=t.data.map(function(t){return t[e]});return n.filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)}).length>.7*n.length})},e.getDateColumns=function(t){return t.headers.filter(function(e){var n=t.data.map(function(t){return t[e]}),r=n.filter(function(t){if("string"==typeof t){var e=new Date(t);return!isNaN(e.getTime())}return!1}).length;return r>.7*n.length})},e.getColumnValues=function(t,e){return t.data.map(function(t){return t[e]}).filter(function(t){return"number"==typeof t&&!isNaN(t)&&isFinite(t)})},e.getTwoColumnData=function(t,e,n){return t.data.map(function(t){return{x:t[e],y:t[n]}}).filter(function(t){return"number"==typeof t.x&&!isNaN(t.x)&&isFinite(t.x)&&"number"==typeof t.y&&!isNaN(t.y)&&isFinite(t.y)})},e.createTimeSeries=function(t,e,n){return t.data.map(function(t){return{date:new Date(t[e]),value:t[n]}}).filter(function(t){return!isNaN(t.date.getTime())&&"number"==typeof t.value&&!isNaN(t.value)&&isFinite(t.value)}).sort(function(t,e){return t.date-e.date})},e.calculateTrend=function(t){var e=t.length,n=t.reduce(function(t,e){return t+e.x},0),r=t.reduce(function(t,e){return t+e.y},0),i=t.reduce(function(t,e){return t+e.x*e.y},0),a=t.reduce(function(t,e){return t+e.x*e.x},0),o=(e*i-n*r)/(e*a-n*n),s=(r-o*n)/e,u=t.map(function(t){return s+o*t.x}),l=t.reduce(function(t,e,n){return t+Math.pow(e.y-u[n],2)},0),c=t.reduce(function(t,n){return t+Math.pow(n.y-r/e,2)},0),f=1-l/c,h=Math.sqrt(l/(e-2)),d=2*(1-this.tCDF(Math.abs(o/h),e-2));return{slope:o,intercept:s,rSquared:f,pValue:d}},e.analyzeSeasonalPattern=function(t){var e=t.map(function(t){return t.value}),n=e.length;if(n<12)return{strength:0};for(var r=12,i=0,a=4;a<=Math.min(n/3,24);a++){var o=this.calculateAutoCorrelation(e,a);o>i&&(i=o,r=a)}var s=this.findPeaks(e),u=this.findValleys(e);return{strength:i,period:r,peaks:s.length,valleys:u.length,type:this.classifySeasonalType(i,s.length,u.length)}},e.findOutliers=function(t){var e=[].concat(t).sort(function(t,e){return t-e}),n=this.calculateQuantile(e,.25),r=this.calculateQuantile(e,.75),i=r-n,a=n-1.5*i,o=r+1.5*i,s=t.filter(function(t){return t<a||t>o});return{count:s.length,percentage:s.length/t.length*100,values:s,bounds:{lower:a,upper:o}}},e.buildCorrelationMatrix=function(t,e){var n=this,r={};return e.forEach(function(i){r[i]={},e.forEach(function(e){if(i===e)r[i][e]=1;else{var a=n.getColumnValues(t,i),o=n.getColumnValues(t,e);r[i][e]=n.calculateCorrelation(a,o)}})}),r},e.findStrongCorrelations=function(t){for(var e=[],n=Object.keys(t),r=0;r<n.length;r++)for(var i=r+1;i<n.length;i++){var a=n[r],o=n[i],s=t[a][o];Math.abs(s)>.7&&e.push({variable1:a,variable2:o,correlation:s,strength:this.getCorrelationStrength(Math.abs(s)),direction:s>0?"positive":"negative"})}return e.sort(function(t,e){return Math.abs(e.correlation)-Math.abs(t.correlation)})},e.findCorrelationClusters=function(t){var e=Object.keys(t),n=[],r=new Set;return e.forEach(function(i){if(!r.has(i)){var a=[i];r.add(i),e.forEach(function(e){!r.has(e)&&Math.abs(t[i][e])>.7&&(a.push(e),r.add(e))}),a.length>1&&n.push(a)}}),n},e.analyzeDistribution=function(t){var e=t.reduce(function(t,e){return t+e},0)/t.length,n=t.reduce(function(t,n){return t+Math.pow(n-e,2)},0)/(t.length-1),r=Math.sqrt(n),i=this.calculateSkewness(t,e,r),a=this.calculateKurtosis(t,e,r);return{mean:e,stdDev:r,skewness:i,kurtosis:a,type:this.classifyDistribution(i,a)}},e.performSimpleKMeans=function(t,e){for(var n=this.initializeCenters(t,e),r=new Array(t.length),i=!0,a=0;i&&a<50;){i=!1;for(var o=function(e){var a=n.map(function(n){return Math.sqrt(Math.pow(t[e].x-n.x,2)+Math.pow(t[e].y-n.y,2))}),o=a.indexOf(Math.min.apply(Math,a));r[e]!==o&&(i=!0,r[e]=o)},s=0;s<t.length;s++)o(s);for(var u=function(e){var i=t.filter(function(t,n){return r[n]===e});i.length>0&&(n[e]={x:i.reduce(function(t,e){return t+e.x},0)/i.length,y:i.reduce(function(t,e){return t+e.y},0)/i.length})},l=0;l<e;l++)u(l);a++}var c=this.calculateClusterQuality(t,r,n);return{centers:n,assignments:r,quality:c}},e.calculateIntervals=function(t){for(var e=[],n=1;n<t.length;n++)e.push(t[n]-t[n-1]);return e},e.determineFrequency=function(t){if(0===t.length)return"unknown";var e=t.reduce(function(t,e){return t+e},0)/t.length;return e<864e5?"sub_daily":e<1728e5?"daily":e<6912e5?"weekly":e<3024e6?"monthly":"yearly"},e.findGaps=function(t,e){for(var n=this.getExpectedInterval(e),r=[],i=1;i<t.length;i++){var a=t[i]-t[i-1];a>2*n&&r.push({start:t[i-1],end:t[i],duration:a})}return r},e.classifyTrendStrength=function(t){return t>.8?"very_strong":t>.6?"strong":t>.4?"moderate":t>.2?"weak":"very_weak"},e.classifyOutlierSeverity=function(t){return t>10?"severe":t>5?"moderate":t>1?"mild":"minimal"},e.classifySeasonalType=function(t,e,n){return t>.7?"strong_seasonal":t>.5?"moderate_seasonal":t>.3?"weak_seasonal":"no_seasonality"},e.classifyDistribution=function(t,e){return Math.abs(t)<.5&&Math.abs(e)<.5?"normal":t>1?"right_skewed":t<-1?"left_skewed":e>1?"heavy_tailed":"irregular"},e.suggestTransformation=function(t){return"normal"===t.type?"none":t.skewness>1?"log_transform":t.skewness<-1?"square_transform":"standardization"},e.getCorrelationStrength=function(t){return t>=.9?"very_strong":t>=.7?"strong":t>=.5?"moderate":t>=.3?"weak":"very_weak"},e.interpretClusterQuality=function(t){return t>.7?"excellent":t>.5?"good":t>.3?"fair":"poor"},e.generateSummary=function(t){var e={};return Object.keys(t).forEach(function(n){e[n]=Array.isArray(t[n])?t[n].length:"object"==typeof t[n]&&null!==t[n]?Object.keys(t[n]).length:0}),e.totalPatterns=Object.values(e).reduce(function(t,e){return t+e},0),e},e.generateInsights=function(t){var e=[];if(t.trends.length>0){var n=t.trends.filter(function(t){return"strong"===t.strength||"very_strong"===t.strength});n.length>0&&e.push({type:"trend",importance:"high",message:"Found "+n.length+" strong trend(s) in your data",details:n.map(function(t){return t.column+": "+t.direction+" trend"})})}if(t.correlations.strongCorrelations.length>0&&e.push({type:"correlation",importance:"medium",message:"Discovered "+t.correlations.strongCorrelations.length+" strong correlation(s)",details:t.correlations.strongCorrelations.slice(0,3).map(function(t){return t.variable1+" ā "+t.variable2+": "+t.strength+" "+t.direction})}),t.outliers.length>0){var r=t.outliers.filter(function(t){return"severe"===t.severity});r.length>0&&e.push({type:"outliers",importance:"high",message:"Detected severe outliers in "+r.length+" column(s)",details:r.map(function(t){return t.column+": "+t.count+" outliers ("+t.percentage.toFixed(1)+"%)"})})}if(t.seasonality.length>0&&e.push({type:"seasonality",importance:"medium",message:"Found seasonal patterns in "+t.seasonality.length+" time series",details:t.seasonality.map(function(t){return t.valueColumn+": "+t.pattern+" (period: "+t.period+")"})}),t.clustering.length>0){var i=t.clustering.filter(function(t){return t.quality>.5});i.length>0&&e.push({type:"clustering",importance:"medium",message:"Identified "+i.length+" natural cluster(s) in the data",details:i.map(function(t){return t.variables.join(" vs ")+": "+t.interpretation+" clusters"})})}return e.sort(function(t,e){var n={high:3,medium:2,low:1};return n[e.importance]-n[t.importance]})},e.calculateAutoCorrelation=function(t,e){if(e>=t.length)return 0;for(var n=t.length-e,r=t.slice(0,n).reduce(function(t,e){return t+e},0)/n,i=t.slice(e).reduce(function(t,e){return t+e},0)/n,a=0,o=0,s=0,u=0;u<n;u++){var l=t[u]-r,c=t[u+e]-i;a+=l*c,o+=l*l,s+=c*c}var f=Math.sqrt(o*s);return 0===f?0:a/f},e.findPeaks=function(t){for(var e=[],n=1;n<t.length-1;n++)t[n]>t[n-1]&&t[n]>t[n+1]&&e.push(n);return e},e.findValleys=function(t){for(var e=[],n=1;n<t.length-1;n++)t[n]<t[n-1]&&t[n]<t[n+1]&&e.push(n);return e},e.calculateQuantile=function(t,e){var n=(t.length-1)*e,r=Math.floor(n),i=Math.ceil(n),a=n%1;return r===i?t[r]:t[r]*(1-a)+t[i]*a},e.calculateCorrelation=function(t,e){if(t.length!==e.length||t.length<3)return 0;for(var n=t.length,r=t.reduce(function(t,e){return t+e},0)/n,i=e.reduce(function(t,e){return t+e},0)/n,a=0,o=0,s=0,u=0;u<n;u++){var l=t[u]-r,c=e[u]-i;a+=l*c,o+=l*l,s+=c*c}var f=Math.sqrt(o*s);return 0===f?0:a/f},e.calculateSkewness=function(t,e,n){if(0===n)return 0;var r=t.length;return r/((r-1)*(r-2))*t.reduce(function(t,r){return t+Math.pow((r-e)/n,3)},0)},e.calculateKurtosis=function(t,e,n){if(0===n)return 0;var r=t.length;return r*(r+1)/((r-1)*(r-2)*(r-3))*t.reduce(function(t,r){return t+Math.pow((r-e)/n,4)},0)-3*Math.pow(r-1,2)/((r-2)*(r-3))},e.initializeCenters=function(t,e){for(var n=[],r=Math.min.apply(Math,t.map(function(t){return t.x})),i=Math.max.apply(Math,t.map(function(t){return t.x})),a=Math.min.apply(Math,t.map(function(t){return t.y})),o=Math.max.apply(Math,t.map(function(t){return t.y})),s=0;s<e;s++)n.push({x:r+Math.random()*(i-r),y:a+Math.random()*(o-a)});return n},e.calculateClusterQuality=function(t,e,n){var r=0,i=0,a=t.reduce(function(t,e){return t+e.x},0)/t.length,o=t.reduce(function(t,e){return t+e.y},0)/t.length;n.forEach(function(n,s){var u=t.filter(function(t,n){return e[n]===s});u.forEach(function(t){r+=Math.pow(t.x-n.x,2)+Math.pow(t.y-n.y,2)}),i+=u.length*(Math.pow(n.x-a,2)+Math.pow(n.y-o,2))});var s=r+i;return s>0?i/s:0},e.calculateAverageCorrelation=function(t){},e.calculateAverageCorrelation=function(t){for(var e=Object.keys(t),n=0,r=0,i=0;i<e.length;i++)for(var a=i+1;a<e.length;a++)n+=Math.abs(t[e[i]][e[a]]),r++;return r>0?n/r:0},e.getExpectedInterval=function(t){switch(t){case"daily":default:return 864e5;case"weekly":return 6048e5;case"monthly":return 2592e6;case"yearly":return 31536e6}},e.tCDF=function(t,e){return e<=0?.5:1-.5*this.incompleteBeta(e/2,.5,e/(t*t+e))},e.incompleteBeta=function(t,e,n){if(n<=0)return 0;if(n>=1)return 1;for(var r=0,i=1,a=0;a<100&&(a>0&&(i*=n*(t+a-1)/a),r+=i/(t+a),!(Math.abs(i)<1e-10));a++);return r*Math.pow(n,t)*Math.pow(1-n,e)},t}(),N=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.interpret=function(t){if(!t||"object"!=typeof t)throw new Error("Invalid test result object");var e=this.identifyTestType(t);return{testType:e,summary:this.generateSummary(t,e),conclusion:this.generateConclusion(t,e),significance:this.interpretSignificance(t),effectSize:this.interpretEffectSize(t,e),confidence:this.assessConfidence(t),assumptions:this.checkAssumptions(e),recommendations:this.generateRecommendations(t,e),plainLanguage:this.generatePlainLanguageSummary(t,e)}},e.identifyTestType=function(t){return t.type?t.type:void 0!==t.correlation?"correlation":void 0!==t.rSquared?"regression":void 0!==t.fStatistic?"anova":void 0!==t.tStatistic||void 0!==t.statistic?void 0!==t.degreesOfFreedom?"t-test":"z-test":void 0!==t.isNormal?"normality-test":void 0!==t.clusters?"clustering":"general-test"},e.generateSummary=function(t,e){switch(e){case"correlation":return this.summarizeCorrelation(t);case"regression":return this.summarizeRegression(t);case"t-test":return this.summarizeTTest(t);case"z-test":return this.summarizeZTest(t);case"anova":return this.summarizeANOVA(t);case"normality-test":return this.summarizeNormalityTest(t);default:return this.summarizeGeneral(t)}},e.summarizeCorrelation=function(t){var e=t.correlation,n=this.getCorrelationStrength(Math.abs(e)),r=t.pValue<.05?"significant":"not significant";return n+" "+(e>0?"positive":"negative")+" correlation (r = "+e.toFixed(3)+") that is "+r},e.summarizeRegression=function(t){var e=t.rSquared,n=(100*e).toFixed(1);return(t.pValueModel<.05?"significant":"not significant")+" regression model explaining "+n+"% of variance (R² = "+e.toFixed(3)+")"},e.summarizeTTest=function(t){return(t.pValue<.05?"significant":"not significant")+" difference between groups (t = "+(t.statistic||t.tStatistic).toFixed(3)+", p = "+t.pValue.toFixed(4)+")"},e.summarizeZTest=function(t){return(t.pValue<.05?"significant":"not significant")+" result compared to population (z = "+(t.statistic||t.zStatistic).toFixed(3)+", p = "+t.pValue.toFixed(4)+")"},e.summarizeANOVA=function(t){return(t.pValueModel<.05?"significant":"not significant")+" differences between groups (F = "+t.fStatistic.toFixed(3)+", p = "+t.pValueModel.toFixed(4)+")"},e.summarizeNormalityTest=function(t){var e;return"Data appears "+(t.isNormal?"normally distributed":"not normally distributed")+" ("+(t.test||"normality test")+", p = "+((null==(e=t.pValue)?void 0:e.toFixed(4))||"N/A")+")"},e.summarizeGeneral=function(t){return void 0!==t.pValue?(t.pValue<.05?"significant":"not significant")+" statistical result (p = "+t.pValue.toFixed(4)+")":"Statistical analysis completed"},e.generateConclusion=function(t,e){var n=t.alpha||.05,r=t.pValue||t.pValueModel;if(void 0===r)return{decision:"inconclusive",statement:"Cannot determine statistical significance - p-value unavailable"};var i=r<n,a=(100*(1-n)).toFixed(0);return{decision:i?"reject_null":"fail_to_reject_null",statement:i?"At the "+a+"% confidence level, we reject the null hypothesis (p = "+r.toFixed(4)+" < "+n+").":"At the "+a+"% confidence level, we fail to reject the null hypothesis (p = "+r.toFixed(4)+" ā„ "+n+").",alpha:n,pValue:r,confidenceLevel:parseInt(a)}},e.interpretSignificance=function(t){var e,n,r=t.pValue||t.pValueModel;return void 0===r?{level:"unknown",interpretation:"P-value not available"}:(r<.001?(e="very_strong",n="Very strong evidence against null hypothesis"):r<.01?(e="strong",n="Strong evidence against null hypothesis"):r<.05?(e="moderate",n="Moderate evidence against null hypothesis"):r<.1?(e="weak",n="Weak evidence against null hypothesis"):(e="none",n="No evidence against null hypothesis"),{level:e,pValue:r,interpretation:n,isSignificant:r<.05})},e.interpretEffectSize=function(t,e){switch(e){case"correlation":return this.interpretCorrelationEffect(t);case"regression":return this.interpretRegressionEffect(t);case"t-test":return this.interpretTTestEffect(t);case"anova":return this.interpretANOVAEffect(t);default:return{interpretation:"Effect size not available for this test type"}}},e.interpretCorrelationEffect=function(t){var e=Math.abs(t.correlation),n=e*e;return{value:e,magnitude:this.getCorrelationStrength(e),varianceExplained:(100*n).toFixed(1)+"%",interpretation:this.getCorrelationStrength(e).toLowerCase()+" relationship",cohen:this.getCohenCorrelation(e)}},e.interpretRegressionEffect=function(t){var e=t.rSquared;return{value:e,magnitude:this.getRSquaredMagnitude(e),varianceExplained:(100*e).toFixed(1)+"%",interpretation:this.getRSquaredMagnitude(e).toLowerCase()+" explanatory power"}},e.interpretTTestEffect=function(t){if(void 0!==t.sample1Mean&&void 0!==t.sample2Mean){var e=Math.abs(t.sample1Mean-t.sample2Mean),n=e/(t.standardError*Math.sqrt(2));return{value:n,magnitude:this.getCohenD(n),interpretation:this.getCohenD(n).toLowerCase()+" effect size",meanDifference:e}}return{interpretation:"Effect size cannot be calculated - insufficient data"}},e.interpretANOVAEffect=function(t){if(t.sumOfSquaresBetween&&t.sumOfSquaresWithin){var e=t.sumOfSquaresBetween/(t.sumOfSquaresBetween+t.sumOfSquaresWithin);return{value:e,magnitude:this.getEtaSquared(e),varianceExplained:(100*e).toFixed(1)+"%",interpretation:this.getEtaSquared(e).toLowerCase()+" effect size"}}return{interpretation:"Effect size cannot be calculated - insufficient data"}},e.assessConfidence=function(t){var e=[],n="medium";t.sampleSize&&(t.sampleSize>100?(e.push("Large sample size increases reliability"),n="high"):t.sampleSize<30&&(e.push("Small sample size may limit reliability"),n="low"));var r=t.pValue||t.pValueModel;if(void 0!==r&&(r<.001?(e.push("Very low p-value strengthens confidence"),n="low"===n?"medium":"high"):r>.1&&(e.push("High p-value suggests weak evidence"),n="low")),t.confidenceInterval){var i=t.confidenceInterval,a=Math.abs(i.upper-i.lower),o=Math.abs((i.upper+i.lower)/2);o>0&&a/o<.2?e.push("Narrow confidence interval indicates precision"):(e.push("Wide confidence interval indicates uncertainty"),n="high"===n?"medium":"low")}return{level:n,factors:e,recommendation:this.getConfidenceRecommendation(n)}},e.checkAssumptions=function(t){var e=[];switch(t){case"t-test":e.push("Normality: Data should be approximately normally distributed","Independence: Observations should be independent","Equal variances: Groups should have similar variances (for independent samples)");break;case"anova":e.push("Normality: Residuals should be normally distributed","Homogeneity: Groups should have equal variances","Independence: Observations should be independent");break;case"correlation":e.push("Linearity: Relationship should be linear","Normality: Variables should be approximately normal","Homoscedasticity: Constant variance across range");break;case"regression":e.push("Linearity: Linear relationship between variables","Independence: Residuals should be independent","Homoscedasticity: Constant variance of residuals","Normality: Residuals should be normally distributed");break;default:e.push("Check test-specific assumptions in documentation")}return{testType:t,assumptions:e,importance:"Violating assumptions may invalidate results"}},e.generateRecommendations=function(t,e){var n=[],r=t.pValue||t.pValueModel;return void 0!==r&&(r<.001?n.push("Very strong result - investigate practical significance and effect size"):r>=.05&&r<.1?n.push("Marginally significant - consider collecting more data or using different approach"):r>=.1&&n.push("No significant effect found - examine data quality and consider alternative hypotheses")),"correlation"===e&&t.sampleSize&&t.sampleSize<30&&n.push("Small sample size - correlation may not be reliable"),"regression"===e&&t.rSquared<.3&&n.push("Low R² - consider additional predictors or different model"),t.assumptions&&t.assumptions.violated&&n.push("Assumptions may be violated - consider alternative tests or data transformations"),n.push("Replicate findings with independent data when possible"),n},e.generatePlainLanguageSummary=function(t,e){var n=t.pValue||t.pValueModel,r=n&&n<.05,i="";switch(i+=r?"ā SIGNIFICANT RESULT: ":"ā NOT SIGNIFICANT: ",e){case"correlation":var a=t.correlation,o=this.getCorrelationStrength(Math.abs(a));i+=r?"Found a "+o.toLowerCase()+" "+(a>0?"positive":"negative")+" relationship between the variables.":"No meaningful relationship found between the variables.";break;case"regression":var s=(100*t.rSquared).toFixed(0);i+=r?"The model successfully predicts the outcome, explaining "+s+"% of the variation.":"The model does not provide meaningful predictions.";break;case"t-test":i+=r?"Found a meaningful difference between the groups.":"No meaningful difference found between the groups.";break;case"anova":i+=r?"Found meaningful differences between at least some groups.":"No meaningful differences found between groups.";break;case"normality-test":i+=t.isNormal?"Data follows a normal distribution - suitable for standard statistical tests.":"Data does not follow a normal distribution - consider alternative tests.";break;default:i+=r?"The statistical test shows a significant result.":"The statistical test shows no significant result."}return void 0!==n&&(i+=" (p-value: "+n.toFixed(4)+")"),i},e.getCorrelationStrength=function(t){return t>=.9?"Very Strong":t>=.7?"Strong":t>=.5?"Moderate":t>=.3?"Weak":"Very Weak"},e.getCohenCorrelation=function(t){return t>=.5?"Large effect":t>=.3?"Medium effect":t>=.1?"Small effect":"Negligible effect"},e.getRSquaredMagnitude=function(t){return t>=.7?"Strong":t>=.5?"Moderate":t>=.3?"Weak":"Very Weak"},e.getCohenD=function(t){return t>=.8?"Large":t>=.5?"Medium":t>=.2?"Small":"Negligible"},e.getEtaSquared=function(t){return t>=.14?"Large":t>=.06?"Medium":t>=.01?"Small":"Negligible"},e.getConfidenceRecommendation=function(t){switch(t){case"high":return"Results appear robust and reliable";case"medium":return"Results are reasonably reliable but verify when possible";case"low":return"Interpret results with caution - consider additional validation";default:return"Assess result reliability based on context"}},e.formatForReport=function(t){return{title:t.testType.toUpperCase()+" Results",summary:t.summary,conclusion:t.conclusion.statement,significance:t.significance.interpretation,effect:t.effectSize.interpretation,confidence:t.confidence.level,recommendations:t.recommendations,plainLanguage:t.plainLanguage}},e.explainStatistic=function(t,e){return{correlation:"Correlation measures the linear relationship between two variables, ranging from -1 to +1.",regression:"R² shows how much variance in the outcome is explained by the predictors.","t-test":"T-test compares means between groups or against a known value.",anova:"ANOVA tests whether there are differences between multiple group means.","z-test":"Z-test compares a sample mean to a population mean when population variance is known.","normality-test":"Tests whether data follows a normal (bell-curve) distribution."}[e]||"Statistical test to evaluate hypotheses about data."},e.generateActionItems=function(t){var e=[],n=t.testType;return t.significance.isSignificant?(e.push("Examine practical significance of the finding"),e.push("Consider replicating with independent data"),"correlation"===n&&e.push("Explore potential causal relationships"),"regression"===n&&e.push("Validate model with new data")):(e.push("Review data collection methods"),e.push("Consider if sample size was adequate"),e.push("Explore alternative analytical approaches")),e.push("Document methodology and assumptions"),e},t}(),E=/*#__PURE__*/function(){function t(t){this.stats=t,this.insights=[],this.visualizations=[]}var e=t.prototype;return e.autoAnalyze=function(t,e){void 0===e&&(e={});var r=n({minCorrelationThreshold:.3,significanceLevel:.05,generateVisualizations:!0,includeAdvancedAnalysis:!0},e);console.log("š Iniciando anĆ”lise automĆ”tica...");var i=this.stats.validateData(t);if(!i.valid)throw new Error("Dados invĆ”lidos: "+i.errors.join(", "));var a=this.classifyVariables(t);console.log("š Identificadas "+a.quantitative.length+" variĆ”veis quantitativas e "+a.qualitative.length+" qualitativas");var o=this.performDescriptiveAnalysis(t,a),s=this.performCorrelationAnalysis(t,a.quantitative,r),u=this.performRegressionAnalysis(t,a.quantitative,s,r),l=this.performDistributionAnalysis(t,a),c=this.performOutlierAnalysis(t,a.quantitative),f=this.performTemporalAnalysis(t,a),h=this.generateAutoInsights(t,{variableTypes:a,descriptiveAnalysis:o,correlationAnalysis:s,regressionAnalysis:u,distributionAnalysis:l,outlierAnalysis:c,temporalAnalysis:f},r),d=this.suggestVisualizations(a,s,l);return console.log("ā
AnĆ”lise concluĆda!"),{metadata:{analysisDate:(new Date).toISOString(),datasetSize:t.length,columnsAnalyzed:t.headers.length,configuration:r},variableClassification:a,descriptiveStatistics:o,correlationAnalysis:s,regressionAnalysis:u,distributionAnalysis:l,outlierAnalysis:c,temporalAnalysis:f,insights:h,visualizationSuggestions:d,summary:this.generateExecutiveSummary(h)}},e.classifyVariables=function(t){var e=this,n=[],r=[],i=[],a=[],o=[];return t.headers.forEach(function(s){var u=t.data.map(function(t){return t[s]}).filter(function(t){return null!=t});if(0!==u.length){var l=e.classifyVariable(u,s);switch(l.type){case"quantitative":n.push(l);break;case"datetime":i.push(l);break;case"binary":a.push(l);break;case"ordinal":o.push(l);break;default:r.push(l)}}else r.push({name:s,type:"empty",description:"Coluna vazia"})}),{quantitative:n,qualitative:r,datetime:i,binary:a,ordinal:o}},e.classifyVariable=function(t,e){var n=[].concat(new Set(t)),r=t.filter(function(t){return"number"==typeof t&&!isNaN(t)}),i=r.length/t.length;if(this.isDateTimeColumn(t))return{name:e,type:"datetime",uniqueCount:n.length,description:"VariĆ”vel temporal"};if(i>.8){var a=this.determineQuantitativeSubtype(r);return{name:e,type:"quantitative",subtype:a,uniqueCount:n.length,description:"VariĆ”vel quantitativa "+a,range:{min:Math.min.apply(Math,r),max:Math.max.apply(Math,r)}}}return 2===n.length?{name:e,type:"binary",categories:n,description:"VariĆ”vel binĆ”ria/dicotĆ“mica"}:this.isOrdinalVariable(n)?{name:e,type:"ordinal",categories:n,uniqueCount:n.length,description:"VariĆ”vel ordinal"}:{name:e,type:"qualitative",subtype:n.length>10?"nominal_many":"nominal",categories:n.slice(0,20),uniqueCount:n.length,description:"VariĆ”vel qualitativa nominal ("+n.length+" categorias)"}},e.performDescriptiveAnalysis=function(t,e){var n=this,r={};return e.quantitative.forEach(function(e){var i=t.data.map(function(t){return t[e.name]}).filter(function(t){return"number"==typeof t&&!isNaN(t)});if(i.length>0){var a=i.length,o=a>=3,s=a>=4;r[e.name]={type:"quantitative",count:a,mean:n.stats.mean(i),median:n.stats.median(i),standardDeviation:n.stats.standardDeviation(i),min:Math.min.apply(Math,i),max:Math.max.apply(Math,i),quartiles:n.stats.quartiles(i),skewness:o?n.stats.skewness(i):null,kurtosis:s?n.stats.kurtosis(i):null}}}),[].concat(e.qualitative,e.binary).forEach(function(e){var i=t.data.map(function(t){return t[e.name]}).filter(function(t){return null!=t});if(i.length>0){var a=n.stats.frequencyTable(i);r[e.name]={type:"qualitative",count:i.length,uniqueValues:e.uniqueCount,frequencyTable:a.slice(0,10),mostFrequent:a[0],concentration:n.calculateConcentration(a)}}}),r},e.performCorrelationAnalysis=function(t,e,n){var r=this;if(e.length<2)return{message:"Insuficientes variĆ”veis quantitativas para anĆ”lise de correlação"};var i=this.stats.correlationMatrix(t),a=(i.strongCorrelations||[]).filter(function(t){return Math.abs(t.correlation)>=n.minCorrelationThreshold}),o=a.map(function(t){var e=r.getCorrelationStrength(Math.abs(t.correlation)),i=t.correlation>0?"positiva":"negativa";return{type:"correlation",priority:Math.abs(t.correlation)>.7?"high":"medium",title:"Correlação "+e+" entre "+t.variable1+" e "+t.variable2,description:"Correlação "+i+" de "+t.correlation.toFixed(3),variables:[t.variable1,t.variable2],correlation:t.correlation,significance:null!=t.pValue?t.pValue<n.significanceLevel:void 0}});return{matrix:i.correlations||i,strongCorrelations:a,insights:o,summary:"Encontradas "+a.length+" correlaƧƵes ā„ "+n.minCorrelationThreshold}},e.performRegressionAnalysis=function(t,e,n,r){var i=this,a=[];return n.strongCorrelations&&n.strongCorrelations.filter(function(t){return Math.abs(t.correlation)>.5}).slice(0,5).forEach(function(e){try{var n=t.data.map(function(t){return t[e.variable1]}).filter(function(t){return"number"==typeof t&&!isNaN(t)}),o=t.data.map(function(t){return t[e.variable2]}).filter(function(t){return"number"==typeof t&&!isNaN(t)});if(n.length===o.length&&n.length>10){var s=i.stats.linearRegression(n,o);a.push({independent:e.variable1,dependent:e.variable2,equation:s.equation,rSquared:s.rSquared,significant:s.pValueModel<r.significanceLevel,interpretation:i.interpretRegressionResult(s),details:s})}}catch(t){console.warn("Erro na regressĆ£o "+e.variable1+" -> "+e.variable2+":",t.message)}}),{models:a,summary:a.length+" modelos de regressĆ£o analisados"}},e.performDistributionAnalysis=function(t,e){var n=this,r={};return e.quantitative.forEach(function(e){var i=t.data.map(function(t){return t[e.name]}).filter(function(t){return"number"==typeof t&&!isNaN(t)});if(i.length>10)try{var a=n.stats.shapiroWilkTest(i),o=n.stats.skewness(i),s=n.stats.kurtosis(i);r[e.name]={isNormal:a.isNormal,normalityPValue:a.pValue,skewness:o,kurtosis:s,distributionType:n.classifyDistributionType(o,s,a.isNormal),recommendation:n.getDistributionRecommendation(o,s,a.isNormal)}}catch(t){r[e.name]={error:"NĆ£o foi possĆvel analisar a distribuição",reason:t.message}}}),r},e.performOutlierAnalysis=function(t,e){var n=this,r={};return e.forEach(function(e){var i=t.data.map(function(t){return t[e.name]}).filter(function(t){return"number"==typeof t&&!isNaN(t)});if(i.length>5){var a=n.stats.detectOutliers(i,"iqr");r[e.name]={count:a.count,percentage:a.percentage,severity:n.classifyOutlierSeverity(a.percentage),values:a.outliers.slice(0,10),recommendation:n.getOutlierRecommendation(a.percentage)}}}),r},e.performTemporalAnalysis=function(t,e){var n=this;if(0===e.datetime.length)return{message:"Nenhuma variĆ”vel temporal detectada"};var r={};return e.datetime.forEach(function(e){var i=t.data.map(function(t){return new Date(t[e.name])}).filter(function(t){return!isNaN(t.getTime())}).sort(function(t,e){return t-e});if(i.length>2){var a=i[i.length-1]-i[0],o=a/(i.length-1);r[e.name]={span:Math.floor(a/864e5)+" dias",frequency:n.determineFrequency(o),earliest:i[0].toISOString().split("T")[0],latest:i[i.length-1].toISOString().split("T")[0],dataPoints:i.length}}}),r},e.generateAutoInsights=function(t,e,n){var r,i=[],a=e.variableTypes;i.push({category:"overview",priority:"high",title:"Composição do Dataset",description:"Dataset com "+t.length+" registros, "+a.quantitative.length+" variĆ”veis numĆ©ricas e "+a.qualitative.length+" categóricas",icon:"š"}),e.correlationAnalysis.insights&&i.push.apply(i,e.correlationAnalysis.insights),Object.entries(e.distributionAnalysis).forEach(function(t){var e=t[0],n=t[1];n.distributionType&&"normal"!==n.distributionType&&i.push({category:"distribution",priority:"medium",title:"Distribuição nĆ£o-normal: "+e,description:n.recommendation,variable:e,icon:"š"})}),Object.entries(e.outlierAnalysis).forEach(function(t){var e=t[0],n=t[1];"high"===n.severity&&i.push({category:"quality",priority:"high",title:"Outliers significativos em "+e,description:n.count+" outliers ("+n.percentage.toFixed(1)+"%) detectados",recommendation:n.recommendation,variable:e,icon:"ā ļø"})}),null==(r=e.regressionAnalysis.models)||r.forEach(function(t){t.significant&&t.rSquared>.5&&i.push({category:"modeling",priority:"high",title:"Modelo preditivo viĆ”vel: "+t.dependent,description:t.independent+" explica "+(100*t.rSquared).toFixed(1)+"% da variação em "+t.dependent,variables:[t.independent,t.dependent],rSquared:t.rSquared,icon:"šÆ"})});var o={high:3,medium:2,low:1};return i.sort(function(t,e){return o[e.priority]-o[t.priority]})},e.suggestVisualizations=function(t,e,n){var r=[];t.quantitative.forEach(function(t){r.push({type:"histogram",variable:t.name,title:"Distribuição de "+t.name,description:"Histogram mostrando a distribuição dos valores",priority:"medium"})}),e.strongCorrelations&&e.strongCorrelations.filter(function(t){return Math.abs(t.correlation)>.5}).slice(0,3).forEach(function(t){r.push({type:"scatter",variables:[t.variable1,t.variable2],title:t.variable1+" vs "+t.variable2,description:"Scatter plot mostrando correlação "+(t.correlation>0?"positiva":"negativa"),priority:"high"})}),[].concat(t.qualitative,t.binary).forEach(function(t){t.uniqueCount<=20&&r.push({type:"bar",variable:t.name,title:"FrequĆŖncia de "+t.name,description:"GrĆ”fico de barras mostrando a distribuição das categorias",priority:"medium"})}),t.quantitative.forEach(function(t){r.push({type:"boxplot",variable:t.name,title:"Box Plot de "+t.name,description:"Box plot para identificar outliers e quartis",priority:"low"})});var i={high:3,medium:2,low:1};return r.sort(function(t,e){return i[e.priority]-i[t.priority]})},e.generateExecutiveSummary=function(t){var e=t.filter(function(t){return"high"===t.priority}),n=[].concat(new Set(t.map(function(t){return t.category})));return{totalInsights:t.length,highPriorityInsights:e.length,categoriesCovered:n,keyFindings:e.slice(0,3).map(function(t){return{title:t.title,description:t.description}}),recommendations:this.generateTopRecommendations(t)}},e.isDateTimeColumn=function(t){var e=Math.min(t.length,20),n=t.slice(0,e).filter(function(t){if("string"==typeof t){var e=new Date(t);return!isNaN(e.getTime())}return!1}).length;return n/e>.7},e.determineQuantitativeSubtype=function(t){return t.filter(function(t){return Number.isInteger(t)}).length/t.length>.9?"discrete":"continuous"},e.isOrdinalVariable=function(t){return[/^(baixo|mĆ©dio|alto)$/i,/^(pequeno|grande)$/i,/^(ruim|regular|bom|ótimo)$/i,/^[1-5]$/,/^(primeiro|segundo|terceiro)$/i].some(function(e){return t.every(function(t){return e.test(String(t))})})},e.calculateConcentration=function(t){return 0===t.length?0:t[0].percentage},e.getCorrelationStrength=function(t){return t>=.8?"muito forte":t>=.6?"forte":t>=.4?"moderada":t>=.2?"fraca":"muito fraca"},e.interpretRegressionResult=function(t){var e=(100*t.rSquared).toFixed(1);return{quality:t.rSquared>.7?"excelente":t.rSquared>.5?"boa":t.rSquared>.3?"moderada":"fraca",explanation:"O modelo explica "+e+"% da variação",isSignificant:t.pValueModel<.05}},e.classifyDistributionType=function(t,e,n){return n?"normal":Math.abs(t)>1?t>0?"assimĆ©trica_direita":"assimĆ©trica_esquerda":Math.abs(e)>1?e>0?"leptocĆŗrtica":"platicĆŗrtica":"aproximadamente_normal"},e.getDistributionRecommendation=function(t,e,n){return n?"Distribuição normal - ideal para testes paramĆ©tricos":Math.abs(t)>1?"Considere transformação logarĆtmica para normalizar":Math.abs(e)>1?"Distribuição com caudas atĆpicas - use testes robustos":"Distribuição aproximadamente normal"},e.classifyOutlierSeverity=function(t){return t>10?"high":t>5?"medium":"low"},e.getOutlierRecommendation=function(t){return t>10?"Investigar e possivelmente remover outliers":t>5?"Verificar se outliers sĆ£o valores legĆtimos":"Poucos outliers - monitorar"},e.determineFrequency=function(t){var e=864e5;return t<e?"diĆ”ria":t<7*e?"semanal":t<30*e?"mensal":"anual"},e.generateTopRecommendations=function(t){var e=[];return t.filter(function(t){return"correlation"===t.category}).length>0&&e.push("Explore as correlaƧƵes identificadas para possĆvel modelagem preditiva"),t.filter(function(t){return"quality"===t.category&&"high"===t.priority}).length>0&&e.push("Trate os outliers identificados antes de prosseguir com anĆ”lises"),t.filter(function(t){return"distribution"===t.category}).length>0&&e.push("Considere transformaƧƵes para normalizar distribuiƧƵes assimĆ©tricas"),e},t}(),A=/*#__PURE__*/function(){function t(){this.trained=!1,this.model=null,this.features=null,this.target=null,this.trainingMetrics={}}var e=t.prototype;return e.validateTrainingData=function(t,e){if(!Array.isArray(t)||0===t.length)throw new Error("X must be a non-empty array");if(!Array.isArray(e)||0===e.length)throw new Error("y must be a non-empty array");if(t.length!==e.length)throw new Error("X and y must have the same length")},e.validatePredictionData=function(t){if(!this.trained)throw new Error("Model must be trained before making predictions");if(!Array.isArray(t)||0===t.length)throw new Error("X must be a non-empty array")},e.normalizeFeatures=function(t){for(var e=t.length,n=t[0].length,r=[],i=[],a=[],o=function(n){var r=t.map(function(t){return t[n]}),o=r.reduce(function(t,e){return t+e},0)/e,s=r.reduce(function(t,e){return t+Math.pow(e-o,2)},0)/e,u=Math.sqrt(s);i.push(o),a.push(0===u?1:u)},s=0;s<n;s++)o(s);for(var u=0;u<e;u++){for(var l=[],c=0;c<n;c++)l.push((t[u][c]-i[c])/a[c]);r.push(l)}return{normalized:r,means:i,stds:a}},e.splitTrainTest=function(t,e,n,r){void 0===n&&(n=.2),void 0===r&&(r=!0);var i=t.length,a=Array.from({length:i},function(t,e){return e});if(r)for(var o=i-1;o>0;o--){var s=Math.floor(Math.random()*(o+1)),u=[a[s],a[o]];a[o]=u[0],a[s]=u[1]}var l=i-Math.floor(i*n),c=a.slice(0,l),f=a.slice(l);return{X_train:c.map(function(e){return t[e]}),X_test:f.map(function(e){return t[e]}),y_train:c.map(function(t){return e[t]}),y_test:f.map(function(t){return e[t]})}},e.save=function(){if(!this.trained)throw new Error("Cannot save untrained model");return{model:this.model,features:this.features,target:this.target,trainingMetrics:this.trainingMetrics,timestamp:(new Date).toISOString()}},e.load=function(t){this.model=t.model,this.features=t.features,this.target=t.target,this.trainingMetrics=t.trainingMetrics,this.trained=!0},t}(),C=/*#__PURE__*/function(t){function e(e,n,r,i){var a;return void 0===e&&(e=.01),void 0===n&&(n=1e3),void 0===r&&(r=null),void 0===i&&(i=.01),(a=t.call(this)||this).learningRate=e,a.iterations=n,a.regularization=r,a.lambda=i,a.weights=null,a.bias=null,a.normParams=null,a}r(e,t);var n=e.prototype;return n.fit=function(t,e,n){var r=this;void 0===n&&(n=!0),this.validateTrainingData(t,e);var i=t.map(function(t){return Array.isArray(t)?t:[t]});if(n){var a=this.normalizeFeatures(i);i=a.normalized,this.normParams={means:a.means,stds:a.stds}}var o=i.length,s=i[0].length;this.weights=Array(s).fill(0),this.bias=0;for(var u=[],l=0;l<this.iterations;l++){for(var c=i.map(function(t){return r.predictSingle(t)}),f=c.map(function(t,n){return t-e[n]}),h=Array(s).fill(0),d=0,p=0;p<o;p++){d+=f[p];for(var m=0;m<s;m++)h[m]+=f[p]*i[p][m]}for(var g=0;g<s;g++)"l2"===this.regularization?h[g]+=this.lambda*this.weights[g]:"l1"===this.regularization&&(h[g]+=this.lambda*Math.sign(this.weights[g])),this.weights[g]-=this.learningRate/o*h[g];this.bias-=this.learningRate/o*d;var v=this.calculateLoss(c,e);u.push(v)}return this.trained=!0,this.trainingMetrics={finalLoss:u[u.length-1],losses:u,weights:[].concat(this.weights),bias:this.bias},this},n.predictSingle=function(t){for(var e=this.bias,n=0;n<this.weights.length;n++)e+=this.weights[n]*t[n];return e},n.predict=function(t){var e=this;this.validatePredictionData(t);var n=t.map(function(t){return Array.isArray(t)?t:[t]});if(this.normParams){var r=this.normParams,i=r.means,a=r.stds;n=n.map(function(t){return t.map(function(t,e){return(t-i[e])/a[e]})})}return n.map(function(t){return e.predictSingle(t)})},n.calculateLoss=function(t,e){var n=t.reduce(function(t,n,r){return t+Math.pow(n-e[r],2)},0)/t.length;if("l2"===this.regularization){var r=this.weights.reduce(function(t,e){return t+e*e},0);return n+this.lambda*r}if("l1"===this.regularization){var i=this.weights.reduce(function(t,e){return t+Math.abs(e)},0);return n+this.lambda*i}return n},n.score=function(t,e){var n=this.predict(t),r=e.reduce(function(t,e){return t+e},0)/e.length,i=n.reduce(function(t,n,r){return t+Math.pow(e[r]-n,2)},0),a=e.reduce(function(t,e){return t+Math.pow(e-r,2)},0),o=i/e.length;return{r2Score:1-i/a,mse:o,rmse:Math.sqrt(o),mae:n.reduce(function(t,n,r){return t+Math.abs(e[r]-n)},0)/e.length,predictions:n,residuals:n.map(function(t,n){return e[n]-t})}},n.getCoefficients=function(){if(!this.trained)throw new Error("Model must be trained first");return{weights:[].concat(this.weights),bias:this.bias,equation:this.getEquation()}},n.getEquation=function(){var t="y = "+this.bias.toFixed(4);return this.weights.forEach(function(e,n){t+=" "+(e>=0?"+":"")+" "+e.toFixed(4)+"*x"+(n+1)}),t},n.summary=function(){if(!this.trained)throw new Error("Model must be trained first");return{modelType:"Linear Regression",coefficients:this.getCoefficients(),trainingMetrics:this.trainingMetrics,hyperparameters:{learningRate:this.learningRate,iterations:this.iterations,regularization:this.regularization,lambda:this.lambda}}},e}(A),q=/*#__PURE__*/function(t){function n(e){var n,r=void 0===e?{}:e,i=r.learningRate,a=void 0===i?.01:i,o=r.iterations,s=void 0===o?1e3:o,u=r.batchSize,l=void 0===u?null:u,c=r.regularization,f=void 0===c?null:c,h=r.lambda,d=void 0===h?.01:h,p=r.earlyStopping,m=void 0!==p&&p,g=r.tol,v=void 0===g?1e-6:g,y=r.randomInit,b=void 0===y||y;return(n=t.call(this)||this).learningRate=a,n.iterations=s,n.batchSize=l,n.regularization=f,n.lambda=d,n.earlyStopping=m,n.tol=v,n.randomInit=b,n.weights=null,n.bias=null,n.normParams=null,n.classes=null,n.multiclass=!1,n.losses=[],n}r(n,t);var i=n.prototype;return i.sigmoid=function(t){return 1/(1+Math.exp(-t))},i.softmax=function(t){var e=Math.max.apply(Math,t),n=t.map(function(t){return Math.exp(t-e)}),r=n.reduce(function(t,e){return t+e},0);return n.map(function(t){return t/r})},i.fit=function(t,e,n){void 0===n&&(n=!0),this.validateTrainingData(t,e),this.classes=[].concat(new Set(e)).sort(function(t,e){return"number"==typeof t&&"number"==typeof e?t-e:String(t).localeCompare(String(e))}),this.multiclass=this.classes.length>2;var r=t.map(function(t){return Array.isArray(t)?t:[t]});if(n){var i=this.normalizeFeaturesSafe(r);r=i.normalized,this.normParams={means:i.means,stds:i.stds}}return this.multiclass?this.fitMulticlass(r,e):this.fitBinary(r,e),this.trained=!0,this},i.fitBinary=function(t,e){var n=this,r=t[0].length,i=e.map(function(t){return t===n.classes[1]?1:0});this.weights=this.randomInit?Array(r).fill(0).map(function(){return.01*Math.random()}):Array(r).fill(0),this.bias=0;var a=Infinity;this.losses=[];for(var o=0;o<this.iterations;o++){for(var s=this.getBatch(t,i),u=s.Xb,l=s.yb,c=u.map(function(t){return n.sigmoid(n.linear(t))}),f=this.gradientBinary(u,l,c),h=f.weightGradients,d=f.biasGradient,p=0;p<r;p++)this.weights[p]-=this.learningRate/u.length*h[p];this.bias-=this.learningRate/u.length*d;var m=this.calculateBinaryLoss(c,l);if(this.losses.push(m),this.earlyStopping&&Math.abs(a-m)<this.tol)break;a=m}this.trainingMetrics={finalLoss:this.losses[this.losses.length-1],losses:this.losses,weights:[].concat(this.weights),bias:this.bias}},i.fitMulticlass=function(t,e){var n=this,r=t[0].length,i=this.classes.length,a=this.oneHotEncode(e,i);this.weights=Array(i).fill(0).map(function(){return n.randomInit?Array(r).fill(0).map(function(){return.01*Math.random()}):Array(r).fill(0)}),this.bias=Array(i).fill(0);var o=Infinity;this.losses=[];for(var s=0;s<this.iterations;s++){for(var u=this.getBatch(t,a),l=u.Xb,c=u.yb,f=l.map(function(t){return n.forwardMulticlass(t)}),h=0;h<i;h++){for(var d=this.gradientMulticlass(l,c,f,h),p=0;p<r;p++)this.weights[h][p]-=this.learningRate/l.length*d.weight[p];this.bias[h]-=this.learningRate/l.length*d.bias}var m=this.calculateMulticlassLoss(f,c);if(this.losses.push(m),this.earlyStopping&&Math.abs(o-m)<this.tol)break;o=m}this.trainingMetrics={finalLoss:this.losses[this.losses.length-1],losses:this.losses}},i.predict=function(t,e){void 0===e&&(e=!1),this.validatePredictionData(t);var n=t.map(function(t){return Array.isArray(t)?t:[t]});if(this.normParams){var r=this.normParams,i=r.means,a=r.stds;n=n.map(function(t){return t.map(function(t,e){return(t-i[e])/(a[e]||1)})})}return this.multiclass?this.predictMulticlass(n,e):this.predictBinary(n,e)},i.predictBinary=function(t,e){var n=this;return t.map(function(t){var r,i=n.sigmoid(n.linear(t));return e?((r={})[n.classes[0]]=1-i,r[n.classes[1]]=i,r):i>=.5?n.classes[1]:n.classes[0]})},i.predictMulticlass=function(t,e){var n=this;return t.map(function(t){var r=n.forwardMulticlass(t);if(e){var i={};return n.classes.forEach(function(t,e){return i[t]=r[e]}),i}var a=r.indexOf(Math.max.apply(Math,r));return n.classes[a]})},i.linear=function(t){var e=this;return this.bias+t.reduce(function(t,n,r){return t+n*e.weights[r]},0)},i.forwardMulticlass=function(t){var e=this,n=this.bias.map(function(n,r){return n+t.reduce(function(t,n,i){return t+n*e.weights[r][i]},0)});return this.softmax(n)},i.getBatch=function(t,e){if(!this.batchSize||this.batchSize>=t.length)return{Xb:t,yb:e};var n=Math.floor(Math.random()*(t.length-this.batchSize));return{Xb:t.slice(n,n+this.batchSize),yb:e.slice(n,n+this.batchSize)}},i.gradientBinary=function(t,e,n){for(var r=t[0].length,i=Array(r).fill(0),a=0,o=0;o<t.length;o++){var s=n[o]-e[o];a+=s;for(var u=0;u<r;u++)i[u]+=s*t[o][u]}if(this.regularization)for(var l=0;l<r;l++)"l2"===this.regularization&&(i[l]+=this.lambda*this.weights[l]),"l1"===this.regularization&&(i[l]+=this.lambda*Math.sign(this.weights[l]));return{weightGradients:i,biasGradient:a}},i.gradientMulticlass=function(t,e,n,r){for(var i=t[0].length,a=Array(i).fill(0),o=0,s=0;s<t.length;s++){var u=n[s][r]-e[s][r];o+=u;for(var l=0;l<i;l++)a[l]+=u*t[s][l]}if("l2"===this.regularization)for(var c=0;c<i;c++)a[c]+=this.lambda*this.weights[r][c];return{weight:a,bias:o}},i.normalizeFeaturesSafe=function(t){for(var e=t[0].length,n=Array(e).fill(0),r=Array(e).fill(0),i=function(e){var i=t.map(function(t){return t[e]}),a=i.reduce(function(t,e){return t+e},0)/i.length,o=Math.sqrt(i.reduce(function(t,e){return t+Math.pow(e-a,2)},0)/i.length);n[e]=a,r[e]=o||1},a=0;a<e;a++)i(a);var o=t.map(function(t){return t.map(function(t,e){return(t-n[e])/r[e]})});return{normalized:o,means:n,stds:r}},i.oneHotEncode=function(t,e){var n=this;return t.map(function(t){var r=Array(e).fill(0);return r[n.classes.indexOf(t)]=1,r})},i.calculateBinaryLoss=function(t,e){for(var n=0,r=0;r<t.length;r++){var i=Math.min(Math.max(t[r],1e-15),1-1e-15);n-=e[r]*Math.log(i)+(1-e[r])*Math.log(1-i)}if(n/=t.length,"l2"===this.regularization){var a=this.weights.reduce(function(t,e){return t+e*e},0);n+=this.lambda/2*a}return n},i.calculateMulticlassLoss=function(t,e){for(var n=0,r=0;r<t.length;r++)for(var i=0;i<e[r].length;i++){var a=Math.min(Math.max(t[r][i],1e-15),1-1e-15);n-=e[r][i]*Math.log(a)}return n/t.length},i.rocCurve=function(t,n){var r=this;if(this.multiclass)return console.warn("ROC Curve disponĆvel apenas para problemas binĆ”rios"),null;for(var i,a=this.predict(t,!0).map(function(t){return t[r.classes[1]]}),o=[],s=e([].concat(new Set(a)).sort(function(t,e){return e-t}));!(i=s()).done;){for(var u=i.value,l=0,c=0,f=0,h=0,d=0;d<n.length;d++){var p=n[d]===this.classes[1]?1:0,m=a[d]>=u?1:0;1===p&&1===m?l++:0===p&&1===m?c++:0===p&&0===m?f++:1===p&&0===m&&h++}o.push({fpr:c/(c+f),tpr:l/(l+h)})}return o.sort(function(t,e){return t.fpr-e.fpr}),o},i.aucScore=function(t,e){var n=this.rocCurve(t,e);if(!n)return null;for(var r=0,i=1;i<n.length;i++)r+=(n[i].fpr-n[i-1].fpr)*(n[i-1].tpr+n[i].tpr)/2;return Math.abs(r)},i.score=function(t,e){var n=this.predict(t),r=this.predict(t,!0),i=n.filter(function(t,n){return t===e[n]}).length/e.length,a=this.confusionMatrix(e,n),o=this.calculateClassMetrics(a);return{accuracy:i,auc:this.multiclass?null:this.aucScore(t,e),roc:this.multiclass?null:this.rocCurve(t,e),confusionMatrix:a,classMetrics:o,predictions:n,probabilities:r}},i.summary=function(){if(!this.trained)throw new Error("Model must be trained first");return{modelType:"Logistic Regression",classes:this.classes,multiclass:this.multiclass,trainingMetrics:this.trainingMetrics,hyperparameters:{learningRate:this.learningRate,iterations:this.iterations,regularization:this.regularization,lambda:this.lambda,batchSize:this.batchSize,earlyStopping:this.earlyStopping}}},n}(A),k=/*#__PURE__*/function(t){function e(e,n,r){var i;return void 0===e&&(e=5),void 0===n&&(n="euclidean"),void 0===r&&(r="uniform"),(i=t.call(this)||this).k=e,i.metric=n,i.weights=r,i.X_train=null,i.y_train=null,i.normParams=null,i.taskType=null,i}r(e,t);var n=e.prototype;return n.euclideanDistance=function(t,e){return Math.sqrt(t.reduce(function(t,n,r){return t+Math.pow(n-e[r],2)},0))},n.manhattanDistance=function(t,e){return t.reduce(function(t,n,r){return t+Math.abs(n-e[r])},0)},n.minkowskiDistance=function(t,e,n){return void 0===n&&(n=3),Math.pow(t.reduce(function(t,r,i){return t+Math.pow(Math.abs(r-e[i]),n)},0),1/n)},n.calculateDistance=function(t,e){switch(this.metric){case"manhattan":return this.manhattanDistance(t,e);case"minkowski":return this.minkowskiDistance(t,e);default:return this.euclideanDistance(t,e)}},n.fit=function(t,e,n,r){void 0===n&&(n=!0),void 0===r&&(r="classification"),this.validateTrainingData(t,e),this.taskType=r;var i=t.map(function(t){return Array.isArray(t)?t:[t]});if(n){var a=this.normalizeFeatures(i),o=a.means,s=a.stds;this.X_train=a.normalized,this.normParams={means:o,stds:s}}else this.X_train=i;return this.y_train=[].concat(e),this.trained=!0,this.trainingMetrics={samples:this.X_train.length,features:this.X_train[0].length,taskType:this.taskType},this},n.findKNearest=function(t){var e=this,n=this.X_train.map(function(n,r){return{distance:e.calculateDistance(t,n),index:r,label:e.y_train[r]}});return n.sort(function(t,e){return t.distance-e.distance}),n.slice(0,this.k)},n.predictSingleClassification=function(t){var e=this.findKNearest(t);if("uniform"===this.weights){var n={};return e.forEach(function(t){n[t.label]=(n[t.label]||0)+1}),Object.keys(n).reduce(function(t,e){return n[t]>n[e]?t:e})}var r={};return e.forEach(function(t){r[t.label]=(r[t.label]||0)+(0===t.distance?1e10:1/t.distance)}),Object.keys(r).reduce(function(t,e){return r[t]>r[e]?t:e})},n.predictSingleRegression=function(t){var e=this.findKNearest(t);if("uniform"===this.weights)return e.reduce(function(t,e){return t+e.label},0)/e.length;var n=0,r=0;return e.forEach(function(t){var e=0===t.distance?1e10:1/t.distance;n+=t.label*e,r+=e}),n/r},n.predict=function(t){var e=this;this.validatePredictionData(t);var n=t.map(function(t){return Array.isArray(t)?t:[t]});if(this.normParams){var r=this.normParams,i=r.means,a=r.stds;n=n.map(function(t){return t.map(function(t,e){return(t-i[e])/a[e]})})}return n.map("classification"===this.taskType?function(t){return e.predictSingleClassification(t)}:function(t){return e.predictSingleRegression(t)})},n.predictProba=function(t){var e=this;if("classification"!==this.taskType)throw new Error("predictProba is only available for classification tasks");this.validatePredictionData(t);var n=t.map(function(t){return Array.isArray(t)?t:[t]});if(this.normParams){var r=this.normParams,i=r.means,a=r.stds;n=n.map(function(t){return t.map(function(t,e){return(t-i[e])/a[e]})})}var o=[].concat(new Set(this.y_train)).sort();return n.map(function(t){var n=e.findKNearest(t),r={};if(o.forEach(function(t){r[t]=0}),"uniform"===e.weights)n.forEach(function(t){r[t.label]+=1/e.k});else{var i=0,a={};n.forEach(function(t){var e=0===t.distance?1e10:1/t.distance;a[t.label]=(a[t.label]||0)+e,i+=e}),Object.keys(a).forEach(function(t){r[t]=a[t]/i})}return r})},n.score=function(t,e){var n=this.predict(t);if("classification"===this.taskType){for(var r=0,i=0;i<e.length;i++)n[i]===e[i]&&r++;var a=r/e.length,o=[].concat(new Set([].concat(e,n))).sort(),s=this.confusionMatrix(e,n,o);return{accuracy:a,confusionMatrix:s,classMetrics:this.calculateClassMetrics(s,o),predictions:n}}var u=e.reduce(function(t,e){return t+e},0)/e.length,l=n.reduce(function(t,n,r){return t+Math.pow(e[r]-n,2)},0),c=1-l/e.reduce(function(t,e){return t+Math.pow(e-u,2)},0),f=l/e.length,h=Math.sqrt(f),d=n.reduce(function(t,n,r){return t+Math.abs(e[r]-n)},0)/e.length;return{r2Score:c,mse:f,rmse:h,mae:d,predictions:n,residuals:n.map(function(t,n){return e[n]-t})}},n.confusionMatrix=function(t,e,n){for(var r=n.length,i=Array(r).fill(0).map(function(){return Array(r).fill(0)}),a=0;a<t.length;a++){var o=n.indexOf(t[a]),s=n.indexOf(e[a]);i[o][s]++}return{matrix:i,classes:n,display:this.formatConfusionMatrix(i,n)}},n.formatConfusionMatrix=function(t,e){var n=Math.max.apply(Math,t.flat().map(function(t){return t.toString().length}).concat([8])),r=function(t){return t.toString().padStart(n)},i="\n"+" ".repeat(n+2)+"Predicted\n";i+=" ".repeat(n+2)+e.map(function(t){return r(t)}).join(" ")+"\n";for(var a=0;a<t.length;a++)i+=0===a?"Actual ":" ",i+=r(e[a])+" ",i+=t[a].map(function(t){return r(t)}).join(" ")+"\n";return i},n.calculateClassMetrics=function(t,e){var n=t.matrix,r={};return e.forEach(function(t,e){var i=n[e][e],a=n[e].reduce(function(t,e){return t+e},0)-i,o=n.map(function(t){return t[e]}).reduce(function(t,e){return t+e},0)-i,s=i+o>0?i/(i+o):0,u=i+a>0?i/(i+a):0;r[t]={precision:s,recall:u,f1Score:s+u>0?s*u*2/(s+u):0,support:i+a}}),r},n.summary=function(){if(!this.trained)throw new Error("Model must be trained first");return{modelType:"K-Nearest Neighbors",taskType:this.taskType,trainingMetrics:this.trainingMetrics,hyperparameters:{k:this.k,metric:this.metric,weights:this.weights}}},e}(A),_=/*#__PURE__*/function(t){function n(e,n,r,i){var a;return void 0===e&&(e=10),void 0===n&&(n=2),void 0===r&&(r=1),void 0===i&&(i="gini"),(a=t.call(this)||this).maxDepth=e,a.minSamplesSplit=n,a.minSamplesLeaf=r,a.criterion=i,a.tree=null,a.taskType=null,a.classes=null,a}r(n,t);var i=n.prototype;return i.fit=function(t,e,n){void 0===n&&(n="classification"),this.validateTrainingData(t,e),this.taskType=n;var r=t.map(function(t){return Array.isArray(t)?t:[t]});return"classification"===n&&(this.classes=[].concat(new Set(e)).sort()),this.tree=this.buildTree(r,e,0),this.trained=!0,this.trainingMetrics={treeDepth:this.getTreeDepth(this.tree),leafCount:this.getLeafCount(this.tree),nodeCount:this.getNodeCount(this.tree),taskType:this.taskType},this},i.buildTree=function(t,n,r){var i=t[0].length;if(r>=this.maxDepth||t.length<this.minSamplesSplit||this.isPure(n))return this.createLeaf(n);for(var a=null,o=-Infinity,s=0;s<i;s++)for(var u,l=e(this.getThresholds(t,s));!(u=l()).done;){var c=u.value,f=this.splitData(t,n,s,c),h=f.left,d=f.right;if(!(h.y.length<this.minSamplesLeaf||d.y.length<this.minSamplesLeaf)){var p=this.calculateSplitScore(n,h.y,d.y);p>o&&(o=p,a={featureIdx:s,threshold:c,left:h,right:d})}}return a?{featureIdx:a.featureIdx,threshold:a.threshold,left:this.buildTree(a.left.X,a.left.y,r+1),right:this.buildTree(a.right.X,a.right.y,r+1),isLeaf:!1}:this.createLeaf(n)},i.getThresholds=function(t,e){for(var n=[].concat(new Set(t.map(function(t){return t[e]}))).sort(function(t,e){return t-e}),r=[],i=0;i<n.length-1;i++)r.push((n[i]+n[i+1])/2);return r},i.splitData=function(t,e,n,r){for(var i=[],a=[],o=[],s=[],u=0;u<t.length;u++)t[u][n]<=r?(i.push(t[u]),a.push(e[u])):(o.push(t[u]),s.push(e[u]));return{left:{X:i,y:a},right:{X:o,y:s}}},i.isPure=function(t){return 1===new Set(t).size},i.createLeaf=function(t){if("classification"===this.taskType){var e={};return t.forEach(function(t){e[t]=(e[t]||0)+1}),{isLeaf:!0,prediction:Object.keys(e).reduce(function(t,n){return e[t]>e[n]?t:n}),samples:t.length,distribution:e}}return{isLeaf:!0,prediction:t.reduce(function(t,e){return t+e},0)/t.length,samples:t.length}},i.calculateSplitScore=function(t,e,n){if("classification"===this.taskType){var r=this.calculateImpurity(t),i=t.length,a=n.length;return r-(e.length/i*this.calculateImpurity(e)+a/i*this.calculateImpurity(n))}var o=this.calculateVariance(t),s=t.length,u=n.length;return o-(e.length/s*this.calculateVariance(e)+u/s*this.calculateVariance(n))},i.calculateImpurity=function(t){var e={};t.forEach(function(t){e[t]=(e[t]||0)+1});var n=t.length,r=Object.values(e).map(function(t){return t/n});return"gini"===this.criterion?1-r.reduce(function(t,e){return t+e*e},0):"entropy"===this.criterion?-r.reduce(function(t,e){return t+e*Math.log2(e)},0):void 0},i.calculateVariance=function(t){if(0===t.length)return 0;var e=t.reduce(function(t,e){return t+e},0)/t.length;return t.reduce(function(t,n){return t+Math.pow(n-e,2)},0)/t.length},i.predictSingle=function(t,e){return void 0===e&&(e=this.tree),e.isLeaf?e.prediction:this.predictSingle(t,t[e.featureIdx]<=e.threshold?e.left:e.right)},i.predict=function(t){var e=this;return this.validatePredictionData(t),t.map(function(t){return Array.isArray(t)?t:[t]}).map(function(t){return e.predictSingle(t)})},i.predictProba=function(t){var e=this;if("classification"!==this.taskType)throw new Error("predictProba is only available for classification tasks");return this.validatePredictionData(t),t.map(function(t){return Array.isArray(t)?t:[t]}).map(function(t){var n=e.findLeaf(t),r=n.samples,i={};return e.classes.forEach(function(t){i[t]=(n.distribution[t]||0)/r}),i})},i.findLeaf=function(t,e){return void 0===e&&(e=this.tree),e.isLeaf?e:this.findLeaf(t,t[e.featureIdx]<=e.threshold?e.left:e.right)},i.score=function(t,e){var n=this.predict(t);if("classification"===this.taskType){for(var r=0,i=0;i<e.length;i++)n[i]===e[i]&&r++;var a=r/e.length,o=this.confusionMatrix(e,n);return{accuracy:a,confusionMatrix:o,classMetrics:this.calculateClassMetrics(o),predictions:n}}var s=e.reduce(function(t,e){return t+e},0)/e.length,u=n.reduce(function(t,n,r){return t+Math.pow(e[r]-n,2)},0),l=1-u/e.reduce(function(t,e){return t+Math.pow(e-s,2)},0),c=u/e.length,f=Math.sqrt(c),h=n.reduce(function(t,n,r){return t+Math.abs(e[r]-n)},0)/e.length;return{r2Score:l,mse:c,rmse:f,mae:h,predictions:n,residuals:n.map(function(t,n){return e[n]-t})}},i.confusionMatrix=function(t,e){for(var n=this.classes.length,r=Array(n).fill(0).map(function(){return Array(n).fill(0)}),i=0;i<t.length;i++){var a=this.classes.indexOf(t[i]),o=this.classes.indexOf(e[i]);r[a][o]++}return{matrix:r,classes:this.classes,display:this.formatConfusionMatrix(r)}},i.formatConfusionMatrix=function(t){var e=Math.max.apply(Math,t.flat().map(function(t){return t.toString().length}).concat([8])),n=function(t){return t.toString().padStart(e)},r="\n"+" ".repeat(e+2)+"Predicted\n";r+=" ".repeat(e+2)+this.classes.map(function(t){return n(t)}).join(" ")+"\n";for(var i=0;i<t.length;i++)r+=0===i?"Actual ":" ",r+=n(this.classes[i])+" ",r+=t[i].map(function(t){return n(t)}).join(" ")+"\n";return r},i.calculateClassMetrics=function(t){var e=t.matrix,n={};return this.classes.forEach(function(t,r){var i=e[r][r],a=e[r].reduce(function(t,e){return t+e},0)-i,o=e.map(function(t){return t[r]}).reduce(function(t,e){return t+e},0)-i,s=i+o>0?i/(i+o):0,u=i+a>0?i/(i+a):0;n[t]={precision:s,recall:u,f1Score:s+u>0?s*u*2/(s+u):0,support:i+a}}),n},i.getTreeDepth=function(t){return t.isLeaf?0:1+Math.max(this.getTreeDepth(t.left),this.getTreeDepth(t.right))},i.getLeafCount=function(t){return t.isLeaf?1:this.getLeafCount(t.left)+this.getLeafCount(t.right)},i.getNodeCount=function(t){return t.isLeaf?1:1+this.getNodeCount(t.left)+this.getNodeCount(t.right)},i.getFeatureImportance=function(){var t={};this.calculateImportance(this.tree,t);var e=Object.values(t).reduce(function(t,e){return t+e},0);return Object.keys(t).forEach(function(n){t[n]/=e}),t},i.calculateImportance=function(t,e){if(!t.isLeaf){var n="feature_"+t.featureIdx;e[n]=(e[n]||0)+1,this.calculateImportance(t.left,e),this.calculateImportance(t.right,e)}},i.summary=function(){if(!this.trained)throw new Error("Model must be trained first");return{modelType:"Decision Tree",taskType:this.taskType,trainingMetrics:this.trainingMetrics,featureImportance:this.getFeatureImportance(),hyperparameters:{maxDepth:this.maxDepth,minSamplesSplit:this.minSamplesSplit,minSamplesLeaf:this.minSamplesLeaf,criterion:this.criterion}}},n}(A),F=/*#__PURE__*/function(t){function e(e,n,r,i,a,o,s){var u;return void 0===e&&(e=100),void 0===n&&(n=10),void 0===r&&(r=2),void 0===i&&(i=1),void 0===a&&(a="sqrt"),void 0===o&&(o="gini"),void 0===s&&(s=!0),(u=t.call(this)||this).nEstimators=e,u.maxDepth=n,u.minSamplesSplit=r,u.minSamplesLeaf=i,u.maxFeatures=a,u.criterion=o,u.bootstrap=s,u.trees=[],u.taskType=null,u.classes=null,u.featureIndices=[],u}r(e,t);var n=e.prototype;return n.fit=function(t,e,n){var r=this;void 0===n&&(n="classification"),this.validateTrainingData(t,e),this.taskType=n;var i=t.map(function(t){return Array.isArray(t)?t:[t]}),a=i[0].length;"classification"===n&&(this.classes=[].concat(new Set(e)).sort());for(var o=this.getMaxFeaturesCount(a),s=function(){var t=r.bootstrap?r.bootstrapSample(i,e):{X_sample:i,y_sample:e},s=t.X_sample,u=t.y_sample,l=r.selectRandomFeatures(a,o);r.featureIndices.push(l);var c=s.map(function(t){return l.map(function(e){return t[e]})}),f=new _(r.maxDepth,r.minSamplesSplit,r.minSamplesLeaf,r.criterion);f.fit(c,u,n),r.trees.push(f)},u=0;u<this.nEstimators;u++)s();return this.trained=!0,this.trainingMetrics={nEstimators:this.nEstimators,avgTreeDepth:this.trees.reduce(function(t,e){return t+e.trainingMetrics.treeDepth},0)/this.nEstimators,avgLeafCount:this.trees.reduce(function(t,e){return t+e.trainingMetrics.leafCount},0)/this.nEstimators,taskType:this.taskType},this},n.getMaxFeaturesCount=function(t){return"number"==typeof this.maxFeatures?Math.min(this.maxFeatures,t):"sqrt"===this.maxFeatures?Math.floor(Math.sqrt(t)):"log2"===this.maxFeatures?Math.floor(Math.log2(t)):t},n.selectRandomFeatures=function(t,e){for(var n=Array.from({length:t},function(t,e){return e}),r=[],i=0;i<e;i++){var a=Math.floor(Math.random()*n.length);r.push(n[a]),n.splice(a,1)}return r.sort(function(t,e){return t-e})},n.bootstrapSample=function(t,e){for(var n=t.length,r=[],i=[],a=0;a<n;a++){var o=Math.floor(Math.random()*n);r.push(t[o]),i.push(e[o])}return{X_sample:r,y_sample:i}},n.predict=function(t){var e=this;return this.validatePredictionData(t),t.map(function(t){return Array.isArray(t)?t:[t]}).map("classification"===this.taskType?function(t){var n={};return e.trees.forEach(function(r,i){var a=e.featureIndices[i].map(function(e){return t[e]}),o=r.predict([a])[0];n[o]=(n[o]||0)+1}),Object.keys(n).reduce(function(t,e){return n[t]>n[e]?t:e})}:function(t){var n=e.trees.map(function(n,r){var i=e.featureIndices[r].map(function(e){return t[e]});return n.predict([i])[0]});return n.reduce(function(t,e){return t+e},0)/n.length})},n.predictProba=function(t){var e=this;if("classification"!==this.taskType)throw new Error("predictProba is only available for classification tasks");return this.validatePredictionData(t),t.map(function(t){return Array.isArray(t)?t:[t]}).map(function(t){var n={};e.classes.forEach(function(t){n[t]=0}),e.trees.forEach(function(r,i){var a=e.featureIndices[i].map(function(e){return t[e]}),o=r.predictProba([a])[0];Object.keys(o).forEach(function(t){n[t]+=o[t]})});var r={};return Object.keys(n).forEach(function(t){r[t]=n[t]/e.nEstimators}),r})},n.score=function(t,e){var n=this.predict(t);if("classification"===this.taskType){for(var r=0,i=0;i<e.length;i++)n[i]===e[i]&&r++;var a=r/e.length,o=this.confusionMatrix(e,n);return{accuracy:a,confusionMatrix:o,classMetrics:this.calculateClassMetrics(o),predictions:n}}var s=e.reduce(function(t,e){return t+e},0)/e.length,u=n.reduce(function(t,n,r){return t+Math.pow(e[r]-n,2)},0),l=1-u/e.reduce(function(t,e){return t+Math.pow(e-s,2)},0),c=u/e.length,f=Math.sqrt(c),h=n.reduce(function(t,n,r){return t+Math.abs(e[r]-n)},0)/e.length;return{r2Score:l,mse:c,rmse:f,mae:h,predictions:n,residuals:n.map(function(t,n){return e[n]-t})}},n.confusionMatrix=function(t,e){for(var n=this.classes.length,r=Array(n).fill(0).map(function(){return Array(n).fill(0)}),i=0;i<t.length;i++){var a=this.classes.indexOf(t[i]),o=this.classes.indexOf(e[i]);r[a][o]++}return{matrix:r,classes:this.classes,display:this.formatConfusionMatrix(r)}},n.formatConfusionMatrix=function(t){var e=Math.max.apply(Math,t.flat().map(function(t){return t.toString().length}).concat([8])),n=function(t){return t.toString().padStart(e)},r="\n"+" ".repeat(e+2)+"Predicted\n";r+=" ".repeat(e+2)+this.classes.map(function(t){return n(t)}).join(" ")+"\n";for(var i=0;i<t.length;i++)r+=0===i?"Actual ":" ",r+=n(this.classes[i])+" ",r+=t[i].map(function(t){return n(t)}).join(" ")+"\n";return r},n.calculateClassMetrics=function(t){var e=t.matrix,n={};return this.classes.forEach(function(t,r){var i=e[r][r],a=e[r].reduce(function(t,e){return t+e},0)-i,o=e.map(function(t){return t[r]}).reduce(function(t,e){return t+e},0)-i,s=i+o>0?i/(i+o):0,u=i+a>0?i/(i+a):0;n[t]={precision:s,recall:u,f1Score:s+u>0?s*u*2/(s+u):0,support:i+a}}),n},n.getFeatureImportance=function(){var t=this,e=Array(this.featureIndices[0].length).fill(0);this.trees.forEach(function(n,r){var i=n.getFeatureImportance(),a=t.featureIndices[r];Object.keys(i).forEach(function(t){var n=parseInt(t.split("_")[1]);e[a[n]]+=i[t]})});var n=e.reduce(function(t,e){return t+e},0);return e.map(function(t){return t/n})},n.summary=function(){if(!this.trained)throw new Error("Model must be trained first");return{modelType:"Random Forest",taskType:this.taskType,trainingMetrics:this.trainingMetrics,featureImportance:this.getFeatureImportance(),hyperparameters:{nEstimators:this.nEstimators,maxDepth:this.maxDepth,minSamplesSplit:this.minSamplesSplit,minSamplesLeaf:this.minSamplesLeaf,maxFeatures:this.maxFeatures,criterion:this.criterion,bootstrap:this.bootstrap}}},e}(A),T=/*#__PURE__*/function(t){function e(e){var n;return void 0===e&&(e="gaussian"),(n=t.call(this)||this).type=e,n.classes=null,n.classPriors={},n.parameters={},n}r(e,t);var n=e.prototype;return n.fit=function(t,e){var n=this;this.validateTrainingData(t,e);var r=t.map(function(t){return Array.isArray(t)?t:[t]});this.classes=[].concat(new Set(e)).sort();var i=r.length,a=r[0].length;return this.classes.forEach(function(t){var r=e.filter(function(e){return e===t}).length;n.classPriors[t]=r/i}),"gaussian"===this.type?this.fitGaussian(r,e,a):"multinomial"===this.type?this.fitMultinomial(r,e,a):"bernoulli"===this.type&&this.fitBernoulli(r,e,a),this.trained=!0,this.trainingMetrics={nClasses:this.classes.length,nFeatures:a,nSamples:i,type:this.type},this},n.fitGaussian=function(t,e,n){var r=this;this.classes.forEach(function(i){var a=t.filter(function(t,n){return e[n]===i});r.parameters[i]={means:[],variances:[]};for(var o=function(t){var e=a.map(function(e){return e[t]}),n=e.reduce(function(t,e){return t+e},0)/e.length,o=e.reduce(function(t,e){return t+Math.pow(e-n,2)},0)/e.length;r.parameters[i].means.push(n),r.parameters[i].variances.push(o+1e-9)},s=0;s<n;s++)o(s)})},n.fitMultinomial=function(t,e,n){var r=this;this.classes.forEach(function(i){var a=t.filter(function(t,n){return e[n]===i});r.parameters[i]={featureProbs:[]};for(var o=function(t){var e=a.reduce(function(e,n){return e+n[t]},0),o=a.reduce(function(t,e){return t+e.reduce(function(t,e){return t+e},0)},0);r.parameters[i].featureProbs.push((e+1)/(o+1*n))},s=0;s<n;s++)o(s)})},n.fitBernoulli=function(t,e,n){var r=this;this.classes.forEach(function(i){var a=t.filter(function(t,n){return e[n]===i}),o=a.length;r.parameters[i]={featureProbs:[]};for(var s=function(t){var e=a.filter(function(e){return 1===e[t]}).length;r.parameters[i].featureProbs.push((e+1)/(o+2))},u=0;u<n;u++)s(u)})},n.gaussianProbability=function(t,e,n){return Math.exp(-Math.pow(t-e,2)/(2*n))/Math.sqrt(2*Math.PI*n)},n.predictSingle=function(t){var e=this,n={};return this.classes.forEach(function(r){var i=Math.log(e.classPriors[r]);if("gaussian"===e.type)for(var a=e.parameters[r],o=0;o<t.length;o++){var s=e.gaussianProbability(t[o],a.means[o],a.variances[o]);i+=Math.log(s+1e-9)}else if("multinomial"===e.type)for(var u=e.parameters[r],l=0;l<t.length;l++)i+=t[l]*Math.log(u.featureProbs[l]+1e-9);else if("bernoulli"===e.type)for(var c=e.parameters[r],f=0;f<t.length;f++)i+=Math.log((1===t[f]?c.featureProbs[f]:1-c.featureProbs[f])+1e-9);n[r]=i}),Object.keys(n).reduce(function(t,e){return n[t]>n[e]?t:e})},n.predict=function(t){var e=this;return this.validatePredictionData(t),t.map(function(t){return Array.isArray(t)?t:[t]}).map(function(t){return e.predictSingle(t)})},n.predictProba=function(t){var e=this;return this.validatePredictionData(t),t.map(function(t){return Array.isArray(t)?t:[t]}).map(function(t){var n={};e.classes.forEach(function(r){var i=Math.log(e.classPriors[r]);if("gaussian"===e.type)for(var a=e.parameters[r],o=0;o<t.length;o++){var s=e.gaussianProbability(t[o],a.means[o],a.variances[o]);i+=Math.log(s+1e-9)}else if("multinomial"===e.type)for(var u=e.parameters[r],l=0;l<t.length;l++)i+=t[l]*Math.log(u.featureProbs[l]+1e-9);else if("bernoulli"===e.type)for(var c=e.parameters[r],f=0;f<t.length;f++)i+=Math.log((1===t[f]?c.featureProbs[f]:1-c.featureProbs[f])+1e-9);n[r]=i});var r=Math.max.apply(Math,Object.values(n)),i={},a=0;e.classes.forEach(function(t){i[t]=Math.exp(n[t]-r),a+=i[t]});var o={};return e.classes.forEach(function(t){o[t]=i[t]/a}),o})},n.score=function(t,e){for(var n=this.predict(t),r=0,i=0;i<e.length;i++)n[i]===e[i]&&r++;var a=r/e.length,o=this.confusionMatrix(e,n);return{accuracy:a,confusionMatrix:o,classMetrics:this.calculateClassMetrics(o),predictions:n}},n.confusionMatrix=function(t,e){for(var n=this.classes.length,r=Array(n).fill(0).map(function(){return Array(n).fill(0)}),i=0;i<t.length;i++){var a=this.classes.indexOf(t[i]),o=this.classes.indexOf(e[i]);r[a][o]++}return{matrix:r,classes:this.classes,display:this.formatConfusionMatrix(r)}},n.formatConfusionMatrix=function(t){var e=Math.max.apply(Math,t.flat().map(function(t){return t.toString().length}).concat([8])),n=function(t){return t.toString().padStart(e)},r="\n"+" ".repeat(e+2)+"Predicted\n";r+=" ".repeat(e+2)+this.classes.map(function(t){return n(t)}).join(" ")+"\n";for(var i=0;i<t.length;i++)r+=0===i?"Actual ":" ",r+=n(this.classes[i])+" ",r+=t[i].map(function(t){return n(t)}).join(" ")+"\n";return r},n.calculateClassMetrics=function(t){var e=t.matrix,n={};return this.classes.forEach(function(t,r){var i=e[r][r],a=e[r].reduce(function(t,e){return t+e},0)-i,o=e.map(function(t){return t[r]}).reduce(function(t,e){return t+e},0)-i,s=i+o>0?i/(i+o):0,u=i+a>0?i/(i+a):0;n[t]={precision:s,recall:u,f1Score:s+u>0?s*u*2/(s+u):0,support:i+a}}),n},n.summary=function(){if(!this.trained)throw new Error("Model must be trained first");return{modelType:"Naive Bayes",naiveBayesType:this.type,classes:this.classes,classPriors:this.classPriors,trainingMetrics:this.trainingMetrics}},e}(A),D=/*#__PURE__*/function(t){function e(e,n,r,i,a,o){var s;return void 0===e&&(e=1),void 0===n&&(n="linear"),void 0===r&&(r="scale"),void 0===i&&(i=3),void 0===a&&(a=.001),void 0===o&&(o=1e3),(s=t.call(this)||this).C=e,s.kernel=n,s.gamma=r,s.degree=i,s.learningRate=a,s.iterations=o,s.weights=null,s.bias=null,s.supportVectors=null,s.classes=null,s.normParams=null,s}r(e,t);var n=e.prototype;return n.fit=function(t,e,n){var r=this;void 0===n&&(n=!0),this.validateTrainingData(t,e);var i=t.map(function(t){return Array.isArray(t)?t:[t]});if(this.classes=[].concat(new Set(e)).sort(),2!==this.classes.length)throw new Error("SVM currently only supports binary classification");var a=e.map(function(t){return t===r.classes[1]?1:-1});if(n){var o=this.normalizeFeatures(i);i=o.normalized,this.normParams={means:o.means,stds:o.stds}}var s=i.length,u=i[0].length;if("scale"===this.gamma){var l=this.calculateVariance(i);this.gamma=1/(u*l)}else"auto"===this.gamma&&(this.gamma=1/u);this.weights=Array(u).fill(0),this.bias=0;for(var c=[],f=0;f<this.iterations;f++){for(var h=0,d=0;d<s;d++){var p=i[d],m=a[d],g=m*this.decisionFunction([p])[0];if(g<1){for(var v=0;v<u;v++)this.weights[v]+=this.learningRate*(m*p[v]-1/this.C*2*this.weights[v]);this.bias+=this.learningRate*m,h+=1-g}else for(var y=0;y<u;y++)this.weights[y]+=this.learningRate*(1/this.C*-2*this.weights[y])}var b=1/this.C*this.weights.reduce(function(t,e){return t+e*e},0);c.push(h/s+b)}return this.identifySupportVectors(i,a),this.trained=!0,this.trainingMetrics={finalLoss:c[c.length-1],losses:c,nSupportVectors:this.supportVectors.length,supportVectorRatio:this.supportVectors.length/s},this},n.calculateVariance=function(t){for(var e=t.length,n=t[0].length,r=0,i=function(n){var i=t.map(function(t){return t[n]}),a=i.reduce(function(t,e){return t+e},0)/e,o=i.reduce(function(t,e){return t+Math.pow(e-a,2)},0)/e;r+=o},a=0;a<n;a++)i(a);return r/n},n.identifySupportVectors=function(t,e){this.supportVectors=[];for(var n=0;n<t.length;n++){var r=this.decisionFunction([t[n]])[0],i=Math.abs(r);i<1.5&&this.supportVectors.push({index:n,vector:t[n],label:e[n],margin:i})}},n.kernelFunction=function(t,e){if("linear"===this.kernel)return t.reduce(function(t,n,r){return t+n*e[r]},0);if("rbf"===this.kernel){var n=t.reduce(function(t,n,r){return t+Math.pow(n-e[r],2)},0);return Math.exp(-this.gamma*n)}if("poly"===this.kernel){var r=t.reduce(function(t,n,r){return t+n*e[r]},0);return Math.pow(r+1,this.degree)}return 0},n.decisionFunction=function(t){var e=this;return t.map(function(t){for(var n=e.bias,r=0;r<e.weights.length;r++)n+=e.weights[r]*t[r];return n})},n.predict=function(t){var e=this;this.validatePredictionData(t);var n=t.map(function(t){return Array.isArray(t)?t:[t]});if(this.normParams){var r=this.normParams,i=r.means,a=r.stds;n=n.map(function(t){return t.map(function(t,e){return(t-i[e])/a[e]})})}return this.decisionFunction(n).map(function(t){return t>=0?e.classes[1]:e.classes[0]})},n.predictProba=function(t){var e=this;this.validatePredictionData(t);var n=t.map(function(t){return Array.isArray(t)?t:[t]});if(this.normParams){var r=this.normParams,i=r.means,a=r.stds;n=n.map(function(t){return t.map(function(t,e){return(t-i[e])/a[e]})})}return this.decisionFunction(n).map(function(t){var n,r=1/(1+Math.exp(-t));return(n={})[e.classes[0]]=1-r,n[e.classes[1]]=r,n})},n.score=function(t,e){for(var n=this.predict(t),r=0,i=0;i<e.length;i++)n[i]===e[i]&&r++;var a=r/e.length,o=this.confusionMatrix(e,n);return{accuracy:a,confusionMatrix:o,classMetrics:this.calculateClassMetrics(o),predictions:n}},n.confusionMatrix=function(t,e){for(var n=this.classes.length,r=Array(n).fill(0).map(function(){return Array(n).fill(0)}),i=0;i<t.length;i++){var a=this.classes.indexOf(t[i]),o=this.classes.indexOf(e[i]);r[a][o]++}return{matrix:r,classes:this.classes,display:this.formatConfusionMatrix(r)}},n.formatConfusionMatrix=function(t){var e=Math.max.apply(Math,t.flat().map(function(t){return t.toString().length}).concat([8])),n=function(t){return t.toString().padStart(e)},r="\n"+" ".repeat(e+2)+"Predicted\n";r+=" ".repeat(e+2)+this.classes.map(function(t){return n(t)}).join(" ")+"\n";for(var i=0;i<t.length;i++)r+=0===i?"Actual ":" ",r+=n(this.classes[i])+" ",r+=t[i].map(function(t){return n(t)}).join(" ")+"\n";return r},n.calculateClassMetrics=function(t){var e=t.matrix,n={};return this.classes.forEach(function(t,r){var i=e[r][r],a=e[r].reduce(function(t,e){return t+e},0)-i,o=e.map(function(t){return t[r]}).reduce(function(t,e){return t+e},0)-i,s=i+o>0?i/(i+o):0,u=i+a>0?i/(i+a):0;n[t]={precision:s,recall:u,f1Score:s+u>0?s*u*2/(s+u):0,support:i+a}}),n},n.summary=function(){if(!this.trained)throw new Error("Model must be trained first");return{modelType:"Support Vector Machine",classes:this.classes,trainingMetrics:this.trainingMetrics,hyperparameters:{C:this.C,kernel:this.kernel,gamma:this.gamma,degree:this.degree,learningRate:this.learningRate,iterations:this.iterations}}},e}(A),I=/*#__PURE__*/function(){function t(){}var e=t.prototype;return e.createLinearRegression=function(t){void 0===t&&(t={});var e=t.learningRate,n=t.iterations,r=t.regularization,i=t.lambda;return new C(void 0===e?.01:e,void 0===n?1e3:n,void 0===r?null:r,void 0===i?.01:i)},e.createLogisticRegression=function(t){void 0===t&&(t={});var e=t.learningRate,n=t.iterations,r=t.regularization,i=t.lambda;return new q(void 0===e?.01:e,void 0===n?1e3:n,void 0===r?null:r,void 0===i?.01:i)},e.createKNN=function(t){void 0===t&&(t={});var e=t.k,n=t.metric,r=t.weights;return new k(void 0===e?5:e,void 0===n?"euclidean":n,void 0===r?"uniform":r)},e.createDecisionTree=function(t){void 0===t&&(t={});var e=t.maxDepth,n=t.minSamplesSplit,r=t.minSamplesLeaf,i=t.criterion;return new _(void 0===e?10:e,void 0===n?2:n,void 0===r?1:r,void 0===i?"gini":i)},e.createRandomForest=function(t){void 0===t&&(t={});var e=t.nEstimators,n=t.maxDepth,r=t.minSamplesSplit,i=t.minSamplesLeaf,a=t.maxFeatures,o=t.criterion,s=t.bootstrap;return new F(void 0===e?100:e,void 0===n?10:n,void 0===r?2:r,void 0===i?1:i,void 0===a?"sqrt":a,void 0===o?"gini":o,void 0===s||s)},e.createNaiveBayes=function(t){void 0===t&&(t={});var e=t.type;return new T(void 0===e?"gaussian":e)},e.createSVM=function(t){void 0===t&&(t={});var e=t.C,n=t.kernel,r=t.gamma,i=t.degree,a=t.learningRate,o=t.iterations;return new D(void 0===e?1:e,void 0===n?"linear":n,void 0===r?"scale":r,void 0===i?3:i,void 0===a?.001:a,void 0===o?1e3:o)},e.crossValidate=function(t,e,n,r,i){void 0===r&&(r=5),void 0===i&&(i="classification");for(var a=e.length,o=Math.floor(a/r),s=Array.from({length:a},function(t,e){return e}),u=a-1;u>0;u--){var l=Math.floor(Math.random()*(u+1)),c=[s[l],s[u]];s[u]=c[0],s[l]=c[1]}for(var f=[],h=0;h<r;h++){var d=h*o,p=h===r-1?a:d+o,m=s.slice(d,p),g=[].concat(s.slice(0,d),s.slice(p)),v=g.map(function(t){return e[t]}),y=g.map(function(t){return n[t]}),b=m.map(function(t){return e[t]}),w=m.map(function(t){return n[t]}),M=Object.create(Object.getPrototypeOf(t));Object.assign(M,t),M.fit(v,y,i);var x=M.score(b,w);f.push("classification"===i?x.accuracy:x.r2Score)}var S=f.reduce(function(t,e){return t+e},0)/f.length,N=Math.sqrt(f.reduce(function(t,e){return t+Math.pow(e-S,2)},0)/f.length);return{scores:f,meanScore:S,stdScore:N,folds:r}},e.trainTestSplit=function(t,e,n,r){void 0===n&&(n=.2),void 0===r&&(r=!0);var i=t.length,a=Array.from({length:i},function(t,e){return e});if(r)for(var o=i-1;o>0;o--){var s=Math.floor(Math.random()*(o+1)),u=[a[s],a[o]];a[o]=u[0],a[s]=u[1]}var l=i-Math.floor(i*n),c=a.slice(0,l),f=a.slice(l);return{X_train:c.map(function(e){return t[e]}),X_test:f.map(function(e){return t[e]}),y_train:c.map(function(t){return e[t]}),y_test:f.map(function(t){return e[t]})}},e.compareModels=function(t,e,n,r){void 0===r&&(r="classification");var i=this.trainTestSplit(e,n,.2),a=i.X_train,o=i.X_test,s=i.y_train,u=i.y_test,l=[];return t.forEach(function(t){var e=t.name,n=t.model,i=Date.now();n.fit(a,s,r);var c=Date.now()-i,f=Date.now(),h=n.score(o,u),d=Date.now()-f;l.push({name:e,score:"classification"===r?h.accuracy:h.r2Score,trainTime:c,evalTime:d,fullScore:h})}),l.sort(function(t,e){return e.score-t.score}),{results:l,bestModel:l[0],comparison:this.generateComparisonReport(l,r)}},e.generateComparisonReport=function(t,e){var n="classification"===e?"Accuracy":"R² Score",r="\n"+"=".repeat(70)+"\n";return r+="š MODEL COMPARISON REPORT\n",r+="=".repeat(70)+"\n\n",r+="Metric: "+n+"\n\n",r+="Rank | Model | Score | Train Time | Eval Time\n",r+="-----+-------------------------+----------+------------+-----------\n",t.forEach(function(t,e){var n=(e+1).toString().padStart(4),i=t.name.padEnd(24),a=t.score.toFixed(4).padStart(8),o=(t.trainTime+"ms").padStart(10),s=(t.evalTime+"ms").padStart(9);r+=n+" | "+i+" | "+a+" | "+o+" | "+s+"\n"}),r+="\n"+"=".repeat(70)+"\n",r+="š Best Model: "+t[0].name+" ("+n+": "+t[0].score.toFixed(4)+")\n",r+="=".repeat(70)+"\n"},e.polynomialFeatures=function(t,e){return void 0===e&&(e=2),t.map(function(t){for(var n=[].concat(t),r=2;r<=e;r++)for(var i=0;i<t.length;i++)n.push(Math.pow(t[i],r));if(e>=2)for(var a=0;a<t.length;a++)for(var o=a+1;o<t.length;o++)n.push(t[a]*t[o]);return n})},e.standardScaler=function(t){for(var e=t.length,n=t[0].length,r=[],i=[],a=function(n){var a=t.map(function(t){return t[n]}),o=a.reduce(function(t,e){return t+e},0)/e,s=a.reduce(function(t,e){return t+Math.pow(e-o,2)},0)/e,u=Math.sqrt(s);r.push(o),i.push(0===u?1:u)},o=0;o<n;o++)a(o);var s=t.map(function(t){return t.map(function(t,e){return(t-r[e])/i[e]})});return{scaled:s,means:r,stds:i,transform:function(t){return t.map(function(t){return t.map(function(t,e){return(t-r[e])/i[e]})})}}},e.minMaxScaler=function(t,e){void 0===e&&(e=[0,1]);for(var n=t[0].length,r=[],i=[],a=e[0],o=e[1],s=function(e){var n=t.map(function(t){return t[e]});r.push(Math.min.apply(Math,n)),i.push(Math.max.apply(Math,n))},u=0;u<n;u++)s(u);var l=t.map(function(t){return t.map(function(t,e){var n=i[e]-r[e];return 0===n?a:a+(t-r[e])/n*(o-a)})});return{scaled:l,mins:r,maxs:i,transform:function(t){return t.map(function(t){return t.map(function(t,e){var n=i[e]-r[e];return 0===n?a:a+(t-r[e])/n*(o-a)})})}}},e.rocCurve=function(t,e){var n=e.map(function(e,n){return{probability:"object"==typeof e?Object.values(e)[1]:e,label:t[n]}});n.sort(function(t,e){return e.probability-t.probability});var r=t.filter(function(t){return 1===t||!0===t}).length,i=t.length-r,a=[0],o=[0],s=0,u=0;n.forEach(function(t){1===t.label||!0===t.label?s++:u++,a.push(s/r),o.push(u/i)});for(var l=0,c=1;c<o.length;c++)l+=(o[c]-o[c-1])*(a[c]+a[c-1])/2;return{fpr:o,tpr:a,auc:l,thresholds:n.map(function(t){return t.probability})}},e.precisionRecallCurve=function(t,e){var n=e.map(function(e,n){return{probability:"object"==typeof e?Object.values(e)[1]:e,label:t[n]}});n.sort(function(t,e){return e.probability-t.probability});var r=[],i=[],a=0,o=0,s=t.filter(function(t){return 1===t||!0===t}).length;return n.forEach(function(t){1===t.label||!0===t.label?a++:o++;var e=a/s;r.push(a/(a+o)),i.push(e)}),{precision:r,recall:i,thresholds:n.map(function(t){return t.probability})}},e.quickTrain=function(t,e,n,r){void 0===r&&(r={});var i,a=r.taskType,o=void 0===a?"classification":a,s=r.testSize,u=void 0===s?.2:s,l=r.normalize,c=void 0===l||l;switch(t.toLowerCase()){case"linear":case"linearregression":i=this.createLinearRegression(r);break;case"logistic":case"logisticregression":i=this.createLogisticRegression(r);break;case"knn":i=this.createKNN(r);break;case"tree":case"decisiontree":i=this.createDecisionTree(r);break;case"forest":case"randomforest":i=this.createRandomForest(r);break;case"naivebayes":case"nb":i=this.createNaiveBayes(r);break;case"svm":i=this.createSVM(r);break;default:throw new Error("Unknown model type: "+t)}var f=this.trainTestSplit(e,n,u),h=f.X_train,d=f.X_test,p=f.y_train,m=f.y_test;console.log("\nš Training "+t+"...");var g=Date.now();i.fit(h,p,c,o);var v=Date.now()-g;console.log("ā
Training completed in "+v+"ms"),console.log("\nš Evaluating model...");var y=i.score(d,m);return console.log("\n"+"=".repeat(60)),console.log("š RESULTS"),console.log(""+"=".repeat(60)),"classification"===o?(console.log("Accuracy: "+(100*y.accuracy).toFixed(2)+"%"),console.log("\nConfusion Matrix:"+y.confusionMatrix.display),console.log("\nPer-Class Metrics:"),Object.keys(y.classMetrics).forEach(function(t){var e=y.classMetrics[t];console.log(" "+t+":"),console.log(" Precision: "+(100*e.precision).toFixed(2)+"%"),console.log(" Recall: "+(100*e.recall).toFixed(2)+"%"),console.log(" F1-Score: "+(100*e.f1Score).toFixed(2)+"%")})):(console.log("R² Score: "+y.r2Score.toFixed(4)),console.log("MSE: "+y.mse.toFixed(4)),console.log("RMSE: "+y.rmse.toFixed(4)),console.log("MAE: "+y.mae.toFixed(4))),console.log("\n"+"=".repeat(60)+"\n"),{model:i,score:y,trainTime:v,summary:i.summary()}},t}(),V="http://www.w3.org/1999/xhtml",z={svg:"http://www.w3.org/2000/svg",xhtml:V,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function P(t){var e=t+="",n=e.indexOf(":");return n>=0&&"xmlns"!==(e=t.slice(0,n))&&(t=t.slice(n+1)),z.hasOwnProperty(e)?{space:z[e],local:t}:t}function R(t){return function(){var e=this.ownerDocument,n=this.namespaceURI;return n===V&&e.documentElement.namespaceURI===V?e.createElement(t):e.createElementNS(n,t)}}function O(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function L(t){var e=P(t);return(e.local?O:R)(e)}function j(){}function B(t){return null==t?j:function(){return this.querySelector(t)}}function $(t){return null==t?[]:Array.isArray(t)?t:Array.from(t)}function W(){return[]}function H(t){return function(e){return e.matches(t)}}var G=Array.prototype.find;function X(){return this.firstElementChild}var Q=Array.prototype.filter;function U(){return Array.from(this.children)}function K(t){return new Array(t.length)}function J(t,e){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=e}function Y(t,e,n,r,i,a){for(var o,s=0,u=e.length,l=a.length;s<l;++s)(o=e[s])?(o.__data__=a[s],r[s]=o):n[s]=new J(t,a[s]);for(;s<u;++s)(o=e[s])&&(i[s]=o)}function Z(t,e,n,r,i,a,o){var s,u,l,c=new Map,f=e.length,h=a.length,d=new Array(f);for(s=0;s<f;++s)(u=e[s])&&(d[s]=l=o.call(u,u.__data__,s,e)+"",c.has(l)?i[s]=u:c.set(l,u));for(s=0;s<h;++s)l=o.call(t,a[s],s,a)+"",(u=c.get(l))?(r[s]=u,u.__data__=a[s],c.delete(l)):n[s]=new J(t,a[s]);for(s=0;s<f;++s)(u=e[s])&&c.get(d[s])===u&&(i[s]=u)}function tt(t){return t.__data__}function et(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function nt(t,e){return t<e?-1:t>e?1:t>=e?0:NaN}function rt(t){return function(){this.removeAttribute(t)}}function it(t){return function(){this.removeAttributeNS(t.space,t.local)}}function at(t,e){return function(){this.setAttribute(t,e)}}function ot(t,e){return function(){this.setAttributeNS(t.space,t.local,e)}}function st(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttribute(t):this.setAttribute(t,n)}}function ut(t,e){return function(){var n=e.apply(this,arguments);null==n?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,n)}}function lt(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function ct(t){return function(){this.style.removeProperty(t)}}function ft(t,e,n){return function(){this.style.setProperty(t,e,n)}}function ht(t,e,n){return function(){var r=e.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,n)}}function dt(t){return function(){delete this[t]}}function pt(t,e){return function(){this[t]=e}}function mt(t,e){return function(){var n=e.apply(this,arguments);null==n?delete this[t]:this[t]=n}}function gt(t){return t.trim().split(/^|\s+/)}function vt(t){return t.classList||new yt(t)}function yt(t){this._node=t,this._names=gt(t.getAttribute("class")||"")}function bt(t,e){for(var n=vt(t),r=-1,i=e.length;++r<i;)n.add(e[r])}function wt(t,e){for(var n=vt(t),r=-1,i=e.length;++r<i;)n.remove(e[r])}function Mt(t){return function(){bt(this,t)}}function xt(t){return function(){wt(this,t)}}function St(t,e){return function(){(e.apply(this,arguments)?bt:wt)(this,t)}}function Nt(){this.textContent=""}function Et(t){return function(){this.textContent=t}}function At(t){return function(){var e=t.apply(this,arguments);this.textContent=null==e?"":e}}function Ct(){this.innerHTML=""}function qt(t){return function(){this.innerHTML=t}}function kt(t){return function(){var e=t.apply(this,arguments);this.innerHTML=null==e?"":e}}function _t(){this.nextSibling&&this.parentNode.appendChild(this)}function Ft(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function Tt(){return null}function Dt(){var t=this.parentNode;t&&t.removeChild(this)}function It(){var t=this.cloneNode(!1),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function Vt(){var t=this.cloneNode(!0),e=this.parentNode;return e?e.insertBefore(t,this.nextSibling):t}function zt(t){return function(){var e=this.__on;if(e){for(var n,r=0,i=-1,a=e.length;r<a;++r)n=e[r],t.type&&n.type!==t.type||n.name!==t.name?e[++i]=n:this.removeEventListener(n.type,n.listener,n.options);++i?e.length=i:delete this.__on}}}function Pt(t,e,n){return function(){var r,i=this.__on,a=function(t){return function(e){t.call(this,e,this.__data__)}}(e);if(i)for(var o=0,s=i.length;o<s;++o)if((r=i[o]).type===t.type&&r.name===t.name)return this.removeEventListener(r.type,r.listener,r.options),this.addEventListener(r.type,r.listener=a,r.options=n),void(r.value=e);this.addEventListener(t.type,a,n),r={type:t.type,name:t.name,value:e,listener:a,options:n},i?i.push(r):this.__on=[r]}}function Rt(t,e,n){var r=lt(t),i=r.CustomEvent;"function"==typeof i?i=new i(e,n):(i=r.document.createEvent("Event"),n?(i.initEvent(e,n.bubbles,n.cancelable),i.detail=n.detail):i.initEvent(e,!1,!1)),t.dispatchEvent(i)}function Ot(t,e){return function(){return Rt(this,t,e)}}function Lt(t,e){return function(){return Rt(this,t,e.apply(this,arguments))}}J.prototype={constructor:J,appendChild:function(t){return this._parent.insertBefore(t,this._next)},insertBefore:function(t,e){return this._parent.insertBefore(t,e)},querySelector:function(t){return this._parent.querySelector(t)},querySelectorAll:function(t){return this._parent.querySelectorAll(t)}},yt.prototype={add:function(t){this._names.indexOf(t)<0&&(this._names.push(t),this._node.setAttribute("class",this._names.join(" ")))},remove:function(t){var e=this._names.indexOf(t);e>=0&&(this._names.splice(e,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var jt=[null];function Bt(t,e){this._groups=t,this._parents=e}function $t(t,e){return null==t||null==e?NaN:t<e?-1:t>e?1:t>=e?0:NaN}function Wt(t,e){return null==t||null==e?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function Ht(t){let e,n,r;function i(t,r,i=0,a=t.length){if(i<a){if(0!==e(r,r))return a;do{const e=i+a>>>1;n(t[e],r)<0?i=e+1:a=e}while(i<a)}return i}return 2!==t.length?(e=$t,n=(e,n)=>$t(t(e),n),r=(e,n)=>t(e)-n):(e=t===$t||t===Wt?t:Gt,n=t,r=t),{left:i,center:function(t,e,n=0,a=t.length){const o=i(t,e,n,a-1);return o>n&&r(t[o-1],e)>-r(t[o],e)?o-1:o},right:function(t,r,i=0,a=t.length){if(i<a){if(0!==e(r,r))return a;do{const e=i+a>>>1;n(t[e],r)<=0?i=e+1:a=e}while(i<a)}return i}}}function Gt(){return 0}Bt.prototype={constructor:Bt,select:function(t){"function"!=typeof t&&(t=B(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o,s=e[i],u=s.length,l=r[i]=new Array(u),c=0;c<u;++c)(a=s[c])&&(o=t.call(a,a.__data__,c,s))&&("__data__"in a&&(o.__data__=a.__data__),l[c]=o);return new Bt(r,this._parents)},selectAll:function(t){t="function"==typeof t?function(t){return function(){return $(t.apply(this,arguments))}}(t):function(t){return null==t?W:function(){return this.querySelectorAll(t)}}(t);for(var e=this._groups,n=e.length,r=[],i=[],a=0;a<n;++a)for(var o,s=e[a],u=s.length,l=0;l<u;++l)(o=s[l])&&(r.push(t.call(o,o.__data__,l,s)),i.push(o));return new Bt(r,i)},selectChild:function(t){return this.select(null==t?X:function(t){return function(){return G.call(this.children,t)}}("function"==typeof t?t:H(t)))},selectChildren:function(t){return this.selectAll(null==t?U:function(t){return function(){return Q.call(this.children,t)}}("function"==typeof t?t:H(t)))},filter:function(t){"function"!=typeof t&&(t=function(t){return function(){return this.matches(t)}}(t));for(var e=this._groups,n=e.length,r=new Array(n),i=0;i<n;++i)for(var a,o=e[i],s=o.length,u=r[i]=[],l=0;l<s;++l)(a=o[l])&&t.call(a,a.__data__,l,o)&&u.push(a);return new Bt(r,this._parents)},data:function(t,e){if(!arguments.length)return Array.from(this,tt);var n=e?Z:Y,r=this._parents,i=this._groups;"function"!=typeof t&&(t=function(t){return function(){return t}}(t));for(var a=i.length,o=new Array(a),s=new Array(a),u=new Array(a),l=0;l<a;++l){var c=r[l],f=i[l],h=f.length,d=et(t.call(c,c&&c.__data__,l,r)),p=d.length,m=s[l]=new Array(p),g=o[l]=new Array(p);n(c,f,m,g,u[l]=new Array(h),d,e);for(var v,y,b=0,w=0;b<p;++b)if(v=m[b]){for(b>=w&&(w=b+1);!(y=g[w])&&++w<p;);v._next=y||null}}return(o=new Bt(o,r))._enter=s,o._exit=u,o},enter:function(){return new Bt(this._enter||this._groups.map(K),this._parents)},exit:function(){return new Bt(this._exit||this._groups.map(K),this._parents)},join:function(t,e,n){var r=this.enter(),i=this,a=this.exit();return"function"==typeof t?(r=t(r))&&(r=r.selection()):r=r.append(t+""),null!=e&&(i=e(i))&&(i=i.selection()),null==n?a.remove():n(a),r&&i?r.merge(i).order():i},merge:function(t){for(var e=t.selection?t.selection():t,n=this._groups,r=e._groups,i=n.length,a=Math.min(i,r.length),o=new Array(i),s=0;s<a;++s)for(var u,l=n[s],c=r[s],f=l.length,h=o[s]=new Array(f),d=0;d<f;++d)(u=l[d]||c[d])&&(h[d]=u);for(;s<i;++s)o[s]=n[s];return new Bt(o,this._parents)},selection:function(){return this},order:function(){for(var t=this._groups,e=-1,n=t.length;++e<n;)for(var r,i=t[e],a=i.length-1,o=i[a];--a>=0;)(r=i[a])&&(o&&4^r.compareDocumentPosition(o)&&o.parentNode.insertBefore(r,o),o=r);return this},sort:function(t){function e(e,n){return e&&n?t(e.__data__,n.__data__):!e-!n}t||(t=nt);for(var n=this._groups,r=n.length,i=new Array(r),a=0;a<r;++a){for(var o,s=n[a],u=s.length,l=i[a]=new Array(u),c=0;c<u;++c)(o=s[c])&&(l[c]=o);l.sort(e)}return new Bt(i,this._parents).order()},call:function(){var t=arguments[0];return arguments[0]=this,t.apply(null,arguments),this},nodes:function(){return Array.from(this)},node:function(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r=t[e],i=0,a=r.length;i<a;++i){var o=r[i];if(o)return o}return null},size:function(){let t=0;for(const e of this)++t;return t},empty:function(){return!this.node()},each:function(t){for(var e=this._groups,n=0,r=e.length;n<r;++n)for(var i,a=e[n],o=0,s=a.length;o<s;++o)(i=a[o])&&t.call(i,i.__data__,o,a);return this},attr:function(t,e){var n=P(t);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((null==e?n.local?it:rt:"function"==typeof e?n.local?ut:st:n.local?ot:at)(n,e))},style:function(t,e,n){return arguments.length>1?this.each((null==e?ct:"function"==typeof e?ht:ft)(t,e,null==n?"":n)):function(t,e){return t.style.getPropertyValue(e)||lt(t).getComputedStyle(t,null).getPropertyValue(e)}(this.node(),t)},property:function(t,e){return arguments.length>1?this.each((null==e?dt:"function"==typeof e?mt:pt)(t,e)):this.node()[t]},classed:function(t,e){var n=gt(t+"");if(arguments.length<2){for(var r=vt(this.node()),i=-1,a=n.length;++i<a;)if(!r.contains(n[i]))return!1;return!0}return this.each(("function"==typeof e?St:e?Mt:xt)(n,e))},text:function(t){return arguments.length?this.each(null==t?Nt:("function"==typeof t?At:Et)(t)):this.node().textContent},html:function(t){return arguments.length?this.each(null==t?Ct:("function"==typeof t?kt:qt)(t)):this.node().innerHTML},raise:function(){return this.each(_t)},lower:function(){return this.each(Ft)},append:function(t){var e="function"==typeof t?t:L(t);return this.select(function(){return this.appendChild(e.apply(this,arguments))})},insert:function(t,e){var n="function"==typeof t?t:L(t),r=null==e?Tt:"function"==typeof e?e:B(e);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})},remove:function(){return this.each(Dt)},clone:function(t){return this.select(t?Vt:It)},datum:function(t){return arguments.length?this.property("__data__",t):this.node().__data__},on:function(t,e,n){var r,i,a=function(t){return t.trim().split(/^|\s+/).map(function(t){var e="",n=t.indexOf(".");return n>=0&&(e=t.slice(n+1),t=t.slice(0,n)),{type:t,name:e}})}(t+""),o=a.length;if(!(arguments.length<2)){for(s=e?Pt:zt,r=0;r<o;++r)this.each(s(a[r],e,n));return this}var s=this.node().__on;if(s)for(var u,l=0,c=s.length;l<c;++l)for(r=0,u=s[l];r<o;++r)if((i=a[r]).type===u.type&&i.name===u.name)return u.value},dispatch:function(t,e){return this.each(("function"==typeof e?Lt:Ot)(t,e))},[Symbol.iterator]:function*(){for(var t=this._groups,e=0,n=t.length;e<n;++e)for(var r,i=t[e],a=0,o=i.length;a<o;++a)(r=i[a])&&(yield r)}};const Xt=Ht($t).right;Ht(function(t){return null===t?NaN:+t});var Qt=Xt;function Ut(t,e){let n,r;if(void 0===e)for(const e of t)null!=e&&(void 0===n?e>=e&&(n=r=e):(n>e&&(n=e),r<e&&(r=e)));else{let i=-1;for(let a of t)null!=(a=e(a,++i,t))&&(void 0===n?a>=a&&(n=r=a):(n>a&&(n=a),r<a&&(r=a)))}return[n,r]}class Kt extends Map{constructor(t,e=Yt){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:e}}),null!=t)for(const[e,n]of t)this.set(e,n)}get(t){return super.get(Jt(this,t))}has(t){return super.has(Jt(this,t))}set(t,e){return super.set(function({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):(t.set(r,n),n)}(this,t),e)}delete(t){return super.delete(function({_intern:t,_key:e},n){const r=e(n);return t.has(r)&&(n=t.get(r),t.delete(r)),n}(this,t))}}function Jt({_intern:t,_key:e},n){const r=e(n);return t.has(r)?t.get(r):n}function Yt(t){return null!==t&&"object"==typeof t?t.valueOf():t}function Zt(t){return t}function te(t,e){return(null==t||!(t>=t))-(null==e||!(e>=e))||(t<e?-1:t>e?1:0)}var ee=Array.prototype.slice;function ne(t){return()=>t}const re=Math.sqrt(50),ie=Math.sqrt(10),ae=Math.sqrt(2);function oe(t,e,n){const r=(e-t)/Math.max(0,n),i=Math.floor(Math.log10(r)),a=r/Math.pow(10,i),o=a>=re?10:a>=ie?5:a>=ae?2:1;let s,u,l;return i<0?(l=Math.pow(10,-i)/o,s=Math.round(t*l),u=Math.round(e*l),s/l<t&&++s,u/l>e&&--u,l=-l):(l=Math.pow(10,i)*o,s=Math.round(t/l),u=Math.round(e/l),s*l<t&&++s,u*l>e&&--u),u<s&&.5<=n&&n<2?oe(t,e,2*n):[s,u,l]}function se(t,e,n){if(!((n=+n)>0))return[];if((t=+t)===(e=+e))return[t];const r=e<t,[i,a,o]=r?oe(e,t,n):oe(t,e,n);if(!(a>=i))return[];const s=a-i+1,u=new Array(s);if(r)if(o<0)for(let t=0;t<s;++t)u[t]=(a-t)/-o;else for(let t=0;t<s;++t)u[t]=(a-t)*o;else if(o<0)for(let t=0;t<s;++t)u[t]=(i+t)/-o;else for(let t=0;t<s;++t)u[t]=(i+t)*o;return u}function ue(t,e,n){return oe(t=+t,e=+e,n=+n)[2]}function le(t){return Math.max(1,Math.ceil(Math.log(function(t){let e=0;for(let n of t)null!=n&&(n=+n)>=n&&++e;return e}(t))/Math.LN2)+1)}function ce(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n<e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n<i||void 0===n&&i>=i)&&(n=i)}return n}function fe(t,e){let n;if(void 0===e)for(const e of t)null!=e&&(n>e||void 0===n&&e>=e)&&(n=e);else{let r=-1;for(let i of t)null!=(i=e(i,++r,t))&&(n>i||void 0===n&&i>=i)&&(n=i)}return n}function he(t,e,n=0,r=Infinity,i){if(e=Math.floor(e),n=Math.floor(Math.max(0,n)),r=Math.floor(Math.min(t.length-1,r)),!(n<=e&&e<=r))return t;for(i=void 0===i?te:function(t=$t){if(t===$t)return te;if("function"!=typeof t)throw new TypeError("compare is not a function");return(e,n)=>{const r=t(e,n);return r||0===r?r:(0===t(n,n))-(0===t(e,e))}}(i);r>n;){if(r-n>600){const a=r-n+1,o=e-n+1,s=Math.log(a),u=.5*Math.exp(2*s/3),l=.5*Math.sqrt(s*u*(a-u)/a)*(o-a/2<0?-1:1);he(t,e,Math.max(n,Math.floor(e-o*u/a+l)),Math.min(r,Math.floor(e+(a-o)*u/a+l)),i)}const a=t[e];let o=n,s=r;for(de(t,n,e),i(t[r],a)>0&&de(t,n,r);o<s;){for(de(t,o,s),++o,--s;i(t[o],a)<0;)++o;for(;i(t[s],a)>0;)--s}0===i(t[n],a)?de(t,n,s):(++s,de(t,s,r)),s<=e&&(n=s+1),e<=s&&(r=s-1)}return t}function de(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function pe(t,e,n){t=+t,e=+e,n=(i=arguments.length)<2?(e=t,t=0,1):i<3?1:+n;for(var r=-1,i=0|Math.max(0,Math.ceil((e-t)/n)),a=new Array(i);++r<i;)a[r]=t+r*n;return a}function me(t,e){switch(arguments.length){case 0:break;case 1:this.range(t);break;default:this.range(e).domain(t)}return this}function ge(t,e){switch(arguments.length){case 0:break;case 1:"function"==typeof t?this.interpolator(t):this.range(t);break;default:this.domain(t),"function"==typeof e?this.interpolator(e):this.range(e)}return this}const ve=Symbol("implicit");function ye(){var t=new Kt,e=[],n=[],r=ve;function i(i){let a=t.get(i);if(void 0===a){if(r!==ve)return r;t.set(i,a=e.push(i)-1)}return n[a%n.length]}return i.domain=function(n){if(!arguments.length)return e.slice();e=[],t=new Kt;for(const r of n)t.has(r)||t.set(r,e.push(r)-1);return i},i.range=function(t){return arguments.length?(n=Array.from(t),i):n.slice()},i.unknown=function(t){return arguments.length?(r=t,i):r},i.copy=function(){return ye(e,n).unknown(r)},me.apply(i,arguments),i}function be(){var t,e,n=ye().unknown(void 0),r=n.domain,i=n.range,a=0,o=1,s=!1,u=0,l=0,c=.5;function f(){var n=r().length,f=o<a,h=f?o:a,d=f?a:o;t=(d-h)/Math.max(1,n-u+2*l),s&&(t=Math.floor(t)),h+=(d-h-t*(n-u))*c,e=t*(1-u),s&&(h=Math.round(h),e=Math.round(e));var p=pe(n).map(function(e){return h+t*e});return i(f?p.reverse():p)}return delete n.unknown,n.domain=function(t){return arguments.length?(r(t),f()):r()},n.range=function(t){return arguments.length?([a,o]=t,a=+a,o=+o,f()):[a,o]},n.rangeRound=function(t){return[a,o]=t,a=+a,o=+o,s=!0,f()},n.bandwidth=function(){return e},n.step=function(){return t},n.round=function(t){return arguments.length?(s=!!t,f()):s},n.padding=function(t){return arguments.length?(u=Math.min(1,l=+t),f()):u},n.paddingInner=function(t){return arguments.length?(u=Math.min(1,t),f()):u},n.paddingOuter=function(t){return arguments.length?(l=+t,f()):l},n.align=function(t){return arguments.length?(c=Math.max(0,Math.min(1,t)),f()):c},n.copy=function(){return be(r(),[a,o]).round(s).paddingInner(u).paddingOuter(l).align(c)},me.apply(f(),arguments)}function we(t){var e=t.copy;return t.padding=t.paddingOuter,delete t.paddingInner,delete t.paddingOuter,t.copy=function(){return we(e())},t}function Me(t,e,n){t.prototype=e.prototype=n,n.constructor=t}function xe(t,e){var n=Object.create(t.prototype);for(var r in e)n[r]=e[r];return n}function Se(){}var Ne=.7,Ee=1/Ne,Ae="\\s*([+-]?\\d+)\\s*",Ce="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",qe="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",ke=/^#([0-9a-f]{3,8})$/,_e=new RegExp(`^rgb\\(${Ae},${Ae},${Ae}\\)$`),Fe=new RegExp(`^rgb\\(${qe},${qe},${qe}\\)$`),Te=new RegExp(`^rgba\\(${Ae},${Ae},${Ae},${Ce}\\)$`),De=new RegExp(`^rgba\\(${qe},${qe},${qe},${Ce}\\)$`),Ie=new RegExp(`^hsl\\(${Ce},${qe},${qe}\\)$`),Ve=new RegExp(`^hsla\\(${Ce},${qe},${qe},${Ce}\\)$`),ze={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};function Pe(){return this.rgb().formatHex()}function Re(){return this.rgb().formatRgb()}function Oe(t){var e,n;return t=(t+"").trim().toLowerCase(),(e=ke.exec(t))?(n=e[1].length,e=parseInt(e[1],16),6===n?Le(e):3===n?new $e(e>>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?je(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?je(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=_e.exec(t))?new $e(e[1],e[2],e[3],1):(e=Fe.exec(t))?new $e(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=Te.exec(t))?je(e[1],e[2],e[3],e[4]):(e=De.exec(t))?je(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Ie.exec(t))?Ue(e[1],e[2]/100,e[3]/100,1):(e=Ve.exec(t))?Ue(e[1],e[2]/100,e[3]/100,e[4]):ze.hasOwnProperty(t)?Le(ze[t]):"transparent"===t?new $e(NaN,NaN,NaN,0):null}function Le(t){return new $e(t>>16&255,t>>8&255,255&t,1)}function je(t,e,n,r){return r<=0&&(t=e=n=NaN),new $e(t,e,n,r)}function Be(t,e,n,r){return 1===arguments.length?((i=t)instanceof Se||(i=Oe(i)),i?new $e((i=i.rgb()).r,i.g,i.b,i.opacity):new $e):new $e(t,e,n,null==r?1:r);var i}function $e(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function We(){return`#${Qe(this.r)}${Qe(this.g)}${Qe(this.b)}`}function He(){const t=Ge(this.opacity);return`${1===t?"rgb(":"rgba("}${Xe(this.r)}, ${Xe(this.g)}, ${Xe(this.b)}${1===t?")":`, ${t})`}`}function Ge(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Xe(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Qe(t){return((t=Xe(t))<16?"0":"")+t.toString(16)}function Ue(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new Je(t,e,n,r)}function Ke(t){if(t instanceof Je)return new Je(t.h,t.s,t.l,t.opacity);if(t instanceof Se||(t=Oe(t)),!t)return new Je;if(t instanceof Je)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),o=NaN,s=a-i,u=(a+i)/2;return s?(o=e===a?(n-r)/s+6*(n<r):n===a?(r-e)/s+2:(e-n)/s+4,s/=u<.5?a+i:2-a-i,o*=60):s=u>0&&u<1?0:o,new Je(o,s,u,t.opacity)}function Je(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function Ye(t){return(t=(t||0)%360)<0?t+360:t}function Ze(t){return Math.max(0,Math.min(1,t||0))}function tn(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Me(Se,Oe,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Pe,formatHex:Pe,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Ke(this).formatHsl()},formatRgb:Re,toString:Re}),Me($e,Be,xe(Se,{brighter(t){return t=null==t?Ee:Math.pow(Ee,t),new $e(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Ne:Math.pow(Ne,t),new $e(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new $e(Xe(this.r),Xe(this.g),Xe(this.b),Ge(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:We,formatHex:We,formatHex8:function(){return`#${Qe(this.r)}${Qe(this.g)}${Qe(this.b)}${Qe(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:He,toString:He})),Me(Je,function(t,e,n,r){return 1===arguments.length?Ke(t):new Je(t,e,n,null==r?1:r)},xe(Se,{brighter(t){return t=null==t?Ee:Math.pow(Ee,t),new Je(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Ne:Math.pow(Ne,t),new Je(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new $e(tn(t>=240?t-240:t+120,i,r),tn(t,i,r),tn(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Je(Ye(this.h),Ze(this.s),Ze(this.l),Ge(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Ge(this.opacity);return`${1===t?"hsl(":"hsla("}${Ye(this.h)}, ${100*Ze(this.s)}%, ${100*Ze(this.l)}%${1===t?")":`, ${t})`}`}}));var en=t=>()=>t;function nn(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):en(isNaN(t)?e:t)}var rn,an=function t(e){var n=function(t){return 1===(t=+t)?nn:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):en(isNaN(e)?n:e)}}(e);function r(t,e){var r=n((t=Be(t)).r,(e=Be(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),o=nn(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=o(e),t+""}}return r.gamma=t,r}(1),on=(rn=function(t){var e=t.length-1;return function(n){var r=n<=0?n=0:n>=1?(n=1,e-1):Math.floor(n*e),i=t[r],a=t[r+1];return function(t,e,n,r,i){var a=t*t,o=a*t;return((1-3*t+3*a-o)*e+(4-6*a+3*o)*n+(1+3*t+3*a-3*o)*r+o*i)/6}((n-r/e)*e,r>0?t[r-1]:2*i-a,i,a,r<e-1?t[r+2]:2*a-i)}},function(t){var e,n,r=t.length,i=new Array(r),a=new Array(r),o=new Array(r);for(e=0;e<r;++e)n=Be(t[e]),i[e]=n.r||0,a[e]=n.g||0,o[e]=n.b||0;return i=rn(i),a=rn(a),o=rn(o),n.opacity=1,function(t){return n.r=i(t),n.g=a(t),n.b=o(t),n+""}});function sn(t,e){e||(e=[]);var n,r=t?Math.min(e.length,t.length):0,i=e.slice();return function(a){for(n=0;n<r;++n)i[n]=t[n]*(1-a)+e[n]*a;return i}}function un(t,e){var n,r=e?e.length:0,i=t?Math.min(r,t.length):0,a=new Array(i),o=new Array(r);for(n=0;n<i;++n)a[n]=mn(t[n],e[n]);for(;n<r;++n)o[n]=e[n];return function(t){for(n=0;n<i;++n)o[n]=a[n](t);return o}}function ln(t,e){var n=new Date;return t=+t,e=+e,function(r){return n.setTime(t*(1-r)+e*r),n}}function cn(t,e){return t=+t,e=+e,function(n){return t*(1-n)+e*n}}function fn(t,e){var n,r={},i={};for(n in null!==t&&"object"==typeof t||(t={}),null!==e&&"object"==typeof e||(e={}),e)n in t?r[n]=mn(t[n],e[n]):i[n]=e[n];return function(t){for(n in r)i[n]=r[n](t);return i}}var hn=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,dn=new RegExp(hn.source,"g");function pn(t,e){var n,r,i,a=hn.lastIndex=dn.lastIndex=0,o=-1,s=[],u=[];for(t+="",e+="";(n=hn.exec(t))&&(r=dn.exec(e));)(i=r.index)>a&&(i=e.slice(a,i),s[o]?s[o]+=i:s[++o]=i),(n=n[0])===(r=r[0])?s[o]?s[o]+=r:s[++o]=r:(s[++o]=null,u.push({i:o,x:cn(n,r)})),a=dn.lastIndex;return a<e.length&&(i=e.slice(a),s[o]?s[o]+=i:s[++o]=i),s.length<2?u[0]?function(t){return function(e){return t(e)+""}}(u[0].x):function(t){return function(){return t}}(e):(e=u.length,function(t){for(var n,r=0;r<e;++r)s[(n=u[r]).i]=n.x(t);return s.join("")})}function mn(t,e){var n,r=typeof e;return null==e||"boolean"===r?en(e):("number"===r?cn:"string"===r?(n=Oe(e))?(e=n,an):pn:e instanceof Oe?an:e instanceof Date?ln:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}(e)?sn:Array.isArray(e)?un:"function"!=typeof e.valueOf&&"function"!=typeof e.toString||isNaN(e)?fn:cn)(t,e)}function gn(t,e){return t=+t,e=+e,function(n){return Math.round(t*(1-n)+e*n)}}function vn(t){return+t}var yn=[0,1];function bn(t){return t}function wn(t,e){return(e-=t=+t)?function(n){return(n-t)/e}:function(t){return function(){return t}}(isNaN(e)?NaN:.5)}function Mn(t,e,n){var r=t[0],i=t[1],a=e[0],o=e[1];return i<r?(r=wn(i,r),a=n(o,a)):(r=wn(r,i),a=n(a,o)),function(t){return a(r(t))}}function xn(t,e,n){var r=Math.min(t.length,e.length)-1,i=new Array(r),a=new Array(r),o=-1;for(t[r]<t[0]&&(t=t.slice().reverse(),e=e.slice().reverse());++o<r;)i[o]=wn(t[o],t[o+1]),a[o]=n(e[o],e[o+1]);return function(e){var n=Qt(t,e,1,r)-1;return a[n](i[n](e))}}function Sn(t,e){if((n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"))<0)return null;var n,r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function Nn(t){return(t=Sn(Math.abs(t)))?t[1]:NaN}var En,An=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Cn(t){if(!(e=An.exec(t)))throw new Error("invalid format: "+t);var e;return new qn({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function qn(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function kn(t,e){var n=Sn(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}Cn.prototype=qn.prototype,qn.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var _n={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>kn(100*t,e),r:kn,s:function(t,e){var n=Sn(t,e);if(!n)return t+"";var r=n[0],i=n[1],a=i-(En=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,o=r.length;return a===o?r:a>o?r+new Array(a-o+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+Sn(t,Math.max(0,e+a-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function Fn(t){return t}var Tn,Dn,In,Vn=Array.prototype.map,zn=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Pn(t){var e=t.domain;return t.ticks=function(t){var n=e();return se(n[0],n[n.length-1],null==t?10:t)},t.tickFormat=function(t,n){var r=e();return function(t,e,n,r){var i,a=function(t,e,n){n=+n;const r=(e=+e)<(t=+t),i=r?ue(e,t,n):ue(t,e,n);return(r?-1:1)*(i<0?1/-i:i)}(t,e,n);switch((r=Cn(null==r?",f":r)).type){case"s":var o=Math.max(Math.abs(t),Math.abs(e));return null!=r.precision||isNaN(i=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(Nn(e)/3)))-Nn(Math.abs(t)))}(a,o))||(r.precision=i),In(r,o);case"":case"e":case"g":case"p":case"r":null!=r.precision||isNaN(i=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,Nn(e)-Nn(t))+1}(a,Math.max(Math.abs(t),Math.abs(e))))||(r.precision=i-("e"===r.type));break;case"f":case"%":null!=r.precision||isNaN(i=function(t){return Math.max(0,-Nn(Math.abs(t)))}(a))||(r.precision=i-2*("%"===r.type))}return Dn(r)}(r[0],r[r.length-1],null==t?10:t,n)},t.nice=function(n){null==n&&(n=10);var r,i,a=e(),o=0,s=a.length-1,u=a[o],l=a[s],c=10;for(l<u&&(i=u,u=l,l=i,i=o,o=s,s=i);c-- >0;){if((i=ue(u,l,n))===r)return a[o]=u,a[s]=l,e(a);if(i>0)u=Math.floor(u/i)*i,l=Math.ceil(l/i)*i;else{if(!(i<0))break;u=Math.ceil(u*i)/i,l=Math.floor(l*i)/i}r=i}return t},t}function Rn(t){return t}Tn=function(t){var e,n,r=void 0===t.grouping||void 0===t.thousands?Fn:(e=Vn.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var i=t.length,a=[],o=0,s=e[0],u=0;i>0&&s>0&&(u+s+1>r&&(s=Math.max(1,r-u)),a.push(t.substring(i-=s,i+s)),!((u+=s+1)>r));)s=e[o=(o+1)%e.length];return a.reverse().join(n)}),i=void 0===t.currency?"":t.currency[0]+"",a=void 0===t.currency?"":t.currency[1]+"",o=void 0===t.decimal?".":t.decimal+"",s=void 0===t.numerals?Fn:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(Vn.call(t.numerals,String)),u=void 0===t.percent?"%":t.percent+"",l=void 0===t.minus?"ā":t.minus+"",c=void 0===t.nan?"NaN":t.nan+"";function f(t){var e=(t=Cn(t)).fill,n=t.align,f=t.sign,h=t.symbol,d=t.zero,p=t.width,m=t.comma,g=t.precision,v=t.trim,y=t.type;"n"===y?(m=!0,y="g"):_n[y]||(void 0===g&&(g=12),v=!0,y="g"),(d||"0"===e&&"="===n)&&(d=!0,e="0",n="=");var b="$"===h?i:"#"===h&&/[boxX]/.test(y)?"0"+y.toLowerCase():"",w="$"===h?a:/[%p]/.test(y)?u:"",M=_n[y],x=/[defgprs%]/.test(y);function S(t){var i,a,u,h=b,S=w;if("c"===y)S=M(t)+S,t="";else{var N=(t=+t)<0||1/t<0;if(t=isNaN(t)?c:M(Math.abs(t),g),v&&(t=function(t){t:for(var e,n=t.length,r=1,i=-1;r<n;++r)switch(t[r]){case".":i=e=r;break;case"0":0===i&&(i=r),e=r;break;default:if(!+t[r])break t;i>0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t}(t)),N&&0===+t&&"+"!==f&&(N=!1),h=(N?"("===f?f:l:"-"===f||"("===f?"":f)+h,S=("s"===y?zn[8+En/3]:"")+S+(N&&"("===f?")":""),x)for(i=-1,a=t.length;++i<a;)if(48>(u=t.charCodeAt(i))||u>57){S=(46===u?o+t.slice(i+1):t.slice(i))+S,t=t.slice(0,i);break}}m&&!d&&(t=r(t,Infinity));var E=h.length+t.length+S.length,A=E<p?new Array(p-E+1).join(e):"";switch(m&&d&&(t=r(A+t,A.length?p-S.length:Infinity),A=""),n){case"<":t=h+t+S+A;break;case"=":t=h+A+t+S;break;case"^":t=A.slice(0,E=A.length>>1)+h+t+S+A.slice(E);break;default:t=A+h+t+S}return s(t)}return g=void 0===g?6:/[gprs]/.test(y)?Math.max(1,Math.min(21,g)):Math.max(0,Math.min(20,g)),S.toString=function(){return t+""},S}return{format:f,formatPrefix:function(t,e){var n=f(((t=Cn(t)).type="f",t)),r=3*Math.max(-8,Math.min(8,Math.floor(Nn(e)/3))),i=Math.pow(10,-r),a=zn[8+r/3];return function(t){return n(i*t)+a}}}}({thousands:",",grouping:[3],currency:["$",""]}),Dn=Tn.format,In=Tn.formatPrefix;var On=1e-6;function Ln(t){return"translate("+t+",0)"}function jn(t){return"translate(0,"+t+")"}function Bn(t){return e=>+t(e)}function $n(t,e){return e=Math.max(0,t.bandwidth()-2*e)/2,t.round()&&(e=Math.round(e)),n=>+t(n)+e}function Wn(){return!this.__axis}function Hn(t,e){var n=[],r=null,i=null,a=6,o=6,s=3,u="undefined"!=typeof window&&window.devicePixelRatio>1?0:.5,l=1===t||4===t?-1:1,c=4===t||2===t?"x":"y",f=1===t||3===t?Ln:jn;function h(h){var d=null==r?e.ticks?e.ticks.apply(e,n):e.domain():r,p=null==i?e.tickFormat?e.tickFormat.apply(e,n):Rn:i,m=Math.max(a,0)+s,g=e.range(),v=+g[0]+u,y=+g[g.length-1]+u,b=(e.bandwidth?$n:Bn)(e.copy(),u),w=h.selection?h.selection():h,M=w.selectAll(".domain").data([null]),x=w.selectAll(".tick").data(d,e).order(),S=x.exit(),N=x.enter().append("g").attr("class","tick"),E=x.select("line"),A=x.select("text");M=M.merge(M.enter().insert("path",".tick").attr("class","domain").attr("stroke","currentColor")),x=x.merge(N),E=E.merge(N.append("line").attr("stroke","currentColor").attr(c+"2",l*a)),A=A.merge(N.append("text").attr("fill","currentColor").attr(c,l*m).attr("dy",1===t?"0em":3===t?"0.71em":"0.32em")),h!==w&&(M=M.transition(h),x=x.transition(h),E=E.transition(h),A=A.transition(h),S=S.transition(h).attr("opacity",On).attr("transform",function(t){return isFinite(t=b(t))?f(t+u):this.getAttribute("transform")}),N.attr("opacity",On).attr("transform",function(t){var e=this.parentNode.__axis;return f((e&&isFinite(e=e(t))?e:b(t))+u)})),S.remove(),M.attr("d",4===t||2===t?o?"M"+l*o+","+v+"H"+u+"V"+y+"H"+l*o:"M"+u+","+v+"V"+y:o?"M"+v+","+l*o+"V"+u+"H"+y+"V"+l*o:"M"+v+","+u+"H"+y),x.attr("opacity",1).attr("transform",function(t){return f(b(t)+u)}),E.attr(c+"2",l*a),A.attr(c,l*m).text(p),w.filter(Wn).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",2===t?"start":4===t?"end":"middle"),w.each(function(){this.__axis=b})}return h.scale=function(t){return arguments.length?(e=t,h):e},h.ticks=function(){return n=Array.from(arguments),h},h.tickArguments=function(t){return arguments.length?(n=null==t?[]:Array.from(t),h):n.slice()},h.tickValues=function(t){return arguments.length?(r=null==t?null:Array.from(t),h):r&&r.slice()},h.tickFormat=function(t){return arguments.length?(i=t,h):i},h.tickSize=function(t){return arguments.length?(a=o=+t,h):a},h.tickSizeInner=function(t){return arguments.length?(a=+t,h):a},h.tickSizeOuter=function(t){return arguments.length?(o=+t,h):o},h.tickPadding=function(t){return arguments.length?(s=+t,h):s},h.offset=function(t){return arguments.length?(u=+t,h):u},h}function Gn(t){for(var e=t.length/6|0,n=new Array(e),r=0;r<e;)n[r]="#"+t.slice(6*r,6*++r);return n}var Xn,Qn=Gn("1f77b4ff7f0e2ca02cd627289467bd8c564be377c27f7f7fbcbd2217becf"),Un=on((Xn=new Array(3).concat("fc8d59ffffbf91bfdb","d7191cfdae61abd9e92c7bb6","d7191cfdae61ffffbfabd9e92c7bb6","d73027fc8d59fee090e0f3f891bfdb4575b4","d73027fc8d59fee090ffffbfe0f3f891bfdb4575b4","d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4","d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4","a50026d73027f46d43fdae61fee090e0f3f8abd9e974add14575b4313695","a50026d73027f46d43fdae61fee090ffffbfe0f3f8abd9e974add14575b4313695").map(Gn))[Xn.length-1]);function Kn(t){var e=t.length;return function(n){return t[Math.max(0,Math.min(e-1,Math.floor(n*e)))]}}var Jn=Kn(Gn("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));function Yn(t){return function(){return t}}Kn(Gn("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf")),Kn(Gn("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4")),Kn(Gn("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));const Zn=Math.abs,tr=Math.atan2,er=Math.cos,nr=Math.max,rr=Math.min,ir=Math.sin,ar=Math.sqrt,or=1e-12,sr=Math.PI,ur=sr/2,lr=2*sr;function cr(t){return t>=1?ur:t<=-1?-ur:Math.asin(t)}const fr=Math.PI,hr=2*fr,dr=1e-6,pr=hr-dr;function mr(t){this._+=t[0];for(let e=1,n=t.length;e<n;++e)this._+=arguments[e]+t[e]}class gr{constructor(t){this._x0=this._y0=this._x1=this._y1=null,this._="",this._append=null==t?mr:function(t){let e=Math.floor(t);if(!(e>=0))throw new Error(`invalid digits: ${t}`);if(e>15)return mr;const n=10**e;return function(t){this._+=t[0];for(let e=1,r=t.length;e<r;++e)this._+=Math.round(arguments[e]*n)/n+t[e]}}(t)}moveTo(t,e){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}`}closePath(){null!==this._x1&&(this._x1=this._x0,this._y1=this._y0,this._append`Z`)}lineTo(t,e){this._append`L${this._x1=+t},${this._y1=+e}`}quadraticCurveTo(t,e,n,r){this._append`Q${+t},${+e},${this._x1=+n},${this._y1=+r}`}bezierCurveTo(t,e,n,r,i,a){this._append`C${+t},${+e},${+n},${+r},${this._x1=+i},${this._y1=+a}`}arcTo(t,e,n,r,i){if(t=+t,e=+e,n=+n,r=+r,(i=+i)<0)throw new Error(`negative radius: ${i}`);let a=this._x1,o=this._y1,s=n-t,u=r-e,l=a-t,c=o-e,f=l*l+c*c;if(null===this._x1)this._append`M${this._x1=t},${this._y1=e}`;else if(f>dr)if(Math.abs(c*s-u*l)>dr&&i){let h=n-a,d=r-o,p=s*s+u*u,m=h*h+d*d,g=Math.sqrt(p),v=Math.sqrt(f),y=i*Math.tan((fr-Math.acos((p+f-m)/(2*g*v)))/2),b=y/v,w=y/g;Math.abs(b-1)>dr&&this._append`L${t+b*l},${e+b*c}`,this._append`A${i},${i},0,0,${+(c*h>l*d)},${this._x1=t+w*s},${this._y1=e+w*u}`}else this._append`L${this._x1=t},${this._y1=e}`}arc(t,e,n,r,i,a){if(t=+t,e=+e,a=!!a,(n=+n)<0)throw new Error(`negative radius: ${n}`);let o=n*Math.cos(r),s=n*Math.sin(r),u=t+o,l=e+s,c=1^a,f=a?r-i:i-r;null===this._x1?this._append`M${u},${l}`:(Math.abs(this._x1-u)>dr||Math.abs(this._y1-l)>dr)&&this._append`L${u},${l}`,n&&(f<0&&(f=f%hr+hr),f>pr?this._append`A${n},${n},0,1,${c},${t-o},${e-s}A${n},${n},0,1,${c},${this._x1=u},${this._y1=l}`:f>dr&&this._append`A${n},${n},0,${+(f>=fr)},${c},${this._x1=t+n*Math.cos(i)},${this._y1=e+n*Math.sin(i)}`)}rect(t,e,n,r){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}}function vr(t){let e=3;return t.digits=function(n){if(!arguments.length)return e;if(null==n)e=null;else{const t=Math.floor(n);if(!(t>=0))throw new RangeError(`invalid digits: ${n}`);e=t}return t},()=>new gr(e)}function yr(t){return t.innerRadius}function br(t){return t.outerRadius}function wr(t){return t.startAngle}function Mr(t){return t.endAngle}function xr(t){return t&&t.padAngle}function Sr(t,e,n,r,i,a,o){var s=t-n,u=e-r,l=(o?a:-a)/ar(s*s+u*u),c=l*u,f=-l*s,h=t+c,d=e+f,p=n+c,m=r+f,g=(h+p)/2,v=(d+m)/2,y=p-h,b=m-d,w=y*y+b*b,M=i-a,x=h*m-p*d,S=(b<0?-1:1)*ar(nr(0,M*M*w-x*x)),N=(x*b-y*S)/w,E=(-x*y-b*S)/w,A=(x*b+y*S)/w,C=(-x*y+b*S)/w,q=N-g,k=E-v,_=A-g,F=C-v;return q*q+k*k>_*_+F*F&&(N=A,E=C),{cx:N,cy:E,x01:-c,y01:-f,x11:N*(i/M-1),y11:E*(i/M-1)}}function Nr(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function Er(t){this._context=t}function Ar(t){return new Er(t)}function Cr(t){return t[0]}function qr(t){return t[1]}function kr(t,e){var n=Yn(!0),r=null,i=Ar,a=null,o=vr(s);function s(s){var u,l,c,f=(s=Nr(s)).length,h=!1;for(null==r&&(a=i(c=o())),u=0;u<=f;++u)!(u<f&&n(l=s[u],u,s))===h&&((h=!h)?a.lineStart():a.lineEnd()),h&&a.point(+t(l,u,s),+e(l,u,s));if(c)return a=null,c+""||null}return t="function"==typeof t?t:void 0===t?Cr:Yn(t),e="function"==typeof e?e:void 0===e?qr:Yn(e),s.x=function(e){return arguments.length?(t="function"==typeof e?e:Yn(+e),s):t},s.y=function(t){return arguments.length?(e="function"==typeof t?t:Yn(+t),s):e},s.defined=function(t){return arguments.length?(n="function"==typeof t?t:Yn(!!t),s):n},s.curve=function(t){return arguments.length?(i=t,null!=r&&(a=i(r)),s):i},s.context=function(t){return arguments.length?(null==t?r=a=null:a=i(r=t),s):r},s}function _r(t,e){return e<t?-1:e>t?1:e>=t?0:NaN}function Fr(t){return t}function Tr(t,e,n){t._context.bezierCurveTo((2*t._x0+t._x1)/3,(2*t._y0+t._y1)/3,(t._x0+2*t._x1)/3,(t._y0+2*t._y1)/3,(t._x0+4*t._x1+e)/6,(t._y0+4*t._y1+n)/6)}function Dr(t){this._context=t}Er.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}},Dr.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:Tr(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1)}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:Tr(this,t,e)}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e}};var Ir={select:function(t){return"string"==typeof t?new Bt([[document.querySelector(t)]],[document.documentElement]):new Bt([[t]],jt)},selectAll:function(t){return"string"==typeof t?new Bt([document.querySelectorAll(t)],[document.documentElement]):new Bt([$(t)],jt)},scaleLinear:function t(){var e=function(){var t,e,n,r,i,a,o=yn,s=yn,u=mn,l=bn;function c(){var t,e,n,u=Math.min(o.length,s.length);return l!==bn&&((t=o[0])>(e=o[u-1])&&(n=t,t=e,e=n),l=function(n){return Math.max(t,Math.min(e,n))}),r=u>2?xn:Mn,i=a=null,f}function f(e){return null==e||isNaN(e=+e)?n:(i||(i=r(o.map(t),s,u)))(t(l(e)))}return f.invert=function(n){return l(e((a||(a=r(s,o.map(t),cn)))(n)))},f.domain=function(t){return arguments.length?(o=Array.from(t,vn),c()):o.slice()},f.range=function(t){return arguments.length?(s=Array.from(t),c()):s.slice()},f.rangeRound=function(t){return s=Array.from(t),u=gn,c()},f.clamp=function(t){return arguments.length?(l=!!t||bn,c()):l!==bn},f.interpolate=function(t){return arguments.length?(u=t,c()):u},f.unknown=function(t){return arguments.length?(n=t,f):n},function(n,r){return t=n,e=r,c()}}()(bn,bn);return e.copy=function(){return n=e,t().domain(n.domain()).range(n.range()).interpolate(n.interpolate()).clamp(n.clamp()).unknown(n.unknown());var n},me.apply(e,arguments),Pn(e)},scaleBand:be,scalePoint:function(){return we(be.apply(null,arguments).paddingInner(1))},scaleOrdinal:ye,scaleSequential:function t(){var e=Pn(function(){var t,e,n,r,i,a=0,o=1,s=bn,u=!1;function l(e){return null==e||isNaN(e=+e)?i:s(0===n?.5:(e=(r(e)-t)*n,u?Math.max(0,Math.min(1,e)):e))}function c(t){return function(e){var n,r;return arguments.length?([n,r]=e,s=t(n,r),l):[s(0),s(1)]}}return l.domain=function(i){return arguments.length?([a,o]=i,t=r(a=+a),e=r(o=+o),n=t===e?0:1/(e-t),l):[a,o]},l.clamp=function(t){return arguments.length?(u=!!t,l):u},l.interpolator=function(t){return arguments.length?(s=t,l):s},l.range=c(mn),l.rangeRound=c(gn),l.unknown=function(t){return arguments.length?(i=t,l):i},function(i){return r=i,t=i(a),e=i(o),n=t===e?0:1/(e-t),l}}()(bn));return e.copy=function(){return n=e,t().domain(n.domain()).interpolator(n.interpolator()).clamp(n.clamp()).unknown(n.unknown());var n},ge.apply(e,arguments)},extent:Ut,max:ce,min:fe,sum:function(t,e){let n=0;if(void 0===e)for(let e of t)(e=+e)&&(n+=e);else{let r=-1;for(let i of t)(i=+e(i,++r,t))&&(n+=i)}return n},deviation:function(t,e){const n=function(t,e){let n,r=0,i=0,a=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(n=e-i,i+=n/++r,a+=n*(e-i));else{let o=-1;for(let s of t)null!=(s=e(s,++o,t))&&(s=+s)>=s&&(n=s-i,i+=n/++r,a+=n*(s-i))}if(r>1)return a/(r-1)}(t,e);return n?Math.sqrt(n):n},mean:function(t,e){let n=0,r=0;if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(++n,r+=e);else{let i=-1;for(let a of t)null!=(a=e(a,++i,t))&&(a=+a)>=a&&(++n,r+=a)}if(n)return r/n},quantile:function(t,e,n){if(t=Float64Array.from(function*(t,e){if(void 0===e)for(let e of t)null!=e&&(e=+e)>=e&&(yield e);else{let n=-1;for(let r of t)null!=(r=e(r,++n,t))&&(r=+r)>=r&&(yield r)}}(t,n)),(r=t.length)&&!isNaN(e=+e)){if(e<=0||r<2)return fe(t);if(e>=1)return ce(t);var r,i=(r-1)*e,a=Math.floor(i),o=ce(he(t,a).subarray(0,a+1));return o+(fe(t.subarray(a+1))-o)*(i-a)}},histogram:function(){var t=Zt,e=Ut,n=le;function r(r){Array.isArray(r)||(r=Array.from(r));var i,a,o,s=r.length,u=new Array(s);for(i=0;i<s;++i)u[i]=t(r[i],i,r);var l=e(u),c=l[0],f=l[1],h=n(u,c,f);if(!Array.isArray(h)){const t=f,n=+h;if(e===Ut&&([c,f]=function(t,e,n){let r;for(;;){const i=ue(t,e,n);if(i===r||0===i||!isFinite(i))return[t,e];i>0?(t=Math.floor(t/i)*i,e=Math.ceil(e/i)*i):i<0&&(t=Math.ceil(t*i)/i,e=Math.floor(e*i)/i),r=i}}(c,f,n)),(h=se(c,f,n))[0]<=c&&(o=ue(c,f,n)),h[h.length-1]>=f)if(t>=f&&e===Ut){const t=ue(c,f,n);isFinite(t)&&(t>0?f=(Math.floor(f/t)+1)*t:t<0&&(f=(Math.ceil(f*-t)+1)/-t))}else h.pop()}for(var d=h.length,p=0,m=d;h[p]<=c;)++p;for(;h[m-1]>f;)--m;(p||m<d)&&(h=h.slice(p,m),d=m-p);var g,v=new Array(d+1);for(i=0;i<=d;++i)(g=v[i]=[]).x0=i>0?h[i-1]:c,g.x1=i<d?h[i]:f;if(isFinite(o)){if(o>0)for(i=0;i<s;++i)null!=(a=u[i])&&c<=a&&a<=f&&v[Math.min(d,Math.floor((a-c)/o))].push(r[i]);else if(o<0)for(i=0;i<s;++i)if(null!=(a=u[i])&&c<=a&&a<=f){const t=Math.floor((c-a)*o);v[Math.min(d,t+(h[t]<=a))].push(r[i])}}else for(i=0;i<s;++i)null!=(a=u[i])&&c<=a&&a<=f&&v[Qt(h,a,0,d)].push(r[i]);return v}return r.value=function(e){return arguments.length?(t="function"==typeof e?e:ne(e),r):t},r.domain=function(t){return arguments.length?(e="function"==typeof t?t:ne([t[0],t[1]]),r):e},r.thresholds=function(t){return arguments.length?(n="function"==typeof t?t:ne(Array.isArray(t)?ee.call(t):t),r):n},r},range:pe,axisBottom:function(t){return Hn(3,t)},axisLeft:function(t){return Hn(4,t)},line:kr,area:function(t,e,n){var r=null,i=Yn(!0),a=null,o=Ar,s=null,u=vr(l);function l(l){var c,f,h,d,p,m=(l=Nr(l)).length,g=!1,v=new Array(m),y=new Array(m);for(null==a&&(s=o(p=u())),c=0;c<=m;++c){if(!(c<m&&i(d=l[c],c,l))===g)if(g=!g)f=c,s.areaStart(),s.lineStart();else{for(s.lineEnd(),s.lineStart(),h=c-1;h>=f;--h)s.point(v[h],y[h]);s.lineEnd(),s.areaEnd()}g&&(v[c]=+t(d,c,l),y[c]=+e(d,c,l),s.point(r?+r(d,c,l):v[c],n?+n(d,c,l):y[c]))}if(p)return s=null,p+""||null}function c(){return kr().defined(i).curve(o).context(a)}return t="function"==typeof t?t:void 0===t?Cr:Yn(+t),e="function"==typeof e?e:Yn(void 0===e?0:+e),n="function"==typeof n?n:void 0===n?qr:Yn(+n),l.x=function(e){return arguments.length?(t="function"==typeof e?e:Yn(+e),r=null,l):t},l.x0=function(e){return arguments.length?(t="function"==typeof e?e:Yn(+e),l):t},l.x1=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:Yn(+t),l):r},l.y=function(t){return arguments.length?(e="function"==typeof t?t:Yn(+t),n=null,l):e},l.y0=function(t){return arguments.length?(e="function"==typeof t?t:Yn(+t),l):e},l.y1=function(t){return arguments.length?(n=null==t?null:"function"==typeof t?t:Yn(+t),l):n},l.lineX0=l.lineY0=function(){return c().x(t).y(e)},l.lineY1=function(){return c().x(t).y(n)},l.lineX1=function(){return c().x(r).y(e)},l.defined=function(t){return arguments.length?(i="function"==typeof t?t:Yn(!!t),l):i},l.curve=function(t){return arguments.length?(o=t,null!=a&&(s=o(a)),l):o},l.context=function(t){return arguments.length?(null==t?a=s=null:s=o(a=t),l):a},l},curveBasis:function(t){return new Dr(t)},pie:function(){var t=Fr,e=_r,n=null,r=Yn(0),i=Yn(lr),a=Yn(0);function o(o){var s,u,l,c,f,h=(o=Nr(o)).length,d=0,p=new Array(h),m=new Array(h),g=+r.apply(this,arguments),v=Math.min(lr,Math.max(-lr,i.apply(this,arguments)-g)),y=Math.min(Math.abs(v)/h,a.apply(this,arguments)),b=y*(v<0?-1:1);for(s=0;s<h;++s)(f=m[p[s]=s]=+t(o[s],s,o))>0&&(d+=f);for(null!=e?p.sort(function(t,n){return e(m[t],m[n])}):null!=n&&p.sort(function(t,e){return n(o[t],o[e])}),s=0,l=d?(v-h*b)/d:0;s<h;++s,g=c)m[u=p[s]]={data:o[u],index:s,value:f=m[u],startAngle:g,endAngle:c=g+(f>0?f*l:0)+b,padAngle:y};return m}return o.value=function(e){return arguments.length?(t="function"==typeof e?e:Yn(+e),o):t},o.sortValues=function(t){return arguments.length?(e=t,n=null,o):e},o.sort=function(t){return arguments.length?(n=t,e=null,o):n},o.startAngle=function(t){return arguments.length?(r="function"==typeof t?t:Yn(+t),o):r},o.endAngle=function(t){return arguments.length?(i="function"==typeof t?t:Yn(+t),o):i},o.padAngle=function(t){return arguments.length?(a="function"==typeof t?t:Yn(+t),o):a},o},arc:function(){var t=yr,e=br,n=Yn(0),r=null,i=wr,a=Mr,o=xr,s=null,u=vr(l);function l(){var l,c,f=+t.apply(this,arguments),h=+e.apply(this,arguments),d=i.apply(this,arguments)-ur,p=a.apply(this,arguments)-ur,m=Zn(p-d),g=p>d;if(s||(s=l=u()),h<f&&(c=h,h=f,f=c),h>or)if(m>lr-or)s.moveTo(h*er(d),h*ir(d)),s.arc(0,0,h,d,p,!g),f>or&&(s.moveTo(f*er(p),f*ir(p)),s.arc(0,0,f,p,d,g));else{var v,y,b=d,w=p,M=d,x=p,S=m,N=m,E=o.apply(this,arguments)/2,A=E>or&&(r?+r.apply(this,arguments):ar(f*f+h*h)),C=rr(Zn(h-f)/2,+n.apply(this,arguments)),q=C,k=C;if(A>or){var _=cr(A/f*ir(E)),F=cr(A/h*ir(E));(S-=2*_)>or?(M+=_*=g?1:-1,x-=_):(S=0,M=x=(d+p)/2),(N-=2*F)>or?(b+=F*=g?1:-1,w-=F):(N=0,b=w=(d+p)/2)}var T=h*er(b),D=h*ir(b),I=f*er(x),V=f*ir(x);if(C>or){var z,P=h*er(w),R=h*ir(w),O=f*er(M),L=f*ir(M);if(m<sr)if(z=function(t,e,n,r,i,a,o,s){var u=n-t,l=r-e,c=o-i,f=s-a,h=f*u-c*l;if(!(h*h<or))return[t+(h=(c*(e-a)-f*(t-i))/h)*u,e+h*l]}(T,D,O,L,P,R,I,V)){var j=T-z[0],B=D-z[1],$=P-z[0],W=R-z[1],H=1/ir(function(t){return t>1?0:t<-1?sr:Math.acos(t)}((j*$+B*W)/(ar(j*j+B*B)*ar($*$+W*W)))/2),G=ar(z[0]*z[0]+z[1]*z[1]);q=rr(C,(f-G)/(H-1)),k=rr(C,(h-G)/(H+1))}else q=k=0}N>or?k>or?(v=Sr(O,L,T,D,h,k,g),y=Sr(P,R,I,V,h,k,g),s.moveTo(v.cx+v.x01,v.cy+v.y01),k<C?s.arc(v.cx,v.cy,k,tr(v.y01,v.x01),tr(y.y01,y.x01),!g):(s.arc(v.cx,v.cy,k,tr(v.y01,v.x01),tr(v.y11,v.x11),!g),s.arc(0,0,h,tr(v.cy+v.y11,v.cx+v.x11),tr(y.cy+y.y11,y.cx+y.x11),!g),s.arc(y.cx,y.cy,k,tr(y.y11,y.x11),tr(y.y01,y.x01),!g))):(s.moveTo(T,D),s.arc(0,0,h,b,w,!g)):s.moveTo(T,D),f>or&&S>or?q>or?(v=Sr(I,V,P,R,f,-q,g),y=Sr(T,D,O,L,f,-q,g),s.lineTo(v.cx+v.x01,v.cy+v.y01),q<C?s.arc(v.cx,v.cy,q,tr(v.y01,v.x01),tr(y.y01,y.x01),!g):(s.arc(v.cx,v.cy,q,tr(v.y01,v.x01),tr(v.y11,v.x11),!g),s.arc(0,0,f,tr(v.cy+v.y11,v.cx+v.x11),tr(y.cy+y.y11,y.cx+y.x11),g),s.arc(y.cx,y.cy,q,tr(y.y11,y.x11),tr(y.y01,y.x01),!g))):s.arc(0,0,f,x,M,g):s.lineTo(I,V)}else s.moveTo(0,0);if(s.closePath(),l)return s=null,l+""||null}return l.centroid=function(){var n=(+t.apply(this,arguments)+ +e.apply(this,arguments))/2,r=(+i.apply(this,arguments)+ +a.apply(this,arguments))/2-sr/2;return[er(r)*n,ir(r)*n]},l.innerRadius=function(e){return arguments.length?(t="function"==typeof e?e:Yn(+e),l):t},l.outerRadius=function(t){return arguments.length?(e="function"==typeof t?t:Yn(+t),l):e},l.cornerRadius=function(t){return arguments.length?(n="function"==typeof t?t:Yn(+t),l):n},l.padRadius=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:Yn(+t),l):r},l.startAngle=function(t){return arguments.length?(i="function"==typeof t?t:Yn(+t),l):i},l.endAngle=function(t){return arguments.length?(a="function"==typeof t?t:Yn(+t),l):a},l.padAngle=function(t){return arguments.length?(o="function"==typeof t?t:Yn(+t),l):o},l.context=function(t){return arguments.length?(s=null==t?null:t,l):s},l},schemeCategory10:Qn,interpolateViridis:Jn,interpolateRdYlBu:Un},Vr=/*#__PURE__*/function(){function t(t){void 0===t&&(t="dataviz-container"),this.containerId=t,this.defaultWidth=800,this.defaultHeight=600,this.defaultMargin={top:40,right:40,bottom:60,left:60},this.colors=Ir.schemeCategory10}var e=t.prototype;return e.createContainer=function(t,e,n){void 0===e&&(e=this.defaultWidth),void 0===n&&(n=this.defaultHeight);var r=t||this.containerId,i=Ir.select("#"+r);i.empty()&&(i=Ir.select("body").append("div").attr("id",r).style("margin","20px")),i.selectAll("*").remove();var a=i.append("svg").attr("width",e).attr("height",n).style("background","#fff").style("border","1px solid #ddd").style("border-radius","8px");return{container:i,svg:a}},e.histogram=function(t,e){void 0===e&&(e={});var n=e.title,r=void 0===n?"Histogram":n,i=e.xlabel,a=void 0===i?"Value":i,o=e.ylabel,s=void 0===o?"Frequency":o,u=e.bins,l=void 0===u?30:u,c=e.color,f=void 0===c?"#4299e1":c,h=e.width,d=void 0===h?this.defaultWidth:h,p=e.height,m=void 0===p?this.defaultHeight:p,g=e.containerId,v=this.createContainer(void 0===g?null:g,d,m).svg,y=this.defaultMargin,b=d-y.left-y.right,w=m-y.top-y.bottom,M=v.append("g").attr("transform","translate("+y.left+","+y.top+")"),x=Ir.scaleLinear().domain(Ir.extent(t)).range([0,b]),S=Ir.histogram().domain(x.domain()).thresholds(x.ticks(l))(t),N=Ir.scaleLinear().domain([0,Ir.max(S,function(t){return t.length})]).range([w,0]);return M.selectAll("rect").data(S).join("rect").attr("x",function(t){return x(t.x0)+1}).attr("width",function(t){return Math.max(0,x(t.x1)-x(t.x0)-2)}).attr("y",function(t){return N(t.length)}).attr("height",function(t){return w-N(t.length)}).attr("fill",f).attr("opacity",.8).on("mouseover",function(){Ir.select(this).attr("opacity",1)}).on("mouseout",function(){Ir.select(this).attr("opacity",.8)}),M.append("g").attr("transform","translate(0,"+w+")").call(Ir.axisBottom(x)).append("text").attr("x",b/2).attr("y",40).attr("fill","#000").attr("text-anchor","middle").text(a),M.append("g").call(Ir.axisLeft(N)).append("text").attr("transform","rotate(-90)").attr("x",-w/2).attr("y",-40).attr("fill","#000").attr("text-anchor","middle").text(s),v.append("text").attr("x",d/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(r),this},e.boxplot=function(t,e){void 0===e&&(e={});var n=e.title,r=void 0===n?"Box Plot":n,i=e.xlabel,a=void 0===i?"Category":i,o=e.ylabel,s=void 0===o?"Value":o,u=e.labels,l=void 0===u?null:u,c=e.color,f=void 0===c?"#4299e1":c,h=e.width,d=void 0===h?this.defaultWidth:h,p=e.height,m=void 0===p?this.defaultHeight:p,g=e.containerId,v=this.createContainer(void 0===g?null:g,d,m).svg,y=this.defaultMargin,b=d-y.left-y.right,w=m-y.top-y.bottom,M=v.append("g").attr("transform","translate("+y.left+","+y.top+")"),x=Array.isArray(t[0])?t:[t],S=l||x.map(function(t,e){return"Group "+(e+1)}),N=x.map(function(t,e){var n=[].concat(t).sort(function(t,e){return t-e}),r=Ir.quantile(n,.25),i=Ir.quantile(n,.5),a=Ir.quantile(n,.75),o=a-r,s=Math.max(Ir.min(n),r-1.5*o),u=Math.min(Ir.max(n),a+1.5*o),l=n.filter(function(t){return t<s||t>u});return{label:S[e],q1:r,median:i,q3:a,min:s,max:u,outliers:l}}),E=Ir.scaleBand().domain(S).range([0,b]).padding(.3),A=Ir.scaleLinear().domain([Ir.min(N,function(t){return t.min}),Ir.max(N,function(t){return t.max})]).nice().range([w,0]);return N.forEach(function(t,e){var n=E(t.label)+E.bandwidth()/2,r=E.bandwidth();M.append("line").attr("x1",n).attr("x2",n).attr("y1",A(t.min)).attr("y2",A(t.max)).attr("stroke","#000").attr("stroke-width",1),M.append("rect").attr("x",E(t.label)).attr("y",A(t.q3)).attr("width",r).attr("height",A(t.q1)-A(t.q3)).attr("fill",f).attr("stroke","#000").attr("opacity",.7),M.append("line").attr("x1",E(t.label)).attr("x2",E(t.label)+r).attr("y1",A(t.median)).attr("y2",A(t.median)).attr("stroke","#000").attr("stroke-width",2),[t.min,t.max].forEach(function(t){M.append("line").attr("x1",n-r/4).attr("x2",n+r/4).attr("y1",A(t)).attr("y2",A(t)).attr("stroke","#000").attr("stroke-width",1)}),t.outliers.forEach(function(t){M.append("circle").attr("cx",n).attr("cy",A(t)).attr("r",3).attr("fill","red").attr("opacity",.6)})}),M.append("g").attr("transform","translate(0,"+w+")").call(Ir.axisBottom(E)).append("text").attr("x",b/2).attr("y",40).attr("fill","#000").attr("text-anchor","middle").text(a),M.append("g").call(Ir.axisLeft(A)).append("text").attr("transform","rotate(-90)").attr("x",-w/2).attr("y",-40).attr("fill","#000").attr("text-anchor","middle").text(s),v.append("text").attr("x",d/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(r),this},e.scatter=function(t,e,n){void 0===n&&(n={});var r=n.title,i=void 0===r?"Scatter Plot":r,a=n.xlabel,o=void 0===a?"X":a,s=n.ylabel,u=void 0===s?"Y":s,l=n.color,c=void 0===l?"#4299e1":l,f=n.size,h=void 0===f?5:f,d=n.labels,p=void 0===d?null:d,m=n.width,g=void 0===m?this.defaultWidth:m,v=n.height,y=void 0===v?this.defaultHeight:v,b=n.containerId,w=this.createContainer(void 0===b?null:b,g,y).svg,M=this.defaultMargin,x=g-M.left-M.right,S=y-M.top-M.bottom,N=w.append("g").attr("transform","translate("+M.left+","+M.top+")"),E=t.map(function(t,n){return{x:t,y:e[n],label:p?p[n]:null}}),A=Ir.scaleLinear().domain(Ir.extent(t)).nice().range([0,x]),C=Ir.scaleLinear().domain(Ir.extent(e)).nice().range([S,0]),q=Ir.select("body").append("div").style("position","absolute").style("background","rgba(0,0,0,0.8)").style("color","#fff").style("padding","8px").style("border-radius","4px").style("font-size","12px").style("pointer-events","none").style("opacity",0);return N.selectAll("circle").data(E).join("circle").attr("cx",function(t){return A(t.x)}).attr("cy",function(t){return C(t.y)}).attr("r",h).attr("fill",c).attr("opacity",.7).on("mouseover",function(t,e){Ir.select(this).attr("r",1.5*h).attr("opacity",1),q.style("opacity",1).html("X: "+e.x.toFixed(2)+"<br>Y: "+e.y.toFixed(2)+(e.label?"<br>"+e.label:"")).style("left",t.pageX+10+"px").style("top",t.pageY-10+"px")}).on("mouseout",function(){Ir.select(this).attr("r",h).attr("opacity",.7),q.style("opacity",0)}),N.append("g").attr("transform","translate(0,"+S+")").call(Ir.axisBottom(A)).append("text").attr("x",x/2).attr("y",40).attr("fill","#000").attr("text-anchor","middle").text(o),N.append("g").call(Ir.axisLeft(C)).append("text").attr("transform","rotate(-90)").attr("x",-S/2).attr("y",-40).attr("fill","#000").attr("text-anchor","middle").text(u),w.append("text").attr("x",g/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(i),this},e.line=function(t,e,n){void 0===n&&(n={});var r=n.title,i=void 0===r?"Line Chart":r,a=n.xlabel,o=void 0===a?"X":a,s=n.ylabel,u=void 0===s?"Y":s,l=n.color,c=void 0===l?"#4299e1":l,f=n.lineWidth,h=void 0===f?2:f,d=n.showPoints,p=void 0===d||d,m=n.width,g=void 0===m?this.defaultWidth:m,v=n.height,y=void 0===v?this.defaultHeight:v,b=n.containerId,w=this.createContainer(void 0===b?null:b,g,y).svg,M=this.defaultMargin,x=g-M.left-M.right,S=y-M.top-M.bottom,N=w.append("g").attr("transform","translate("+M.left+","+M.top+")"),E=t.map(function(t,n){return{x:t,y:e[n]}}),A=Ir.scaleLinear().domain(Ir.extent(t)).range([0,x]),C=Ir.scaleLinear().domain(Ir.extent(e)).nice().range([S,0]),q=Ir.line().x(function(t){return A(t.x)}).y(function(t){return C(t.y)});return N.append("path").datum(E).attr("fill","none").attr("stroke",c).attr("stroke-width",h).attr("d",q),p&&N.selectAll("circle").data(E).join("circle").attr("cx",function(t){return A(t.x)}).attr("cy",function(t){return C(t.y)}).attr("r",4).attr("fill",c),N.append("g").attr("transform","translate(0,"+S+")").call(Ir.axisBottom(A)).append("text").attr("x",x/2).attr("y",40).attr("fill","#000").attr("text-anchor","middle").text(o),N.append("g").call(Ir.axisLeft(C)).append("text").attr("transform","rotate(-90)").attr("x",-S/2).attr("y",-40).attr("fill","#000").attr("text-anchor","middle").text(u),w.append("text").attr("x",g/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(i),this},e.bar=function(t,e,n){void 0===n&&(n={});var r=n.title,i=void 0===r?"Bar Chart":r,a=n.xlabel,o=void 0===a?"Category":a,s=n.ylabel,u=void 0===s?"Value":s,l=n.color,c=void 0===l?"#4299e1":l,f=n.horizontal,h=void 0!==f&&f,d=n.width,p=void 0===d?this.defaultWidth:d,m=n.height,g=void 0===m?this.defaultHeight:m,v=n.containerId,y=this.createContainer(void 0===v?null:v,p,g).svg,b=this.defaultMargin,w=p-b.left-b.right,M=g-b.top-b.bottom,x=y.append("g").attr("transform","translate("+b.left+","+b.top+")"),S=t.map(function(t,n){return{category:t,value:e[n]}});if(h){var N=Ir.scaleLinear().domain([0,Ir.max(e)]).nice().range([0,w]),E=Ir.scaleBand().domain(t).range([0,M]).padding(.2);x.selectAll("rect").data(S).join("rect").attr("x",0).attr("y",function(t){return E(t.category)}).attr("width",function(t){return N(t.value)}).attr("height",E.bandwidth()).attr("fill",c).attr("opacity",.8).on("mouseover",function(){Ir.select(this).attr("opacity",1)}).on("mouseout",function(){Ir.select(this).attr("opacity",.8)}),x.append("g").attr("transform","translate(0,"+M+")").call(Ir.axisBottom(N)),x.append("g").call(Ir.axisLeft(E))}else{var A=Ir.scaleBand().domain(t).range([0,w]).padding(.2),C=Ir.scaleLinear().domain([0,Ir.max(e)]).nice().range([M,0]);x.selectAll("rect").data(S).join("rect").attr("x",function(t){return A(t.category)}).attr("y",function(t){return C(t.value)}).attr("width",A.bandwidth()).attr("height",function(t){return M-C(t.value)}).attr("fill",c).attr("opacity",.8).on("mouseover",function(){Ir.select(this).attr("opacity",1)}).on("mouseout",function(){Ir.select(this).attr("opacity",.8)}),x.append("g").attr("transform","translate(0,"+M+")").call(Ir.axisBottom(A)).selectAll("text").attr("transform","rotate(-45)").style("text-anchor","end"),x.append("g").call(Ir.axisLeft(C))}return y.append("text").attr("x",p/2).attr("y",g-10).attr("text-anchor","middle").text(o),y.append("text").attr("transform","rotate(-90)").attr("x",-g/2).attr("y",15).attr("text-anchor","middle").text(u),y.append("text").attr("x",p/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(i),this},e.pie=function(t,e,n){void 0===n&&(n={});var r=n.title,i=void 0===r?"Pie Chart":r,a=n.width,o=void 0===a?this.defaultWidth:a,s=n.height,u=void 0===s?this.defaultHeight:s,l=n.showLabels,c=void 0===l||l,f=n.showPercentage,h=void 0===f||f,d=n.containerId,p=this.createContainer(void 0===d?null:d,o,u).svg,m=Math.min(o,u)/2-40,g=p.append("g").attr("transform","translate("+o/2+","+u/2+")"),v=t.map(function(t,n){return{label:t,value:e[n]}}),y=Ir.sum(e),b=Ir.scaleOrdinal().domain(t).range(this.colors),w=Ir.pie().value(function(t){return t.value}),M=Ir.arc().innerRadius(0).outerRadius(m),x=Ir.arc().innerRadius(.7*m).outerRadius(.7*m),S=g.selectAll("arc").data(w(v)).join("g").attr("class","arc");return S.append("path").attr("d",M).attr("fill",function(t){return b(t.data.label)}).attr("stroke","#fff").attr("stroke-width",2).attr("opacity",.8).on("mouseover",function(){Ir.select(this).attr("opacity",1)}).on("mouseout",function(){Ir.select(this).attr("opacity",.8)}),c&&S.append("text").attr("transform",function(t){return"translate("+x.centroid(t)+")"}).attr("text-anchor","middle").style("font-size","12px").style("font-weight","bold").style("fill","#fff").text(function(t){if(h){var e=(t.data.value/y*100).toFixed(1);return t.data.label+"\n"+e+"%"}return t.data.label}),p.append("text").attr("x",o/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(i),this},e.heatmap=function(t,e){void 0===e&&(e={});for(var n=e.title,r=void 0===n?"Heatmap":n,i=e.labels,a=void 0===i?null:i,o=e.colorScheme,s=void 0===o?"RdYlBu":o,u=e.showValues,l=void 0===u||u,c=e.width,f=void 0===c?this.defaultWidth:c,h=e.height,d=void 0===h?this.defaultHeight:h,p=e.containerId,m=this.createContainer(void 0===p?null:p,f,d).svg,g=f-80-40,v=d-80-80,y=m.append("g").attr("transform","translate(80,80)"),b=t.length,w=a||Array.from({length:b},function(t,e){return"Var"+(e+1)}),M=a||Array.from({length:b},function(t,e){return"Var"+(e+1)}),x=[],S=0;S<b;S++)for(var N=0;N<b;N++)x.push({row:S,col:N,value:t[S][N],rowLabel:w[S],colLabel:M[N]});var E=Ir.scaleBand().domain(M).range([0,g]).padding(.05),A=Ir.scaleBand().domain(w).range([0,v]).padding(.05),C=Ir.scaleSequential().domain([-1,1]).interpolator(Ir["interpolate"+s]);y.selectAll("rect").data(x).join("rect").attr("x",function(t){return E(t.colLabel)}).attr("y",function(t){return A(t.rowLabel)}).attr("width",E.bandwidth()).attr("height",A.bandwidth()).attr("fill",function(t){return C(t.value)}).attr("stroke","#fff").attr("stroke-width",1),l&&y.selectAll("text.value").data(x).join("text").attr("class","value").attr("x",function(t){return E(t.colLabel)+E.bandwidth()/2}).attr("y",function(t){return A(t.rowLabel)+A.bandwidth()/2}).attr("text-anchor","middle").attr("dominant-baseline","middle").style("font-size","10px").style("fill",function(t){return Math.abs(t.value)>.5?"#fff":"#000"}).text(function(t){return t.value.toFixed(2)}),y.append("g").attr("transform","translate(0,"+v+")").call(Ir.axisBottom(E)).selectAll("text").attr("transform","rotate(-45)").style("text-anchor","end"),y.append("g").call(Ir.axisLeft(A));var q=m.append("g").attr("transform","translate("+(f-40-200)+",40)"),k=Ir.scaleLinear().domain([-1,1]).range([0,200]),_=Ir.axisBottom(k).ticks(5);return q.selectAll("rect").data(Ir.range(-1,1,.01)).join("rect").attr("x",function(t){return k(t)}).attr("y",0).attr("width",1).attr("height",20).attr("fill",function(t){return C(t)}),q.append("g").attr("transform","translate(0,20)").call(_),m.append("text").attr("x",f/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(r),this},e.violin=function(t,e){void 0===e&&(e={});var n=e.title,r=void 0===n?"Violin Plot":n,i=e.xlabel,a=void 0===i?"Category":i,o=e.ylabel,s=void 0===o?"Value":o,u=e.labels,l=void 0===u?null:u,c=e.color,f=void 0===c?"#4299e1":c,h=e.width,d=void 0===h?this.defaultWidth:h,p=e.height,m=void 0===p?this.defaultHeight:p,g=e.containerId,v=this.createContainer(void 0===g?null:g,d,m).svg,y=this.defaultMargin,b=d-y.left-y.right,w=m-y.top-y.bottom,M=v.append("g").attr("transform","translate("+y.left+","+y.top+")"),x=Array.isArray(t[0])?t:[t],S=l||x.map(function(t,e){return"Group "+(e+1)}),N=Ir.scaleBand().domain(S).range([0,b]).padding(.3),E=x.flat(),A=Ir.scaleLinear().domain(Ir.extent(E)).nice().range([w,0]);return x.forEach(function(t,e){var n=function(t,e){return void 0===e&&(e=.5),A.ticks(50).map(function(n){var r=Ir.mean(t,function(t){return Math.exp(-.5*Math.pow((t-n)/e,2))/(e*Math.sqrt(2*Math.PI))});return[n,r]})}(t),r=Ir.max(n,function(t){return t[1]}),i=Ir.scaleLinear().domain([0,r]).range([0,N.bandwidth()/2]),a=Ir.area().x0(function(t){return N(S[e])+N.bandwidth()/2-i(t[1])}).x1(function(t){return N(S[e])+N.bandwidth()/2+i(t[1])}).y(function(t){return A(t[0])}).curve(Ir.curveBasis);M.append("path").datum(n).attr("fill",f).attr("opacity",.6).attr("stroke","#000").attr("stroke-width",1).attr("d",a)}),M.append("g").attr("transform","translate(0,"+w+")").call(Ir.axisBottom(N)).append("text").attr("x",b/2).attr("y",40).attr("fill","#000").attr("text-anchor","middle").text(a),M.append("g").call(Ir.axisLeft(A)).append("text").attr("transform","rotate(-90)").attr("x",-w/2).attr("y",-40).attr("fill","#000").attr("text-anchor","middle").text(s),v.append("text").attr("x",d/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(r),this},e.qqplot=function(t,e){var n=this;void 0===e&&(e={});var r=e.title,i=void 0===r?"Q-Q Plot":r,a=e.xlabel,o=void 0===a?"Theoretical Quantiles":a,s=e.ylabel,u=void 0===s?"Sample Quantiles":s,l=e.color,c=void 0===l?"#4299e1":l,f=e.width,h=void 0===f?this.defaultWidth:f,d=e.height,p=void 0===d?this.defaultHeight:d,m=e.containerId,g=this.createContainer(void 0===m?null:m,h,p).svg,v=this.defaultMargin,y=h-v.left-v.right,b=p-v.top-v.bottom,w=g.append("g").attr("transform","translate("+v.left+","+v.top+")"),M=[].concat(t).sort(function(t,e){return t-e}),x=M.length,S=M.map(function(t,e){return n.invNormalCDF((e+.5)/x)}),N=S.map(function(t,e){return{x:t,y:M[e]}}),E=Ir.scaleLinear().domain(Ir.extent(S)).nice().range([0,y]),A=Ir.scaleLinear().domain(Ir.extent(M)).nice().range([b,0]),C=Math.max(E.domain()[0],A.domain()[0]),q=Math.min(E.domain()[1],A.domain()[1]);return w.append("line").attr("x1",E(C)).attr("y1",A(C)).attr("x2",E(q)).attr("y2",A(q)).attr("stroke","red").attr("stroke-width",2).attr("stroke-dasharray","5,5"),w.selectAll("circle").data(N).join("circle").attr("cx",function(t){return E(t.x)}).attr("cy",function(t){return A(t.y)}).attr("r",4).attr("fill",c).attr("opacity",.7),w.append("g").attr("transform","translate(0,"+b+")").call(Ir.axisBottom(E)).append("text").attr("x",y/2).attr("y",40).attr("fill","#000").attr("text-anchor","middle").text(o),w.append("g").call(Ir.axisLeft(A)).append("text").attr("transform","rotate(-90)").attr("x",-b/2).attr("y",-40).attr("fill","#000").attr("text-anchor","middle").text(u),g.append("text").attr("x",h/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(i),this},e.invNormalCDF=function(t){var e,n,r=-.00778489400243029,i=-.322396458041136,a=-2.40075827716184,o=-2.54973253934373,s=4.37466414146497,u=2.93816398269878,l=.00778469570904146,c=.32246712907004,f=2.445134137143,h=3.75440866190742;return t<.02425?(((((r*(e=Math.sqrt(-2*Math.log(t)))+i)*e+a)*e+o)*e+s)*e+u)/((((l*e+c)*e+f)*e+h)*e+1):t<=.97575?(((((-39.6968302866538*(n=(e=t-.5)*e)+220.946098424521)*n-275.928510446969)*n+138.357751867269)*n-30.6647980661472)*n+2.50662827745924)*e/(((((-54.4760987982241*n+161.585836858041)*n-155.698979859887)*n+66.8013118877197)*n-13.2806815528857)*n+1):-(((((r*(e=Math.sqrt(-2*Math.log(1-t)))+i)*e+a)*e+o)*e+s)*e+u)/((((l*e+c)*e+f)*e+h)*e+1)},e.density=function(t,e){void 0===e&&(e={});var n=e.title,r=void 0===n?"Density Plot":n,i=e.xlabel,a=void 0===i?"Value":i,o=e.ylabel,s=void 0===o?"Density":o,u=e.color,l=void 0===u?"#4299e1":u,c=e.bandwidth,f=void 0===c?null:c,h=e.width,d=void 0===h?this.defaultWidth:h,p=e.height,m=void 0===p?this.defaultHeight:p,g=e.containerId,v=this.createContainer(void 0===g?null:g,d,m).svg,y=this.defaultMargin,b=d-y.left-y.right,w=m-y.top-y.bottom,M=v.append("g").attr("transform","translate("+y.left+","+y.top+")"),x=f||1.06*Ir.deviation(t)*Math.pow(t.length,-.2),S=Ir.extent(t),N=S[1]-S[0],E=Ir.range(S[0]-.1*N,S[1]+.1*N,N/200),A=E.map(function(e){var n=Ir.mean(t,function(t){return Math.exp(-.5*Math.pow((t-e)/x,2))/(x*Math.sqrt(2*Math.PI))});return{x:e,y:n}}),C=Ir.scaleLinear().domain([E[0],E[E.length-1]]).range([0,b]),q=Ir.scaleLinear().domain([0,Ir.max(A,function(t){return t.y})]).nice().range([w,0]),k=Ir.area().x(function(t){return C(t.x)}).y0(w).y1(function(t){return q(t.y)}).curve(Ir.curveBasis),_=Ir.line().x(function(t){return C(t.x)}).y(function(t){return q(t.y)}).curve(Ir.curveBasis);return M.append("path").datum(A).attr("fill",l).attr("opacity",.3).attr("d",k),M.append("path").datum(A).attr("fill","none").attr("stroke",l).attr("stroke-width",2).attr("d",_),M.append("g").attr("transform","translate(0,"+w+")").call(Ir.axisBottom(C)).append("text").attr("x",b/2).attr("y",40).attr("fill","#000").attr("text-anchor","middle").text(a),M.append("g").call(Ir.axisLeft(q)).append("text").attr("transform","rotate(-90)").attr("x",-w/2).attr("y",-40).attr("fill","#000").attr("text-anchor","middle").text(s),v.append("text").attr("x",d/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(r),this},e.parallel=function(t,e,n){void 0===n&&(n={});var r=n.title,i=void 0===r?"Parallel Coordinates":r,a=n.colors,o=void 0===a?null:a,s=n.width,u=void 0===s?this.defaultWidth:s,l=n.height,c=void 0===l?this.defaultHeight:l,f=n.containerId,h=this.createContainer(void 0===f?null:f,u,c).svg,d=u-40-40,p=c-60-40,m=h.append("g").attr("transform","translate(40,60)"),g={};e.forEach(function(e){g[e]=Ir.scaleLinear().domain(Ir.extent(t,function(t){return t[e]})).range([p,0])});var v=Ir.scalePoint().domain(e).range([0,d]),y=Ir.line(),b=o?Ir.scaleOrdinal().domain(Ir.range(t.length)).range(o):Ir.scaleSequential(Ir.interpolateViridis).domain([0,t.length]);return m.selectAll("path.line").data(t).join("path").attr("class","line").attr("d",function(t){return y(e.map(function(e){return[v(e),g[e](t[e])]}))}).attr("fill","none").attr("stroke",function(t,e){return b(e)}).attr("opacity",.3).attr("stroke-width",2).on("mouseover",function(){Ir.select(this).attr("opacity",1).attr("stroke-width",3)}).on("mouseout",function(){Ir.select(this).attr("opacity",.3).attr("stroke-width",2)}),e.forEach(function(t){m.append("g").attr("transform","translate("+v(t)+",0)").call(Ir.axisLeft(g[t])).append("text").attr("y",-10).attr("text-anchor","middle").style("fill","#000").style("font-weight","bold").text(t)}),h.append("text").attr("x",u/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(i),this},e.pairplot=function(t,e,n){void 0===n&&(n={});var r=n.title,i=void 0===r?"Pair Plot":r,a=n.color,o=void 0===a?"#4299e1":a,s=n.size,u=void 0===s?3:s,l=n.width,c=void 0===l?900:l,f=n.height,h=void 0===f?900:f,d=n.containerId,p=this.createContainer(void 0===d?null:d,c,h).svg,m=e.length,g=(Math.min(c,h)-120)/m,v={};e.forEach(function(e){v[e]=Ir.scaleLinear().domain(Ir.extent(t,function(t){return t[e]})).range([0,g-20])});for(var y=0;y<m;y++)for(var b=function(){var n=e[w],r=e[y],i=p.append("g").attr("transform","translate("+(60+w*g)+","+(60+y*g)+")");if(y===w){var a=t.map(function(t){return t[n]}),s=Ir.histogram().domain(v[n].domain()).thresholds(20)(a),l=Ir.scaleLinear().domain([0,Ir.max(s,function(t){return t.length})]).range([g-20,0]);i.selectAll("rect").data(s).join("rect").attr("x",function(t){return v[n](t.x0)}).attr("y",function(t){return l(t.length)}).attr("width",function(t){return v[n](t.x1)-v[n](t.x0)-1}).attr("height",function(t){return g-20-l(t.length)}).attr("fill",o).attr("opacity",.7)}else i.selectAll("circle").data(t).join("circle").attr("cx",function(t){return v[n](t[n])}).attr("cy",function(t){return v[r](t[r])}).attr("r",u).attr("fill",o).attr("opacity",.5);y===m-1&&i.append("g").attr("transform","translate(0,"+(g-20)+")").call(Ir.axisBottom(v[n]).ticks(3)),0===w&&i.append("g").call(Ir.axisLeft(v[r]).ticks(3)),y===m-1&&i.append("text").attr("x",(g-20)/2).attr("y",g-5).attr("text-anchor","middle").style("font-size","10px").text(n),0===w&&i.append("text").attr("transform","rotate(-90)").attr("x",-(g-20)/2).attr("y",-25).attr("text-anchor","middle").style("font-size","10px").text(r)},w=0;w<m;w++)b();return p.append("text").attr("x",c/2).attr("y",30).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(i),this},e.multiline=function(t,e){void 0===e&&(e={});var n=e.title,r=void 0===n?"Multi-Line Chart":n,i=e.xlabel,a=void 0===i?"X":i,o=e.ylabel,s=void 0===o?"Y":o,u=e.legend,l=void 0===u||u,c=e.width,f=void 0===c?this.defaultWidth:c,h=e.height,d=void 0===h?this.defaultHeight:h,p=e.containerId,m=this.createContainer(void 0===p?null:p,f,d).svg,g=this.defaultMargin,v=f-g.left-g.right,y=d-g.top-g.bottom,b=m.append("g").attr("transform","translate("+g.left+","+g.top+")"),w=t.flatMap(function(t){return t.data.map(function(t){return t.x})}),M=t.flatMap(function(t){return t.data.map(function(t){return t.y})}),x=Ir.scaleLinear().domain(Ir.extent(w)).range([0,v]),S=Ir.scaleLinear().domain(Ir.extent(M)).nice().range([y,0]),N=Ir.scaleOrdinal().domain(t.map(function(t){return t.name})).range(this.colors),E=Ir.line().x(function(t){return x(t.x)}).y(function(t){return S(t.y)});if(t.forEach(function(t){b.append("path").datum(t.data).attr("fill","none").attr("stroke",N(t.name)).attr("stroke-width",2).attr("d",E)}),b.append("g").attr("transform","translate(0,"+y+")").call(Ir.axisBottom(x)).append("text").attr("x",v/2).attr("y",40).attr("fill","#000").attr("text-anchor","middle").text(a),b.append("g").call(Ir.axisLeft(S)).append("text").attr("transform","rotate(-90)").attr("x",-y/2).attr("y",-40).attr("fill","#000").attr("text-anchor","middle").text(s),l){var A=m.append("g").attr("transform","translate("+(f-g.right-100)+","+g.top+")");t.forEach(function(t,e){var n=A.append("g").attr("transform","translate(0,"+25*e+")");n.append("line").attr("x1",0).attr("x2",30).attr("y1",10).attr("y2",10).attr("stroke",N(t.name)).attr("stroke-width",2),n.append("text").attr("x",35).attr("y",15).style("font-size","12px").text(t.name)})}return m.append("text").attr("x",f/2).attr("y",20).attr("text-anchor","middle").style("font-size","16px").style("font-weight","bold").text(r),this},t}(),zr=/*#__PURE__*/function(){function t(){this.dataLoader=new c,this.validator=new f,this.utils=new h,this.centralTendency=new d,this.dispersion=new p,this.position=new m,this.shape=new g,this.hypothesisTesting=new v,this.confidenceIntervals=new y,this.normalityTests=new b,this.correlation=new w,this.regression=new M,this.reportGenerator=new x,this.patternDetector=new S,this.interpreter=new N,this.autoAnalyzer=new E(this),this.ml=new I,this.viz=new Vr}var e=t.prototype;return e.loadCSV=function(t,e){void 0===e&&(e={});try{return Promise.resolve(this.dataLoader.loadCSV(t,e))}catch(t){return Promise.reject(t)}},e.loadJSON=function(t,e){void 0===e&&(e={});try{return Promise.resolve(this.dataLoader.loadJSON(t,e))}catch(t){return Promise.reject(t)}},e.cleanData=function(t){return this.dataLoader.cleanData(t)},e.getColumn=function(t,e){return this.dataLoader.getColumn(t,e)},e.getColumns=function(t,e){return this.dataLoader.getColumns(t,e)},e.validateData=function(t){return this.validator.validateData(t)},e.getDataInfo=function(t){return this.dataLoader.getDataInfo(t)},e.mean=function(t){return this.centralTendency.mean(t)},e.median=function(t){return this.centralTendency.median(t)},e.mode=function(t){return this.centralTendency.mode(t)},e.geometricMean=function(t){return this.centralTendency.geometricMean(t)},e.harmonicMean=function(t){return this.centralTendency.harmonicMean(t)},e.trimmedMean=function(t,e){return this.centralTendency.trimmedMean(t,e)},e.variance=function(t){return this.dispersion.variance(t)},e.standardDeviation=function(t){return this.dispersion.standardDeviation(t)},e.range=function(t){return this.dispersion.range(t)},e.interquartileRange=function(t){return this.dispersion.interquartileRange(t)},e.coefficientOfVariation=function(t){return this.dispersion.coefficientOfVariation(t)},e.meanAbsoluteDeviation=function(t){return this.dispersion.meanAbsoluteDeviation(t)},e.quantile=function(t,e){return this.position.quantile(t,e)},e.percentile=function(t,e){return this.position.percentile(t,e)},e.quartiles=function(t){return this.position.quartiles(t)},e.quintiles=function(t){return this.position.quintiles(t)},e.deciles=function(t){return this.position.deciles(t)},e.percentileRank=function(t,e){return this.position.percentileRank(t,e)},e.zScore=function(t,e){return this.position.zScore(t,e)},e.boxplotStats=function(t){return this.position.boxplotStats(t)},e.fiveNumberSummary=function(t){return this.position.fiveNumberSummary(t)},e.rank=function(t,e){return void 0===e&&(e="average"),this.position.rank(t,e)},e.normalizedRank=function(t){return this.position.normalizedRank(t)},e.standardizedValues=function(t){return this.position.standardizedValues(t)},e.skewness=function(t){return this.shape.skewness(t)},e.kurtosis=function(t){return this.shape.kurtosis(t)},e.isNormalDistribution=function(t){return this.shape.isNormalDistribution(t)},e.correlationPearson=function(t,e){return this.correlation.pearson(t,e)},e.correlationSpearman=function(t,e){return this.correlation.spearman(t,e)},e.correlationMatrix=function(t){return this.correlation.matrix(t)},e.covariance=function(t,e){return this.correlation.covariance(t,e)},e.tTest=function(t,e,n){return void 0===n&&(n="two-sample"),this.hypothesisTesting.tTest(t,e,n)},e.zTest=function(t,e,n){return this.hypothesisTesting.zTest(t,e,n)},e.anovaTest=function(t){return this.hypothesisTesting.anovaTest(t)},e.chiSquareTest=function(t,e){return this.hypothesisTesting.chiSquareTest(t,e)},e.confidenceInterval=function(t,e){return void 0===e&&(e=.95),this.confidenceIntervals.mean(t,e)},e.shapiroWilkTest=function(t){return this.normalityTests.shapiroWilk(t)},e.linearRegression=function(t,e){return this.regression.linear(t,e)},e.detectOutliers=function(t,e){return void 0===e&&(e="iqr"),this.utils.detectOutliers(t,e)},e.frequencyTable=function(t){return this.utils.frequencyTable(t)},e.groupBy=function(t,e,n){return this.utils.groupBy(t,e,n)},e.sample=function(t,e,n){return void 0===n&&(n="random"),this.utils.sample(t,e,n)},e.generateSummaryReport=function(t){return this.reportGenerator.summary(t)},e.identifyPatterns=function(t){return this.patternDetector.analyze(t)},e.interpretResults=function(t){return this.interpreter.interpret(t)},e.autoAnalyze=function(t,e){return void 0===e&&(e={}),this.autoAnalyzer.autoAnalyze(t,e)},e.autoAnalyzeFromFile=function(t,e,n){void 0===e&&(e={}),void 0===n&&(n={});try{var r,i=function(t){return a.autoAnalyze(r,n)},a=this,o=t.toLowerCase(),s=o.endsWith(".csv")?Promise.resolve(a.loadCSV(t,e)).then(function(t){r=t}):function(){if(o.endsWith(".json"))return Promise.resolve(a.loadJSON(t,e)).then(function(t){r=t});throw new Error("Formato de arquivo nĆ£o suportado. Use CSV ou JSON.")}();return Promise.resolve(s&&s.then?s.then(i):i())}catch(t){return Promise.reject(t)}},e.quickAnalysis=function(t,e){void 0===e&&(e={});try{return Promise.resolve(this.autoAnalyzeFromFile(t,{},e)).then(function(t){return console.log("\n"+"=".repeat(60)),console.log("š AUTO REPORT"),console.log("=".repeat(60)),console.log("\nš EXECUTIVE RESUME:"),console.log("⢠Total insights: "+t.summary.totalInsights),console.log("⢠Priority Insights: "+t.summary.highPriorityInsights),console.log("\nš MAIN INSIGHTS:"),t.summary.keyFindings.forEach(function(t,e){console.log(e+1+". "+t.title),console.log(" "+t.description)}),console.log("\nš” RECOMMENDATIONS:"),t.summary.recommendations.forEach(function(t,e){console.log(e+1+". "+t)}),console.log("\n"+"=".repeat(60)),t})}catch(t){return Promise.reject(t)}},e.createLinearRegression=function(t){return this.ml.createLinearRegression(t)},e.createLogisticRegression=function(t){return this.ml.createLogisticRegression(t)},e.createKNN=function(t){return this.ml.createKNN(t)},e.createDecisionTree=function(t){return this.ml.createDecisionTree(t)},e.createRandomForest=function(t){return this.ml.createRandomForest(t)},e.createNaiveBayes=function(t){return this.ml.createNaiveBayes(t)},e.createSVM=function(t){return this.ml.createSVM(t)},e.trainTestSplit=function(t,e,n,r){return void 0===n&&(n=.2),void 0===r&&(r=!0),this.ml.trainTestSplit(t,e,n,r)},e.crossValidate=function(t,e,n,r,i){return void 0===r&&(r=5),void 0===i&&(i="classification"),this.ml.crossValidate(t,e,n,r,i)},e.compareModels=function(t,e,n,r){return void 0===r&&(r="classification"),this.ml.compareModels(t,e,n,r)},e.quickTrain=function(t,e,n,r){return void 0===r&&(r={}),this.ml.quickTrain(t,e,n,r)},e.polynomialFeatures=function(t,e){return void 0===e&&(e=2),this.ml.polynomialFeatures(t,e)},e.standardScaler=function(t){return this.ml.standardScaler(t)},e.minMaxScaler=function(t,e){return void 0===e&&(e=[0,1]),this.ml.minMaxScaler(t,e)},e.rocCurve=function(t,e){return this.ml.rocCurve(t,e)},e.precisionRecallCurve=function(t,e){return this.ml.precisionRecallCurve(t,e)},e.plotHistogram=function(t,e){return this.viz.histogram(t,e)},e.plotBoxplot=function(t,e){return this.viz.boxplot(t,e)},e.plotScatter=function(t,e,n){return this.viz.scatter(t,e,n)},e.plotLine=function(t,e,n){return this.viz.line(t,e,n)},e.plotBar=function(t,e,n){return this.viz.bar(t,e,n)},e.plotPie=function(t,e,n){return this.viz.pie(t,e,n)},e.plotHeatmap=function(t,e){return this.viz.heatmap(t,e)},e.plotViolin=function(t,e){return this.viz.violin(t,e)},e.plotDensity=function(t,e){return this.viz.density(t,e)},e.plotQQ=function(t,e){return this.viz.qqplot(t,e)},e.plotParallel=function(t,e,n){return this.viz.parallel(t,e,n)},e.plotPairplot=function(t,e,n){return this.viz.pairplot(t,e,n)},e.plotMultiline=function(t,e){return this.viz.multiline(t,e)},e.plotCorrelationMatrix=function(t,e){var r=this;void 0===e&&(e={});for(var i=Object.keys(t[0]).filter(function(e){return"number"==typeof t[0][e]}),a=i.length,o=Array(a).fill(0).map(function(){return Array(a).fill(0)}),s=function(e){for(var n=function(n){var a=t.map(function(t){return t[i[e]]}),s=t.map(function(t){return t[i[n]]});o[e][n]=r.correlationPearson(a,s)},s=0;s<a;s++)n(s)},u=0;u<a;u++)s(u);return this.viz.heatmap(o,n({title:"Correlation Matrix",labels:i},e))},e.plotDistribution=function(t,e,r){void 0===r&&(r={});var i=t.map(function(t){return t[e]}).filter(function(t){return!isNaN(t)});return this.viz.histogram(i,n({title:"Distribution of "+e,xlabel:e,ylabel:"Frequency"},r))},e.plotMultipleDistributions=function(t,e,r){void 0===r&&(r={});var i=e.map(function(e){return t.map(function(t){return t[e]}).filter(function(t){return!isNaN(t)})});return this.viz.boxplot(i,n({title:"Distribution Comparison",labels:e},r))},t}();export{zr as default};
|