I'm trying to calculate the weighted average of a statistic sample (vector) in R using this form:
The function takes a vector and the weight is adjusted according by a second parameter (1 - 3), which are:
where s
is the standard deviation.
I've adjusted the weight accordingly if the parameter is 1 or 3 using else-if
's, but I'm having trouble with the 2nd one given that there is criteria to meet...
I've been calculating X - xBar
as a vector: m = x-mean(x)
I've been calculating s
with an R function: s = sd(x)
My query is regarding how "the meeting of the conditions should be programmed" in the 2nd critera. So far I have an if
for each condition, but...
When calculating the weighted average, (taking the top one as an eg), does each element of the x
vector (m/s
) need to be less than 1? or do I need to test each element and assign a weight from the 3 conditions accordingly?
eg. if the first elements answer was less than 1, assign a weight or 1, but second elements answer was inbetween 1 and 2, assign it a weight of 0.5?
I hope this makes sense. In R it throws a warning message saying the logic is only comparing the first element of the vector... so thats what raised the question.
Thanks in advance.