Generate weekly data from daily data with predictors

Hello Team ,

@Scott @Jim_Grace Please any tips on how to generate weekly data from daily data with predictors ?

ie. COVID-19 confirmed cases

Days : d1 = 1, d2 = 2, d3 = 2, d4 = 2 , d5 = 1, d6 = 1, d7 = 1, d8 = 0, d9 = 2, d10 = 1, d11=2, d12 = 1, d13 = 5, d14 = 4

Weeks : w1 = 10 , W2 = 15

Sincerely

Hi @Guy_Ekani,

Sure. Just create a weekly predictor, and use the input data element as the generator expression, like

#{pOov3eithai}

That should do it. The predictor will automatically get data from any daily periods that are within the weekly period. For the predictor period type you can choose “Weekly” if you want your weeks to start on Monday, or you can also choose “Weekly starting Wednesday”, “Weekly starting Thursday”, “Weekly starting Saturday”, or “Weekly starting Sunday”.

As with any predictor, you will need to define a data element for the output of the prediction, and assign that to the predictor as the output data element.

If you just want to summarize the daily counts within a week, for that week, the predictor generator expression should not use any aggregation function like sum() in the generator expression, and you can just specify zero for the Sequential sample count and Annual sample count. These features are just needed if you want to time-shift data, for example if you want to store in a weekly period the average weekly sum of some number of preceding weeks.

When you run the predictor, you can specify start and end dates that just have the predictions made for the most recently-completed week, or for any number of prior weeks (in case older data has been subsequently corrected).

Let me know if you have any further questions!

Cheers,
Jim

2 Likes

Thank you for your clear explanation @Jim_Grace,

Now, i have trouble with generator to evaluate when a datalement with type Yes/No it’s empty or not in DHIS 2.35.12

Please any help

image

Hi,
You can use the “if(test, valueIfTrue, valueIfFalse)” function in the generator expression.

Example:

if(isNull(#{T7OyqQpUpNd}), 0, 1)

Meaning: If the data element T7OyqQpUpNd is null in the period being predicted, then 0, otherwise 1.

1 Like

@lens_Kamdem Thank you, that’s right!

@Guy_Ekani Unfortunately predictors in 2.35 only work with data elements having numeric values. This was fixed in 2.36.7, see DHIS2-10818. (The fix was for both validation rules and predictors.) The fix was extensive (43 files). The code that was fixed had changed significantly between 2.35 and 2.36 due to a major performance improvement for predictors, DHIS2-9317, so a backport to 2.35 was not attempted.

To make this work, you can use a formula as @lens_Kamdem describes, and also you will need to upgrade your instance to 2.36.7 or later.

2 Likes