View source: R/person_parameters.R
| person_parameters | R Documentation |
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.
person_parameters(
model,
item_var = item,
person_var = id,
draws = FALSE,
center = TRUE,
theta_range = c(-7, 7)
)
model |
A fitted
|
item_var |
An unquoted variable name identifying the item
grouping variable in the model data. Default is |
person_var |
An unquoted variable name identifying the person
grouping variable in the model data. Default is |
draws |
Logical. If |
center |
Logical. If |
theta_range |
A numeric vector of length 2 specifying the
range for the Newton-Raphson WLE search. Default is
|
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 using Newton-Raphson iteration
with adaptive step damping on the Warm-corrected likelihood.
WLE adds a bias correction term J(\theta) / (2 I(\theta))
to the score equations, where I(\theta) is the test
information and J(\theta) = \sum_i \sum_c (c - E_i)^3 P_{ic}
is the sum of third central moments. This produces estimates with
reduced finite-sample bias compared to MLE, especially at
extreme scores (Warm, 1989).
The Newton-Raphson algorithm uses adaptive step damping following the approach in iarm (Mueller): the maximum allowed step size shrinks by a factor of 1.05 each iteration, preventing overshoot and ensuring convergence for near-extreme scores.
For extreme scores (sum score = 0 or maximum possible), the
WLE is not well-defined. These cases are assigned the boundary
values of theta_range with NA standard errors.
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.
A list with the following elements:
A tibble with one
row per person containing: the person ID, sum_score,
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).
A tibble mapping each
observed ordinal sum score to its mean EAP, mean EAP SE,
WLE, and WLE SE. Extreme scores (0 and maximum) receive
WLE estimates at the boundary of theta_range with
NA standard errors.
(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.
Warm, T. A. (1989). Weighted likelihood estimation of ability in item response theory. Psychometrika, 54(3), 427–450. \Sexpr[results=rd]{tools:::Rd_expr_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. \Sexpr[results=rd]{tools:::Rd_expr_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.
RMUreliability, plot_targeting,
ranef, as_draws_df.
library(brms)
library(dplyr)
library(tidyr)
library(tibble)
# --- Dichotomous Rasch Model (random items) ---
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 = 2, iter = 1000 # use more iter and cores
)
# Basic usage — rows match original person order
pp <- person_parameters(fit_rm)
pp$person_estimates
pp$score_table
# With full posterior draws (e.g., for RMUreliability)
pp_draws <- person_parameters(fit_rm, draws = TRUE)
RMUreliability(pp_draws$draws_matrix)
# --- Polytomous PCM (acat) ---
df_pcm <- eRm::pcmdat2 %>%
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
)
pp_pcm <- person_parameters(fit_pcm)
pp_pcm$score_table
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.