Estimate reliability (Relative Measurement Uncertainty) from Bayesian measurement models
Source:R/reliabilityRMU.R
RMUreliability.Rd
This function measures reliability using posterior draws from a fitted Bayesian model.
Value
A list containing:
hdci: A data frame with a point-estimate (posterior mean) and highest density continuous interval for reliability, calculated using the ggdist::mean_hdci function
reliability_posterior_draws: A numeric vector of posterior draws for reliability, of length K/2 (K = number of columns/draws in your input_draws matrix)
Details
To use this function, you will need to provide a matrix (input_draws) that contains the posterior draws for the parameter you wish to calculate reliability. The function assumes that rows of input_draws represent subjects and columns represent posterior draws.
For an example of how to apply this function to calculate mean score reliability using brms, see this tutorial.
For an example of how to apply this function to go/go-no task data using brms, see this tutorial.
References
Bignardi, G., Kievit, R., & Bürkner, P. C. (2025). A general method for estimating reliability using Bayesian Measurement Uncertainty. PsyArXiv. doi:10.31234/osf.io/h54k8
Examples
if (FALSE) { # \dontrun{
# See https://www.bignardi.co.uk/8_bayes_reliability/tutorial_rmu_sum_score_reliability.html for more details on this example
# Simulate data
set.seed(1)
N = 5000 # number of subjects (mice)
J = 3 # number of measurements per subject
true_score_variance = 1
error_variance = 10
df = expand.grid(j = 1:J, mouse = 1:N)
true_scores = rnorm(N, mean = 10, sd = sqrt(true_score_variance))
measurement_error = rnorm(N*J, mean = 0, sd = sqrt(error_variance))
df$measurement = true_scores[df$mouse] + measurement_error
df_average_lengths = df %>%
group_by(mouse) %>%
summarise(average_measurement = mean(measurement))
# Reliability should equal this:
true_score_variance/(true_score_variance+error_variance/J)
# Approximately the same as:
cor(df_average_lengths$average_measurement, true_scores)^2
# Fit model and calculate RMU
brms_model = brm(
measurement ~ 1 + (1 | mouse),
data = df
)
# Extract posterior draws from brms model
posterior_draws = brms_model %>%
as_draws_df() %>%
select(starts_with("r_mouse")) %>%
t()
# Calculate RMU
reliability(posterior_draws)$hdci
} # }