-2

I have a dataset with three variables: 1) mutual fund returns (MF), 2) stock index returns (SI), 3) oil price returns (OP).

I have computed a rolling window of correlation coefficients between i) MF and OP, and between ii) SI and OP. The eyeball-metric seems to indicate that case i) has a much higher correlation coefficient than case ii). However, I want to test this statistically. How should this be done? Is there a package for this in R?

Thomas

Sébastien Rochette
  • 6,536
  • 2
  • 22
  • 43
Thomas.LRV
  • 23
  • 6
  • 1
    This is more of a stats than programing question so I would suggest asking on (CrossValidated)[https://stats.stackexchange.com/]. That said the t-statistic for a correlation coefficient can be calculated as follows `r*sqrt((n-2)/(1-r^2))` df=N-2, This (site)[http://janda.org/c10/Lectures/topic06/L24-significanceR.htm] has some good explanantions – emilliman5 Oct 02 '17 at 14:06
  • can you add an example dataset and how you would like the output to be? – DataTx Oct 02 '17 at 14:51
  • `cor.test` function of the stats package provides a confidence interval for correlations which you could compare. If the intervals don't overlap you could say there's a significant difference. However if there is overlap there might still be a significant difference. I think you can test a correlation against a specific H0 by using a Fisher transformation https://en.wikipedia.org/wiki/Fisher_transformation – Niek Oct 02 '17 at 15:12

1 Answers1

0

You can use the rcorr() function of the Hmisc package to get the level of significance for the pearson and spearman correlations. Here is an example

mcor <- cor(mtcars)
head(mcor)
cor(mtcars, use = "complete.obs")

library(Hmisc)
# correlation coefficients and level of significance
rcorr(as.matrix(mtcars[,1:7]))
# correlation coefficient between mpg and cyl, and level of significance
rcorr(mtcars$mpg, mtcars$cyl, type = "pearson") 
# correlation coefficient between mpg and qsec, and level of significance
rcorr(mtcars$mpg, mtcars$qsec, type = "pearson")
nghauran
  • 6,648
  • 2
  • 20
  • 29