Imagine there are a hundred bunnies alive right now, and we want to figure out how many bunnies there are going to be in the future.
The only two things that can change the number of bunnies are the number of bunnies born and the number of bunnies that die.
What you are going to do is play with the birth rate and the death rate to have some number of bunnies around a hundred years from now. Pay attention to the shape of the curve, and to how much difference between births and deaths you need to get different results.
b <- 0.200d <- 0.200N <- numeric(101); N[1] <- 100for (t in 1:100) N[t+1] <- N[t] + b*N[t] - d*N[t]plot(0:100, N, type = "l")N[101]# the same thing in one line100 * (1 + b - d)^100
Returning to the Grants and their study of finches on Daphne Major: because they captured every single one, they know how many birds are alive on their small island each year.
Instead of measuring their beak size, the way we did in Lesson 5, this is the number of birds on the island in each year of their study. What we are going to do is fit the birth rate and the death rate to try to match their data.
In 1977 there was a drought and a lot of birds died. So first we are going to try to get the number of birds down to the size of the crash. Then we are going to try to predict the number of birds alive in 2012.
p <- read.csv("data/clean/finch_pop.csv")b <- 0.20d <- 0.20N <- numeric(nrow(p)); N[1] <- p$scandens[1]for (t in 2:nrow(p)) N[t] <- N[t-1] * (1 + b - d)# how far off it is in an average year, in birdsmean(abs(N - p$scandens))
Only two things, births and deaths, can change the population. Yet there was no combination of births and deaths that matched the whole trajectory across time in the Grants' finch data.
Obviously the birds are going to have a different birth rate and death rate every single year. You could find the 40 different birth rates and 40 different death rates to perfectly fit the data.
But if you do that: what's the death rate for year 41? The birth rate?
Having 80 parameters (40 death rates + 40 birth rates) gets you zero error… but if you're finding them by just setting them to the data, you've gained no information. You haven't learned how to predict how many birds there will be next year.
What we'd like is to use the data we have — changes in population size over time — to predict the future.
Your goal isn't to get zero error; that's trivial to do by just throwing parameters that teach you nothing at the data. Your goal is to make better predictions about the future.
So instead of trying to predict 40 years of data with 80 parameters that are each made up to fit what we've already seen, we're going to try to predict 40 years of what we've seen using three or four parameters, and see how far we're off. Using fewer parameters means we can test how reliable each one is. We won't fit the data as well, but we'll be on firmer footing when we try to predict the next piece of data in advance.
p <- read.csv("data/clean/finch_pop.csv")r <- read.csv("data/clean/grant_rainfall.csv")wet <- log10(r[match(p$year, r$Year), 2] + 1) - 1.88b0 <- 0.30d0 <- 0.30rainPull <- 0.00crowdPull <- 0.00N <- numeric(nrow(p)); N[1] <- p$scandens[1]for (t in 2:nrow(p)) { b <- b0 + rainPull * wet[t-1] d <- d0 + crowdPull * (log10(N[t-1]) - 2.24) N[t] <- N[t-1] * (1 + b - d)}mean(abs(N - p$scandens))
Moose have been counted on Isle Royale every winter since 1959. Here are the first forty-two years of it, and nothing else — no weather, no browse, no predators.
One birth rate and one death rate for the whole record, as before. Then a third number: how much extra of the herd dies in a bad year. You decide which years were bad by clicking them.
Every year you mark costs you a click and buys you some fit. Find the fewest that get you there.
d0 <- read.csv("data/clean/isle_royale.csv")d0 <- d0[d0$year <= 2000, ]b <- 0.200d <- 0.200ex <- 0.00bad <- c()N <- numeric(nrow(d0)); N[1] <- d0$moose[1]for (t in 2:nrow(d0)) { dd <- d + ifelse(d0$year[t-1] %in% bad, ex, 0) N[t] <- N[t-1] * (1 + b - dd)}mean(abs(N - d0$moose))
Choosing the bad years leaves us with a problem: we can fit the data better, but why were those years bad? If we don't know the reason, then we're just guessing about whether next year will be good or bad. We haven't learned any information really — we haven't improved our ability to predict the future.
Instead of manually choosing the bad years, it would be better if we had a way to predict the bad years.
Fortunately, moose aren't the only thing they've been counting on Isle Royale! They've also counted the wolves.
Below are the population counts for moose and wolves on the island over the same 42 winters. Now what we can do is tie our moose birth and death rates to the wolf population numbers. Below the graphs is your model. Build it piece by piece.
You want the best fit possible… but the more parameters you have, the harder it is to predict the future with confidence. So as before, we're trying to balance how right we can be about the data in front of us with how confident we are about future, unseen data.
d0 <- read.csv("data/clean/isle_royale.csv")d0 <- d0[d0$year <= 2000, ]mb <- 0.200md <- 0.200beta <- 0.00 # wolves -> moose deathsM <- numeric(nrow(d0)); M[1] <- d0$moose[1]for (t in 2:nrow(d0)) M[t] <- M[t-1] * (1 + mb - md - beta * d0$wolves[t-1]/50)mean(abs(M - d0$moose))gam <- 0.00 # moose -> wolf birthsW <- numeric(nrow(d0)); W[1] <- d0$wolves[1]for (t in 2:nrow(d0)) W[t] <- W[t-1] * (1 + wb + gam * d0$moose[t-1]/1000 - wd)mean(abs(W - d0$wolves))