eco-detectives / eco_detective

Reading/coding group for The Ecological Detective
1 stars 3 forks source link

poisson distribution in pc7.4 #11

Open couture322 opened 6 years ago

couture322 commented 6 years ago

What did people use for lambda in pseudocode 7.4?

rpois(n,lambda)

I used 4 because it looked right-ish but don't know if that's correct or the correct way to make that decision

oharac commented 6 years ago

Playing around with 7.4 - I think the pseudocode is off. I think step 4 should read more like:

"Calculate the actual observation using a Poisson distribution, using the results from step 3 as the parameter." Here's my code:

df <- data.frame(D = 1:20) %>%
  rowwise() %>%
  mutate(I_det = max(0, (p + q * D) / (1 + r * D))) %>%
  ungroup() %>%
  mutate(obs = rpois(n(), I_det))

The index is the expected value of observations given an actual abundance, and for a Poisson, the expected value (and the variance) are both identical to the parameter. Adding a Poisson to the result of step 3 doesn't make sense.

I tried this and got a plot pretty similar to that in the book:

image

oharac commented 6 years ago

7.5 was a pain in the butt, figuring out how to estimate the parameters p, q, and r for each of the four models. Models A and B were fine, since they're just linear, but C and D have the nonlinear term, so I used nls() which sometimes threw a "singular matrix" error.

If anyone knows a better way please post it!

couture322 commented 6 years ago

Thanks for the help with pc7.4, @oharac ...I'll keep messing with 7.5 but I'm thinking you get this one better than I do still :/