Re: Calculate Standard Deviation with R




"Bruce Weaver" <bweaver@xxxxxxxxxxxx> a écrit dans le message de news:
f3f3ff02om1@xxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxxxxxxxxxxx
R User wrote:
"Anon." <bob.ohara@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le
message de news: f3ejpo$p8k$1@xxxxxxxxxxxxxxxxxxxxxxxxxx
R User wrote:
"Anon." <bob.ohara@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> a écrit dans le
message de news: f3e3tp$bon$1@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))"

You 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.
ok thank you,
could you confirm what I means : this not a miracle function which
gives me the standard deviation ?
No, it gives you the weighted variance.
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)
ni=c(1,3,6,8,13,9,5,3,2)
sqrt(cov.wt(data.frame(xi), ni)$cov)
xi
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.

I find the same results as you but why do you minore N by 1 : 50- 1 ?



--
Bruce Weaver
bweaver@xxxxxxxxxxxx
www.angelfire.com/wv/bwhomedir


.



Relevant Pages

  • Re: Calculate Standard Deviation with R
    ... de news: f3erb6$2ff$1@xxxxxxxxxxxxxxxxxxxxxxxxxx ... I found this using help.search("weighted variance"). ... Just give it a vector of values, and a vector of weights, and it'll give you the weighted covariance matrix. ... Descriptive Statistics ...
    (sci.stat.math)
  • Re: Calculate Standard Deviation with R
    ... de news: f3erb6$2ff$1@xxxxxxxxxxxxxxxxxxxxxxxxxx ... I found this using help.search("weighted variance"). ... Just give it a vector of values, and a vector of weights, and it'll give you the weighted covariance matrix. ... STD 4,25571511 ...
    (sci.stat.math)
  • Re: Calculate Standard Deviation with R
    ... de news: f3erb6$2ff$1@xxxxxxxxxxxxxxxxxxxxxxxxxx ... it gives you the weighted variance. ... Just give it a vector of values, and a vector of weights, and it'll give ... STD 4,25571511 ...
    (sci.stat.math)
  • Re: About Bootstrap and replacement
    ... It's also not too difficult to show that the variance of your estimate of the mean is larger than the standard estimate, so your estimator will be worse than the bootstrap estimator. ... algorithm without replacement and my *strange weighting* are ... If you had bothered to do the sums, hten you would have found out that the variance of a weighted mean of x_i with weights w_i is * sum w_i^2)/^2. ... From this you can work out that the minimum varaince occurs when the weights are equal. ...
    (sci.stat.math)
  • Re: A multiple regression stumper
    ... > variable in a standard multiple regression model. ... > of optimal weights that minimize the variance of e. ... > I would like to compute R2 for non-optimal sets of weights. ...
    (sci.stat.math)