Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Contact Us
  • Home
  • CDMS
  • Castor CDMS Calculations Manual
  • General calculation templates

Calculate the average in EDC/CDMS

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • CDMS
    Castor CDMS Manual Castor CDMS Calculations Manual Frequently Asked Questions Articles for Data Managers Castor CDMS Compliance Release Documents
  • eConsent
    Castor eConsent Manual Castor eConsent Compliance Release Documents
  • SMS
    Castor SMS Manual Castor SMS Compliance Release Documents
  • Castor Connect
    Castor Connect Compliance Release Documents Castor Connect Manual Castor Connect - Participant Quick Start Guide
  • Helpdesk
    News Other Resources Castor products knowledge resources
  • Status page
  • Completing a Study
+ More

Table of Contents

The calculation Step by step

The average of a set of numeric field values is calculated by adding up all values and dividing the result by the number of values we have:


average = (value 1 + value 2 + value n) / n


See also how you can calculate the median.


As simple as this seems, it can be a bit more difficult to calculate it when we do not know how many values we will have in the end.


For example, in our study we ask the patients to track the hours of sleep for each day, from Monday to Friday. A patient may miss the result for one day, or even some fields can be marked as missing. Before entering any data we can see the following:


While we enter data the calculation updates. Below is an example with the day 4 and 5 marked as missing:


Average = (5+8+6)/3 --> Average = 19/3


The calculation

Here is the code to use. Remember to replace the variables in the example with your own variable names:

'##allowempty##';
var myVariables = [{day1}, {day2}, {day3}, {day4}, {day5}];
var list = 0;
var listLen = 0;
for (i=0; i < myVariables.length; i++) {
 var value = myVariables[i];
 if (value > 0) {
 list += value
 listLen += 1;
}};
if(isNaN(list/listLen)){
"";
} else{
list/listLen;
}


Step by step


  1.  First, we need to allow the calculation to work with empty results. Otherwise it will not execute until all our variables contain data. To this end we use '##allowempty##'.
  2. Then we need to create a list with our fields, and two more variables with the starting value 0. "list" will be the sum of the values entered in our fields, while "listLen" will count the number of values that we have.
  3. Next, we use a loop to analyze the list variable "myVariables". Each value in our fields ({day1}, {day2}, etc.) that is greater than 0, will be added to the variable "list" and +1 will be also added to "listLen". This part is important because it will not take into account the values in fields marked as missing.
  4. To end with, we introduce a final check. While there is no data in our fields the result of the calculation will show "NaN". To prevent this we will use the final if-else clause: if the result of our average is 'NaN', nothing will be shown. When there is a different result, our average will show up.
tabulate mean compute mean

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Allow data entry with different measurement units in EDC/CDMS
  • Validate grid field values in EDC/CDMS
ISO 27001
FDA - 21 CFR part 11
ICH GCP compliant
HIPAA compliant
CDISC
ISO 9001
gdpr compliant

Products & Industries

  • Electronic Data Capture (EDC)
  • ePRO
  • eConsent
  • Decentralized Clinical Trials (DCT)
  • Clinical Data Management
  • Medical Device & Diagnostics
  • Biotech & Pharma
  • CROs
  • Academic Research

Resources

  • Thought Leadership
  • Blog
  • Castor Academy
  • Knowledge Base

 

Company

  • About Us
  • Careers
  • News
  • Contact Support
  • Contact Us

Legal & Compliance

  • Terms of Use
  • Privacy & Cookie Statement
  • Responsible Disclosure Policy
  • Good Clinical Practice (GCP)
  • ISO Compliance Certificates
  • GDPR & HIPAA Compliance
  • Security Statement

© 2022, Castor. All Rights Reserved.

Follow us on social media


Knowledge Base Software powered by Helpjuice

Definition by Author

0
0
Expand