Re: Calculate Standard Deviation with R
- From: Bruce Weaver <bweaver@xxxxxxxxxxxx>
- Date: Mon, 28 May 2007 13:28:35 -0400
R User wrote:
"R User" <Ruser@xxxxxxxxx> a écrit dans le message de news: 465afc41$0$19926$426a74cc@xxxxxxxxxxxxxxx"Anon." <bob.ohara@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message de news: f3erb6$2ff$1@xxxxxxxxxxxxxxxxxxxxxxxxxxR User wrote:Thank you but it does not work. I tried with this serie"Anon." <bob.ohara@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message de news: f3ejpo$p8k$1@xxxxxxxxxxxxxxxxxxxxxxxxxxNo, it gives you the weighted variance.R User wrote:ok thank you,"Anon." <bob.ohara@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message de news: f3e3tp$bon$1@xxxxxxxxxxxxxxxxxxxxxxxxxxYou have 2 closed brackets. And after that, rnorm() will still be screwed: check its help page (?rnorm): I was only generating x and wt to give an example of R working.R User wrote:Ok thank you,Hello,You could either write the function yourself, or use cov.wt:
I begin with R and I am searching a way to calculate a ST of a weighed serie :
xi(10,20,30)
ni(1,5,10)
I found the function VAR which uses a vector of one dimension but dot not care about coefficients.
x=rnorm(10)
wt=1:10
cov.wt(data.frame(x), wt)
I found this using help.search("weighted variance").
If I understand you affect a coefficient of 1 on the value 10 ?
But how do I do if I have several observations ?
I tried this :
x=rnorm(496,497,498,499,500,501,502,503,504))Erreur : erreur de syntaxe dans "x=rnorm(496,497,498,499,500,501,502,503,504))"
could you confirm what I means : this not a miracle function which gives me the standard deviation ?Do I need to compute all intermediaries steps ?Just give it a vector of values, and a vector of weights, and it'll give you the weighted covariance matrix (actually, it gives you a couple of other things as well). Then take the square root of that: if you're giving it the
How would you to calculate the standard deviation of a weighted serie like this :If ni are the weights, then this will do it:
xi(5,6,8,9,10)
ni(1,5,3,2,6)
xi=c(5,6,8,9,10)
ni=c(1,5,3,2,6)
sqrt(cov.wt(data.frame(xi), ni)$cov)xi=c(496,497,498,499,500,501,502,503,504)xi
ni=c(1,3,6,8,13,9,5,3,2)
sqrt(cov.wt(data.frame(xi), ni)$cov)
xi 1.967988
I found 1.967 as the standard deviation and if I computer it with excel I find : 4.25
496 1
497 3
498 6
499 8
500 13
501 9
502 5
503 3
504 2
Average 500
Variance 18,1111111
STD 4,25571511
I made a mistake, here is the result :
xi-X (xi-X)^2*ni
496 1 -4 16
497 3 -3 27
498 6 -2 24
499 8 -1 8
500 13 0 0
501 9 1 9
502 5 2 20
503 3 3 27
504 2 4 32
TOTAL 163
Average 500 3,26
Variance 3,26
STD 1,80554701
it is even different from the R solution
This is how I would do it in SPSS.
data list list / x n (2f5.0).
begin data.
496 1
497 3
498 6
499 8
500 13
501 9
502 5
503 3
504 2
end data.
weight by n.
descriptives x /stat = min max mean stddev var.
Descriptive Statistics
|---------------|--|-------|-------|------|--------------|--------|
| |N |Minimum|Maximum|Mean |Std. Deviation|Variance|
|---------------|--|-------|-------|------|--------------|--------|
|x |50|496 |504 |500.06|1.823 |3.323 |
|---------------|--|-------|-------|------|--------------|--------|
|Valid N |50| | | | | |
|(listwise) | | | | | | |
|---------------|--|-------|-------|------|--------------|--------|
The SD and variance are computed with n-1 in the denominator. With division by N, the variance would be approximately 3.323 * 49/50 = 3.165.
--
Bruce Weaver
bweaver@xxxxxxxxxxxx
www.angelfire.com/wv/bwhomedir
.
- Follow-Ups:
- Re: Calculate Standard Deviation with R
- From: John Kane
- Re: Calculate Standard Deviation with R
- From: R User
- Re: Calculate Standard Deviation with R
- References:
- Calculate Standard Deviation with R
- From: R User
- Re: Calculate Standard Deviation with R
- From: Anon.
- Re: Calculate Standard Deviation with R
- From: R User
- Re: Calculate Standard Deviation with R
- From: Anon.
- Re: Calculate Standard Deviation with R
- From: R User
- Re: Calculate Standard Deviation with R
- From: Anon.
- Re: Calculate Standard Deviation with R
- From: R User
- Re: Calculate Standard Deviation with R
- From: R User
- Calculate Standard Deviation with R
- Prev by Date: Re: Calculate Standard Deviation with R
- Next by Date: MSW (moving split window)
- Previous by thread: Re: Calculate Standard Deviation with R
- Next by thread: Re: Calculate Standard Deviation with R
- Index(es):
Relevant Pages
|