ra_truncate: Truncate a distribution

View source: R/ra_truncate.R

ra_truncateR Documentation

Truncate a distribution

Description

Truncates a vector of numeric variables to a specific range. Different methods of truncating the distribution are provided. 'ignore' will ignore the values outside the provided range. 'sub' will substitute the values outside the provided range with the min and max. 'resample' will bootstrap resample the values outside the distribution from the input values

Usage

ra_truncate(x, range, method = "ignore")

Arguments

x

vector of values to truncate

range

range of values to truncate at

method

method for the truncation. default is 'ignore', which will ignore all the values out of the range. 'sub' will substitute the values out of the range for the min and max values. 'resample' will resample the values of out range from the values inside the range.

Value

A vector of numeric values with the truncated values

Examples

# sample from a pert distribution
x <- ra_sample('pert(60, 80, 120)', n = 1000)

# method, ignore: ignore values out of bounds
ra_truncate(x = x, range = c(10, 90)) %>% 
 ra_plot_dist(main = 'Ignore')
 
# method substitute: substitute values out of bounds for min max provided
ra_truncate(x = x, range = c(10, 90), method = 'sub') %>%
  ra_plot_dist(main = 'Substitution')
# Method resample: Resample values out of bounds for values inside bounds
ra_truncate(x = x, range = c(10, 90), method = 'resample') %>% 
  ra_plot_dist(main = 'Resample')
 

jpablo91/QuantRRA documentation built on July 3, 2024, 10:46 p.m.