Skip to content

Commit b18f8c5

Browse files
committed
add extractor for overall p-value
1 parent 9aee2a4 commit b18f8c5

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

R/extract.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ measr_extract <- function(model, ...) {
7777
#' Model fit information must first be added to the model using [add_fit()].
7878
#' * `ppmc_odds_ratio_flags`: A subset of the PPMC odds ratios where the _ppp_
7979
#' is outside the specified `ppmc_interval`.
80+
#' * `ppmc_pvalue`: The observed and posterior predicted proportion of correct
81+
#' responses to each item. See [fit_ppmc()] for details.
82+
#' * `ppmc_pvalue_flags`: A subset of the PPMC proportion correct values where
83+
#' the _ppp_ is outside the specified `ppmc_interval`.
8084
#' * `loo`: The leave-one-out cross validation results. See [loo::loo()] for
8185
#' details. The information criterion must first be added to the model using
8286
#' [add_criterion()].
@@ -146,6 +150,8 @@ measr_extract.measrdcm <- function(model, what, ...) {
146150
ppmc_conditional_prob_flags = dcm_extract_ppmc_cond_prob(model, ...),
147151
ppmc_odds_ratio = extract_or(model, ppmc_interval = NULL),
148152
ppmc_odds_ratio_flags = extract_or(model, ...),
153+
ppmc_pvalue = dcm_extract_ppmc_pvalue(model, ppmc_interval = NULL),
154+
ppmc_pvalue_flags = dcm_extract_ppmc_pvalue(model, ...),
149155
loo = extract_info_crit(model, "loo"),
150156
waic = extract_info_crit(model, "waic"),
151157
pattern_reliability = dcm_extract_patt_reli(model),

R/utils-extract.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,31 @@ dcm_extract_ppmc_cond_prob <- function(model, ppmc_interval = 0.95) {
187187
return(res)
188188
}
189189

190+
dcm_extract_ppmc_pvalue <- function(model, ppmc_interval = 0.95) {
191+
if (!is.null(ppmc_interval)) {
192+
ppmc_interval <- check_double(ppmc_interval, lb = 0, ub = 1,
193+
name = "ppmc_interval")
194+
}
195+
196+
if (is.null(model$fit$ppmc$item_fit$pvalue)) {
197+
rlang::abort(message = glue::glue("Model fit information must be ",
198+
"added to a model object before ",
199+
"p-values can be ",
200+
"extracted. See `?add_fit()`."))
201+
}
202+
203+
res <- if (is.null(ppmc_interval)) {
204+
model$fit$ppmc$item_fit$pvalue
205+
} else {
206+
model$fit$ppmc$item_fit$pvalue %>%
207+
dplyr::filter(!dplyr::between(.data$ppp,
208+
(1 - ppmc_interval) / 2,
209+
1 - ((1 - ppmc_interval) / 2)))
210+
}
211+
212+
return(res)
213+
}
214+
190215
dcm_extract_patt_reli <- function(model) {
191216
if (identical(model$reliability, list())) {
192217
rlang::abort(message = glue::glue("Reliability information must be ",

man/measr_extract.Rd

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)