Feature Request: Function to strip stanfit of extra parameters
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 1.1k
- Forks
- 266
- Avg merge
- 2h 56m
- Merged PRs (30d)
- 1
Description
Summary:
I often find myself capturing the entire output of all parameters, transformed parameters, and generated data when running a stan model. However, this object is very large, too large in fact for things like shinystan. It would be nice to have a built in way strip the stanfit object down to the essential variables.
Description:
I wrote the following function, which could be potentially integrated into the RStan package. I would do a pull request, but I'm not too familiar with S4 classes so don't know how to integrate it.
cleanObject <- function(object,pars){
pars <- c(pars,'lp__')
nn <- paste0('^',pars,'(\\[|$)',collapse="|")
ids <- grep(nn, object@sim$fnames_oi)
ids.2 <- which(names(object@par_dims) %in% pars)
for(i in 1:4){
a <- attributes(object@sim$samples[[i]])
x <- object@sim$samples[[i]][ids]
for(j in c('names','inits','mean_pars'))
a[[j]] <- a[[j]][ids]
attributes(x) <- a
object@sim$samples[[i]] <- x
}
object@par_dims <- object@par_dims[ids.2]
object@sim$dims_oi <- object@sim$dims_oi[ids.2]
object@sim$pars_oi<- object@sim$pars_oi[ids.2]
object@sim$fnames_oi <- object@sim$fnames_oi[ids]
object@sim$n_flatnames <- length(object@sim$fnames_oi)
object
}
RStan Version:
packageVersion("rstan")
[1] ‘2.15.1’
R Version:
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 locating the stanfit S4 class and the cleanObject function described in the issue, including the sim and par_dims slots it modifies. Define the supported parameter-selection behavior and verify that the resulting object retains the requested variables and lp__ while remaining usable; the issue names no implementation file or test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100