0

I want to calculate in r weighted mean and weighted standard deviation (the weights are sample weights, for a survey sample. It is suppose to show how many units in the population represent each unit in the sample).

I tried to calculate this by two ways and got the same answers for the means, but different answers for the s.d.

Is one of the ways correct?

the first way-

a<-c(1,2,3)
b_gender<-c('men','men','women')
c_weight<-c(1,1,2)
table1<-tableby(gender~a, weights=c_wei)

another way-

a<-c(1,2,3)
gender<-c('men','men','women')
c_weight<-c(1,1,2)
w.mean(a, c_wei)
   w.ds(a, c_wei)
aa1
  • 3
  • 1
  • for the first way I used arsenal package, for the second way I used Weighted.Desc.Stat. – aa1 Dec 05 '20 at 21:04
  • I assume the funciton used is `w.sd` instead of `w.ds`?. In the documentation, it says the function defined is `function(x, mu) ( (sum(mu*x*x)/sum(mu)) - w.mean(x,mu)^2 )^`. – akrun Dec 05 '20 at 21:07

0 Answers0