|
|
|
|
|
by dxbydt
911 days ago
|
|
Sir, I worked thru your dog & cat adoption example. I had a few questions. So you have x & y vectors, and want the vector z, as below: x<- c(1,2,3)
y <- c(4,5,6)
z<- c(1+4, (1*2+4*5)/(1+4), sqrt((1*(4+9) + 4*(25+36))/(1+4) - ((1*2+4*5)/(1+4))^2))
But your z[2] is just an elaborate weighted mean, I would use the following built-in function - weighted.mean(c(2,5),c(1/(1+4),4/(1+4)))
Similarly, your z[3] is just the weighted standard deviation, available in library modi. I was wondering, isn't it better to store the data in some vector x & the weights in a different vector y, and compute the weighted mean & weighted variance in a straightforward fashion like above, or am I missing something. Thanks. |
|