Search code examples
rcorrelationr-corrplot

different coefficient corrplot() and cor.test()


I calculated the correlation coefficient for all possible combinations of the flights data set. I did this first using a corrplot. The resulted in a coefficient of 1 for the combination hour and sched_dep_time. However using cor.test() it tells me the value approaches 1 but is 0.9906496.

Here is my code:

# the corrplot
a <- flights %>% select(year, month, day, dep_time, sched_dep_time, dep_delay, arr_time, sched_arr_time, arr_delay, flight, air_time, distance, hour, minute)
corrplot(cor(na.omit(a)), method = "number")
# using cor.test
cor.test(flights$hour, flights$sched_dep_time, method = "pearson")

What is the explanation for this difference?


Solution

  • This seems to be a rounding issue. When you do

    library("corrplot")
    corrplot(cor(na.omit(a)), method = "number", number.digits=4, number.cex=.5)
    

    the coefficients match better.