Mav, do you have an idea as to what would cause this error. When you do something with 1 predictor and a constant, like
fit <- stanglm(RTEN ~ INTG, data = USJudgeRatings)
the standata list looks like this before calling stan()
debug: stanfit <- rstan:::stan(fit = stanfit, data = standata, init = start,
...)
Browse[2]> str(standata)
List of 17
$ N : int 43
$ K : int 2
$ X : num [1:43, 1:2] 1 1 1 1 1 1 1 1 1 1 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:43] "AARONSON,L.H." "ALEXANDER,J.M." "ARMENTANO,A.J." "BERDON,R.I." ...
.. ..$ : chr [1:2] "(Intercept)" "INTG"
..- attr(*, "assign")= int [1:2] 0 1
$ y : Named num [1:43] 7.8 8.7 7.8 8.7 4.8 8.6 9 5 8.8 7.9 ...
..- attr(*, "names")= chr [1:43] "AARONSON,L.H." "ALEXANDER,J.M." "ARMENTANO,A.J." "BERDON,R.I." ...
$ family : int 2
$ link : int 1
$ has_weights : int 0
$ weights : num [1:43] 1 1 1 1 1 1 1 1 1 1 ...
$ has_offset : int 0
$ offset : num [1:43] 0 0 0 0 0 0 0 0 0 0 ...
$ prior_scale : num 3.57
$ prior_scale_for_intercept : num 22
$ prior_mean : num 0
$ prior_mean_for_intercept : num 0
$ prior_df : num 1
$ prior_df_for_intercept : num 1
$ prior_scale_for_dispersion: num 5
which yields a mismatch
Error : mismatch in number dimensions declared and found in context; processing stage=data initialization; dims declared=(1); dims found=()
failed to create the sampler; sampling not done
but when there is more than one predictor, then it is fine
fit <- stanglm(RTEN ~ INTG + ORAL, data = USJudgeRatings)
despite the standata list being essentially the same
Browse[2]> str(standata)
List of 17
$ N : int 43
$ K : int 3
$ X : num [1:43, 1:3] 1 1 1 1 1 1 1 1 1 1 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:43] "AARONSON,L.H." "ALEXANDER,J.M." "ARMENTANO,A.J." "BERDON,R.I." ...
.. ..$ : chr [1:3] "(Intercept)" "INTG" "ORAL"
..- attr(*, "assign")= int [1:3] 0 1 2
$ y : Named num [1:43] 7.8 8.7 7.8 8.7 4.8 8.6 9 5 8.8 7.9 ...
..- attr(*, "names")= chr [1:43] "AARONSON,L.H." "ALEXANDER,J.M." "ARMENTANO,A.J." "BERDON,R.I." ...
$ family : int 2
$ link : int 1
$ has_weights : int 0
$ weights : num [1:43] 1 1 1 1 1 1 1 1 1 1 ...
$ has_offset : int 0
$ offset : num [1:43] 0 0 0 0 0 0 0 0 0 0 ...
$ prior_scale : num [1:2] 3.57 2.73
$ prior_scale_for_intercept : num 22
$ prior_mean : num [1:2] 0 0
$ prior_mean_for_intercept : num 0
$ prior_df : num [1:2] 1 1
$ prior_df_for_intercept : num 1
$ prior_scale_for_dispersion: num 5
Only X is different and it just has one more column, so I don't know why that would make a difference in this data block
# GLM for a Gaussian outcome via Stan
data {
int<lower=1> N; # number of observations
int<lower=1> K; # number of predictors
matrix[N,K] X; # predictor matrix
vector[N] y; # continuous outcome
# link function from location to linear predictor
int<lower=1,upper=3> link; # 1 = identity, 2 = log, 3 = inverse
int<lower=0,upper=1> has_weights; # 0 = No (weights is a ones vector), 1 = Yes
vector[N] weights;
int<lower=0,upper=1> has_offset; # 0 = No (offset is a zero vector), 1 = Yes
vector[N] offset;
# values for hyperparameters
vector<lower=0>[K-1] prior_scale;
real<lower=0> prior_scale_for_intercept;
vector[K-1] prior_mean;
real prior_mean_for_intercept;
vector<lower=0>[K-1] prior_df;
real<lower=0> prior_df_for_intercept;
real<lower=0> prior_scale_for_dispersion;
}
Ben