R/agreement.h.R
# This file is automatically generated, you probably don't want to edit this
agreementOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"agreementOptions",
inherit = jmvcore::Options,
public = list(
initialize = function(
vars = NULL,
sft = FALSE,
wght = "unweighted",
exct = FALSE, ...) {
super$initialize(
package="ClinicoPath",
name="agreement",
requiresData=TRUE,
...)
private$..vars <- jmvcore::OptionVariables$new(
"vars",
vars,
suggested=list(
"ordinal",
"nominal"),
permitted=list(
"factor"))
private$..sft <- jmvcore::OptionBool$new(
"sft",
sft,
default=FALSE)
private$..wght <- jmvcore::OptionList$new(
"wght",
wght,
options=list(
"unweighted",
"squared",
"equal"),
default="unweighted")
private$..exct <- jmvcore::OptionBool$new(
"exct",
exct,
default=FALSE)
self$.addOption(private$..vars)
self$.addOption(private$..sft)
self$.addOption(private$..wght)
self$.addOption(private$..exct)
}),
active = list(
vars = function() private$..vars$value,
sft = function() private$..sft$value,
wght = function() private$..wght$value,
exct = function() private$..exct$value),
private = list(
..vars = NA,
..sft = NA,
..wght = NA,
..exct = NA)
)
agreementResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"agreementResults",
inherit = jmvcore::Group,
active = list(
irrtable = function() private$.items[["irrtable"]],
text2 = function() private$.items[["text2"]],
text = function() private$.items[["text"]]),
private = list(),
public=list(
initialize=function(options) {
super$initialize(
options=options,
name="",
title="Interrater Reliability",
refs=list(
"irr",
"PathologyKappa",
"ClinicoPathJamoviModule"))
self$add(jmvcore::Table$new(
options=options,
name="irrtable",
title="Interrater Reliability",
swapRowsColumns=TRUE,
rows=1,
columns=list(
list(
`name`="method",
`title`="Method",
`type`="text"),
list(
`name`="subjects",
`title`="Subjects",
`type`="integer"),
list(
`name`="raters",
`title`="Raters",
`type`="integer"),
list(
`name`="peragree",
`title`="Agreement %",
`type`="integer"),
list(
`name`="kappa",
`title`="Kappa",
`type`="number"),
list(
`name`="z",
`title`="z",
`type`="number"),
list(
`name`="p",
`title`="p-value",
`type`="number",
`format`="zto,pvalue")),
clearWith=list(
"vars",
"wght",
"exct")))
self$add(jmvcore::Html$new(
options=options,
name="text2",
title="Table",
visible="(sft)",
clearWith=list(
"vars",
"wght",
"exct")))
self$add(jmvcore::Preformatted$new(
options=options,
name="text",
title="Table",
visible="(sft)",
clearWith=list(
"vars",
"wght",
"exct")))}))
agreementBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"agreementBase",
inherit = jmvcore::Analysis,
public = list(
initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
super$initialize(
package = "ClinicoPath",
name = "agreement",
version = c(1,0,0),
options = options,
results = agreementResults$new(options=options),
data = data,
datasetId = datasetId,
analysisId = analysisId,
revision = revision,
pause = NULL,
completeWhenFilled = FALSE,
requiresMissings = FALSE,
weightsSupport = 'auto')
}))
#' Interrater Reliability
#'
#' Function for Interrater Reliability.
#'
#' @examples
#' \dontrun{
#' # example will be added
#'}
#' @param data The data as a data frame.
#' @param vars A string naming the variable from \code{data} that contains the
#' diagnosis given by the observer, variable can be categorical, ordinal or
#' numeric.
#' @param sft Boolean selection whether to show frequency table. Default is
#' 'false'.
#' @param wght A list for the argument weight (wght), for weighted kappa
#' analysis. Default is 'unweighted'. 'squared' or 'equal' should be selected
#' only with ordinal variables. The function gives error if the variable type
#' is not ordinal.
#' @param exct Boolean selection whether to use exact kappa. Effects only more
#' than 3 observers.
#' @return A results object containing:
#' \tabular{llllll}{
#' \code{results$irrtable} \tab \tab \tab \tab \tab a table \cr
#' \code{results$text2} \tab \tab \tab \tab \tab a html \cr
#' \code{results$text} \tab \tab \tab \tab \tab a preformatted \cr
#' }
#'
#' Tables can be converted to data frames with \code{asDF} or \code{\link{as.data.frame}}. For example:
#'
#' \code{results$irrtable$asDF}
#'
#' \code{as.data.frame(results$irrtable)}
#'
#' @export
agreement <- function(
data,
vars,
sft = FALSE,
wght = "unweighted",
exct = FALSE) {
if ( ! requireNamespace("jmvcore", quietly=TRUE))
stop("agreement requires jmvcore to be installed (restart may be required)")
if ( ! missing(vars)) vars <- jmvcore::resolveQuo(jmvcore::enquo(vars))
if (missing(data))
data <- jmvcore::marshalData(
parent.frame(),
`if`( ! missing(vars), vars, NULL))
for (v in vars) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])
options <- agreementOptions$new(
vars = vars,
sft = sft,
wght = wght,
exct = exct)
analysis <- agreementClass$new(
options = options,
data = data)
analysis$run()
analysis$results
}