r-不同的系数corrplot()和cor.test()



我计算了航班数据集所有可能组合的相关系数。我首先使用了一个corrplot。导致组合小时和sched_dep_time的系数为1。然而,使用cor.test((,它告诉我该值接近1,但为0.9906496。

这是我的代码:

# 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")

对这种差异的解释是什么?

这似乎是一个舍入问题。当你做

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

系数匹配得更好。

最新更新