Input help with an equation in Redcap

370 views
Skip to first unread message

Philip Olsson

unread,
Sep 21, 2021, 5:19:32 AM9/21/21
to redcap open

I am working on a CRF with recap for a master project however I have run into a problem with some programming.

Im trying to set up an equation for some intervalls, the following example is for body temperature (in Celsius). I am trying to integrate a scoring model into one of my instruments. If the temperatur is 36-38.4 it is supposed to give 0 points, if it is between 32-33.9 it will give 2 points etc. My problem is that both a very low numer and a very high number gives 4 points and I can't figure out how to program the equation.

This is how redcap uses conditional logic: if (CONDITION, value if condition is TRUE, value if condition is FALSE).

This is a equation that works for example:

if([cpis_temp] > 35.9,if([cpis_temp] > 38.4,if([cpis_temp] >=39, 2, 1),0),2)

Now I want to make another but with more intervalls but i can't get the equation to work, these are the intervalls:

0 if: 36-38.4

1 if: 34-35.9 or 38.5-38.9

2 if: 32-33.9

3 if: 30-31.9 or 39-40.9

4 if: <=29.9 or >=41

This is what I have managed to formulate so far:

if([cpis_temp]>1,if([cpis_temp]>20,if([cpis_temp]>=30,if([cpis_temp]>=32,if([cpis_temp]>=34,if([cpis_temp]>=36,if([cpis_temp]=>38.5,if([cpis_temp]>=39,if([cpis_temp]>=41,4,0),3),1),0),1),2),3),4),0)

Grateful for some input and help!



Simon Vanderschaeghe

unread,
Sep 21, 2021, 7:07:53 AM9/21/21
to redcap open
Hi,

To improve readability, I would use a sum instead of nesting if-statements:
sum(
if(([cpis_temp]>=34 and [cpis_temp]<36) or ([cpis_temp]>=38.5 and [cpis_temp]<39), 1, 0),
if([cpis_temp]>=32 and [cpis_temp]<34, 2, 0),
if(([cpis_temp]>=30 and [cpis_temp]<32) or ([cpis_temp]>=39 and [cpis_temp]<41), 3, 0),
if([cpis_temp]<30 or [cpis_temp]>=41, 4, 0)
)

To make sure that the calculation does not return any result if the temperature is empty, you could add the following if-statement around the sum:
if([cpis_temp]='', '', sum(...))

Kind regards,
Simon
Op dinsdag 21 september 2021 om 11:19:32 UTC+2 schreef grana...@gmail.com:

Luciana R C Barros

unread,
Sep 21, 2021, 7:11:33 AM9/21/21
to Philip Olsson, redcap open
Hello,

Your formula is not correct. You need to add the value when the condition is true. For example:

if([cpis_temp] > 35.9, 0, 
if([cpis_temp] > 38.4, 2,
if([cpis_temp] >=39, 4, ‘’)

You don’t need to add in separated lines as I do, but it is easier to formulated in this way. 

The first line is if the temperature is higher than 35.9, give me the value 0. In the second line is if the temperature is higher than 38.4, give me 2. And the third is if the temperature is higher or equal to 39.4, give me 4. The last term is ‘’, where if none of the conditions above is true, give me ‘’ which means an empty field.

The logical for the second formula os the same, always put the condition followed by the number, than the new condition.

Hope I could help,


Luciana Barros 



--
You received this message because you are subscribed to the Google Groups "redcap open" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redcap_open...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redcap_open/8e8e20b1-87d6-4de1-bfa8-62811c43b78dn%40googlegroups.com.
--
Luciana R C Barros

Centro de Investigação Translacional em Oncologia
Instituto do Câncer do Estado de São Paulo
Faculdade de Medicina da Universidade de São Paulo
Av. Dr. Arnaldo, 251.  Cerqueira César
CEP 01246-000 - São Paulo - SP - Brasil
Tel: + 55 11 38933014


Peter Macisaac (POP)

unread,
Sep 21, 2021, 7:14:31 AM9/21/21
to Luciana R C Barros, Philip Olsson, redcap open
Thanks for the response Luciana

You may need to add two more “)” at the end - one for each nested if statement

Peter

Philip Olsson

unread,
Sep 21, 2021, 7:17:55 AM9/21/21
to redcap open
Thank you so much for the answers! It is working very well now :)
Reply all
Reply to author
Forward
0 new messages