Learn R Programming

UPMASK (version 1.2)

meanThreeSigRej: Perform cuts in the data

Description

meanThreeSigRej will perform an interative rejection using the mean and three sigma of the data. The function will compute the mean and standard deviation of the input vector, reject all entries lying farther than three-sigma, and iterate until the mean varies (fractionaly) by less than the tolerance value. The function will return a data frame with the mean, standard deviation value and the number of iterations until the convergence was reached.

Usage

meanThreeSigRej(vec, maxI, tolerance)

Arguments

vec

a vector with the data to consider

maxI

an integer with the maximum amount of iterations allowed

tolerance

a double with the tolerance value (as (old-new)/old)

Value

A data frame with the fields mean, sd (the standard deviation) and convergenceAtIter (the iteration where the convergence was reached).

Examples

Run this code
# NOT RUN {
# Create a simple data set with the values and errors
toyData <- c(rnorm(30, mean=0, sd=5), 10000, 1000)

# Call the function to perform cuts
toyDataItStat <- meanThreeSigRej(toyData)

cat(paste("True mean             = 0\n"))
cat(paste("Before rejection mean =",round(mean(toyData),2),"\n"))
cat(paste("After rejetion mean   =",round(toyDataItStat$mean,2),"\n"))

# Clean the environment
rm(list=c("toyData", "toyDataItStat"))
 
# }

Run the code above in your browser using DataLab