Skip to main content
michelled19159583
Known Participant
Jun 6, 2017 1:00 PM UTC
Question

Custom Calculation Script - Standard Deviation

I am having trouble creating a Custom calculation script in my Adobe Acrobat XI Standard. I have a table with fields 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. I have a field that already calculates the mean, that field name is mean. So far I have been able to create this but it does not work:

sqrt(((((row_1-mean)^2)+((row_2-mean)^2)+((row_3-mean)^2)+((row_4-mean)^2)+((row_5-mean)^2)+((row_6-mean)^2)+((row_7-mean)^2)+((row_8-mean)^2)+((row_9-mean)^2)+((row_10-mean)^2)+((row_11-mean)^2)+((row_12-mean)^2)+((row_13-mean)^2)+((row_14-mean)^2)+((row_15-mean)^2)))/15)

This topic is closed to new replies. Start a new post to keep the conversation going.

22 replies

michelled19159583
Known Participant
Jun 8, 2017 6:45 PM UTC

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 fields

for (var i = 0; i < n; i++) {
    v = this.getField(fieldName).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

Translate
Bernd Alheit
Community Expert
Community Expert
Jun 9, 2017 8:47 AM UTC

sd = Math.sqrt(s / (n - 1));

Translate
michelled19159583
Known Participant
Jun 6, 2017 5:43 PM UTC

Right now this is working separately.

In one form field(Simplified field notation) named MEAN_2 I have:

((((row_1-mean)*(row_1-mean))+((row_2-mean)*(row_2-mean))+((row_3-mean)*(row_3-mean))+((row_4-mean)*(row_4-mean))+((row_5-mean)*(row_5-mean))+((row_6-mean)*(row_6-mean))+((row_7-mean)*(row_7-mean))+((row_8-mean)*(row_8-mean))+((row_9-mean)*(row_9-mean))+((row_10-mean)*(row_10-mean))+((row_11-mean)*(row_11-mean))+((row_12-mean)*(row_12-mean))+((row_13-mean)*(row_13-mean))+((row_14-mean)*(row_14-mean))+((row_15-mean)*(row_15-mean)))/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.

Translate
Bernd Alheit
Community Expert
Community Expert
Jun 6, 2017 5:51 PM UTC

In the simplified field notation you can only use the operators + - * /

You must change the whole code to JavaScript.

Translate
michelled19159583
Known Participant
Jun 7, 2017 12:04 PM UTC

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_1-mean)*(row_1-mean))+((row_2-mean)*(row_2-mean))+((row_3-mean)*(row_3-mean))+((row_4-mean)*(row_4-mean))+((row_5-mean)*(row_5-mean))+((row_6-mean)*(row_6-mean))+((row_7-mean)*(row_7-mean))+((row_8-mean)*(row_8-mean))+((row_9-mean)*(row_9-mean))+((row_10-mean)*(row_10-mean))+((row_11-mean)*(row_11-mean))+((row_12-mean)*(row_12-mean))+((row_13-mean)*(row_13-mean))+((row_14-mean)*(row_14-mean))+((row_15-mean)*(row_15-mean)))/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?

Translate
try67
Community Expert
Community Expert
Jun 6, 2017 2:07 PM UTC

And here you can learn how to perform basic mathematical operations (like square root and power) in JS: JavaScript Math Object

Translate
michelled19159583
Known Participant
Jun 6, 2017 5:45 PM UTC

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?

Translate
try67
Community Expert
Community Expert
Jun 6, 2017 5:49 PM UTC

Why would it work? Did you create a function called stdev? There's no such function built-in to JavaScript or Acrobat, so there's no reason to assume it will magically work...

Translate
Bernd Alheit
Community Expert
Community Expert
Jun 6, 2017 1:45 PM UTC

You must change your code.

E.g. you will get value of field row_1 with:

this.getField("row_1").value

Translate
michelled19159583
Known Participant
Jun 6, 2017 5:47 PM UTC

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?

Translate