Calculating ratios

Protobi is smart enough to make calculating ratios simple

Conceptual diagram showing a ratio calculation with two survey questions labeled Q1 and Q2. The diagram displays two browser window icons with question labels connected by a diagonal division line, illustrating the concept of dividing one question by another to create a ratio.

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.

Example

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?
Protobi data view showing question S8 with the text 'How many of the Condition X patients do you manage are on a GA (gamma antagonist)?' The view displays a horizontal bar chart showing patient count ranges from 1-10 up to 141-150, with percentages for each range. The highest percentage is 27.0% for the 11-20 range. Protobi data view showing question Q2 asking about therapy usage. The display is set to 'Compact to Mean' and shows seven therapy products (Product A through G plus Other) with their mean values and blue horizontal bars. Values range from 0.745 (Other) to 12.6 (Product A).

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).

Clone the group (optional)

You might 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 unless you want to see both the original counts and the ratio. In this example, we've opted to clone Q2 and name the new group Q2vS8. It's necessary to use a recursive clone because we want to clone the parent group, but also create independent copies of its children.

Set denominator

For the new group, press the square edit icon and choose "More properties..." from the context menu. Then, next to "denominator" enter "S8".

Element properties dialog showing configuration for question Q2vS8. The dialog displays various fields including key, displayKey, title, and type. Two fields are highlighted with red borders: 'scale' set to 100, and 'denominator' set to S8, demonstrating the key settings for creating ratio calculations.

Scale the percentages to 100

In the same properties dialog, 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.

Result

Voilá! After setting denominator, and using a scale of 100, we now have a new group that is defined as Q2_x / S8.

Protobi data view showing the calculated ratio results for question Q2vS8. The display shows therapy percentages after dividing Q2 values by S8 and scaling to 100. Each product (A through G plus Other) now displays multiple percentage ranges with horizontal bars, showing the distribution of percentage values across respondents.

Additional options

Select custom value bins

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".

Close-up of element properties showing the showMissing dropdown menu expanded with three options: Yes (selected and highlighted in blue), No, and (default). This setting controls whether missing values are displayed in the data view.

2. Choose "Recode..." from the context menu. Drag [NA] over to the "(New code)" button and name it "0". 

Recode dialog showing the interface for recoding missing values to zero. The left side shows 'Codes' with a blue '(New code)' button and a box containing '0' as the new code value with '[NA]' listed below it. The right side shows 'Uncoded values' with '(uncoded)' and a count of 0.

Limit the question to a subset of respondents

If you want to consider only a certain subset of respondents for the question, 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.

Side-by-side view of two questions: Q2vS8 showing therapy percentages compacted to mean, and S1 showing specialty selection. In S1, 'Practice Nurse' is highlighted with a yellow bar showing 100.0% and appears selected with an orange arrow indicator, while 'General Practitioner' shows 0.0%.

Then, choose "Filters..." from Q2vS8 context menu and apply the current filters. 

Filters dialog showing options for applying filters to an element. The dialog displays two radio button options: 'Clear filters' and 'Apply current filters to this element' (which is selected). Below is explanatory text about using filters for skip patterns.

The element is now permanently limited to Practice nurses, and this is automatically labeled in the footnote.

<img src="/uploads/upload/image/5200/direct/1587649934993-1587649934993.png" alt="Protobi data view of Q2vS8 after applying permanent filter, showing therapy percentages compacted to mean for Practice Nurses only. Seven products are listed with their percentage values and blue bars. At the bottom, a red-outlined footnote reads 'S1 is 'Practice Nurse*', automatically documenting the applied filter."" style="text-align: center;" class="fr-fic fr-dib">

Edit footnotes

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. 

Close-up of element properties showing the footnote field with a text input box containing 'Among all Practice Nurses'. This demonstrates how to manually edit or customize footnote text for an element.

Scale bars using maxValue

If you prefer not to scale percentages to 100, then you might want to scale the bars. By default bars are scaled to 100, but if the percentages are being displayed in the interval of 0 to 1, the default setting won't be ideal.  

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. 

Close-up of element properties showing the maxValue field with a text input box containing the value '1'. This setting controls the scale used for drawing horizontal bars when displaying mean values.

Q3 compacted to mean, without maxValue:

Protobi data view of question Q3 compacted to mean without maxValue set. Shows seven therapy products with very small decimal values (ranging from 0.0170 to 0.289) and correspondingly very short blue horizontal bars that are barely visible, demonstrating the problem when percentages are on 0-1 scale but bars default to 0-100 scale.

After maxValue is set to 1:

Protobi data view of question Q3 compacted to mean after maxValue is set to 1. Shows the same seven therapy products with the same decimal values (0.289 to 0.0170), but now with appropriately scaled blue horizontal bars that are clearly visible and proportional to the values, demonstrating the solution to the bar scaling problem.

Calculate 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). 

Calculate 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:

"ratioMean":false

Q2vS8 turning "ratioMean" off:

Protobi data view of Q2vS8 with ratioMean turned off, showing compacted mean values for seven therapy products. The values and bar lengths differ from the default ratio calculation, demonstrating how disabling ratioMean changes from weighted ratio average (sum of numerators / sum of denominators) to simple average of individual ratios.

Video tutorial

Calculate ratios