0

I'm trying to calculate the Pearson correlation for my data. So far I successfuly did it for daily and hourly returns, however I'm struggeling with Minuten returns.

This is what I did:

cor_df_min <- merge(usdt_min_return_cor, pax_min_return_cor, dgx_min_return_cor, btc_min_return_cor)
cor_df_min


Correlation_matrix_min = cor(cor_df_min, use = "pairwise.complete.obs")
print(Correlation_matrix_min)

But I still have NAs in my correlation matrix as you can see below:

             ClosePrice ClosePrice.1 ClosePrice.2 ClosePrice.3
 ClosePrice   1.00000000   0.02417688           NA   0.01711407
 ClosePrice.1 0.02417688   1.00000000   0.03966081  -0.20275678
 ClosePrice.2         NA   0.03966081   1.00000000           NA
 ClosePrice.3 0.01711407  -0.20275678           NA   1.00000000

Note: I have quite a few missing values and values very close or equal to zero in my data. Is that the problem? How can I fix it?

user438383
  • 5,716
  • 8
  • 28
  • 43
Nina
  • 11
  • 2
  • It is very hard to diagnose a problem with no data or any information about the data. The correlation coefficient will be NA if there are no pairs of non-missing data. Have you analyzed the amount and pattern of the missing data? For example, `rowSums(is.na(cor_df_min))`, `colSums(is.na(cor_df_min))`. The `rcorr` function in package `Hmisc` returns a correlation matrix, a matrix showing the number of observations used for each correlation, and the p-value of each correlation. – dcarlson Jul 24 '21 at 15:02
  • I tried what you suggestest and my result for both rowSums() and colSums is ClosePrice: 1 ClosePrice.1: 0 ClosePrice.2 :2 ClosePrice.3 :1 What does that tell me in terms of why I get NAs in my correlation matrix? – Nina Jul 25 '21 at 06:09
  • You need to provide more information on your data. What is cor_df_min? Is it created by merging other correlation matrices? Show your actual code in your question. If `cor_df_min` is a data matrix, you should not have the same variables as row and column names. – dcarlson Jul 25 '21 at 14:00

0 Answers0