This function takes a continuous (double) column of data and converts it to have 0 as the lower bound and 1 as the upper bound.
Usage
normalize(outcome, true_bounds = NULL)
Arguments
outcome
Any non-character vector. Factors will be converted to numeric via coercion.
true_bounds
Specify this parameter with the lower and upper bound if the observed min/max of the outcome should not be used. Useful when an upper or lower bound exists but the observed data is less than/more than that bound. The normalization function will respect these bounds.
Details
Beta regression can only be done with a response that is continuous with a lower bound of 0 and an upper bound of 1. However, it is straightforward to transform any lower and upper-bounded continuous variable to the [0,1] interval. This function does the transformation and saves the original bounds as attributes so that the bounds can be reverse-transformed.
Value
A numeric vector with an upper bound of 1 and a lower bound of 0. The original bounds are saved in the attributes "lower_bound" and "upper_bound".
Examples
library(ordbetareg)# set up arbitrary upper and lower-bounded vectoroutcome <-runif(1000, min=-33, max=445)# normalize to \[0,1\]trans_outcome <-normalize(outcome=outcome)summary(trans_outcome)
Min. 1st Qu. Median Mean 3rd Qu. Max.
0.0000 0.2655 0.4860 0.4951 0.7367 1.0000
# only works with numeric vectors and factorstry(normalize(outcome=c('a','b')))
Error in normalize(outcome = c("a", "b")) :
Please do not pass a character vector as a response/outcome.
That really doesn't make any sense.