Hi all, Can anyone tell me why I am getting different results in calculating SD of 2 numbers ?> (1.25-0.95)/2[1] 0.15> sd(c(1.25, 0.95))[1] 0.2121320 # why it is different from 0.15? Regards, Send instant messages to your online friends http://uk.messenger.yahoo.com [[alternative HTML version deleted]]
Bjørn-Helge Mevik
2008-Jan-16 08:34 UTC
[R] Different results in calculating SD of 2 numbers
Ron Michael <ron_michael70 at yahoo.com> writes:> Can anyone tell me why I am getting different results in calculating > SD of 2 numbers ? > >> (1.25-0.95)/2 > [1] 0.15Because this is not the SD? Try> (1.25-0.95)/sqrt(2):-)>> sd(c(1.25, 0.95)) > [1] 0.2121320 # why it is different from 0.15?-- Bj?rn-Helge Mevik
Daniel Nordlund
2008-Jan-16 08:39 UTC
[R] Different results in calculating SD of 2 numbers
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of Ron Michael > Sent: Wednesday, January 16, 2008 12:15 AM > To: r-help at stat.math.ethz.ch > Subject: [R] Different results in calculating SD of 2 numbers > > Hi all, > > Can anyone tell me why I am getting different results in calculating SD of 2 numbers ? > > > (1.25-0.95)/2 > [1] 0.15Because the above is not the standard deviation of two numbers. The sample based estimate of the population standard deviation of a set of numbers (which is what sd() computes) is (sum((x-mean(x))^2 )/(length(x)-1))^.5 which for your two numbers would be ( (1.25 - 1.1)^2 + (.95 - 1.1)^2 )^.5> > sd(c(1.25, 0.95)) > [1] 0.2121320 # why it is different from 0.15? > > Regards, >Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA
Martin Maechler
2008-Jan-16 08:45 UTC
[R] Different results in calculating SD of 2 numbers
>>>>> "RM" == Ron Michael <ron_michael70 at yahoo.com> >>>>> on Wed, 16 Jan 2008 00:14:56 -0800 (PST) writes:RM> Hi all, RM> Can anyone tell me why I am getting different results in calculating SD of 2 numbers ? >> (1.25-0.95)/2 RM> [1] 0.15 >> sd(c(1.25, 0.95)) RM> [1] 0.2121320 # why it is different from 0.15? because 1 is different from 2 ! If 2 was 1, than sqrt(2) == 1 as well, but actually I don't think the universe and we all would exist in that case .... Martin Maechler, ETH
Ben Fairbank
2008-Jan-16 17:08 UTC
[R] [PS] Different results in calculating SD of 2 numbers
And another problem, in addition to the points made by others, is that the formula for the SD gives a biased estimate (it underestimates it) of the population SD for small n when sampling from a normal distribution. When n is about twelve or so or more, the bias can usually be ignored (it is about 2.2%), but when you have only two numbers, the correction factor is about 1.25. The approximate correction formula, as I understand it, is (n-.75)/(n-1), so if n = 2, then it is 1.25/1, but this is not exact. The "real" formula is more complex (not difficult, but involves the gamma function) and my reference to it is not at this office, or I would give it. HTH, Ben -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ron Michael Sent: Wednesday, January 16, 2008 2:15 AM To: r-help at stat.math.ethz.ch Subject: [PS] [R] Different results in calculating SD of 2 numbers Hi all, Can anyone tell me why I am getting different results in calculating SD of 2 numbers ?> (1.25-0.95)/2[1] 0.15> sd(c(1.25, 0.95))[1] 0.2121320 # why it is different from 0.15? Regards, Send instant messages to your online friends http://uk.messenger.yahoo.com [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.