Calculations and Branching Logic in REDCap

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
• http://www.biostat.wustl.edu/redcap
– 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
Data Entry
Forms
Add Users
and
Set User
Rights
Define
Study Events
(Longitudinal)
add Schedule
(optional)
Recent Changes
• Hardware
– Improved Dedicated MySQL Database server
• Software (REDCap 4.8.x)
– Data Query Module
– New data validation types
– Search Tool
– External Links
Public HTTPS Access
Biostatistics Secure Domain
WEB Server
File Server
Authenticated Access
Sync
MySQL Server
WU Campus
Sidedoor
Server
Data Entry /Admin
WEB Server
MySQL Slave Server
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)
Type of calculation
Notes / examples
round(number,decimal
places)
Round
roundup(number,decimal
places)
Round Up
rounddown(number,deci
mal places)
Round Down
sqrt(number)
Square Root
datediff([date1], [date2], "units", "dateformat",
returnSignedValue)
datediff([dob],[date_enrolled],"d")
datediff([dob],"05-31-2007","h","mdy",true)
Units
"y"
years
1 year = 365.2425
days
"M"
months
1 month = 30.44
days
(number)^(exponent)
Exponents
abs(number)
Absolute Value
"d"
days
min(number,number,...)
Minimum
"h"
hours
max(number,number,...)
Maximum
"m"
minutes
mean(number,number,...
)
Mean
"s"
seconds
median(number,number,.
..)
Median
sum(number,number,...)
Sum
stdev(number,number,...)
Standard Deviation
Date
Formats
"ymd"
Y-M-D (default)
"mdy"
M-D-Y
"dmy"
D-M-Y
Javascript Math Library
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Math.abs(a)
Math.acos(a)
Math.asin(a)
Math.atan(a)
Math.atan2(a,b)
Math.ceil(a)
Math.cos(a)
Math.exp(a)
Math.floor(a)
Math.log(a)
Math.max(a,b)
Math.min(a,b)
Math.pow(a,b)
Math.random()
Math.round(a)
Math.sin(a)
Math.sqrt(a)
Math.tan(a)
// the absolute value of a
// arc cosine of a
// arc sine of a
// arc tangent of a
// arc tangent of a/b
// integer closest to a and not less than a
// cosine of a
// exponent of a (Math.E to the power a)
// integer closest to a, not greater than a
// log of a base e
// the maximum of a and b
// the minimum of a and b
// a to the power b
// pseudorandom number 0 to 1
// integer closest to a
// sine of a
// square root of a
// tangent of a
http://www.javascripter.net/faq/mathfunc.htm
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]*.45359237
• 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
[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)
– [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"
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)
External Links
• Embed hyperlinks in the REDCap project menu.
– Websites, Other REDCap Projects, web tools
Data Search Tool
“?!!?”
User Rights
REDCap Lifelines
• Built-in tutorial videos
• Built-in Frequently Asked Question (FAQ)
guide
• Demonstration Databases (Some Online, more
to come)
• WUSM Biostat REDCap Email Help Queue
– [redcap@rt.biostat.wustl.edu]
– Monitored by 4 to 5 Administrators
REDCap Email Support
redcap@rt.biostat.wustl.edu
REDCap Goals
•
•
•
•
•
Easy to use
Metadata Driven
Adaptable Features
Data entry validation
Self service tool
Questions?