Existing function for combining standard deviations in R?

I have 4 populations with known means and standard deviations. I would like to know a grandiose and great thing. The average value is obviously easy to calculate, but R has a convenient utility function, weighted.mean (). Is there a similar function for combining standard deviations?

The calculation is not complicated , but the existing function will make my code more understandable and understandable.

Bonus question, what tools do you use to find such features? I know that he should be there, but I searched a lot and can’t find him. Thank!

+5
source share
2 answers

Are populations non-overlapping?

library(fishmethods)
combinevar

, wikipedia :

xbar <- c(70,65)
s<-c(3,2)
n <- c(1,1)
combinevar(xbar,s,n)

sqrt (combvar (xbar, s, n) [2])

, :

combinevar <- 
function (xbar = NULL, s_squared = NULL, n = NULL) 
{
    if (length(xbar) != length(s_squared) | length(xbar) != length(n) | 
        length(s_squared) != length(n)) 
        stop("Vector lengths are different.")
    sum_of_squares <- sum((n - 1) * s_squared + n * xbar^2)
    grand_mean <- sum(n * xbar)/sum(n)
    combined_var <- (sum_of_squares - sum(n) * grand_mean^2)/(sum(n) - 
        1)
    return(c(grand_mean, combined_var))
}
+4

, , , . , :

## N: vector of sizes
## M: vector of means
## S: vector of standard deviations

grand.mean <- function(M, N) {weighted.mean(M, N)}
grand.sd   <- function(S, M, N) {sqrt(weighted.mean(S^2 + M^2, N) -
                                      weighted.mean(M, N)^2)}
+4

All Articles