/
rater_model_class.R
87 lines (78 loc) · 1.42 KB
/
rater_model_class.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#' Print a `rater_model` object.
#'
#' @param x A `rater_model` object.
#' @param ... Other arguments
#'
#' @examples
#' mod <- dawid_skene()
#' print(mod)
#'
#' @export
#'
print.rater_model <- function(x, ...) {
cat(get_name(x), "\n\n")
pars <- get_parameters(x)
cat("Prior parameters:\n\n")
for (i in 1:length(pars)) {
cat(paste0(names(pars)[[i]], ":"))
if (!is.null(pars[[i]])) {
cat("\n \n")
print(pars[[i]])
cat("\n")
} else {
cat(" default\n")
}
}
}
#' Summarise a `rater_model`.
#'
#' @param object A `rater_model` object.
#' @param ... Other arguments.
#'
#' @examples
#' mod <- dawid_skene()
#' summary(mod)
#'
#' @method summary rater_model
#'
#' @export
#'
summary.rater_model <- function(object, ...) {
cat(get_name(object))
}
is.dawid_skene <- function(model) {
inherits(model, "dawid_skene")
}
is.hier_dawid_skene <- function(m) {
inherits(m, "hier_dawid_skene")
}
is.rater_model <- function(m) {
inherits(m, "rater_model")
}
is.class_conditional_dawid_skene <- function(m) {
inherits(m, "class_conditional_dawid_skene")
}
#' Gets the long name of a model
#'
#' @param m Object of type `rater_model`.
#'
#' @noRd
#'
get_name <- function(m) {
m$name
}
#' Gets the stan file name of a model
#'
#' @param m object of type `rater_model`.
#'
#' @noRd
#'
get_file <- function(m) {
m$file
}
get_K <- function(m) {
m$K
}
get_parameters <- function(m) {
m$parameters
}