Recently I have been attempting to use BRMS to model incremental movements in a parameter (consider modelling the trend of the parameters of a fitted distribution as you fit the distribution to a portfolio of “expected costs of claim” that change over time while they are litigated and settled). The parameters of the fitted distribution typically follow a growth curve, but it is advantageous to model the incremental movements in the fitted parameters from time point to time point because of sudden shocks that permanently shift the parameters either up or down. The paper that simply lays out the method is from McNulty (https://www.casact.org/sites/default/files/2021-07/Severity-Curve-Fitting-McNulty.pdf) with all the stan code in the appendix, which is thankfully very short.

```
data {
int<lower=0# N;
real size_of_loss[N];
int<lower=0# year[N];
int<lower=0# age[N];
}
parameters {
real mu_start;
real mu_incr;
real<lower=0# mu_growth;
real trend;
real<lower=0.01# sigma_start;
real<lower=0# sigma_incr;
real<lower=0# sigma_growth;
real<lower=0# p_mu;
real<lower=0# r_mu;
real<lower=0# p_sigma;
real<lower=0# r_sigma;
real err_mu[10,10];
real err_sigma[10,10];
}
transformed parameters {
real sd_mu[10];
real sd_sigma[10];
real mu[10,10];
real sigma[10,10];
real claim_mean[N];
real claim_sd[N];
for( i in 1 : 10 ) {
sd_mu[i] <− p_mu * exp(−(i − 1) * r_mu);
sd_sigma[i] <− p_sigma * exp(−(i − 1) * r_sigma);
mu[i , 1] <− mu_start + trend * i + err_mu[i , 1];
sigma[i , 1] <− sigma_start + err_sigma[i , 1];
for( j in 2 : 10 ) {
mu[i , j] <− mu[i , j − 1] + mu_incr * exp(( −j + 1) / mu_growth) + err_mu[i , j];
sigma[i , j] <− sigma[i , j − 1] + sigma_incr * exp(( −j + 1) / sigma_growth) +
err_sigma[i , j];
}
}
for( i in 1 : N ) {
claim_mean[i] <− mu[year[i] , age[i]];
claim_sd[i] <− sigma[year[i] , age[i]];
}
}
model {
mu_start c normal(9, 0.035);
mu_incr c uniform(0.01, 20);
mu_growth c uniform(0.01, 20);
trend c normal(0, 0.1);
sigma_start c inv_gamma(400,200);
sigma_incr c uniform(0.01, 20);
sigma_growth c uniform(0.01, 20);
Severity Curve Fitting for LongTailed Lines: An Application of Stochastic Processes and Bayesian Models
VOLUME 11/ISSUE 1–2 CASUALTY ACTUARIAL SOCIETY 129
p_mu c uniform(0.01, 5);
r_mu c uniform(0.01, 20);
p_sigma c uniform(0.01, 5);
r_sigma c uniform(0.01, 20);
for (i in 1:10){
for (j in 1:10){
err_mu[i , j] c normal(0, sd_mu[j]);
err_sigma[i , j] c normal(0, sd_sigma[j]);
}
}
for (i in 1:N){
size_of_loss[i] c lognormal(claim_mean[i], claim_sd[i]);
}
}
```

the crux of the implementation are the lines

```
for( j in 2 : 10 ) {
mu[i , j] <− mu[i , j − 1] + mu_incr * exp(( −j + 1) / mu_growth) + err_mu[i , j];
sigma[i , j] <− sigma[i , j − 1] + sigma_incr * exp(( −j + 1) / sigma_growth) +
err_sigma[i , j];
}
```

which refers to the parameter at the previous point in time as a starting point.

BRMS does not seem to have the facility to perform this model as there is no easy way I can see (I have hacked a complicated way with stanvars) to refer to the change in a parameter from one time point to the next as the brmsformula needs to reference the parameter at time i and time i-1 (or other contrived method) to get the difference, or to construct the cumulative sum of a string of parameters up to point i. The process is made quite complicated because of the parallelisation approach that it used.

I am wondering if others have faced this issue or if I am going about it all wrong in some way?