
1. Re: Custom Calculation Script  Standard Deviation
Bernd Alheit Jun 6, 2017 6:45 AM (in response to michelled19159583)You must change your code.
E.g. you will get value of field row_1 with:
this.getField("row_1").value

2. Re: Custom Calculation Script  Standard Deviation
try67 Jun 6, 2017 7:07 AM (in response to michelled19159583)And here you can learn how to perform basic mathematical operations (like square root and power) in JS: JavaScript Math Object

3. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 6, 2017 10:43 AM (in response to michelled19159583)Right now this is working separately.
In one form field(Simplified field notation) named MEAN_2 I have:
((((row_1mean)*(row_1mean))+((row_2mean)*(row_2mean))+((row_3mean)*(row_3mean))+((ro w_4mean)*(row_4mean))+((row_5mean)*(row_5mean))+((row_6mean)*(row_6mean))+((row_7me an)*(row_7mean))+((row_8mean)*(row_8mean))+((row_9mean)*(row_9mean))+((row_10mean)*( row_10mean))+((row_11mean)*(row_11mean))+((row_12mean)*(row_12mean))+((row_13mean)*( row_13mean))+((row_14mean)*(row_14mean))+((row_15mean)*(row_15mean)))/15)
In another form field(Custom calculation script) I have:
event.value = Math.sqrt(this.getField("MEAN_2").value) ;
The second one correctly outputs the Standard deviation of the mean. But, I would like to not have two form fields. All I need is the standard deviation of the form field mean. But for some reason stdev(mean) wont work.

4. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 6, 2017 10:45 AM (in response to try67)My issue isn't writing the actually code. I just cannot seem to get any of them to actually work within Adobe Acrobat. For example, if I want the Standard Deviation of the field name mean. Example: stdev(mean). This will not work in the Custom calculation script. Can you please help me. am I missing something in front of the code?

5. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 6, 2017 10:47 AM (in response to Bernd Alheit)What must I change it to? I am stuck. row_1, row_2, etc. are imputed values that the user manually enters. My issue is I need to find an equation that will work in Adobe Acrobat that finds standard deviation of a set of numbers. Do you know how to do this?

6. Re: Custom Calculation Script  Standard Deviation
try67 Jun 6, 2017 10:49 AM (in response to michelled19159583)Why would it work? Did you create a function called stdev? There's no such function builtin to JavaScript or Acrobat, so there's no reason to assume it will magically work...

7. Re: Custom Calculation Script  Standard Deviation
Bernd Alheit Jun 6, 2017 10:51 AM (in response to michelled19159583)In the simplified field notation you can only use the operators +  * /
You must change the whole code to JavaScript.

8. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 7, 2017 4:59 AM (in response to try67)Currently it works! I am not sure what you mean! stdev() is a standard JavaScript function.

9. Re: Custom Calculation Script  Standard Deviation
try67 Jun 7, 2017 5:01 AM (in response to michelled19159583)AFAIK, it's not. Show me where it's documented...

10. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 7, 2017 5:04 AM (in response to Bernd Alheit)Hi Bernd. Do you have any idea of how I could change the entire thing to JavaScript?
So far, I have a "Value is the average" in one form field which creates the mean, this form field is labeled 'mean'. In the next form field I have a "Simplified field notation" : ((((row_1mean)*(row_1mean))+((row_2mean)*(row_2mean))+((row_3mean)*(row_3mean))+((r ow_4mean)*(row_4mean))+((row_5mean)*(row_5mean))+((row_6mean)*(row_6mean))+((row_7m ean)*(row_7mean))+((row_8mean)*(row_8mean))+((row_9mean)*(row_9mean))+((row_10mean)* (row_10mean))+((row_11mean)*(row_11mean))+((row_12mean)*(row_12mean))+((row_13mean)* (row_13mean))+((row_14mean)*(row_14mean))+((row_15mean)*(row_15mean)))/15). This is part of the equation to find the standard deviation, this second form field is labeled 'MEAN_2'. In the third and final form field I created a "Custom calculation script" : event.value = Math.sqrt(this.getField("MEAN_2").value) ;. That last script takes the square root of the form field MEAN_2, thus giving me the standard deviation. Any idea of how I can combine them all into one?

11. Re: Custom Calculation Script  Standard Deviation
Bernd Alheit Jun 7, 2017 6:30 AM (in response to michelled19159583)One sample for standard deviation:

12. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 7, 2017 6:52 AM (in response to Bernd Alheit)Bernd
This is what I have come up with thus far:
var MyValues = new Array();
var MyFields = new Array("row_1", "row_2", "row_3", "row_4", "row_5");
var oField;
var nField;
for(var i = 0; i < MyFields.length; i++)
{
nField = '';
nField = GetField(this, MyFields[i]).valueAsString;
if(nField != "") MyValues.push(Number(nField));
}
event.value = standardDeviation(MyValues);
Any help is much appreciated.
Thanks,
Michelle

13. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 7, 2017 7:23 AM (in response to Bernd Alheit)Bernd
I found this. But it doesn't work right now. Am I listing the row_'s wrong? Do I have to add something before I list them?
var average = this.getField("mean").value;
var v = 0;
var fieldName = "row_1, row_2, row_3, row_4, row_5, row_6, row_7, row_8, row_9, row_10, row_11, row_12, row_13, row_14, row_15";
var s = 0;
var sd = 0;
n = 15; //number of fieldsfor (var i = 1; i < n+1; i++) {
v = this.getField(fieldName + i).value;
s = s + Math.pow((v  average), 2);
}sd = Math.sqrt(s / n); //standar deviation
event.value = sd;Thanks,
Michelle

14. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 7, 2017 7:29 AM (in response to michelled19159583)This won't work either:
var average = this.getField("mean").value;
var v = 0;
var fieldNames = new Array("row_1", "row_2", "row_3", "row_4", "row_5", "row_6", "row_7", "row_8", "row_9", "row_10", "row_11", "row_12", "row_13", "row_14", "row_15");
var s = 0;
var sd = 0;
n = 15; //number of fieldsfor (var i = 1; i < n+1; i++) {
v = this.getField(fieldNames + i).value;
s = s + Math.pow((v  average), 2);
}sd = Math.sqrt(s / n); //standar deviation
event.value = sd; 
15. Re: Custom Calculation Script  Standard Deviation
Bernd Alheit Jun 7, 2017 7:42 AM (in response to michelled19159583)Look at the sample. It doesn't use an array. You must use:
var fieldName = "row_";

16. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 7, 2017 8:57 AM (in response to Bernd Alheit)Hi Bernd,
It doesn't work with just var fieldname="row_";
var average = this.getField("mean").value;
var v = 0;
var fieldName = "row_";
var s = 0;
var sd = 0;
n = 15; //number of fieldsfor (var i = 1; i < n+1; i++) {
v = this.getField(fieldNames + i).value;
s = s + Math.pow((v  average), 2);
}sd = Math.sqrt(s / n); //standar deviation
event.value = sd; 
17. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 7, 2017 10:57 AM (in response to michelled19159583)This doesn't work either:
var average = this.getField("mean").value;
var v = 0;
var fieldName = ("row_1", "row_2", "row_3", "row_4", "row_5", "row_6", "row_7", "row_8", "row_9", "row_10", "row_11", "row_12", "row_13", "row_14", "row_15");
var s = 0;
var sd = 0;
n = 15; //number of fieldsfor (var i = 1; i < n+1; i++) {
v = this.getField(fieldNames + i).value;
s = s + Math.pow((v  average), 2);
}sd = Math.sqrt(s / n); //standar deviation
event.value = sd; 
18. Re: Custom Calculation Script  Standard Deviation
gkaiseril Jun 7, 2017 12:43 PM (in response to michelled19159583)Open Acrobat's JavaScript Console and see if there are any errors.
You use the <Ctrl/Options> +"J" key combination.
It appears line 9 of the script is trying to access a field that does not exist.
You need to make a couple of changes. Fix the name of the array and fix the index value for walking the array's elements.
Try:
var average = this.getField("mean").value;
var v = 0;
var fieldName = new Array("row_1", "row_2", "row_3", "row_4", "row_5", "row_6", "row_7", "row_8", "row_9", "row_10", "row_11", "row_12", "row_13", "row_14", "row_15");
var s = 0;
var sd = 0;
n = 15; //number of fieldsfor (var i = 0; i < n; i++) {
v = this.getField(fieldName[i]).value;
s = s + Math.pow((v  average), 2);
}sd = Math.sqrt(s / n); //standar deviation
event.value = sd;If your values are small and there is very little variation, it is possible that your standard deviation maybe close to zero and the calculation will result in a value expressed in scientific notation which for a field formatted as a number will throw an error about value not matching the field's format.

19. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 8, 2017 5:04 AM (in response to gkaiseril)gkaiseril 
You are amazing!!! It works, thanks so much.

20. Re: Custom Calculation Script  Standard Deviation
michelled19159583 Jun 8, 2017 11:45 AM (in response to michelled19159583)Update:
This is the current script I have and it works properly to calculate the Population Standard Deviation:
var average = this.getField("mean").value;
var v = 0;
var fieldName = new Array("row_1", "row_2", "row_3", "row_4", "row_5", "row_6", "row_7", "row_8", "row_9", "row_10", "row_11", "row_12", "row_13", "row_14", "row_15");
var s = 0;
var sd = 0;
n = 15; //number of fieldsfor (var i = 0; i < n; i++) {
v = this.getField(fieldName[i]).value;
s = s + Math.pow((v  average), 2);
}sd = Math.sqrt(s / n); //standar deviation
event.value = sd;However, I need the Sample Standard Deviation. Can anyone help me?
Thanks,
Michelle

21. Re: Custom Calculation Script  Standard Deviation
Bernd Alheit Jun 9, 2017 1:47 AM (in response to michelled19159583)sd = Math.sqrt(s / (n  1));

22. Re: Custom Calculation Script  Standard Deviation
gkaiseril Jun 9, 2017 7:58 AM (in response to michelled19159583)Instead of dividing by the population n one divides by the sample n  1.