Skip to contents

Extracts person ability estimates from a fitted Bayesian Rasch model. Returns both Bayesian EAP (expected a posteriori) estimates with posterior SDs and frequentist WLE (Warm's weighted likelihood) estimates with standard errors, plus a lookup table mapping ordinal sum scores to both scales.

Usage

person_parameters(
  model,
  item_var = item,
  person_var = id,
  draws = FALSE,
  center = TRUE,
  theta_range = c(-7, 7)
)

Arguments

model

A fitted brmsfit object. Supported parameterisations:

Polytomous ordinal (PCM)

e.g., family = acat with thres(gr = item), producing item-specific thresholds.

Dichotomous Rasch (random items)

e.g., response ~ 1 + (1 | item) + (1 | id) with family = bernoulli().

Dichotomous 1PL (fixed items)

e.g., response ~ 0 + item + (1 | id) with family = bernoulli().

Rating scale model

family = acat with common thresholds and item effects, e.g., response ~ 1 + (1 | item) + (1 | id).

item_var

An unquoted variable name identifying the item grouping variable in the model data. Default is item.

person_var

An unquoted variable name identifying the person grouping variable in the model data. Default is id.

draws

Logical. If TRUE, a matrix of full posterior draws (persons x draws) is included in the output. Default is FALSE.

center

Logical. If TRUE (the default), person parameters and item difficulties are recentered so that the mean item difficulty is zero, matching the convention in frequentist CML Rasch estimation. If FALSE, raw brms parameterisation is used.

theta_range

A numeric vector of length 2 specifying the search range for the WLE. A WLE outside it is set to the nearer bound with an NA standard error. Default is c(-7, 7).

Value

A list with the following elements:

person_estimates

A tibble with one row per person containing: the person ID, n_items (number of items answered), sum_score (sum of the item scores, each scored from 0), eap (posterior mean of person random effect), eap_se (posterior SD), wle (Warm's weighted likelihood estimate), and wle_se (asymptotic SE of the WLE). Rows are ordered to match the original person order in the model data (i.e., the order of first appearance of each person ID).

score_table

A tibble mapping each sum score observed among persons who answered every item to the number of such persons, their mean EAP and mean EAP SE, and the WLE and WLE SE for that score on the complete item set.

draws_matrix

(Only if draws = TRUE) A numeric matrix with rows = persons and columns = posterior draws. Row names are person IDs. Rows are ordered to match the original person order in the model data. Can be passed directly to RMUreliability.

Details

EAP estimates are extracted as the posterior means of the person random effects (r_id[j, Intercept]) from as_draws_df, with the posterior SD serving as the standard error. These are the standard Bayesian point estimates and reflect shrinkage toward the population mean.

WLE estimates (Warm, 1989) are computed from the posterior mean item parameters by solving the Warm-corrected score equation $$r - E(\theta) + J(\theta) / (2 I(\theta)) = 0$$ with uniroot, where \(r\) is the sum score, \(E(\theta)\) the expected sum score, \(I(\theta)\) the test information and \(J(\theta) = \sum_i \sum_c (c - E_i)^3 P_{ic}\) the sum of third central moments. The correction reduces the finite-sample bias of the MLE and keeps the estimate finite at the minimum and maximum scores. The standard error is \(1 / \sqrt{I(\theta)}\).

A sum score only has a WLE relative to the items that make it up. Persons with missing responses therefore get the WLE for their sum score on the items they answered, computed separately for each set of answered items.

When center = TRUE (the default), item difficulty parameters are shifted so their mean is zero, and EAP person parameters are shifted by the same constant. WLE is computed from the centered item parameters. This matches the convention in frequentist CML Rasch estimation.

Row ordering: Both person_estimates and draws_matrix preserve the original person order from the model data (order of first appearance of each person ID). This allows direct row-binding with the source data without re-matching.

References

Warm, T. A. (1989). Weighted likelihood estimation of ability in item response theory. Psychometrika, 54(3), 427–450. doi:10.1007/BF02294627

Bürkner, P.-C. (2021). Bayesian Item Response Modeling in R with brms and Stan. Journal of Statistical Software, 100, 1–54. doi:10.18637/jss.v100.i05

Christensen, K. B., Kreiner, S. & Mesbah, M. (Eds.) (2013). Rasch Models in Health. Iste and Wiley, pp. 63–70.

Examples

# \donttest{
library(brms)
library(dplyr)
library(tidyr)
library(tibble)

# --- Dichotomous Rasch Model (random items) ---

# PHQ-9 items dichotomised (any symptom vs none), for illustration only
df_rm <- phq9[1:200, 1:9] %>%
  mutate(across(everything(), ~ as.integer(.x > 0))) %>%
  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 = 2, iter = 1000 # use more iter and cores
)
#> Compiling Stan program...
#> Error in .fun(model_code = .x1): Boost not found; call install.packages('BH')

# Basic usage — rows match original person order
pp <- person_parameters(fit_rm)
#> Error: object 'fit_rm' not found
pp$person_estimates
#> Error: object 'pp' not found
pp$score_table
#> Error: object 'pp' not found

# With full posterior draws (e.g., for RMUreliability)
pp_draws <- person_parameters(fit_rm, draws = TRUE)
#> Error: object 'fit_rm' not found
RMUreliability(pp_draws$draws_matrix)
#> Error: object 'pp_draws' not found

# --- Polytomous PCM (acat) ---

df_pcm <- phq9[1:200, 1:9] %>%
  mutate(across(everything(), ~ .x + 1)) %>%
  rownames_to_column("id") %>%
  pivot_longer(!id, names_to = "item", values_to = "response")

fit_pcm <- brm(
  response | thres(gr = item) ~ 1 + (1 | id),
  data   = df_pcm,
  family = acat,
  chains = 4, cores = 2, iter = 1000 # use more iter and cores
)
#> Compiling Stan program...
#> Error in .fun(model_code = .x1): Boost not found; call install.packages('BH')

pp_pcm <- person_parameters(fit_pcm)
#> Error: object 'fit_pcm' not found
pp_pcm$score_table
#> Error: object 'pp_pcm' not found
# }