-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
44 generalize setting the priors dependent on the specified formula #106
44 generalize setting the priors dependent on the specified formula #106
Conversation
For now this only sets the main prior. My idea is that, you would also be able to specify a prior on the differences (e.g. session 2 when session 1 is the intercept), by providing one more argument in the prior_list. For example:
|
The basic algorithm for the set_default_priors function is: Algorithm
|
…t-on-the-specified-formula
Generally, I like the logic a lot. I agree that having the option to provide priors for intercept and differences would be great. I will test this myself a bit and give you more detailed feedback once I have played around with your implementations a bit more. Likely this will be Wednesday, as I am pretty busy due to the semester start today and tomorrow. |
- add default priors to sdmSimple
- change prior + to combine prior for setsize 1 to avoid duplicate priors
…t-on-the-specified-formula
Ok, this should be pretty much ready. The function now works with both dpar (as in the sdmSimple) and nlpar (in all other models). You can see the tests I've run and the general design idea here: https://github.com/venpopov/bmm/blob/44-generalize-setting-the-priors-dependent-on-the-specified-formula/.dev/bmm_default_priors.md Feel free to test it and note if you notice any problems (you can add to the |
Hi Ven,
I do not get
|
Actually, if I use |
- 0 + set_size + set_size:session - 0 + set_size:session:cond
Should work now. I hadn't considered that case. Should also work now with tripple interactions. For your example the output now is:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. This looks all good to me now. We will see, if there are more cases that we need to consider, but I think most of the relevant cases should be covered. Thanks for implementing this.
Default priors for bmm models
Introduction
Here I explore options for how to set up default bmm prior flexibly
based on the formula.
How it is done in
brms
First, we can see what happens by default in
brms
. Let’s look at asimple linear regression.
Click to expand
Intercept only
It puts a default prior on all parameters that have only an intercept
Intercept and a predictor
The intercept gets a default prior, but the effects get a flat prior
Intercept supressed
Just flat prior on all coefficients
Intercept supressed and random effects
Intercept predictor and random effects
How should we do it in
bmm
Currently we put a default prior on all parameters, assuming naively
that they are specified with a suppressed intercept (except for the
sdmSimple, for which we have no default priors yet). We don’t want to
follow
brms
approach, because these measurement models need meaningfuldefault priors to help with sampling.
Options: 1) we do it like
brms
and let the user specify priors for allparameters 2) we put reasonable priors on intercepts and on all effects
when an intercept is suprresed, but leave flat priors for effects when
an intercept is present 3) we put reasonable priors on all parameters,
regardless of the formula
I don’t like option 1, because it is not user friendly. For my own
models I don’t want to have to specify the priors every time, unless I
want priors that are different from the defaults. Options 2 and 3 are
both ok, but we need to figure out when to put the priors and when not.
Prior structure for models with non-linear parameters (e.g. mixture3p)
In this section I just print the brms prior structure for a variety of
different formulas. I turn off the bmm priors, and also print the
structure of
terms(formula)
, which can help identify what informationwe need to figure out how to set default priors.
Click to expand
Disable currently used default priors:
Intercept only
All model parameters are
nlpar
so they get classb
with coefIntercept
Intercept and a predictor
For kappa, which we include and intercept and a predictor, we get class
b
with coefIntercept
andsession2
Intercept supressed
For kappa, which we include and intercept and a predictor, we get class
b
with coefsession1
andsession2
Intercept supressed and random effects
Two factors plus intercept
Two factors no intercept
Ok, so this is tricky. coefs session1 and session2 are main levels while
cond=1, but cond2,cond3 and cond4 are additive effects. So we can’t just
check if an intercept is present in coef or not.
What we can do, is for each predictor, check how many levels appear.
Two factors no intercept, yes interaction
Two factors no intercept, yes interaction
Two factors no intercept, no main effects, all levels explicit
Algorithm
Looking at the structure of the priors and the terms(formula$kappa),
here is a suggested algorithm for the initial
set_default_prior
function:
Get dpar names of bmmformula
Loop over dpar names
Get terms from the formula component with stats::terms
Get the value of `attr(terms, “intercept”)
b
, coefIntercept
check number of predictors via rhs_vars
b
check if there is only interaction (e.g. session:cond) via
stats::terms, length(attr(,“order”)) == 1 & attr(,“order”) == 2
b
find the first term in stats::terms attr(,“term.labels”):
b
with coefs equal to thatpredictor with the level appended
Mixture3p: Comparison with new function “set_default_prior”
A helper function to compare the priors with and without the default
priors.
Click to expand
Intercept only
All model parameters are
nlpar
so they get classb
with coefIntercept
Intercept and a predictor
For kappa, which we include and intercept and a predictor, we get class
b
with coefIntercept
andsession2
Intercept supressed
For kappa, which we include and intercept and a predictor, we get class
b
with coefsession1
andsession2
Intercept supressed and random effects
Two factors plus intercept
Two factors no intercept
Two factors no intercept, yes interaction
Two factors no intercept, yes interaction
Two factors no intercept, no main effects, all levels explicit
with non-linear predictors
Check the same for the sdm
Click to expand
Intercept only
All model parameters are
nlpar
so they get classb
with coefIntercept
Intercept and a predictor
For kappa, which we include and intercept and a predictor, we get class
b
with coefIntercept
andsession2
Intercept supressed
For kappa, which we include and intercept and a predictor, we get class
b
with coefsession1
andsession2
Intercept supressed and random effects
Two factors plus intercept
Two factors no intercept
Two factors no intercept, yes interaction
Two factors no intercept, yes interaction
Two factors no intercept, no main effects, all levels explicit