I would like to calculate the standard deviation of a data element (with several Category options) from the past 6 periods. Can this be done with the .periodOffset and what is the exact syntax please?
I know this can be easily configured with a Predictor but in order to avoid configuring a separate “output” field we want to use an Indicator.
Data element: Paracetamol, 500 mg, tablet
Category option (COC): stock distribution
Period: monthly
To get the conversation moving, I asked the AI in the (docs and the developer portal) for some tips:
In DHIS2, the
.periodOffset()
function can indeed be used in an indicator to fetch data from different periods. However, calculating the standard deviation over a period of 6 months directly using an indicator is not straightforward. This is because the standard deviation involves multiple steps of calculations (mean, variance, square root) that cannot be directly implemented using the.periodOffset()
function in an indicator.As you mentioned, this can be easily done using a Predictor in DHIS2, where you can use the
stddevSamp()
function to calculate the standard deviation. However, if you want to avoid configuring a separate “output” field and want to use an Indicator, you might need to create separate indicators for each of the steps involved in calculating the standard deviation (mean, variance, square root) and then combine them.It’s also important to note that the
.periodOffset()
function is used to fetch data from a single period in the past or future, not a range of periods. To calculate the standard deviation over the past 6 months, you would need to fetch the data for each of the past 6 months separately and then perform the standard deviation calculation on these values.Here’s an example of how you might fetch the data for a single past month using
.periodOffset()
:#{Paracetamol_500mg_tablet}.periodOffset(-1)
This expression fetches the data for the “Paracetamol, 500 mg, tablet” data element from 1 month ago.
However, as mentioned earlier, calculating the standard deviation directly using an indicator is not straightforward and might require creating separate indicators for each step of the calculation.
For more information on how to use the
.periodOffset()
function in an indicator, you can refer to the DHIS2 documentation.
Isn’t data quality standard deviation handled by apps such as the WHO Data Quality tool app?
So to add more content to the topic post for future reference, is there a reason why creating a separate “output” field is an issue? Is this something that can be improved in the predictors side?
I hope the tips from the AI response are helpful, but please let me know if you have specific questions that I could experiment on play, research, or ask. Hopefully, this will get other community members to join the discussion.
Thanks!
Thanks Gassim: adding an additional field to the Data entry form is an issue as we have several Indicators and this would make the Data entry form unwieldy, especially when using a mobile device for entering data.