1

I have been trying to put dates from an single column in an excel sheet on the x-axis of a plot for a rollapply correlation function.

cor.fun = function(x){cor(x)[1,2]}
gdp.g <- cbind(economic_data$Global,economic_data$GDP)    
gdp.g.corr <- rollapply(as.zoo(gdp.g), FUN=cor.fun, width=1,
                            by.column=FALSE, align="right")

I've tried to use the below function to plot it but I receive the error message that follows.

plot(economic_data$Year,gdp.g.corr, main="GDP Global",
 ylab="Correlation", lwd=2, col="blue")

 Error in cor(x) : supply both 'x' and 'y' or a matrix-like 'x' 

I'm not sure how to make it so that the date data is compatible with the correlation output or vice versa. There are no error messages until I use 1 for the width. Any other value still provides an output.

Here is some sample data:

Year    GDP     Global
1949    -0.726  -0.074
1950    10.038  -0.173
1951    15.705  -0.052
1952    5.888    0.028
1953    5.956    0.097
1954    0.342   -0.129
1955    8.944   -0.190
1956    5.611   -0.267
1957    5.494   -0.007
brenner
  • 11
  • 2

0 Answers0