Using Logic for Calculations: Difference between revisions
(New page: * Logic for setting up scores in your intervention) |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Logic for setting up scores in your intervention = | |||
Logic commands can be used to score the responses that end-users give to interactions. This is particularly useful for scoring questionnaire items or if your intervention includes a quiz. | |||
The simplest interaction to use is the numeric value interactions as responses are already given a numeric value. However responses to single and multiple choice interactions can also be set with a numeric value. | |||
This logic uses the key command <code>set</code> and any of the mathematical commands (<code>sum</code>, <code>/</code>, <code>*</code>, <code><</code>, <code>></code>, <code>=</code>). | |||
= Example 1: Scoring numeric value interactions = | |||
Numeric value [[interactions]] come in three forms; slider, drop-down box or individual buttons (see figure 1). The logic changes slightly depending on which form is used. | |||
In this example we have named the slider interaction ‘stressq1’, the individual button interaction ‘stressq2’ and the drop-down menu interaction is called ‘stressq3’. | |||
[[Image:measuringstress.JPG]] | |||
'''Figure 1: The three types of numeric value interaction''' | |||
The responses that end-users give on these interactions will need to be set as variables. | |||
In this example the names answer1, answer2 and answer3 are given to the score generated from the interactions called stressq1, stressq2, and stressq3 respectively. | |||
The following logic illustrates how a score can be generated from the three interactions presented in figure 1 and then presented to end-users on the next page. | |||
<code>show</code> stressquestions1 | |||
Shows end-users the page containing the interactions, here this has been given the unique name '''stressquestions1''' | |||
<code>set</code> answer1 <code>to</code> stressquestions1.stressq1 | |||
'''Stressq1''' is the unique name for the slider interaction. In this interaction end-users can indicate where on the slider they would rate their stress levels. This interaction goes up in increments of 5 from 0 to 100. This logic will set the variable name '''answer1''' to whatever number is indicated by the end-user’s response. | |||
<code>set</code> answer2 <code>to</code> (10 <code>*</code> stressquestions1.stressq2) | |||
<code>set</code> answer3 <code>to</code> (10 <code>*</code> stressquestions1.stressq3) | |||
The unique names '''stressq2''' and '''stressq3''' have been given to the individual button and drop down interactions respectively. As these interactions have been set to go up in increments of 1 from 0 to 10 we need to multiply the response given by 10 to get an answer out of 100. This logic will set the variable names '''answer2''' and '''answer3''' to whatever this number will be. | |||
<code>set</code> week1_score <code>to</code> (<code>sum</code> (answer1, answer2, answer3)) | |||
Finally, all three values are summed together and set to the unique variable''' week1_score''' | |||
<code>show</code> stressanswer | |||
<code>set</code> stressanswer.stressscore <code>to</code> week1_score | |||
This score can then be presented to the end-user on another page using a normal textbox where a word (in this case stressscore) has been set as a variable. | |||
This score could also be e-mailed to a research manager or other person managing the intervention (see [[sending e-mails]] for more information) | |||
= Example 2: Scoring multiple choice, single choice and numeric value interactions = | |||
This example is a bit more complex. Here, we will set a score to the responses end-users select from a number of interactions relating to their stress levels, their attitude towards stress and how they feel they can manage their stress. This example will therefore generate three different scores and then provide users with tailored information based on the score they receive. | |||
A demo of this example can be found on the LifeGuide Community website at the following address [http://www.lifeguideonline.org/manager/intervention/show/31] | |||
<code>show</code> page1 | |||
Show end-users the first page containing questions about their stress levels. | |||
<code>set</code> stress1 <code>to</code> page1.overallstress | |||
<code>set</code> stress2 <code>to</code> (10 * page1.stresstoday) | |||
'''overallstress''' and''' stresstoday''' are the unique names given to two numeric value interactions aimed at generating a percentage score for the end-user’s stress levels. | |||
<code>set</code> stresspercent <code>to</code> append<code>(sum (stress1, stress2 / 2), "%")</code> | |||
To obtain a percentage we need to add the two scores together and divide the answer by two. The resulting number will be set to the unique variable '''stresspercent'''. | |||
The logic for presenting this score to end-users needs to come after we have shown the page that we want to present the score on. As we still have more scores to generate relating to the interactions on page1, this logic command will come later. | |||
<code>set em1 to 0</code> | |||
<code>set em2 to 0</code> | |||
<code>set em3 to 0</code> | |||
<code>set em4 to 0</code> | |||
<code>set em5 to 0</code> | |||
<code>set em6 to 0</code> | |||
<code>if (page1.emotion contains "neg1") set em1 to 1</code> | |||
<code>if (page1.emotion contains "neg2") set em2 to 1</code> | |||
<code>if (page1.emotion contains "neg3") set em3 to 1</code> | |||
<code>if (page1.emotion contains "pos1") set em4 to 2</code> | |||
<code>if (page1.emotion contains "pos2") set em5 to 2</code> | |||
<code>if (page1.emotion contains "pos3") set em6 to 2</code> | |||
<code>set overall to (sum (em1, em2, em3, em4, em5, em6))</code> | |||
This logic illustrates how a score can be generated from a multiple choice interaction. '''Page1''' contains an interaction entitled '''emotion''' which asks end-users to choose three responses that best describes how they feel when they are stressed. Three of these responses are negative and three are positive. We want to score all positive answers with 2 and all negative answers with 1 and then provide tailored feedback based on the end-users resulting score (which can range from 3 to 6). | |||
As there are six possible responses for people to choose from we need to include all six when summing the overall score. If we do not, this will confuse the logic and it will subsequently not generate a score and will not present a tailored message. | |||
To get around this we need to first set every answer to 0 so that if the response is not chosen it will still be included in the logic. We will set every response with its own variable so it can be included in the mathematical command. If the end-user does then choose that response, this score will be changed to 1 or 2 depending on whether it is a positive or negative emotion. | |||
An overall score can then be generated by summing the six scores together. A tailored message relating to this score will then be presented to the end-user, however the logic for this needs to come after the page showing the feedback has been shown. | |||
<code>if (page1.stressconf = "cony") set stress3 to 2</code> | |||
<code>if (page1.stressconf = "conn") set stress3 to 1</code> | |||
<code>if (page1.problematic = "proby") set stress4 to 1</code> | |||
<code>if (page1.problematic = "probn") set stress4 to 2</code> | |||
<code>if (page1.effect = "effy") set stress5 to 1</code> | |||
<code>if (page1.effect = "effn") set stress5 to 2</code> | |||
<code>set sm to (sum (stress3, stress4, stress5))</code> | |||
The next part of the questionnaire includes three single choice interactions that relate to the person’s stress management. We want to generate a stress management score '''(unique variable = sm)''' based on the responses to these three questions. An end-user can choose one of two responses to the three questions (yes or no). Responses that indicate good stress management are given a score of 2 but those choices that relate to bad stress management are given a score of 1. As these are all single choice interactions, the end-user will need to give a yes or no response to each interaction. | |||
In this logic a unique variable is given to the possible score for each interaction. So, for the first interaction ('''stressconf''') the unique variable '''stress3''' is given to the score on this interaction. If the end-user selects the yes response to this interaction ('''cony''') then this variable is set to 2. If they choose no ('''conn''') this response is set to 1. | |||
Once all three scores are generated ('''stress3, stress4 and stress5''') these scores are summed and then set to the unique variable '''sm'''. | |||
<code>show</code> page2 | |||
Show end-users the page that will present them with tailored feedback relating to their scores. | |||
<code>set page2.stressscore to stresspercent</code> | |||
This logic will set the variable '''stressscore''' to the '''stresspercent''' score generated in the logic earlier on. '''Stressscore''' is a variable that has been set in a textbox on '''page2'''. | |||
<code>show page2.positive if (overall >= 5)</code> | |||
<code>show page2.negative if (overall <= 4)</code> | |||
This logic refers to the tailored feedback that will be given to the end-users depending on the score they got from the interactions relating to their attitude towards stress. If they have scored 5 or more they will be given feedback telling them they have a positive attitude. If they get a score of 4 or below they will get a message relating to a negative attitude. | |||
<code>show page2.stressmanlow if (sm = 3)</code> | |||
<code>show page2.stressmanmod if (or (sm = 4, sm = 5))</code> | |||
<code>show page2.stressmanhigh if (sm = 6)</code> | |||
This logic refers to the tailored feedback that will be given to the end-users depending on the score they get on the stress management interactions. For example, if their sm score is 3 they will get a tailored message about having a low stress management level. | |||
NB: If your scores or calculations need to be re-used in later sessions then you will need to use the save commands in your logic. |
Latest revision as of 09:35, 28 October 2010
Logic for setting up scores in your intervention
Logic commands can be used to score the responses that end-users give to interactions. This is particularly useful for scoring questionnaire items or if your intervention includes a quiz.
The simplest interaction to use is the numeric value interactions as responses are already given a numeric value. However responses to single and multiple choice interactions can also be set with a numeric value.
This logic uses the key command set
and any of the mathematical commands (sum
, /
, *
, <
, >
, =
).
Example 1: Scoring numeric value interactions
Numeric value interactions come in three forms; slider, drop-down box or individual buttons (see figure 1). The logic changes slightly depending on which form is used.
In this example we have named the slider interaction ‘stressq1’, the individual button interaction ‘stressq2’ and the drop-down menu interaction is called ‘stressq3’.
Figure 1: The three types of numeric value interaction
The responses that end-users give on these interactions will need to be set as variables.
In this example the names answer1, answer2 and answer3 are given to the score generated from the interactions called stressq1, stressq2, and stressq3 respectively.
The following logic illustrates how a score can be generated from the three interactions presented in figure 1 and then presented to end-users on the next page.
show
stressquestions1
Shows end-users the page containing the interactions, here this has been given the unique name stressquestions1
set
answer1 to
stressquestions1.stressq1
Stressq1 is the unique name for the slider interaction. In this interaction end-users can indicate where on the slider they would rate their stress levels. This interaction goes up in increments of 5 from 0 to 100. This logic will set the variable name answer1 to whatever number is indicated by the end-user’s response.
set
answer2 to
(10 *
stressquestions1.stressq2)
set
answer3 to
(10 *
stressquestions1.stressq3)
The unique names stressq2 and stressq3 have been given to the individual button and drop down interactions respectively. As these interactions have been set to go up in increments of 1 from 0 to 10 we need to multiply the response given by 10 to get an answer out of 100. This logic will set the variable names answer2 and answer3 to whatever this number will be.
set
week1_score to
(sum
(answer1, answer2, answer3))
Finally, all three values are summed together and set to the unique variable week1_score
show
stressanswer
set
stressanswer.stressscore to
week1_score
This score can then be presented to the end-user on another page using a normal textbox where a word (in this case stressscore) has been set as a variable.
This score could also be e-mailed to a research manager or other person managing the intervention (see sending e-mails for more information)
Example 2: Scoring multiple choice, single choice and numeric value interactions
This example is a bit more complex. Here, we will set a score to the responses end-users select from a number of interactions relating to their stress levels, their attitude towards stress and how they feel they can manage their stress. This example will therefore generate three different scores and then provide users with tailored information based on the score they receive.
A demo of this example can be found on the LifeGuide Community website at the following address [1]
show
page1
Show end-users the first page containing questions about their stress levels.
set
stress1 to
page1.overallstress
set
stress2 to
(10 * page1.stresstoday)
overallstress and stresstoday are the unique names given to two numeric value interactions aimed at generating a percentage score for the end-user’s stress levels.
set
stresspercent to
append(sum (stress1, stress2 / 2), "%")
To obtain a percentage we need to add the two scores together and divide the answer by two. The resulting number will be set to the unique variable stresspercent.
The logic for presenting this score to end-users needs to come after we have shown the page that we want to present the score on. As we still have more scores to generate relating to the interactions on page1, this logic command will come later.
set em1 to 0
set em2 to 0
set em3 to 0
set em4 to 0
set em5 to 0
set em6 to 0
if (page1.emotion contains "neg1") set em1 to 1
if (page1.emotion contains "neg2") set em2 to 1
if (page1.emotion contains "neg3") set em3 to 1
if (page1.emotion contains "pos1") set em4 to 2
if (page1.emotion contains "pos2") set em5 to 2
if (page1.emotion contains "pos3") set em6 to 2
set overall to (sum (em1, em2, em3, em4, em5, em6))
This logic illustrates how a score can be generated from a multiple choice interaction. Page1 contains an interaction entitled emotion which asks end-users to choose three responses that best describes how they feel when they are stressed. Three of these responses are negative and three are positive. We want to score all positive answers with 2 and all negative answers with 1 and then provide tailored feedback based on the end-users resulting score (which can range from 3 to 6).
As there are six possible responses for people to choose from we need to include all six when summing the overall score. If we do not, this will confuse the logic and it will subsequently not generate a score and will not present a tailored message.
To get around this we need to first set every answer to 0 so that if the response is not chosen it will still be included in the logic. We will set every response with its own variable so it can be included in the mathematical command. If the end-user does then choose that response, this score will be changed to 1 or 2 depending on whether it is a positive or negative emotion.
An overall score can then be generated by summing the six scores together. A tailored message relating to this score will then be presented to the end-user, however the logic for this needs to come after the page showing the feedback has been shown.
if (page1.stressconf = "cony") set stress3 to 2
if (page1.stressconf = "conn") set stress3 to 1
if (page1.problematic = "proby") set stress4 to 1
if (page1.problematic = "probn") set stress4 to 2
if (page1.effect = "effy") set stress5 to 1
if (page1.effect = "effn") set stress5 to 2
set sm to (sum (stress3, stress4, stress5))
The next part of the questionnaire includes three single choice interactions that relate to the person’s stress management. We want to generate a stress management score (unique variable = sm) based on the responses to these three questions. An end-user can choose one of two responses to the three questions (yes or no). Responses that indicate good stress management are given a score of 2 but those choices that relate to bad stress management are given a score of 1. As these are all single choice interactions, the end-user will need to give a yes or no response to each interaction.
In this logic a unique variable is given to the possible score for each interaction. So, for the first interaction (stressconf) the unique variable stress3 is given to the score on this interaction. If the end-user selects the yes response to this interaction (cony) then this variable is set to 2. If they choose no (conn) this response is set to 1.
Once all three scores are generated (stress3, stress4 and stress5) these scores are summed and then set to the unique variable sm.
show
page2
Show end-users the page that will present them with tailored feedback relating to their scores.
set page2.stressscore to stresspercent
This logic will set the variable stressscore to the stresspercent score generated in the logic earlier on. Stressscore is a variable that has been set in a textbox on page2.
show page2.positive if (overall >= 5)
show page2.negative if (overall <= 4)
This logic refers to the tailored feedback that will be given to the end-users depending on the score they got from the interactions relating to their attitude towards stress. If they have scored 5 or more they will be given feedback telling them they have a positive attitude. If they get a score of 4 or below they will get a message relating to a negative attitude.
show page2.stressmanlow if (sm = 3)
show page2.stressmanmod if (or (sm = 4, sm = 5))
show page2.stressmanhigh if (sm = 6)
This logic refers to the tailored feedback that will be given to the end-users depending on the score they get on the stress management interactions. For example, if their sm score is 3 they will get a tailored message about having a low stress management level.
NB: If your scores or calculations need to be re-used in later sessions then you will need to use the save commands in your logic.