1

Good evening,

Even though I know it will "destroy" an actual normal distribution, I need to set a maximum and a minimum to a rnorm function in R. I'm using survival rates in vultures to calculate population trends and although I need it to fluctuate, for logic reasons, survival rates can't be over 1 or under 0. I tried doing it with if's and else's but I think there should be a better way to do it.

Thanks!

arnausc
  • 13
  • 3

1 Answers1

1

You could sample from a large normalized rnorm draw:

rbell <- function(n) {
  r <- rnorm(n * 1000)
  sample((r - min(r)) / diff(range(r)), n)
}

For example:

rbell(10)
#> [1] 0.5177806 0.5713479 0.5330545 0.5987649 0.3312775 0.5508946 0.3654235 0.3897417
#> [9] 0.1925600 0.6043243

hist(rbell(1000))

enter image description here

This will always be curtailed to the interval (0, 1).

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87