相关函数的NA [英] NA from correlation function

查看:91
本文介绍了相关函数的NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否解释一下这两种情况之间的区别?

Could you please explain me the difference between these two cases?

> cor(1:10, rep(10,10))
[1] NA
Warning message:
In cor(1:10, rep(10, 10)) : the standard deviation is zero

> cor(1:10, 1:10)
[1] 1

第一个只是一条直线,而我希望第二条直线是一条。我没有考虑什么?谢谢

the first one is just a straight line as well as the second I would expect the correlation to be one. What am I not considering? Thanks

推荐答案

绘制数据,应该清楚。数据集

Plot the data and it should be clear. The data set

## y doesn't vary
plot(1:10, rep(10,10))

只是一条水平线。对于水平线,相关系数未定义,因为对<$ c的标准偏差进行了估计$ c> y 为0(出现在相关系数的分母上)。

is just a horizontal line. The correlation coefficient undefined for a horizontal line, since the estimate of the standard deviation for y is 0 (this appears on the denominator of the correlation coefficient). While

plot(1:10, 1:10)

是一行:

y = x

这篇关于相关函数的NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