0

How can I normalize a vector between 0.01-0.99 in R to use it in a glmm with a beta distribution.

I have seen an answer for this using python but I need to do it in r.

Update: the phrase I should be using is

“bound every value in a column between 0.01 and 0.99” I have already normalized the data between 0-1 but I need to make it 0.01-0.99 instead

Phil
  • 7,287
  • 3
  • 36
  • 66
  • Show the code you used to bound the column between 0 and 1. Does .98 * x + .01 work on data between 0 and 1? – dcarlson Aug 14 '22 at 03:52
  • see https://stackoverflow.com/questions/5294955/how-to-scale-down-a-range-of-numbers-with-a-known-min-and-max-value for explanation and https://stackoverflow.com/questions/5468280/scale-a-series-between-two-points#comment49916403_5468527 for R code or https://stackoverflow.com/questions/54200933/how-to-scale-int-values-in-r-between-0-and-100?answertab=trending#tab-top for using a package – user20650 Aug 14 '22 at 14:43

1 Answers1

0

An efficient way of Normalizing values is through the Min-Max Scaling method.

With Min-Max Scaling, I scale the data values between a range of 0 to 1 only. Due to this, the effect of outliers on the data values suppresses to a certain extent. Moreover, it helps us have a smaller value of the standard deviation of the data scale.

In the below example, I have used ‘caret’ library to pre-process and scale the data. The preProcess() function enables us to scale the value to a range of 0 to 1 using method = c('range') as an argument. The predict() method applies the actions of the preProcess() function on the entire data frame as shown below.

rm(list = ls())

data = c(1200,34567,3456,12,3456,0985,1211)
library(caret)
process <- preProcess(as.data.frame(data), method="range")
norm_scale <- predict(process, as.data.frame(data))

Output:

data

1   0.03437997

2   1.00000000

3   0.09966720

4   0.00000000

5   0.09966720

6   0.02815801

7   0.03469831
Phil
  • 7,287
  • 3
  • 36
  • 66