gqs() still has some issues with the names of posterior draws
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Summary:
gqs() has issues with "structured" versions of matrix-valued parameters and/or transformed parameters, I am not sure which.
Relates to #695 reported and closed in 2019 by @jgabry.
Description:
corr_matrix parameter declarations results in "subscript out of bounds error"
Reproducible Steps:
mc1 <- "
parameters {
vector<lower = 0>[2] tau_u;
corr_matrix[2] rho_matrix;
vector[2] y;
}
transformed parameters {
cov_matrix[2] Sigma;
Sigma = quad_form_diag(rho_matrix,tau_u);
}
model {
rho_matrix ~ lkj_corr(1);
tau_u ~ cauchy(0,1);
y ~ multi_normal([0,0]', Sigma);
}
"
m1 <- stan_model(model_code = mc1)
f1 <- sampling(m1, iter = 300)
mc2 <- "
parameters {matrix[2,2] Sigma;}
generated quantities {vector[2] yy_new = multi_normal_rng( [0,0]', Sigma );}
"
m2 <- stan_model(model_code = mc2)
f2 <- gqs(m2, draws = as.matrix(f1))
mc3 <- "
parameters {
// variance components
vector<lower = 0>[2] tau_u;
// correlation matrix
corr_matrix[2] rho_matrix;
}
transformed parameters {
cov_matrix[2] Sigma;
// covariance matrix
Sigma = quad_form_diag(rho_matrix,tau_u);
}
generated quantities {vector[2] yy_new = multi_normal_rng( [0,0]', Sigma );}
"
m3 <- stan_model(model_code = mc3)
f3 <- gqs(m3, draws = as.matrix(f1))
f4 <- gqs(m3, draws = as.matrix(f1)[,
c("tau_u[1]", "tau_u[2]",
"rho_matrix[1,1]", "rho_matrix[1,2]", "rho_matrix[2,1]", "rho_matrix[2,2]")] )
Current Output:
f3 <- gqs(m3, draws = as.matrix(f1))
Wrong number of parameter values in draws from fitted model. Expecting 6 columns, found 10 columns.
f4 <- gqs(m3, draws = as.matrix(f1)[,
c("tau_u[1]", "tau_u[2]",
"rho_matrix[1,1]", "rho_matrix[1,2]", "rho_matrix[2,1]", "rho_matrix[2,2]")] )
Error in draws[, draws_colnames, drop = FALSE] : subscript out of bounds
Expected Output:
Stuff should run?..
RStan Version:
packageVersion("rstan")
[1] ‘2.21.3’
R Version:
R.version.string
[1] "R version 4.1.2 (2021-11-01)"
Operating System:
Windows Server 2016 Standard OS Build 14393.5006
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the reproducible mc1–mc3 setup and the f3/f4 gqs() calls, then trace how gqs() handles draws column names for corr_matrix and transformed parameters. Done means the calls no longer produce column-count or subscript errors and generated yy_new draws are returned.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100