% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/reliabilityRMU.R
\name{RMUreliability}
\alias{RMUreliability}
\title{Estimate reliability (Relative Measurement Uncertainty) from Bayesian measurement models}
\usage{
RMUreliability(input_draws, verbose = FALSE, level = 0.95)
}
\arguments{
\item{input_draws}{A matrix or data frame of posterior draws. Rows represent subjects and columns represent draws.}

\item{verbose}{Logical. Print detailed information about the input data. Default is TRUE.}

\item{level}{Numeric. Credibility level for the highest density continuous interval. Default is 0.95.}
}
\value{
A list containing:
\itemize{
\item hdci: A data frame with a point-estimate (posterior mean) and highest density continuous interval for reliability, calculated using the ggdist::mean_hdci function
\item 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)
}
}
\description{
This function measures reliability using posterior draws from a fitted Bayesian model.
}
\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
\href{https://www.bignardi.co.uk/8_bayes_reliability/tutorial_rmu_sum_score_reliability.html}{this tutorial}.

For an example of how to apply this function to go/go-no task data using brms, see
\href{https://www.bignardi.co.uk/8_bayes_reliability/tutorial_calculating_rmu_gonogo.html}{this tutorial}.
}
\examples{
\donttest{
library(brms)
library(dplyr)
library(tidyr)
library(tibble)

# --- Dichotomous Rasch Model ---

df_rm <- eRm::raschdat3 \%>\%
  as.data.frame() \%>\%
  rownames_to_column("id") \%>\%
  pivot_longer(!id, names_to = "item", values_to = "response")

fit_rm <- brm(
  response ~ 1 + (1 | item) + (1 | id),
  data   = df_rm,
  family = bernoulli(),
  chains = 4,
  cores  = 1, # use more cores if you have
  iter   = 500 # use at least 2000 
)

# Extract posterior draws from brms model

posterior_draws = fit_rm \%>\%
  as_draws_df() \%>\%
  as_tibble() \%>\% 
  select(starts_with("r_id")) \%>\%
  t()

# Calculate RMU

RMUreliability(posterior_draws)
}

}
\references{
Bignardi, G., Kievit, R., & Bürkner, P. C. (2025). A general method for estimating reliability using Bayesian Measurement Uncertainty. PsyArXiv. \href{https://osf.io/preprints/psyarxiv/h54k8}{doi:10.31234/osf.io/h54k8}
}
