boogheta / coronavirus-countries

COVID-19 interactive dashboard for the whole world
https://boogheta.github.io/coronavirus-countries/
GNU Affero General Public License v3.0
55 stars 16 forks source link

Allow 7-day averages #49

Closed marcowitz closed 3 years ago

marcowitz commented 3 years ago

This tools is one of the best visualizations on the official case data out there. Congratulations 🎉

It would be really cool, if instead of the single values, one could also look at 7-day averages. Main reason for this is, that relevant data (such as daily confirmed cases) are very noisy (no lab work on weekends, etc.). This is why many analysts and even law-makers now consider the 7-day rolling average as the more relevant number for comparisons and to detect trends.

boogheta commented 3 years ago

Hi and thanks fo your feedback. The option actually already is there, although probably too discrete as you're not the first one to ask for it! :) Whenever you select "daily", a small icon with a line and two arrows appears to let you enable such 7-day average mode. Enjoy! :) smooth

marcowitz commented 3 years ago

I think something is wrong with the 7day moving average:

See here the 7-day averaged data on Sweden from 2 days ago: image

and here the non-smoothend version: image

The smoothened version does not really seem to show the 7-day moving average. If it did, it should also not change with new data (because it only looks into the past). But if I look at sweden today, this is the smoothened curve: image

It seems to me that the average is not really "rolling". In the sense of looking for each day into the past 7 and displaying their average.

RouxRC commented 3 years ago

Here's how it's computed: https://github.com/boogheta/coronavirus-countries/blob/master/js/corona.js#L856 I'm open to suggestions but I don't see how it should be done differently: if you want to display values for the last 3 days, these can only account for the mean of the last 4, 5 and 6 days to be consistent, which results necessarily in these kind of temporary decrease with reportings such as Sweden with a peak each week catching up on the figures from the week-end.

marcowitz commented 3 years ago

At least in Germany official 7-day rolling average numbers are calculated always looking backwards (see: https://www.sueddeutsche.de/muenchen/coronavirus-sieben-tage-inzidenz-berechnen-1.4909107). Meaning that the rolling average value on day X is the one of the past 7 days of day X (including day X, if the data for day X is final). This ensures that the value of the 7-day rolling average is static and will not change when new data comes in.

For the code it would probably mean something like: return d3.mean(values[c.id][cas][typVal].slice(Math.max(0, idx - 7), idx));

boogheta commented 3 years ago

Thanks for your feedback, that would be the way to do so indeed. But I'm a bit split about such a change. It would indeed avoid the varying last days effect my method causes, but it would also: