Re: Calculate Standard Deviation with R
- From: John Kane <jrkrideau@xxxxxxxxx>
- Date: 28 May 2007 12:43:46 -0700
On May 28, 1:28 pm, Bruce Weaver <bwea...@xxxxxxxxxxxx> wrote:
R User wrote:
"R User" <R...@xxxxxxxxx> a écrit dans le message de news:
465afc41$0$19926$426a7...@xxxxxxxxxxxxxxx
"Anon." <bob.oh...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message
denews: f3erb6$2f__BEGIN_MASK_n#9g02mG7!__...__END_MASK_i?a63jfAD$z__@xxxxxxxxxxxxxxxxxxxxxxxxxx
R User wrote:
"Anon." <bob.oh...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le message
denews: f3ejpo$p8__BEGIN_MASK_n#9g02mG7!__...__END_MASK_i?a63jfAD$z__@xxxxxxxxxxxxxxxxxxxxxxxxxx
R User wrote:
"Anon." <bob.oh...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le
message denews: f3e3tp$bo__BEGIN_MASK_n#9g02mG7!__...__END_MASK_i?a63jfAD$z__@xxxxxxxxxxxxxxxxxxxxxxxxxx
R User wrote:
Hello,
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.
You could either write the function yourself, or use cov.wt:
x=rnorm(10)
wt=1:10
cov.wt(data.frame(x), wt)
I found this using help.search("weighted variance").Ok thank you,
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))"
No, it gives you the weighted variance.You have 2 closed brackets. And after that, rnorm() will still beok thank you,
screwed: check its help page (?rnorm): I was only generating x and wt
to give an example of R working.
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 :
xi(5,6,8,9,10)
ni(1,5,3,2,6)
If ni are the weights, then this will do it:
xi=c(5,6,8,9,10)
ni=c(1,5,3,2,6)
sqrt(cov.wt(data.frame(xi), ni)$cov)Thank you but it does not work. I tried with this serie
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
bwea...@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/wv/bwhomedir
I used pure brute force in R :
cnt<- c(496, rep(497,3), rep(498,6), rep(499,8), rep(500,13),
rep(501,9 ), rep(502,5), rep(503,3), rep(504,2))
and get the same results.
sd(cnt)[1] 1.822871
sqrt(3.165)[1] 1.779045
var(cnt)[1] 3.322857
.
- 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
- Re: Calculate Standard Deviation with R
- From: Bruce Weaver
- Calculate Standard Deviation with R
- Prev by Date: Re: Calculate Standard Deviation with R
- Next by Date: Re: Calculate Standard Deviation with R
- Previous by thread: Re: Calculate Standard Deviation with R
- Next by thread: Re: Calculate Standard Deviation with R
- Index(es):
Relevant Pages
|
|