View or change metadata associated with a shinystan object

sso_info(sso)

model_code(sso, code = NULL)

notes(sso, note = NULL, replace = FALSE)

model_name(sso, name = NULL)

Arguments

sso

A shinystan object.

code

A string, containing model code to be added, that can be used as an argument to cat. See Examples.

note

A string containing a note to add to any existing notes or replace existing notes, depending on the value of replace.

replace

If TRUE the existing notes are overwritten by note if note is specified. If FALSE (the default) if note is specified then its content is appended to the existing notes.

name

A string giving the new model name to use.

Value

sso_info prints basic metadata including number of parameters, chains, iterations, warmup iterations, etc. It does not return anything. model_code returns or replaces model code stored in a shinystan object. If code is NULL then any existing model code stored in sso is returned as a character string. If code is specified then an updated shinystan object is returned with code added. For shinystan objects created from stanfit (rstan) and stanreg (rstanarm) objects, model code is automatically taken from that object and does not need to be added manually. From within the 'ShinyStan' interface model code can be viewed on the Model Code page. notes returns, amends, or replaces notes stored in a shinystan object. If note is NULL then any existing notes stored in sso are returned as a character string. If note is specified then an updated shinystan object is returned with either note added to the previous notes (if replace=FALSE) or overwritten by note (if replace = TRUE). From within the 'ShinyStan' interface, notes are viewable on the Notepad page. model_name returns or replaces the model name associated with a shinystan object. If name is NULL then the current model name is returned. If name is specified then sso is returned with an updated model name.

See also

as.shinystan for creating shinystan objects.

drop_parameters to remove parameters from a shinystan object.

generate_quantity to add a new quantity to a shinystan object.

Examples

# use eight_schools example object
sso <- eight_schools

################
### sso_info ###
################

sso_info(sso)
#> sso
#> ---------------------
#> Model name: Demo (Eight Schools)
#> Parameters: 11
#> Parameter groups: 4
#> Chains: 4
#> Iterations: 2000
#> Warmup: 1000
#> Has model code: TRUE
#> Has user notes: FALSE

##################
### model_code ###
##################

# view model code in example shinystan object 'eight_schools'
cat(model_code(sso))
#> data {
#>   int<lower=0> J;          // number of schools
#>   real y[J];               // estimated treatment effect (school j)
#>   real<lower=0> sigma[J];  // std err of effect estimate (school j)
#> }
#> parameters {
#>   real mu;
#>   real theta[J];
#>   real<lower=0> tau;
#> }
#> model {
#>   theta ~ normal(mu, tau); 
#>   y ~ normal(theta,sigma);
#> }

# change the model code in sso 
# some jags style code
my_code <- "
 model {
   for (i in 1:length(Y)) {
     Y[i] ~ dpois(lambda[i])
     log(lambda[i]) <- inprod(X[i,], theta[])
   }
   for (j in 1:J) {
     theta[j] ~ dt(0.0, 1.0, 1.0)
   }
 }
"
sso <- model_code(sso, my_code)
#> Successfully added code.
#> You can view the code in theShinyStan GUI on the 'Model Code' page.
cat(model_code(sso))
#> 
#>  model {
#>    for (i in 1:length(Y)) {
#>      Y[i] ~ dpois(lambda[i])
#>      log(lambda[i]) <- inprod(X[i,], theta[])
#>    }
#>    for (j in 1:J) {
#>      theta[j] ~ dt(0.0, 1.0, 1.0)
#>    }
#>  }

#############
### notes ###
#############

# view existing notes
notes(sso)
#> [1] "Use this space to store notes about your model"

# add a note to the existing notes
sso <- notes(sso, "New note")
#> Successfully added note. 
#> You can view the notes in the ShinyStan GUI on the 'Notepad' page.
notes(sso)
#> [1] "Use this space to store notes about your model"
#> [2] "\n\nNew note"                                  
cat(notes(sso))
#> Use this space to store notes about your model 
#> 
#> New note

# replace existing notes
sso <- notes(sso, "replacement note", replace = TRUE)
#> Successfully added note. 
#> You can view the notes in the ShinyStan GUI on the 'Notepad' page.
notes(sso)
#> [1] "replacement note"
 
##################
### model_name ###
##################

# view model name
model_name(sso)
#> [1] "Demo (Eight Schools)"

# change model name
sso <- model_name(sso, "some other name")
#> Successfully changed model name to some other name
identical(model_name(sso), "some other name")
#> [1] TRUE