@@ -12,7 +12,7 @@ The covidcast package provides some simple utilities for exploring the
1212correlations between two signals, over space or time, which may be helpful for
1313simple analyses and explorations of data.
1414
15- For these examples, we'll load confirmed case and death rates. and restrict our
15+ For these examples, we'll load confirmed case and death rates, and restrict our
1616analysis to counties with at least 500 total cases by August 15th.
1717
1818``` {r, message = FALSE}
@@ -81,18 +81,25 @@ linear relationship. The latter can be addressed using Spearman correlation,
8181accomplished by setting ` method = "spearman" ` in the call to ` covidcast_cor() ` .
8282Spearman correlation is highly robust and invariant to monotone transformations
8383(it doesn't rely on any particular functional form for the dependence between
84- two variables).
84+ two variables).
8585
86- We might also interested in interested in how case rates associate with death
87- rates in the * future* . Using the ` dt_x ` parameter in ` covidcast_cor() ` , we can
88- lag case rates back any number of days we want, before calculating correlations.
86+ ### Lagged correlations
87+
88+ We might also be interested in how case rates associate with death rates in the
89+ * future* . Using the ` dt_x ` parameter in ` covidcast_cor() ` , we can lag case rates
90+ back any number of days we want, before calculating correlations.
91+
92+ Here we set ` dt_x = -10 ` . This means that ` iprop_act ` will be lagged by 10 days,
93+ meaning that cases on June 1st will be correlated with deaths on June 11th. (It
94+ might help to think of it this way: deaths on a certain day will be correlated
95+ with cases with an offset of -10 days.)
8996
9097``` {r, warning = FALSE}
9198# Use Spearman correlation, with case rates and 10-day lagged case rates
9299df_cor1 <- covidcast_cor(iprop_act, dprop_act, by = "time_value",
93- method = "spearman")
100+ method = "spearman")
94101df_cor2 <- covidcast_cor(iprop_act, dprop_act, by = "time_value", dt_x = -10,
95- method = "spearman")
102+ method = "spearman")
96103
97104# Stack rowwise into one data frame, then plot time series
98105df_cor <- rbind(df_cor1, df_cor2)
@@ -106,10 +113,10 @@ ggplot(df_cor, aes(x = time_value, y = value)) +
106113 theme(legend.position = "bottom")
107114```
108115
109- We can see that, for the most part, the Spearman measure has bolstered the
110- correlations; and generally, lagging the case rates time series back by 10 days
111- improves correlations, confirming case rates are better correlated with death
112- rates 10 days from now.
116+ We can see that, for the most part, the Spearman measure has bolstered the
117+ correlations; and generally, lagging the case rates back by 10 days improves
118+ correlations, confirming case rates are better correlated with death rates 10
119+ days from now.
113120
114121## Correlations sliced by county
115122
0 commit comments