I tried the names<-
replacement method to change the parameter
names of an object with class "shinystan"
, using sensible names (no duplicates, …). But the launch_shinystan
function of the shinystan package no longer works as expected after the renaming. For instance, the DIAGNOSE page seems to ignore the parameter names and only diagnoses for the log posterior lp__
.
library(rstan)
ex_model_code <- "
data {
int<lower=0> n;
matrix[n, 3] X; // predictor matrix
vector[n] y; // response
}
parameters {
vector[3] beta; // coefficients
real<lower=0> sigma;
}
model {
y ~ normal(X * beta, sigma); // likelihood
}"
## some data make a "model matrix" as in 'lm'
set.seed(123)
n <- 30
X <- matrix(runif(n * 2, max = 10), ncol = 2)
colnames(X) <- c("foo", "bar")
df <- data.frame(X, y = 1 + X %*% c(1, 2) + rnorm(n, sd = 0.5))
X <- model.matrix(y ~ foo + bar, data = df)
dl <- list(n = n, X = X, y = df$y)
## fit the model
fit <- stan(model_code = ex_model_code, data = dl, chains = 2)
library(shinystan)
my_sso <- launch_shinystan(fit)
## Change the names to standard R lm's names. 'summary' works...
names(fit)
fit2 <- fit
names(fit2) <- c(colnames(X), "sigma", "lp__")
summary(fit2)
## ... but shinystan no longer works
my_sso2 <- launch_shinystan(fit2)