Hey all!
I’m trying to estimate the exponential rate of decay from a time series, and am running into some problems.
I’ve been using Stan for a few years now, mostly to fit ODEs, so I’m sure I’m doing something incredibly obviously wrong, but would appreciate help nonetheless!
My data look like this:
y_samp_repro <- c(49807, 31437, 17739, 10739, 6499, 3836, 2201, 1240, 823, 436, 259, 179, 91, 61, 46, 17, 16, 7, 4, 3, 2, 1)
I’m using this paper as a guide, so started out writing the Stan model as follows:
data {
int LENGTH;
vector[LENGTH] Y;
}
parameters {
real lambda;
}
model {
real alpha;
real beta;
alpha = 1;
beta = 1;
lambda ~ gamma(alpha, beta);
Y ~ exponential(lambda);
}
generated quantities {
real pred;
pred = exponential_rng(lambda);
}
In the paper, they’re looking to estimate the rate of exponential growth, but I’m trying to estimate the rate of decay, which might be where I’m running into issues?
When I fit the model:
model <- stan_model("exp-decay.stan")
fit <- sampling(object = model,
data = list(Y = y_samp_repro, LENGTH = length(y_samp_repro)),
warmup = 500,
iter = 1000,
chains = 2,
cores = 2,
seed = 123); print(fit)
I get an output, but it’s not very reasonable:
Inference for Stan model: anon_model.
2 chains, each with iter=1000; warmup=500; thin=1;
post-warmup draws per chain=500, total post-warmup draws=1000.
mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
lambda 0.00 0.00 0.0 0.00 0.00 0.00 0.00 0.00 400 1
pred 5867.79 191.86 6059.9 167.91 1765.62 4029.63 7692.35 20953.34 998 1
lp__ -212.78 0.04 0.7 -214.89 -212.99 -212.52 -212.32 -212.27 327 1
Samples were drawn using NUTS(diag_e) at Mon Jul 17 17:34:11 2023.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at
convergence, Rhat=1).
Again, I’m sure the problem is really, really obvious (and suspect it has to do with looking at decay rather than growth), but I’m just not really sure where to start, so would appreciate any help at all!
Thank you so much for any help!