How to set up conditions when defining a response in HyperStudy?
Some responses in HyperSudy may need to be conditioned. For instance you may want to apply a different formula:
- Depending if a response is positive or negative
- Depending on the discrete value of a response
The first idea is generally to look for if/else, or case/switch statements as several programming code propose.
HyperStudy expression builder uses an Altair proprietary code, also used in HyperStudy for the parametized file, or in HyperView/HyperGraph/TableView for functions, notes, and parametrized sessions.
Templex does not contain neither if else nor switch/case statements, but still, it allows logical operations.
How to set up a response depending on the sign of a variable/response?
You can use <, >, <= and or >= operators.
If the condition between left hand side and right hand side is met, it will return 1. Otherwise, it will return 0.
Let’s say you would like to apply following statement:
If variable1 > 0
response1=3
else
response1=4
In the expression builder, you will write:
(var_1 > 0)*3+(var1<=0)*4
In the capture below var_1 is equal to 4:
How to set up a response depending on the discrete value of a variable/response?
For this you can use == .
As in the previous case, if the condition between left hand side and right hand side is met, it will return 1. Otherwise, it will return 0.
So let’s say your variable can take three discrete values 0, -1 and 1, and that you want to apply the following condition:
If var_1 = -1
response1 = var_1*var_2
Else if var_1 = 1
response_1=var_1*var_3
Else
response1=0
You can write:
(var_1==-1)*var_2 + (var_1==1)*var_3
You could also add (var_1==0)*0 for the third condition, but it is already respected with the expression above: