diff --git a/DESCRIPTION b/DESCRIPTION index 9aad082..45d53ae 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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: @@ -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 diff --git a/R/fitting.R b/R/fitting.R index b014167..f6bd0f2 100644 --- a/R/fitting.R +++ b/R/fitting.R @@ -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, diff --git a/inst/stan/glmmfields.stan b/inst/stan/glmmfields.stan index 60444df..a6999ad 100644 --- a/inst/stan/glmmfields.stan +++ b/inst/stan/glmmfields.stan @@ -3,19 +3,19 @@ data { int nLocs; int nT; int N; - int stationID[N]; - int yearID[N]; - int 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 stationID; + array[N] int yearID; + array[N] int 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 nCov; @@ -41,20 +41,20 @@ data { parameters { real gp_theta; real gp_sigma; - real df[est_df]; - real sigma[norm_params]; - real CV[gamma_params]; - real nb2_phi[nb2_params]; - real yearEffects[n_year_effects]; - real year_sigma[est_temporalRE]; - vector[nKnots] spatialEffectsKnots[nT]; + array[est_df] real df; + array[norm_params] real sigma; + array[gamma_params] real CV; + array[nb2_params] real nb2_phi; + array[n_year_effects] real yearEffects; + array[est_temporalRE] real year_sigma; + array[nT] vector[nKnots] spatialEffectsKnots; vector[nCov] B; - real phi[est_phi]; - real W[nW]; + array[est_phi] real phi; + array[nW] real 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; @@ -62,7 +62,7 @@ transformed parameters { matrix[nLocs, nKnots] SigmaOffDiagTemp; matrix[nLocs, nKnots] invSigmaKnots; vector[N] y_hat; - real gammaA[gamma_params]; + array[gamma_params] real gammaA; real gp_sigma_sq; gp_sigma_sq = pow(gp_sigma*gp_sigma_scaling_factor, 2.0); @@ -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) {