Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

What is the daily correlation of Confirmed versus Death Cases in Covid-19. In other words, the people who have passed away, on average, how many days ago they have been reported (i.e. “Confirmed”) as Covid-19 new cases.

To answer this question, we can take the correlation between the Daily Confirmed vs Daily Deaths and trying different lag values of the confirmed cases, since the assumption is that it will take some days for someone to pass away since has been diagnosed with Covid-19.

The problem with the data is that are affected by the number of tests and also during some days like weekends they do not report all the cases. This implies that our analysis is not valid, but we will try to see what get. We will analyze Italy.

## Italy: Correlation Between Confirmed Cases and Deaths

```df<-coronavirus%>%filter(country=='Italy', date>='2020-02-15')%>%select(date, country, type, cases)%>%
group_by(date, country, type) %>%pivot_wider(names_from =type, values_from=cases) %>%ungroup()

correlations<-c()
lags<-c(0:20)

for (k in lags) {

tmp<-df%>%mutate(lagk=lag(confirmed,k))%>%select(death,lagk)%>%na.omit()

correlations<-c(correlations,cor(tmp\$death, tmp\$lagk))
}

data.frame(lags, correlations)

data.frame(lags, correlations)%>%ggplot(aes(x=lags, y=correlations))+geom_point()

```

As we see, the argmax correlation is at k=6, which implies (if the data were accurate), that from the people who have passed away, most of them diagnosed with Covid-19 6 days ago.

## Italy: Correlation Between Confirmed Cases and Deaths SMA 5

Let’s do the same analysis, but this time by taking into consideration the Simple Moving Average of 5 days.

```df<-coronavirus%>%filter(country=='Italy', date>='2020-02-15')%>%select(date, country, type, cases)%>%
group_by(date, country, type) %>%pivot_wider(names_from =type, values_from=cases) %>%ungroup()%>%
mutate(confirmed = stats::filter(confirmed, rep(1 / 5, 5), sides = 1), death = stats::filter(death, rep(1 / 5, 5), sides = 1))%>%na.omit()

correlations<-c()
lags<-c(0:20)

for (k in lags) {

tmp<-df%>%mutate(lagk=lag(confirmed,k))%>%select(death,lagk)%>%na.omit()

correlations<-c(correlations,cor(tmp\$death, tmp\$lagk))
}

data.frame(lags, correlations)
data.frame(lags, correlations)%>%ggplot(aes(x=lags, y=correlations))+geom_point()

```

When we consider the SMA of 5 days the maximum correlation is at day 4.

## Belgium: Correlation Between Confirmed Cases and Deaths

Let’s do the same analysis for Belgium.

```df<-coronavirus%>%filter(country=='Belgium', date>='2020-02-15')%>%select(date, country, type, cases)%>%
group_by(date, country, type) %>%pivot_wider(names_from =type, values_from=cases) %>%ungroup()

correlations<-c()
lags<-c(0:20)

for (k in lags) {

tmp<-df%>%mutate(lagk=lag(confirmed,k))%>%select(death,lagk)%>%na.omit()

correlations<-c(correlations,cor(tmp\$death, tmp\$lagk))
}

data.frame(lags, correlations)

data.frame(lags, correlations)%>%ggplot(aes(x=lags, y=correlations))+geom_point()

```

Again, in Belgium, the highest correlation between Confirmed cases and Deaths, occurs after 6 days that people have been reported as new cases.

Finally, let’s run the same analysis by taking into consideration the SMA 5.

```df<-coronavirus%>%filter(country=='Belgium', date>='2020-02-15')%>%select(date, country, type, cases)%>%
group_by(date, country, type) %>%pivot_wider(names_from =type, values_from=cases) %>%ungroup()%>%
mutate(confirmed = stats::filter(confirmed, rep(1 / 5, 5), sides = 1), death = stats::filter(death, rep(1 / 5, 5), sides = 1))%>%na.omit()

correlations<-c()
lags<-c(0:20)

for (k in lags) {

tmp<-df%>%mutate(lagk=lag(confirmed,k))%>%select(death,lagk)%>%na.omit()

correlations<-c(correlations,cor(tmp\$death, tmp\$lagk))
}

data.frame(lags, correlations)
data.frame(lags, correlations)%>%ggplot(aes(x=lags, y=correlations))+geom_point()

```

Again, the maximum correlation observed on the 6th day.

## Discussion

I would like to stress out that this analysis is not valid because we lack much of the information about the way of collecting and reporting the data. However, it is clear that there is a lag between the Confirmed cases and Deaths but we cannot specify the number accurately.