From a vector of data, returns a vector of the number of non-NA elements, the mean, and the 2nd through kth centered sums of the input data.
cent_sums(
v,
max_order = 5L,
na_rm = FALSE,
wts = NULL,
check_wts = FALSE,
normalize_wts = TRUE
)a vector the same size as the input consisting of the adjusted version of the input.
When there are not sufficient (non-nan) elements for the computation, NaN are returned.
a vector
the maximum order of the centered moment to be computed.
whether to remove NA, false by default.
an optional vector of weights. Weights are ‘replication’
weights, meaning a value of 2 is shorthand for having two observations
with the corresponding v value. If NULL, corresponds to
equal unit weights, the default. Note that weights are typically only meaningfully defined
up to a multiplicative constant, meaning the units of weights are
immaterial, with the exception that methods which check for minimum df will,
in the weighted case, check against the sum of weights. For this reason,
weights less than 1 could cause NA to be returned unexpectedly due
to the minimum condition. When weights are NA, the same rules for checking v
are applied. That is, the observation will not contribute to the moment
if the weight is NA when na_rm is true. When there is no
checking, an NA value will cause the output to be NA.
a boolean for whether the code shall check for negative weights, and throw an error when they are found. Default false for speed.
a boolean for whether the weights should be
renormalized to have a mean value of 1. This mean is computed over elements
which contribute to the moments, so if na_rm is set, that means non-NA
elements of wts that correspond to non-NA elements of the data
vector.
Steven E. Pav [email protected]
Terriberry, T. "Computing Higher-Order Moments Online." https://web.archive.org/web/20140423031833/http://people.xiph.org/~tterribe/notes/homs.html
J. Bennett, et. al., "Numerically Stable, Single-Pass, Parallel Statistics Algorithms," Proceedings of IEEE International Conference on Cluster Computing, 2009. tools:::Rd_expr_doi("10.1109/CLUSTR.2009.5289161")
Cook, J. D. "Accurately computing running variance." https://www.johndcook.com/standard_deviation/
Cook, J. D. "Comparing three methods of computing standard deviation." https://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/
set.seed(1234)
x1 <- rnorm(1e3,mean=1)
max_ord <- 6L
rs1 <- cent_sums(x1,max_ord)
Run the code above in your browser using DataLab