Let us assume for this problem that all individuals dying with age between 0 and 1 years old die at 0.5 years old, that all those dying between 1 an 2 years die at 1.5 years old, and so.
We can compute life expectancy at birth directly:
prob = c(0.9,
(1-0.9)*0.5,
(1-0.9)*(1-0.5)*0.2,
(1-0.9)*(1-0.5)*(1-0.2))
age = c(0.5, 1.5, 2.5, 3.5)
cat('Life expectancy at birth is equal to', prob %*% age)
## Life expectancy at birth is equal to 0.69
Or using simple simulation:
fishAgeSim = sample(age, 30000000, replace = TRUE, prob = prob)
cat('Simulated life expectancy at birth is equal to', round(mean(fishAgeSim), 3))
## Simulated life expectancy at birth is equal to 0.69
Direct approach:
Simulation:
hist(fishAgeSim)
We can compute it directly:
cat('The probability that a fish live for between 1 and 3 years is', (1-0.9)*0.5+(1-0.9)*(1-0.5)*0.2)
## The probability that a fish live for between 1 and 3 years is 0.06