[R] population variance and sample variance
Kingsford Jones
kingsfordjones at gmail.com
Fri Feb 5 05:03:46 CET 2010
On Tue, Feb 2, 2010 at 10:25 AM, Peng Yu <pengyu.ut at gmail.com> wrote:
> On Mon, Oct 19, 2009 at 12:53 PM, Kingsford Jones
> <kingsfordjones at gmail.com> wrote:
>>> sum((x-mean(x))^2)/(n)
>> [1] 0.4894708
>>> ((n-1)/n) * var(x)
>> [1] 0.4894708
>
> But this is not a built-in function in R to do so, right?
No because down that path lies bloat....
>
>> hth,
>> Kingsford
>>
>> On Mon, Oct 19, 2009 at 9:30 AM, Peng Yu <pengyu.ut at gmail.com> wrote:
>>> It seems that var() computes sample variance. It is straight forward
>>> to compute population variance from sample variance. However, I feel
>>> that it is still convenient to have a function that can compute
>>> population variance. Is there a population variance function available
>>> in R?
>>>
>>> $ Rscript var.R
>>>> set.seed(0)
>>>> n = 4
>>>> x = rnorm(n)
>>>> var(x)
>>> [1] 0.6526278
>>>> sum((x-mean(x))^2)/(n-1)
>>> [1] 0.6526278
>>>>
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list