Use normal glm distribution for Stan model (#2051)

This commit is contained in:
Andrew Johnson 2022-05-24 20:11:22 +08:00 committed by GitHub
parent 4026f1ca4d
commit 2bbcd2c698
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 15 deletions

View file

@ -98,8 +98,9 @@ data {
}
transformed data {
matrix[T, S] A;
A = get_changepoint_matrix(t, t_change, T, S);
matrix[T, S] A = get_changepoint_matrix(t, t_change, T, S);
matrix[T, K] X_sa = X .* rep_matrix(s_a', T);
matrix[T, K] X_sm = X .* rep_matrix(s_m', T);
}
parameters {
@ -130,10 +131,10 @@ model {
beta ~ normal(0, sigmas);
// Likelihood
y ~ normal(
trend
.* (1 + X * (beta .* s_m))
+ X * (beta .* s_a),
sigma_obs
);
y ~ normal_id_glm(
X_sa,
trend .* (1 + X_sm * beta),
beta,
sigma_obs
);
}

View file

@ -101,8 +101,9 @@ data {
}
transformed data {
matrix[T, S] A;
A = get_changepoint_matrix(t, t_change, T, S);
matrix[T, S] A = get_changepoint_matrix(t, t_change, T, S);
matrix[T, K] X_sa = X .* rep_matrix(s_a', T);
matrix[T, K] X_sm = X .* rep_matrix(s_m', T);
}
parameters {
@ -133,10 +134,10 @@ model {
beta ~ normal(0, sigmas);
// Likelihood
y ~ normal(
trend
.* (1 + X * (beta .* s_m))
+ X * (beta .* s_a),
sigma_obs
y ~ normal_id_glm(
X_sa,
trend .* (1 + X_sm * beta),
beta,
sigma_obs
);
}