paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.28k stars 184 forks source link

Inconsistencies in Frechet parameterisation (?) #1417

Closed markpayneatwork closed 1 year ago

markpayneatwork commented 2 years ago

Is there an inconsistency in the parameterisation of the Frechet distribution in BRMS? The distribution "helper" functions are parameterised like so:

dfrechet(x, loc = 0, scale = 1, shape = 1, log = FALSE)

pfrechet(q, loc = 0, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE)

qfrechet(p, loc = 0, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE)

rfrechet(n, loc = 0, scale = 1, shape = 1)

vignette("brms_families"), however, describes the distribution as so, without a mention of the location parameter:

image where s=μ/Γ(1−1/ν) is a positive scale parameter and ν>1 is a shape parameter so that μ predicts the mean of the Frechet distribution.

However, the object returned by brms appears to use a different parameterisation, using mu and nu instead..

library(brms)
#> Loading required package: Rcpp
#> Loading 'brms' package (version 2.18.0). Useful instructions
#> can be found by typing help('brms'). A more detailed introduction
#> to the package is available through vignette('brms_overview').
#> 
#> Attaching package: 'brms'
#> The following object is masked from 'package:stats':
#> 
#>     ar
dat <- data.frame(x=rfrechet(500,loc=10,scale=2,shape=10))
mdl <- brm(x ~1,data=dat,family=frechet(),cores=4,iter=10000)
#> Compiling Stan program...
#> Start sampling
summary(mdl)
#>  Family: frechet 
#>   Links: mu = log; nu = identity 
#> Formula: x ~ 1 
#>    Data: dat (Number of observations: 500) 
#>   Draws: 4 chains, each with iter = 10000; warmup = 5000; thin = 1;
#>          total post-warmup draws = 20000
#> 
#> Population-Level Effects: 
#>           Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> Intercept     2.50      0.00     2.49     2.50 1.00     8155    10076
#> 
#> Family Specific Parameters: 
#>    Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
#> nu    58.11      2.07    54.09    62.17 1.00     5775     7879
#> 
#> Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
#> and Tail_ESS are effective sample size measures, and Rhat is the potential
#> scale reduction factor on split chains (at convergence, Rhat = 1).

Is my assumption that there should be consistency between these different parts correct? Is it possible to get the dfrechet, rfrechet functions etc in terms of the same parameters used in the rest of BRMS? Or have I misunderstood something?

Mark

paul-buerkner commented 2 years ago

I think I may have fixed this already. Can you double check in brms_families vignette on github?

markpayneatwork commented 2 years ago

There is a commit from about two months ago that fixes a typo in the GEV, but I can't seen anything recently in the Frechet distribution

paul-buerkner commented 2 years ago

I see. Will look into that. thanks!

paul-buerkner commented 1 year ago

I have checked. Indeed, brmsfamily("frechet") uses the parameterization as described in the brms_family vignette. The distribution functions of frechet (dfrechet etc.) have a different parameterization, but the latter are not what is supposed to be described in the families vignette. As such, the provided information is correct, although I admit perhaps a bit confusing, since the location parameter is unused in the frecht family.