
Convert (refit) a Bayesian model to frequentist
Source:R/convert_bayesian_to_frequentist.R
convert_bayesian_as_frequentist.Rd
Refit Bayesian model as frequentist. Can be useful for comparisons.
Usage
convert_bayesian_as_frequentist(model, data = NULL, REML = TRUE)
bayesian_as_frequentist(model, data = NULL, REML = TRUE)
Arguments
- model
A Bayesian model.
- data
Data used by the model. If
NULL
, will try to extract it from the model.- REML
For mixed effects, should models be estimated using restricted maximum likelihood (REML) (
TRUE
, default) or maximum likelihood (FALSE
)?
Examples
# \donttest{
# Rstanarm ----------------------
if (require("rstanarm")) {
# Simple regressions
model <- stan_glm(Sepal.Length ~ Species,
data = iris, chains = 2, refresh = 0
)
bayesian_as_frequentist(model)
}
#>
#> Call:
#> stats::lm(formula = formula$conditional, data = data)
#>
#> Coefficients:
#> (Intercept) Speciesversicolor Speciesvirginica
#> 5.006 0.930 1.582
#>
# }
# \dontrun{
if (require("rstanarm")) {
model <- stan_glm(vs ~ mpg,
family = "binomial",
data = mtcars, chains = 2, refresh = 0
)
bayesian_as_frequentist(model)
# Mixed models
model <- stan_glmer(Sepal.Length ~ Petal.Length + (1 | Species),
data = iris, chains = 2, refresh = 0
)
bayesian_as_frequentist(model)
model <- stan_glmer(vs ~ mpg + (1 | cyl),
family = "binomial",
data = mtcars, chains = 2, refresh = 0
)
bayesian_as_frequentist(model)
}
#> Generalized linear mixed model fit by maximum likelihood (Laplace
#> Approximation) [glmerMod]
#> Family: binomial ( logit )
#> Formula: vs ~ mpg + (1 | cyl)
#> Data: data
#> AIC BIC logLik deviance df.resid
#> 31.1738 35.5710 -12.5869 25.1738 29
#> Random effects:
#> Groups Name Std.Dev.
#> cyl (Intercept) 1.925
#> Number of obs: 32, groups: cyl, 3
#> Fixed Effects:
#> (Intercept) mpg
#> -3.9227 0.1723
# }