epi_cor | R Documentation |
epi_df
objectComputes correlations between variables in an epi_df
object, allowing for
grouping by geo value, time value, or any other variables. See the
correlation vignette
for examples.
epi_cor(
x,
var1,
var2,
dt1 = 0,
dt2 = 0,
shift_by = geo_value,
cor_by = geo_value,
use = "na.or.complete",
method = c("pearson", "kendall", "spearman")
)
x |
The |
var1 , var2 |
The variables in |
dt1 , dt2 |
Time shifts to consider for the two variables, respectively,
before computing correlations. Negative shifts translate into in a lag
value and positive shifts into a lead value; for example, if |
shift_by |
The variables(s) to group by, for the time shifts. The
default is |
cor_by |
The variable(s) to group by, for the correlation
computations. If |
use , method |
Arguments to pass to |
An tibble with the grouping columns first (geo_value
, time_value
,
or possibly others), and then a column cor
, which gives the correlation.
# linear association of case and death rates on any given day
epi_cor(
x = cases_deaths_subset,
var1 = case_rate_7d_av,
var2 = death_rate_7d_av,
cor_by = "time_value"
)
# correlation of death rates and lagged case rates
epi_cor(
x = cases_deaths_subset,
var1 = case_rate_7d_av,
var2 = death_rate_7d_av,
cor_by = time_value,
dt1 = -2
)
# correlation grouped by location
epi_cor(
x = cases_deaths_subset,
var1 = case_rate_7d_av,
var2 = death_rate_7d_av,
cor_by = geo_value
)
# correlation grouped by location and incorporates lagged cases rates
epi_cor(
x = cases_deaths_subset,
var1 = case_rate_7d_av,
var2 = death_rate_7d_av,
cor_by = geo_value,
dt1 = -2
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.