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 median of a set of values 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

While the average is the result of performing some mathematical operations, the median is employed more as descriptive of the data set and usually involves no mathematics. 


The median is thus defined as the the middle value in a list of numbers, that can be sorted in ascending or descending order, leaving half of the values above and the other half below. It is used mainly in statistics.


Let's set a text field {myList} as example, in which the patients need to enter the amount of persons they have been in contact with during the week, day by day. We may end up with a list like this:

[10, 15, 2, 5, 1, 27, 16]


To find the median we need to:

  • order the list, ascending or descending
  • count the number of values in the list and take:
    • the value in the middle, that cuts the list in two halves (if the number of values is odd)
    • the two values in the middle and calculate the average (if the number of values is even) 


In our example, the ordered list would be:

[27, 16, 15, 10, 5, 2, 1]


The list is composed by 7 values, which is an odd number. Therefore, we need to take the value in the middle: 


10 leaves 3 values above (27, 16, 15) and 3 values below (5, 2, 1).


If we add one more item to our list then we will have 8 values, which is an even number. Here our median:


In this case, the ordered list of 8 items leaves 10 and 5 in the center but not a single number that cuts the list in two halves. We then need to calculate the average of those two middle values to get our median:


(10 + 5) / 2 = 7.5


The calculation 


Below is the code to use in the calculation field to obtain the median of a set of values entered in a text field named {nPers}. Remember to replace the name of this variable with your own variable:


//create array with values in the text field
var arrOrig = [];
arrOrig.push({nPers});
//find array length
const len = arrOrig.length;
//order array
const arrSort = arrOrig.sort(function(a, b){return a-b});
const mid = Math.ceil(len/2);
//select the middle value
if(len % 2 == 0){
(arrSort[mid] + arrSort[mid - 1]) / 2;
} else{
arrSort[mid - 1];
}average
value set median calculation

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Calculate with grid fields in EDC/CDMS
  • Check if a number contains X number of digits or decimal places in EDC/CDMS
  • Check if all fields are filled in with in EDC/CDMS
  • Check if the inclusion criteria are met 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