R/update_mean.R

Defines functions update_mean

Documented in update_mean

##' The function updates the mean of a dataset when we have a new data by recursive formula
##'
##' update_mean() can be used to update the mean of a large data set without recalculating the whole data set to make compuation easier. The function can be used to update univariate or multivariate data set.
##' @title Update the Covariance of a dataset
##' @title Update the mean of a dataset
##' @param old_mean the mean of previous dataset
##' @param m the number of data in your previous dataset
##' @param newx value of your new data
##' @return new mean
##' @author Xiulin Xie
##' @export
##' @examples
##' update_mean(mean(c(1:13)),13,14)

update_mean <- function(old_mean, m, newx) {
    new_mean <- newx/(m + 1) + m/(m + 1) * old_mean
    return(new_mean)
}
XiulinXie/SPCmonitor2 documentation built on Dec. 10, 2019, 12:10 a.m.