Skip to content

Commit

Permalink
Merge pull request #16 from andrjohns/array-syntax
Browse files Browse the repository at this point in the history
 Update deprecated syntax for future rstan compatibility
  • Loading branch information
seananderson authored Sep 29, 2023
2 parents 92b44f1 + 04c412f commit 8602b61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Imports:
nlme,
RcppParallel (>= 5.0.1),
reshape2,
rstan (>= 2.18.2),
rstan (>= 2.26.0),
rstantools (>= 2.1.1),
tibble
Suggests:
Expand All @@ -56,8 +56,8 @@ LinkingTo:
Rcpp (>= 0.12.8),
RcppEigen (>= 0.3.3.3.0),
RcppParallel (>= 5.0.1),
rstan (>= 2.18.2),
StanHeaders (>= 2.18.0)
rstan (>= 2.26.0),
StanHeaders (>= 2.26.0)
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion R/fitting.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ glmmfields <- function(formula, data, lon, lat,
prior_rw_sigma = parse_t_prior(prior_rw_sigma),
prior_beta = parse_t_prior(prior_beta),
prior_phi = parse_t_prior(prior_phi),
offset = offset,
input_offset = offset,
cov_func = switch(covariance,
exponential = 0L,
`squared-exponential` = 1L,
Expand Down
50 changes: 25 additions & 25 deletions inst/stan/glmmfields.stan
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ data {
int<lower=1> nLocs;
int<lower=1> nT;
int<lower=1> N;
int<lower=1> stationID[N];
int<lower=1> yearID[N];
int<lower=0> binomialN[N];
real y[N]; // y for normal and gamma obs. model
int y_int[N]; // y for NB2 or poisson or binomial obs. model
real offset[N]; // optional offset, is 0 if not included
real prior_gp_theta[3];
real prior_gp_sigma[3];
real prior_sigma[3];
real prior_rw_sigma[3];
real prior_intercept[3];
real prior_beta[3];
real prior_phi[3];
array[N] int<lower=1> stationID;
array[N] int<lower=1> yearID;
array[N] int<lower=0> binomialN;
array[N] real y; // y for normal and gamma obs. model
array[N] int y_int; // y for NB2 or poisson or binomial obs. model
array[N] real input_offset; // optional offset, is 0 if not included
array[3] real prior_gp_theta;
array[3] real prior_gp_sigma;
array[3] real prior_sigma;
array[3] real prior_rw_sigma;
array[3] real prior_intercept;
array[3] real prior_beta;
array[3] real prior_phi;
matrix[nKnots, nKnots] distKnots;
matrix[nLocs, nKnots] distKnots21;
int<lower=0> nCov;
Expand All @@ -41,28 +41,28 @@ data {
parameters {
real<lower=0> gp_theta;
real<lower=0> gp_sigma;
real<lower=df_lower_bound> df[est_df];
real<lower=0> sigma[norm_params];
real<lower=0> CV[gamma_params];
real<lower=0> nb2_phi[nb2_params];
real yearEffects[n_year_effects];
real<lower=0> year_sigma[est_temporalRE];
vector[nKnots] spatialEffectsKnots[nT];
array[est_df] real<lower=df_lower_bound> df;
array[norm_params] real<lower=0> sigma;
array[gamma_params] real<lower=0> CV;
array[nb2_params] real<lower=0> nb2_phi;
array[n_year_effects] real yearEffects;
array[est_temporalRE] real<lower=0> year_sigma;
array[nT] vector[nKnots] spatialEffectsKnots;
vector[nCov] B;
real<lower=-1, upper=1> phi[est_phi];
real<lower=0> W[nW];
array[est_phi] real<lower=-1, upper=1> phi;
array[nW] real<lower=0> W;
}
transformed parameters {
vector[nKnots] muZeros;
vector[nLocs] spatialEffects[nT];
array[nT] vector[nLocs] spatialEffects;
matrix[nKnots, nKnots] SigmaKnots;
matrix[nKnots, nKnots] transformed_dist;
matrix[nLocs, nKnots] transformed_dist21;
matrix[nLocs, nKnots] SigmaOffDiag;
matrix[nLocs, nKnots] SigmaOffDiagTemp;
matrix[nLocs, nKnots] invSigmaKnots;
vector[N] y_hat;
real<lower=0> gammaA[gamma_params];
array[gamma_params] real<lower=0> gammaA;
real<lower=0> gp_sigma_sq;
gp_sigma_sq = pow(gp_sigma*gp_sigma_scaling_factor, 2.0);

Expand Down Expand Up @@ -127,7 +127,7 @@ transformed parameters {
y_hat[i] = X[i] * B + spatialEffects[yearID[i], stationID[i]] + yearEffects[yearID[i]];
}
}
y_hat[i] = y_hat[i] + offset[i]; // optional offset, additive in link space
y_hat[i] = y_hat[i] + input_offset[i]; // optional offset, additive in link space
}

if (obs_model==0) {
Expand Down

0 comments on commit 8602b61

Please sign in to comment.