# Calculations and Branching Logic

## Presentation on theme: "Calculations and Branching Logic"— Presentation transcript:

Calculations and Branching Logic
By J Kevan Essmyer Acknowledgements: J. Phil Miller (WUSM Biostatistics) Paul Harris (Vanderbilt CTSA) Jack Baty (WUSM REDCap Admin) Yu Tao (WUSM REDCap Admin)

Overview REDCap Overview Calculations Branching Logic
Expanded Data Validation Types Data Quality Module External Links functionality Data Search Tool

Development “Try it” and Production “Study Data” Servers
REDCap User Request forms REDCap Project Request forms (IRB #) Sidedoor security certificate (External Access) Both servers are WUSM HIPAA compliant web-based data capture systems REDCap Policy: Study data should only be collected on the Production server

Project Creation Flow Chart
Create Project –Project Name, Longitudinal or Cross-Sectional/ Survey Move to Production Status and start Data Collection Excel Spreadsheet Or Online Form Designer Test Forms Define Study Events (Longitudinal) add Schedule (optional) Data Entry Forms Add Users and Set User Rights

Recent Changes Hardware Software (REDCap 4.8.x)
Improved Dedicated MySQL Database server Software (REDCap 4.8.x) Data Query Module New data validation types Search Tool External Links

Biostatistics Secure Domain
Public HTTPS Access Biostatistics Secure Domain WEB Server File Server https://redcapsurvey.wustl.edu... REDCap Survey Uploaded Files MySQL Server Authenticated Access Data WEB Server Sync WU Campus Data Entry /Admin MySQL Slave Server Data Entry /Admin Sidedoor Server Installation Files Host Server

Calculations Variable Referrence: [event_id][variable name]
Event Id obtained from events grid Logic Statement: (if(expression),True Result,False Result) Simple [weight]*10000/([height]*[height]) Complex Calculating the Mean of groups with null valid range includes zero The following equation will calculate the Mean of a list of variables ( (if(Math.abs([A])>0,[A],0)) +(if(Math.abs([B])>0,[B],0)) +(if(Math.abs([C])>0,[C],0)) ) / ( (if(Math.abs([A])>0,1,if([A]=0,1,0)) +if(Math.abs([B])>0,1,if([B]=0,1,0)) +if(Math.abs([C])>0,1,if([C]=0,1,0)) )

Built in Functions DATEDIFF F(x) Units Date Formats
Type of calculation Notes / examples round(number,decimal places) Round roundup(number,decimal places) Round Up rounddown(number,decimal places) Round Down sqrt(number) Square Root (number)^(exponent) Exponents abs(number) Absolute Value min(number,number,...) Minimum max(number,number,...) Maximum mean(number,number,...) Mean median(number,number,...) Median sum(number,number,...) Sum stdev(number,number,...) Standard Deviation datediff([date1], [date2], "units", "dateformat", returnSignedValue) datediff([dob],[date_enrolled],"d") datediff([dob]," ","h","mdy",true) Units "y" years 1 year = days "M" months 1 month = days "d" days "h" hours "m" minutes "s" seconds "ymd" Y-M-D (default) "mdy" M-D-Y "dmy" D-M-Y Date Formats

Javascript Math Library
Math.abs(a) // the absolute value of a Math.acos(a) // arc cosine of a Math.asin(a) // arc sine of a Math.atan(a) // arc tangent of a Math.atan2(a,b) // arc tangent of a/b Math.ceil(a) // integer closest to a and not less than a Math.cos(a) // cosine of a Math.exp(a) // exponent of a (Math.E to the power a) Math.floor(a) // integer closest to a, not greater than a Math.log(a) // log of a base e Math.max(a,b) // the maximum of a and b Math.min(a,b) // the minimum of a and b Math.pow(a,b) // a to the power b Math.random() // pseudorandom number 0 to 1 Math.round(a) // integer closest to a Math.sin(a) // sine of a Math.sqrt(a) // square root of a Math.tan(a) // tangent of a

Pitfalls of Calculations
Changes made to equations after the start of data collection Correct new calculated value will display on page load Each form must be individually submitted to re-apply calculation Calculations should be considered a tool not data. Calculation should be reapplied during data analysis. Multiple calculations on a form. Order of execution is determined by the alphabetical ordering of it’s associated variable/field name. Calculation 1 [weight_met] =[weight]* Calculation 2 [BMI]=[weight_met]/([height]^2) !!!Calculation 2 will occur before calculation 1 Calculate BMI in one step (Best Solution) or Rename variable to change order (only other option)

Branching Logic Exposes form question if logic expression is true
[Event Id][Variable Name] = "0" Checkboxes Format [Event Id][variablename(code)] To check the value of the checkboxes: '1' = checked '0' = unchecked [race(2)] = "1" [sex] = "0" display question if sex = female; Female is coded as 0, Female [sex] = "0" and [given_birth] = "1" display question if sex = female and given birth = yes; Yes is codesd as 1, Yes ([height] >= 170 or [weight] < 65) and [sex] = "1" display question if (height is greater than or equal to 170 OR weight is less than 65) AND sex = male; Male is coded as 1, Male [last_name] <> "" display question if last name is not null (aka if last name field is empty)

Online Designer

Branching Logic Calculation with in branching logic
[kwdays] > (10+1) Prevent deletion of With existing logic (other logic statements) or <>"“ Stand alone <>""

Branching logic warning about hiding existing data
Can be a dangerous situation and is best avoided.

Expanded Field Validation Types

Data Quality Module (data queries)

Results

Data Quality Module (data queries)

Websites, Other REDCap Projects, web tools

Data Search Tool

“?!!?” Branching Logic Data Validation User Rights API Data Dictionary
Scheduling Data Dictionary

REDCap Lifelines Built-in tutorial videos
Built-in Frequently Asked Question (FAQ) guide Demonstration Databases (Some Online, more to come) WUSM Biostat REDCap Help Queue Monitored by 4 to 5 Administrators

REDCap Support