Let's say your survey asked for quantities in absolute counts. But now you want the option to report them as percentages. This tutorial demonstrates how you can do just that, and correctly preserve percentages, frequencies and averages.
Here, we have two questions:
- S8: How many patients do you treat for Condition X?
- Q2: How many of those patients do you treat with the following therapies?
To create a new group that displays percentages of respondents' patients being treated with each different therapy we need to calculate a ratio (Q2_x / S8).
Calculate ratios of elements
First, decide if you want to clone Q2 to create a new group for the ratio values (see Move, mirror, clone tutorial.) You don't have to clone the element, but you may want to see both the original counts and the ratio. In this example, we've opted to recursively clone Q2 and name the new group Q2vS8.
For the new group, press the square edit icon and choose "More properties..." from the context menu. Then, next to "denominator" enter "S8".
Set the "scale" to 100. As an analyst you may be familiar seeing percentages in the interval of 0 to 1. But your client may prefer to see ratio on an interval of 0 to 100.
Q2vS8 before scaling:
Voilá! After setting denominator, and using a scale of 100, we now have a new element that is defined as Q2_x / S8.
Press the square edit icon and choose "Round by..." to create custom rounding for the group. For a question measured in percentage, we recommend rounding by 20.
Zero-fill [NA] values
If some respondents were counted as [NA], and you want those values to count as 0 you can showMissing and recode [NA]s to "0".
1. Choose "More properties..." from the context menu. Then, next to "showMissing" choose "Yes".
2. Choose "Recode..." from the context menu. Drag [NA] over to the "(New code)" button and name it "0".
Filter question to a subset
If you want to limit the question to a subset of respondents, create a permanent filter on the group.
In the example below, we want to limit the responses in Q2vS8 to respondents who indicated they are a "Practice Nurse" in S1.
First, press "Practice Nurse" in S1 to create a filter.
Then, choose "Filters..." from Q2vS8 context menu and apply the current filters.
The element is now permanently limited to Practice nurses, and this is automatically labeled in the footnote.
Footnotes can be edited directly by pressing on the existing footnote text.
You can also edit footnotes in "More properties..." from the context menu. Next to "footnote" enter your text.
Set "maxValue" under "More properties..." to reference a value by which to scale bars for the element or group. This is useful when compacting to mean, so that bars can be drawn for means relative to some value.
Q2vS8 compacted to mean, without maxValue:
Note: If you choose compact to percent the bars will automatically be scaled to 100, and you do not need to set maxValue.
Show N size for groups
In compacted groups, N sizes aren't visible unless you press the triangles next to child elements. You can show an N size for the parent group, Q2vS8, by telling it where to source an N size from.
To set N size for group, change:
- Type: Empty to default
- Field: Reference a child element
- Statistics: Uncheck all except "Basis"
Type and Field
Under "More properties..." for Q2vS8 set "type" to default instead of empty. This lets Protobi know that Q2vS8 is meant to have data. Next, change "field" to inform Q2vS8 as to where its meant to source its data from.
For "field" enter the key of a child element (here we're using Product A's key). This will tell Q2vS8 to get its data (hence N size) from that element.
The final step is to adjust "Statistics..." from the context menu. Choose "Basis" (N size) and uncheck other options.
Q2vS8 prior to changing stats:
Q2vS8 after selecting "Basis" only:
Means are ratio averages
By default, when you use the "denominator" property, the mean is intelligently weighted to show the ratio average, (i.e., the sum of numerators over sum of denominators, excluding rows with missing values for either).
Alternative: simple ratios
If you want to calculate a simple ratio, Protobi's default calculation method can be turned off. To calculate average of ratios-- as in, calculate Q2_x/Q8 for each respondent, and then average the resulting ratios, you can turn ratioMean off be using the attribute in JSON:
Q2vS8 turning "ratioMean" off: