venpopov / bmm

An R package for easy and flexible Bayesian Measurement Modeling
https://venpopov.github.io/bmm/
GNU General Public License v2.0
12 stars 3 forks source link

Update vignettes with instructions how to estimate fixed parameters if desired #115

Closed venpopov closed 8 months ago

venpopov commented 9 months ago

For example for the sdmSimple we fix mu to 0, but people might want to estimate bias to response more clockwise or counterclockwise. It's actually really easy to do and we don't have to change anything in the code. For example, this works:

library(dplyr)
library(brms)
library(bmm)

data <- filter(OberauerLin_2017, session == 1, set_size %in% c(1,2,3,4))
formula <- bmf(mu ~ 1, c ~ 0 + set_size, kappa ~ 1)
model <- sdmSimple('dev_rad')
prior <- set_prior("normal(0,0.5)", class="Intercept", dpar='mu')

fit <- fit_model(formula, data, model,
                 prior = prior,
                 parallel = T,
                 backend = 'cmdstanr',
                 sort_data = T)

giving output:

 Family: sdm_simple 
  Links: mu = identity; c = log; kappa = log 
Formula: dev_rad ~ 1 
         mu ~ 1
         c ~ 0 + set_size
         kappa ~ 1
   Data: .x2 (Number of observations: 3800) 
  Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
         total post-warmup draws = 4000

Regression Coefficients:
                Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept           0.05      0.01     0.03     0.06 1.00     4409     2987
kappa_Intercept     1.21      0.04     1.13     1.30 1.00     1065     1662
c_set_size1         2.23      0.05     2.13     2.34 1.00     1334     1780
c_set_size2         1.87      0.04     1.79     1.95 1.00     1394     1881
c_set_size3         1.58      0.04     1.50     1.66 1.00     1550     1918
c_set_size4         1.37      0.04     1.29     1.44 1.00     1564     2079

where the intercept (mu) is now estimated (and in this case there is evidence for bias)

This works with all the other models as well, but using mu1 instead

So we can just add this to vignettes.

venpopov commented 9 months ago

actually this doesn't work if you want to predict mu, because then the default constant intercept is still there and brms throws an error:

Error: The following priors do not correspond to any model parameter: 
Intercept ~ constant(0)
Function 'get_prior' might be helpful to you.