Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Calculating standard deviation of the sample not the population-Error The value entered does not match the format of the field [StdDev4]

New Here ,
May 24, 2017 May 24, 2017

Follow up onneed a custom calculation script to calculate standard deviation since I posted there and didn't get a response

I need to calculate the standard deviation of the sample not the population so how do I change the document JavaScript? Also, when I don't have any variation in my 10 values, I get a warning: JavaScript Window that says The value entered does not match the format of the field [StdDev4]

Here are the Document JavaScripts

Fields:

function GetField(oDoc, cField)

{

var oField = oDoc.getField(cField);

if(oField == null)

{

  app.alert("Error accessing field \"" + cField + "\"!", 1, 0)

}

return oField;

}

StdDev:

function standardDeviation(values)
{
// compute the standard deviation from an array of vlaues;
// compute the average of the vaues;
var stdDev = "";
  var avg = average(values);
  if(avg != "")
  {
// compute the squared difference of the values and the average;
  var squareDiffs = values.map(function(value){
    var diff = value - avg;
    var sqrDiff = diff * diff;
    return sqrDiff;
  });
  // average the squared differences;
  var avgSquareDiff = average(squareDiffs);
    stdDev = Math.sqrt(avgSquareDiff);
    } // end avg not null;
  return stdDev;
}

function average(data)
{
// compute the average of an array of values;
//sum the values in the array;
  var sum = data.reduce(function(sum, value){
    return sum + value;
  }, 0);
  // compute the average of the sum of the values if number of array elements is not 0;
  var avg = '';
  if(data.length > 0)
  {
  var avg = sum / data.length;
  }
  return avg;
  }

function sum(value)
{
// sum an array of values;
var Sum = value.reduce(function(Sum, value){
    return Sum + value;
  }, 0);
return Sum;
}

Custom Calculation Script:

var MyValues = new Array();

var MyFields = new Array("AdjustedResult5.1", "AdjustedResult5.2","AdjustedResult5.3", "AdjustedResult5.4", "AdjustedResult5.5", "AdjustedResult5.6", "AdjustedResult5.7", "AdjustedResult5.8", "AdjustedResult5.9", "AdjustedResult5.10" );

var oField;

var nField;

for(var i = 0; i < MyFields.length; i++)

{

nField = '';

nField = GetField(this, MyFields).valueAsString;

if(nField != "") MyValues.push(Number(nField));

}

event.value = standardDeviation(MyValues);

--------------------------------------------------------------------------------------------------------------------

I  have also tried this for the standard deviation of the sample:

var Ravg = Number(this.getField("AvgAdjResult.1.0").valueAsString); 

var Rsum = 0; 

var Rn = 0; 

