library(brms)
<- brms::brmsformula(Petal.Length ~ 0 + Intercept + Petal.Width)
f
<- brms::brm(f, data = iris, refresh=0) model
10. Linear Models (Comparison)
iris
builtin dataset)?# Fixed Effects
Parameter | Median | 95% CI | pd | Rhat | ESS
------------------------------------------------------------
(Intercept) | 1.09 | [0.93, 1.24] | 100% | 1.002 | 1420.00
Petal.Width | 2.23 | [2.12, 2.33] | 100% | 1.001 | 1413.00
# Sigma
Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------
sigma | 0.48 | [0.43, 0.55] | 100% | 1.000 | 2177.00
Species
is a categorical factor with 3 levels: setosa
, versicolor
, and virginica
Species
as a predictor# Fixed Effects
Parameter | Median | 95% CI | pd | Rhat | ESS
------------------------------------------------------------------
(Intercept) | 1.46 | [1.34, 1.58] | 100% | 1.002 | 3216.00
Speciesversicolor | 2.80 | [2.63, 2.97] | 100% | 1.002 | 2937.00
Speciesvirginica | 4.09 | [3.92, 4.27] | 100% | 1.002 | 3124.00
# Sigma
Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------
sigma | 0.43 | [0.39, 0.48] | 100% | 0.999 | 4063.00
model3 <- brms::brm(Petal.Length ~ 0 + Intercept + Species * Petal.Width,
data = iris, refresh=0)
parameters::parameters(model3)
# Fixed Effects
Parameter | Median | 95% CI | pd | Rhat | ESS
---------------------------------------------------------------------------------
(Intercept) | 1.33 | [ 1.06, 1.58] | 100% | 1.001 | 1327.00
Speciesversicolor | 0.44 | [-0.26, 1.20] | 88.58% | 1.000 | 2045.00
Speciesvirginica | 2.90 | [ 2.09, 3.73] | 100% | 0.999 | 2153.00
Petal.Width | 0.54 | [-0.39, 1.52] | 87.17% | 1.001 | 1261.00
Speciesversicolor:Petal.Width | 1.35 | [ 0.21, 2.35] | 99.00% | 1.000 | 1226.00
Speciesvirginica:Petal.Width | 0.12 | [-0.94, 1.11] | 59.58% | 1.000 | 1219.00
# Sigma
Parameter | Median | 95% CI | pd | Rhat | ESS
----------------------------------------------------------
sigma | 0.36 | [0.33, 0.41] | 100% | 0.999 | 3051.00
Petal.Width
on Petal.Length
changes when the species changesmodelbased::estimate_relation()
is a convenient function to create a datagrid and make predictions
keep_iterations
to add individual predicted iterationslength
(default is 10), the number of points (more points: smoother line, but slower computation)Model-based Expectation
Species | Petal.Width | Predicted | SE | 95% CI | iter_1 | iter_2 | iter_3 | iter_4 | iter_5 | iter_6 | iter_7 | iter_8
----------------------------------------------------------------------------------------------------------------------------------
setosa | 0.10 | 1.38 | 0.09 | [1.20, 1.56] | 1.29 | 1.47 | 1.51 | 1.41 | 1.38 | 1.39 | 1.43 | 1.35
setosa | 0.23 | 1.45 | 0.05 | [1.34, 1.56] | 1.41 | 1.43 | 1.49 | 1.46 | 1.44 | 1.45 | 1.49 | 1.46
setosa | 0.35 | 1.52 | 0.07 | [1.38, 1.67] | 1.53 | 1.40 | 1.48 | 1.52 | 1.50 | 1.50 | 1.55 | 1.58
setosa | 0.48 | 1.59 | 0.12 | [1.35, 1.84] | 1.65 | 1.36 | 1.46 | 1.58 | 1.55 | 1.55 | 1.61 | 1.69
versicolor | 1.11 | 3.86 | 0.08 | [3.71, 4.01] | 3.79 | 3.85 | 3.86 | 3.75 | 3.79 | 3.73 | 3.89 | 3.79
versicolor | 1.24 | 4.09 | 0.06 | [3.98, 4.20] | 4.06 | 4.06 | 4.10 | 4.04 | 4.08 | 4.00 | 4.13 | 4.04
versicolor | 1.36 | 4.33 | 0.05 | [4.23, 4.43] | 4.33 | 4.27 | 4.34 | 4.33 | 4.37 | 4.28 | 4.37 | 4.30
versicolor | 1.49 | 4.57 | 0.07 | [4.43, 4.70] | 4.61 | 4.48 | 4.57 | 4.61 | 4.66 | 4.56 | 4.61 | 4.55
versicolor | 1.62 | 4.80 | 0.09 | [4.61, 4.98] | 4.88 | 4.69 | 4.81 | 4.90 | 4.95 | 4.84 | 4.85 | 4.80
versicolor | 1.74 | 5.04 | 0.12 | [4.79, 5.27] | 5.15 | 4.90 | 5.05 | 5.19 | 5.24 | 5.11 | 5.10 | 5.05
virginica | 1.49 | 5.20 | 0.12 | [4.98, 5.43] | 5.12 | 5.31 | 5.30 | 5.29 | 5.17 | 5.21 | 5.25 | 5.20
virginica | 1.62 | 5.29 | 0.09 | [5.10, 5.47] | 5.23 | 5.36 | 5.37 | 5.35 | 5.25 | 5.30 | 5.32 | 5.29
virginica | 1.74 | 5.37 | 0.08 | [5.22, 5.52] | 5.34 | 5.41 | 5.44 | 5.41 | 5.34 | 5.38 | 5.39 | 5.38
virginica | 1.87 | 5.45 | 0.06 | [5.33, 5.57] | 5.46 | 5.46 | 5.51 | 5.47 | 5.42 | 5.47 | 5.45 | 5.48
virginica | 1.99 | 5.53 | 0.05 | [5.43, 5.63] | 5.57 | 5.51 | 5.58 | 5.53 | 5.51 | 5.55 | 5.52 | 5.57
virginica | 2.12 | 5.61 | 0.05 | [5.51, 5.72] | 5.69 | 5.56 | 5.65 | 5.59 | 5.60 | 5.64 | 5.59 | 5.66
virginica | 2.25 | 5.70 | 0.07 | [5.57, 5.82] | 5.80 | 5.62 | 5.72 | 5.65 | 5.68 | 5.73 | 5.65 | 5.75
virginica | 2.37 | 5.78 | 0.08 | [5.61, 5.94] | 5.91 | 5.67 | 5.79 | 5.71 | 5.77 | 5.81 | 5.72 | 5.85
virginica | 2.50 | 5.86 | 0.10 | [5.66, 6.06] | 6.03 | 5.72 | 5.86 | 5.77 | 5.85 | 5.90 | 5.79 | 5.94
Variable predicted: Petal.Length
Predictors modulated: Species, Petal.Width
# Bayesian R2 with Compatibility Interval
Conditional R2: 0.927 (95% CI [0.920, 0.932])
# Bayesian R2 with Compatibility Interval
Conditional R2: 0.941 (95% CI [0.936, 0.944])
# Bayesian R2 with Compatibility Interval
Conditional R2: 0.958 (95% CI [0.955, 0.961])
Computed from 4000 by 150 log-likelihood matrix
Estimate SE
elpd_waic -104.5 9.5
p_waic 3.3 0.6
waic 208.9 19.0
Computed from 4000 by 150 log-likelihood matrix
Estimate SE
elpd_waic -89.1 10.6
p_waic 4.4 0.8
waic 178.3 21.1
1 (0.7%) p_waic estimates greater than 0.4. We recommend trying loo instead.
Computed from 4000 by 150 log-likelihood matrix
Estimate SE
elpd_waic -64.4 11.5
p_waic 7.0 1.2
waic 128.9 23.1
3 (2.0%) p_waic estimates greater than 0.4. We recommend trying loo instead.
loo_compare()
loo::loo_compare()
to get the difference in ELPD between models
Computed from 4000 by 150 log-likelihood matrix
Estimate SE
elpd_loo -104.5 9.5
p_loo 3.3 0.6
looic 209.0 19.0
------
Monte Carlo SE of elpd_loo is 0.0.
All Pareto k estimates are good (k < 0.5).
See help('pareto-k-diagnostic') for details.
Computed from 4000 by 150 log-likelihood matrix
Estimate SE
elpd_loo -89.1 10.6
p_loo 4.4 0.8
looic 178.3 21.2
------
Monte Carlo SE of elpd_loo is 0.0.
All Pareto k estimates are good (k < 0.5).
See help('pareto-k-diagnostic') for details.
Computed from 4000 by 150 log-likelihood matrix
Estimate SE
elpd_loo -64.5 11.5
p_loo 7.0 1.2
looic 128.9 23.1
------
Monte Carlo SE of elpd_loo is 0.1.
All Pareto k estimates are good (k < 0.5).
See help('pareto-k-diagnostic') for details.
1-pnorm(|z-score|)
to get the one-tailed p-valuesat.act
from the psych
package, analyze the data and answer the questionThank you!