Creating Cross-Correlation

I want to use data in order to study the time delay between the diagnosis of Covid-19 and the death from Covid-19 for cases not surviving the disease. the data is from https://github.com/owid/covid-19-data/tree/master/public/data called owid-covid-data.csv. For two functions of time X(t) and Y(t) (here t is discrete, representing for example days) we define the cross-correlation as follows: cross_{corr}(\Delta_t ; X, Y) = Corr(X(t), Y(t+\Delta_t)). That is, the cross-correlation function at the time-delay \Delta_t for two vectors of length n is obtained by computing the Pearson correlation coefficient of the vector X[1,...,n-\Delta_t] with the vector Y[\Delta_t+1,...,n], for \Delta_t>0. For \Delta_t < 0 we replace the role of X and Y in the formula.

I need you to help me write a function that recieves as input a country name and the name of two columns, and computes the value of their cross-correlation in this country for time delay of up to two months apart, that is for all values of \Delta_t between -60 days and 60 days.

The function should return a vector of length 121 representing these correlations.

Thank you.

Is this your homework?

1 Like

Not sure if this is for personal use, work or school, but do be aware of our homework policy, FAQ: Homework Policy

A good place to start helping you out is by showing how you've approached this. Right now I'm not sure where you're having trouble. There are a number of R packages and online tutorials that will help you get set up (mostly university course resources pages associated with time series courses). For example, the testcorr package implements what you're trying to achieve, here's that package's vignette.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.