# This function calculates the mean, sd, and n from multiple groups combined
# from summary data It was developed from an explanation found here:
# https://www.statstodo.com/CombineMeansSDs_Pgm.php
esci_combine_groups <- function(means, sds, ns) {
vars <- sds^2
dfs <- ns - 1
sum_xs <- means * ns
sum_vars <- vars*dfs + sum_xs^2/ns
total_n <- sum(ns)
total_sum_xs <- sum(sum_xs)
total_sum_vars <- sum(sum_vars)
n <- total_n
m <- total_sum_xs / total_n
s <- sqrt((total_sum_vars-total_sum_xs^2/total_n) / (total_n-1))
res <- list(
m = m,
s = s,
n = n
)
return(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.