I’m trying to fit a simple ricker model to population trajectories with brms, so far with simulated data
library(bayesplot)
library(tidyverse)
library(brms)
ricker_poisson <- function(N0, r = 1.2, alpha = 0.02, timesteps = 100) {
N <- numeric(timesteps + 1)
N[1] <- N0
for (t in 1:timesteps) {
lambda <- N[t] * exp(r - alpha * N[t])
lambda <- max(lambda, 0) # safeguard
N[t + 1] <- rpois(1, lambda)
}
return(N)
}
set.seed(1)
# Simulate population
sim <- ricker_poisson(N0 = 10, r = 1.5, alpha = 0.001, timesteps = 100)
# make dataframe
dat <- data.frame(
N_t = sim[-length(sim)], # population at time t
N_tp1 = sim[-1] # population at time t+1
)
The growth rate (r) and intra-specific competition (alpha) can be fitted as a linear model with offset log(N_t), intercept r, and coefficient for predictor N_t as -alpha, using log link function.
The fitting needs (and will need it even more later when the model expands) some help with seeding values, and I want to specify the initial values for alpha and r. After some trial and error, this gives me some control of the initial parameters, but it’s for the intercept at the centered data, and the traceplots for the coefficient for N_t doesn’t actually start at the specified values (but they are not randomly selected either since they appear to start at the same value when all chains are seeded with the same b).
inits_list ← list(
list(Intercept = 1, b =array(-.001)),
list(Intercept = 1, b =array(-.001)),
list(Intercept = 1, b =array(-.001)),
list(Intercept = 3, b =array(-.001))
)fit ← brm(
formula = N_tp1 ~ 1 + N_t + offset(log(N_t)),
family = poisson(),
data = dat,backend = “rstan”,
chains = 4, cores = 4, iter = 2000,warmup = 1000,
init = inits_list,
save_warmup = TRUE)
summary(fit)
Is there a way to specify initial values for the parameters I want, i.e the non-centered intercept and b_N_t?
