Closed
Description
Perhaps I've missed something, but I can't find a simple way to exclude a parameter. For something like mcmc_parcoord
I often want to remove "lp__" and display all other parameters.
I thought I could use negative lookaheads, but R needs an extra flag for Perl compatible expressions. Can this be passed through to base::grep
?
grepl("^(?!lp).*$", c("par_1", "lp__"), perl = F)
> Error in grepl("^(?!lp).*$", c("par_1", "lp__"), perl = F) :
> invalid regular expression '^(?!lp).*$', reason 'Invalid regexp'
grepl("^(?!lp).*$", c("par_1", "lp__"), perl = T)
> [1] TRUE FALSE
Metadata
Metadata
Assignees
Labels
No labels
Activity
jtimonen commentedon Oct 16, 2018
I am currently using something like this:
Here
x
is the three-dimensional array of posterior samples, andexclude
could have more than one excluded parameter, for examplejgabry commentedon Apr 11, 2019
@aornugent I noticed this hadn't been addressed yet, sorry it's taken so long. Thanks @jtimonen for responding.
There hasn't been a release in a while but we're getting closer to the next release, so maybe we can do something about it before then. I agree that it would be nice to have an easier way of excluding parameters.
If you have a stanfit object from RStan then the simplest way to exclude just
lp__
(or any parameter) would be to usebut that only works for stanfit objects and we don't have a way to do this within bayesplot itself. Here are three options that come to mind for how we could add it to bayesplot, although maybe there's a better solution I haven't thought of:
Allow additional arguments to be passed to
grep
(which is called internally for matchingregexp_pars
) so that @aornugent's approach would work. Right now...
isn't used for anything in the bayesplot functions other than to enforce that after...
all arguments must be named, so we could use it to allow passing arguments togrep
. Alternatively we could add additional named arguments to the plotting functions that correspond to the arguments togrep
.Add arguments
pars_drop
andregex_pars_drop
to allow users to specify parameters to drop before plotting. So for example,mcmc_parcoord(x, pars_drop = "lp__")
would plot all parameters inx
exceptlp__
.Follow what
rstan::extract
does and add a TRUE/FALSE argumentinclude
which indicates whether the parameters named inpars
andregex_pars
should be included or excluded.@tjmahr I don't love these options but I'm not sure if there's a better way. Any preference or other ideas?
tjmahr commentedon Apr 11, 2019
I don't mind
pars_drop
andregex_pars_drop
.My ideal design would be something like
vars()
/tidyselect, so thatvars(x, y)
would select x and y andvars(-x, -matches("beta"))
would drop x and anything matching the regex "beta".jgabry commentedon Apr 12, 2019
@tjmahr good idea. Let's go with tidyselect.
jgabry commentedon Apr 15, 2019
@tjmahr I think I have this working on the
feature-tidyselect
branch if you want to try it out. If you install from that branch and dohelp("tidy-params", "bayesplot")
there are a bunch of examples you can run. I'll make a PR if this looks like the right approach to you, but you know the tidy stuff better than I do so maybe I went about this the wrong way.jgabry commentedon Apr 15, 2019
I opened a separate issue for adding 'tidy' parameter selection, which is broader than just excluding parameters: #183