for (var i=1; i<=10; i++) { 

var Rv = this.getField("AdjustedResult1."+i).valueAsString; 

if (Rv!="") { 

Rsum+=Math.pow((Number(Rv)-Ravg),2);

Rn++; 

if (Rn==0 || Rn==1) event.value = ""; 

else event.value = Math.sqrt(Rsum / (Rn-1));

However, I want the cell to stay blank unless there is an average calculated. Also we have low variability in our 10 replicates so the standard deviation can be zero, but I get the error mentioned above: The value entered does not match the format of the field [StdDev4] because it doesn't like to take the square root of zero. How do I make this error disappear, but the cell still have a numeric value of 0.000000?

I tried changing it to this:

var Ravg = Number(this.getField("AvgAdjResult.1.0").valueAsString);  
var Rsum = 0;  
var Rn = 0;  
for (var i=1; i<=10; i++) {  
var Rv = this.getField("AdjustedResult1."+i).valueAsString;  
if (Rv!="") {  
Rsum+=Math.pow((Number(Rv)-Ravg),2); 
Rn++;  
}  

var b =  +getField("Result1.10").value; 
var c =  Rsum / (Rn-1);
if (b==0) event.value = "";  
else if (c==0) event.value = 0.000000;
else event.value = Math.sqrt (c);

but then I don't get a result at all.

Field names are shown in bold below and an example of the data is below as well

              

Barometric
  Pressure (mm/Hg)
Result 1Result 2Result 3Result 4Result 5Result 6Result 7Result 8Result 9Result 10Average of Adjusted ResultsStandard Deviationof Adj Results%RSD for dry gas standardStandard UncertaintyExpanded Uncertainty 99%, k=3.25UoM g/210L
mmHgActualResult1.1Result1.2Result1.3Result1.4Result1.5Result1.6Result1.7Result1.8Result1.9Result1.10AvgAdjResult.1.0StdDev1RSD1StdUnc1ExpUnc1UoM1
Adjusted*AdjustedResult1.1AdjustedResult1.2AdjustedResult1.3AdjustedResult1.4AdjustedResult1.5AdjustedResult1.6AdjustedResult1.7AdjustedResult1.8AdjustedResult1.9AdjustedResult1.10

 

Barometric
  Pressure (mm/Hg)
Result 1Result 2Result 3Result 4Result 5Result 6Result 7Result 8Result 9Result 10Average of Adjusted ResultsStandard Deviation of Adj Results%RSD for dry gas standardStandard UncertaintyExpanded Uncertainty 99%, k=3.25UoM g/210L
752Actual0.0180.0180.0180.0180.0180.0180.0180.0180.0180.0180.0180.0000000.0000000.0000003.4471460.001
Adjusted*0.0180.0180.0180.0180.0180.0180.0180.0180.0180.018
752Actual0.0360.0360.0360.0360.0360.0360.0360.0360.0360.0360.0360.0000000.0000000.0000003.4471460.001
Adjusted*0.0360.0360.0360.0360.0360.0360.0360.0360.0360.036
752Actual0.0810.0810.0810.0810.0810.0810.0810.0810.0810.0810.0810.0000000.0000000.0000003.4471460.003
Adjusted*0.0820.0820.0820.0820.0820.0820.0820.0820.0820.082
752Actual0.1480.1490.1490.1490.1480.1480.1480.1480.1480.1480.1490.0004880.3276410.0364053.4491750.005
Adjusted*0.1500.1510.1510.1510.1500.1500.1500.1500.1500.150
752Actual0.2970.2970.2970.2970.2970.2970.2960.2960.2960.2960.2990.0005220.1745460.0193943.4477220.010
Adjusted*0.3000.3000.3000.3000.3000.3000.2990.2990.2990.299
TOPICS
PDF forms
681
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2017 May 24, 2017

This error message typically appears when you attempt to divide a value by zero and apply it to a field that is set up as Number.

You need to add checks to your code to prevent that from happening.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 24, 2017 May 24, 2017
LATEST

And what do you expect the Standard Deviation to be for your values?

I would set the format for the field to be "None" and see what the results are. You may need to expand the width of the field to display the entire computed value. Or you could add some console.println(() statements to display the value used in the computation in Acrobat's JavaScript Console.

For some of the values used in your calculation:

N = 10

Average = 0.017999999999999995

Average square root of difference of values and average = 1.2037062152420224e-35

Standard Deviation = 3.469446951953614e-18

The average should have been 0.018 not the irrational number 0.017999999... This value as others have a very small difference from the decimal value because of the known problem in converting decimal numbers to binary numbers. One can add some rounding to reduce this error.

One could add a rounding function with the following code:

function Round(nValue, nDec)

{

return Number(util.printf("%,101." + nDec + "f", nValue));

}

And then change the custom calculation for the standard deviation to include the rounding function and suppress the result if the rounded standard deviation is zero.

// Custom Calculation Script:

var MyValues = new Array();

var MyFields = new Array("AdjustedResult5.1", "AdjustedResult5.2","AdjustedResult5.3", "AdjustedResult5.4", "AdjustedResult5.5", "AdjustedResult5.6", "AdjustedResult5.7", "AdjustedResult5.8", "AdjustedResult5.9", "AdjustedResult5.10" );

var oField;

var nField;

for(var i = 0; i < MyFields.length; i++)

{

nField = '';

nField = GetField(this, MyFields).valueAsString;

if(nField != "") MyValues.push(Number(nField));

}

event.value = Round(standardDeviation(MyValues), 3);

if(event.value == 0)

{

event.value = "";

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines