qesuite 1.0.28 → 1.0.29

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/index.ts CHANGED
@@ -590,7 +590,7 @@ export const Capability = {
590
590
  let lastObservations = LastObservationsChart(data, 25, 'Last 25 Observations');
591
591
  let capabilityHistogram = CreateCapabilityHistogram(data, spec);
592
592
  let capabilityPlot = CreateCapabilityPlot(data, spec);
593
-
593
+ console.log(Capability.Analysis(data, spec))
594
594
  return {
595
595
  charts: {
596
596
  IndividualValue: individualValuePlot,
@@ -780,6 +780,7 @@ export function CreateCapabilityPlot(data: number[], specification: Specificatio
780
780
  value: capability.Cpk
781
781
  }
782
782
  ]
783
+
783
784
  AddInfoTable(ctx, withinInfo, 20, chartSettings.margins.top, chartSettings.width/4, chartSettings.height - chartSettings.margins.top - chartSettings.margins.bottom, "Within");
784
785
 
785
786
  // Add Overall Information
@@ -1575,7 +1576,7 @@ export const Distributions = {
1575
1576
  let N = data.length;
1576
1577
 
1577
1578
  let Z: number[] = [];
1578
- let Y = data.sort(function (a, b){return a-b});
1579
+ let Y = [...data].sort(function (a, b){return a-b});
1579
1580
  let numSum = 0;
1580
1581
  let denSum = 0;
1581
1582
  let mean = Mean(data);
@@ -1651,9 +1652,9 @@ export const Distributions = {
1651
1652
  },
1652
1653
  KolmogorovSmirnov(data){
1653
1654
  let N = data.length;
1654
- data.sort();
1655
- let mean = Mean(data);
1656
- let std = StDev.S(data);
1655
+ let sortedData = [...data].sort();
1656
+ let mean = Mean(sortedData);
1657
+ let std = StDev.S(sortedData);
1657
1658
  let dMinusArray: number[] = [];
1658
1659
  let dPlusArray: number[] = [];
1659
1660
  for(let i = 1; i <= N; i++){
@@ -1890,6 +1891,7 @@ export function MaximumLikelihoodParameters(data: number[], distribution: string
1890
1891
 
1891
1892
  export function ParameterizedCDF(data: number[], distribution: string){
1892
1893
  let params = MaximumLikelihoodParameters(data, distribution);
1894
+
1893
1895
  // Exponential Distributions
1894
1896
  if(distribution.toLowerCase().includes("exponential")){
1895
1897
  if(distribution.includes("2")){
@@ -1938,7 +1940,7 @@ export const GoodnessOfFit = {
1938
1940
  AD(data: number[], cdf: Function){
1939
1941
  let N = data.length;
1940
1942
 
1941
- let Y = data.sort(function(a, b){return a - b});
1943
+ let Y = [...data].sort(function(a, b){return a - b});
1942
1944
 
1943
1945
  let S = 0;
1944
1946
 
@@ -1983,13 +1985,17 @@ export const GoodnessOfFit = {
1983
1985
  Test(data: number[], cdf: Function | String){
1984
1986
  let CDF: any;
1985
1987
  if(typeof cdf === "string"){
1986
- CDF = ParameterizedCDF(data, cdf)
1988
+ if(GoodnessOfFit.Distributions[cdf]){
1989
+ CDF = ParameterizedCDF(data, GoodnessOfFit.Distributions[cdf])
1990
+ }
1987
1991
  }else{
1988
1992
  CDF = cdf
1989
1993
  }
1994
+
1995
+ if(typeof CDF!== "function"){return {AD: undefined, p: undefined}}
1990
1996
  let AD = GoodnessOfFit.AndersonDarling.AD(data, CDF);
1991
1997
  let p = GoodnessOfFit.AndersonDarling.p(AD, data.length);
1992
-
1998
+
1993
1999
  return {
1994
2000
  AD: AD,
1995
2001
  p: p
@@ -2211,8 +2217,8 @@ export function IndividualDistributionPlots(data: number[]){
2211
2217
  gamma3p: QQPlotChart(data, '3-Parameter Gamma'),
2212
2218
  largestExtremeValue: QQPlotChart(data, 'Largest Extreme Value'),
2213
2219
  logistic: QQPlotChart(data, 'Logistic'),
2214
- loglogistic: QQPlotChart(data, 'LogLogistic'),
2215
- lognormal: QQPlotChart(data, 'LogNormal'),
2220
+ loglogistic: QQPlotChart(data, '2-Parameter LogLogistic'),
2221
+ lognormal: QQPlotChart(data, '2-Parameter LogNormal'),
2216
2222
  smallestExtremeValue: QQPlotChart(data, 'Smallest Extreme Value'),
2217
2223
  weibull: QQPlotChart(data, 'Weibull')
2218
2224
  }
@@ -2225,7 +2231,7 @@ export function IndividualDistributionPlots(data: number[]){
2225
2231
 
2226
2232
  export const QQPlot = {
2227
2233
  p(data: number[], method: string = 'Hazen'){
2228
- let orderedData = data.sort();
2234
+ let orderedData = [...data].sort();
2229
2235
  let PValues: number[] = [];
2230
2236
  let N = orderedData.length
2231
2237
  for(let i = 1; i <= N; i++){
@@ -2331,12 +2337,17 @@ export function MovingRange(data: any[], w: number = 2){
2331
2337
  values.push(Number(data[h + j]));
2332
2338
  }
2333
2339
 
2334
- movingRange.push(Range(values))
2340
+ movingRange.push(CalculateRange(values))
2335
2341
  }
2336
2342
 
2337
2343
  return movingRange;
2338
2344
  }
2339
-
2345
+ function CalculateRange(data: any[]) {
2346
+ let dataNumbers = data.map(d => {return Number(d)});
2347
+ let max = Math.max(...dataNumbers);
2348
+ let min = Math.min(...dataNumbers);
2349
+ return max - min
2350
+ }
2340
2351
  export const StDev = {
2341
2352
  /**
2342
2353
  * Calculates the population standard deviation of the array supplied.
@@ -2400,7 +2411,7 @@ export function Sum(data: any[]){
2400
2411
  * @customfunction
2401
2412
  * @param data An array of numbers. The numbers can be supplied as number types or strings
2402
2413
  */
2403
- export function Range(data: any[]) {
2414
+ export function Rang(data: any[]) {
2404
2415
  let dataNumbers = data.map(d => {return Number(d)});
2405
2416
  let max = Math.max(...dataNumbers);
2406
2417
  let min = Math.min(...dataNumbers);
@@ -2801,12 +2812,12 @@ function SetCanvasTextProperties(ctx: CanvasRenderingContext2D, font: EngFont){
2801
2812
  ctx.fillStyle = font.fillColor;
2802
2813
  }
2803
2814
 
2804
- function AddInfoTable(ctx: CanvasRenderingContext2D, data: {key: string, value: any}[], x: number, y: number, width: number, height: number, title: string, font?: EngFont){
2815
+ function AddInfoTable(ctx: CanvasRenderingContext2D, data: {key: string, value: any}[], x: number, y: number, width: number, height: number, title: string, lineHeight: number = 0, font?: EngFont){
2805
2816
  if(!font){font = new EngFont()}
2806
2817
  SetCanvasTextProperties(ctx, font);
2807
2818
 
2808
2819
  ctx.beginPath();
2809
- let lineHeight = Number(font.fontSize.replace("px", "")) + 30
2820
+ lineHeight = lineHeight ? lineHeight : Number(font.fontSize.replace("px", "")) + 30;
2810
2821
  // Set Title to text align center
2811
2822
  ctx.textAlign = 'center'
2812
2823
  ctx.fillText(title, x + width/2, y + Number(font.fontSize.replace("px", "")), width);
@@ -3739,8 +3750,34 @@ export function QQPlotChart(data: number[], distribution: string = 'Normal'){
3739
3750
  }
3740
3751
 
3741
3752
  let middleLineChart = new Chart([], 'function', 'Middle Line', undefined, middleLine);
3753
+
3754
+ let chart = CreateStackedChart([middleLineChart, new Chart([dataset], 'scatter')], `${distribution[0].toUpperCase()}${distribution.substring(1)} Probability Plot`, chartSettings);
3755
+
3756
+ if (distribution.toLowerCase() === "normal" || distribution.toLowerCase().includes("boxcox")) {
3757
+ let AD = GoodnessOfFit.AndersonDarling.Test(data, GoodnessOfFit.Distributions.Normal);
3758
+ let RJ = Distributions.Normal.RyanJoiner.Test(data);
3759
+ let KS = Distributions.Normal.KolmogorovSmirnov(data);
3760
+ let JB = Distributions.Normal.JarqueBera(data);
3761
+ let ctx = chart.getContext("2d");
3762
+ if(ctx){
3763
+ AddInfoTable(ctx, [{ key: "AD:", value: AD.AD }, { key: "p-value:", value: AD.p }, { key: "", value: '' }, { key: "RJ:", value: RJ.RJ }, { key: "crit.:", value: RJ.critical }, { key: "", value: "" }, { key: "KS:", value: KS.KS }, { key: "p-value:", value: KS.p }, { key: "", value: "" }, { key: "JB:", value: JB.JB }, { key: "p-value:", value: JB.p }], 1075, 150, 175, 100, "", 30);
3764
+ }
3765
+ }else{
3766
+ let dist = distribution.replace("-", "").replace("arameter", "").replace(/\s/g, "");
3767
+ if(dist.includes("2P")){
3768
+ dist = dist.replace("2P", "").concat("2P")
3769
+ }
3742
3770
 
3743
- return CreateStackedChart([middleLineChart, new Chart([dataset], 'scatter')], `${distribution[0].toUpperCase()}${distribution.substring(1)} Probability Plot`, chartSettings)
3771
+ let AD = GoodnessOfFit.AndersonDarling.Test(data, dist);
3772
+
3773
+ let ctx = chart.getContext("2d");
3774
+
3775
+ if(ctx && (AD.AD || AD.AD === Infinity || Number.isNaN(AD.AD)) && (AD.p || AD.p === Infinity || Number.isNaN(AD.p))){
3776
+ AddInfoTable(ctx, [{ key: "AD:", value: AD.AD }, { key: "p-value:", value: AD.p }], 1075, 150, 175, 100, "", 30);
3777
+ }
3778
+
3779
+ }
3780
+ return chart;
3744
3781
  }
3745
3782
 
3746
3783
  function QQDistributionModification(p: number, distribution: string){
@@ -4591,4 +4628,4 @@ function SplitObjectArrayByProp(array: any[], prop: string){
4591
4628
  }
4592
4629
  // End Measurement Systems Analysis
4593
4630
  /** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4594
- */
4631
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qesuite",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "Performs advanced statistical analysis of data. Specifically designed for engineering statistical analysis",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -0,0 +1 @@
1
+ Added Anderson-Darling goodness-of-fit results QQPlots when they are generated.