计算 R 中的平方偏差总和 [英] Calculating sum of squared deviations in R
本文介绍了计算 R 中的平方偏差总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何计算向量的平方偏差(与平均值)之和?
How can I calculate the sum of squared deviations(from the mean) of a vector?
我尝试使用命令
sum(x-mean(x))^2
sum(x-mean(x))^2
但不幸的是,这返回的是 -1.998401e-15,这不可能是正确的.是否有一个微妙的运算符,比如括号,我可能在这里遗漏了?
but unfortunately what this returns is -1.998401e-15 which cannot be right. Is there a subtle operator, like a parenthesis, that I am missing here perhaps?
谢谢.
推荐答案
这很可能是正确的.-2.0 的 10^15 次方意味着它基本上为零.但正如贾斯汀刚刚在评论中指出的那样,你有
It may well be correct. -2.0 to the power of 10^15 means it is essentially zero. But as Justin just noted in the comment, you have
(sum (x - mean(x) )^2
你可能的意思是:
sum( (x - mean(x) )^2 )
这篇关于计算 R 中的平方偏差总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文