pearselab / r-world-Wolflab

r-world-Wolflab created by GitHub Classroom
0 stars 0 forks source link

runif for 6.2.1 survive #2

Open Wolflab opened 7 years ago

Wolflab commented 7 years ago

Will: I am at a bit of a loss here. I am not sure why we need to use uniform distribution. Why would we not use rnorm with the mean set to the survive probability for that species? I thought that was the idea for the survive vector? Can you give me a clue as to what I am missing

willpearse commented 7 years ago

We're drawing from a distribution, not setting a value. So we already know the survival probability for each species: let's call it 0.4

We now want to draw from the distribution, and randomly select whether a species will survive or not. If we draw a number from a uniform distribution between 0 and 1, then we have a 0.4 probability of getting a value less than or equal to 0.4. Thus if(runif(1) < 0.4) will give us a 0.4 probability of being TRUE, and so we can use that for our random draw.

If that's confusing, I guess you would get the same thing by doing sample(c(TRUE,FALSE), 1, prob=c(.4,.6)). The way I describe is somewhat the canonical way that is used a lot in statistical programming, since it's normally always possible to get a uniform distribution out of whatever language you're using.