|
| 1 | +#' An S4 class for computerized adaptive tests |
| 2 | +#' |
| 3 | +#' @slot function.call The original function call. |
| 4 | +#' @slot final.theta.estimate Numeric vector of theta estimates calculated by the provided `method`. |
| 5 | +#' @slot eap.theta Numeric vector of theta estimates calculated by `catR::eapEst`. |
| 6 | +#' @slot final.theta.Baker Numeric vector of theta estimates calculated by the internal `iterative.theta.estimate` function. |
| 7 | +#' @slot final.theta.SEM Numeric vector of SEM estimates calculated by the internal `iterative.theta.estimate` function. |
| 8 | +#' @slot final.items.seen Character matrix of the final items seen by each individual. |
| 9 | +#' @slot final.responses Numeric matrix of the response patterns observed. |
| 10 | +#' @slot runtime A `difftime` object of the total run time of the function. |
| 11 | +#' |
| 12 | +#' @importFrom methods new |
| 13 | +#' |
| 14 | +#' @return An S4 object of class `CAT`. |
| 15 | +#' @export |
| 16 | +#' |
| 17 | +setClass('CAT', |
| 18 | + slots = |
| 19 | + list( |
| 20 | + function.call = 'call', |
| 21 | + final.theta.estimate = 'numeric', |
| 22 | + eap.theta = 'numeric', |
| 23 | + final.theta.Baker = 'numeric', |
| 24 | + final.theta.SEM = 'numeric', |
| 25 | + final.items.seen = 'matrix', |
| 26 | + final.responses = 'matrix', |
| 27 | + runtime = 'ANY' |
| 28 | + ) |
| 29 | + ) |
| 30 | + |
| 31 | +setMethod('show', |
| 32 | + signature = 'CAT', |
| 33 | + definition = function(object) { |
| 34 | + Original.Call = object@function.call |
| 35 | + Total.Time = object@runtime |
| 36 | + Average.Theta = mean(object@final.theta.estimate) |
| 37 | + Average.SEM = mean(object@final.theta.SEM, na.rm = T) |
| 38 | + Average.Items = mean(apply(object@final.items.seen, 1, FUN = function(x) sum(!is.na(x)))) |
| 39 | + |
| 40 | + line0 = c("Test Format: Computerized Adaptive Test") |
| 41 | + line1 = Original.Call |
| 42 | + line2 = paste0("Total Run Time: ", round(Total.Time[[1]], 3), " ", attr(Total.Time, "units")) |
| 43 | + line3 = paste0("Average Theta Estimate: ", round(Average.Theta, 3)) |
| 44 | + line4 = paste0("Average SEM: ", round(Average.SEM, 3)) |
| 45 | + line5 = paste0("Average Number of Items Seen: ", round(Average.Items, 3)) |
| 46 | + |
| 47 | + cat(paste0(c(line0, line1, line2, line3, line4, line5), collapse = "\n")) |
| 48 | + }) |
| 49 | + |
| 50 | +#' An S4 method for multistage adaptive tests. |
| 51 | +#' |
| 52 | +#' @slot function.call The original function call. |
| 53 | +#' @slot final.theta.estimate Numeric vector of theta estimates calculated by the provided `method`. |
| 54 | +#' @slot eap.theta Numeric vector of theta estimates calculated by `catR::eapEst`. |
| 55 | +#' @slot final.theta.Baker Numeric vector of theta estimates calculated by the internal `iterative.theta.estimate` function. |
| 56 | +#' @slot final.theta.SEM Numeric vector of SEM estimates calculated by the internal `iterative.theta.estimate` function. |
| 57 | +#' @slot final.items.seen Character matrix of the final items seen by each individual. |
| 58 | +#' @slot modules.seen Numeric matrix of the modules seen by each individual. |
| 59 | +#' @slot final.responses Numeric matrix of the response patterns observed. |
| 60 | +#' @slot transition.matrix Numeric matrix; the transition matrix entered into the function. |
| 61 | +#' @slot n.stages Numeric; the number of stages specified. |
| 62 | +#' @slot nc.list A list of the number correct scoring logic and method, if applicable. Defaults to `NULL`. |
| 63 | +#' @slot runtime A `difftime` object of the total run time of the function. |
| 64 | +#' |
| 65 | +#' @importFrom methods new |
| 66 | +#' |
| 67 | +#' @return An S4 object of class `MST`. |
| 68 | +#' @export |
| 69 | +#' |
| 70 | +setClass('MST', |
| 71 | + slots = |
| 72 | + list( |
| 73 | + function.call = 'call', |
| 74 | + final.theta.estimate = 'numeric', |
| 75 | + eap.theta = 'numeric', |
| 76 | + final.theta.Baker = 'numeric', |
| 77 | + final.theta.SEM = 'numeric', |
| 78 | + final.items.seen = 'matrix', |
| 79 | + modules.seen = 'matrix', |
| 80 | + final.responses = 'matrix', |
| 81 | + transition.matrix = 'matrix', |
| 82 | + n.stages = 'numeric', |
| 83 | + nc.list = 'ANY', |
| 84 | + runtime = 'ANY' |
| 85 | + ) |
| 86 | +) |
| 87 | + |
| 88 | +setMethod('show', |
| 89 | + signature = 'MST', |
| 90 | + definition = function(object) { |
| 91 | + Original.Call = object@function.call |
| 92 | + Total.Time = object@runtime |
| 93 | + Average.Theta = mean(object@final.theta.estimate) |
| 94 | + Average.SEM = mean(object@final.theta.SEM, na.rm = T) |
| 95 | + Path.Taken = apply(object@modules.seen, 1, FUN = function(object) paste0(object, collapse = '-')) |
| 96 | + Most.Path = table(Path.Taken)[which(table(Path.Taken)==max(table(Path.Taken)))] |
| 97 | + |
| 98 | + line0 = ifelse( |
| 99 | + test = is.null(object@nc.list), |
| 100 | + yes = c("Test Format: Multistage Adaptive Test"), |
| 101 | + no = ifelse( |
| 102 | + test = is.null(object@nc.list$method)| |
| 103 | + object@nc.list$method!="module_sum", |
| 104 | + yes = c("Test Format: Multistage Adaptive Test with Cumulative Summation Scoring"), |
| 105 | + no = c("Test Format: Multistage Adaptive Test with Module Summation Scoring") |
| 106 | + ) |
| 107 | + ) |
| 108 | + line1 = Original.Call |
| 109 | + line2 = paste0("Total Run Time: ", round(Total.Time[[1]], 3), " ", attr(Total.Time, "units")) |
| 110 | + line3 = paste0("Average Theta Estimate: ", round(Average.Theta, 3)) |
| 111 | + line4 = paste0("Average SEM: ", round(Average.SEM, 3)) |
| 112 | + line5 = paste0("Most Common Path(s) Taken: ", attr(Most.Path, 'names'), " taken by ", Most.Path, " subjects") |
| 113 | + |
| 114 | + cat(paste0(c(line0, line1, line2, line3, line4, line5), collapse = "\n")) |
| 115 | + }) |
| 116 | + |
| 117 | +#' An S4 method for mixed adaptive tests. |
| 118 | +#' |
| 119 | +#' @slot function.call The original function call. |
| 120 | +#' @slot final.theta.estimate Numeric vector of theta estimates calculated by the provided `method`. |
| 121 | +#' @slot eap.theta Numeric vector of theta estimates calculated by `catR::eapEst`. |
| 122 | +#' @slot final.theta.Baker Numeric vector of theta estimates calculated by the internal `iterative.theta.estimate` function. |
| 123 | +#' @slot final.theta.SEM Numeric vector of SEM estimates calculated by the internal `iterative.theta.estimate` function. |
| 124 | +#' @slot final.items.seen Character matrix of the final items seen by each individual. |
| 125 | +#' @slot modules.seen Numeric matrix of the modules seen by each individual. |
| 126 | +#' @slot final.responses Numeric matrix of the response patterns observed. |
| 127 | +#' @slot transition.matrix Numeric matrix; the transition matrix entered into the function. |
| 128 | +#' @slot n.stages Numeric; the number of stages specified. |
| 129 | +#' @slot runtime A `difftime` object of the total run time of the function. |
| 130 | +#' |
| 131 | +#' @importFrom methods new |
| 132 | +#' |
| 133 | +#' @return An S4 object of class `MAT`. |
| 134 | +#' @export |
| 135 | +#' |
| 136 | +setClass('MAT', |
| 137 | + slots = |
| 138 | + list( |
| 139 | + function.call = 'call', |
| 140 | + final.theta.estimate = 'numeric', |
| 141 | + eap.theta = 'numeric', |
| 142 | + final.theta.Baker = 'numeric', |
| 143 | + final.theta.SEM = 'numeric', |
| 144 | + final.items.seen = 'matrix', |
| 145 | + modules.seen = 'matrix', |
| 146 | + final.responses = 'matrix', |
| 147 | + transition.matrix = 'matrix', |
| 148 | + n.stages = 'numeric', |
| 149 | + runtime = 'ANY' |
| 150 | + ) |
| 151 | +) |
| 152 | + |
| 153 | +setMethod('show', |
| 154 | + signature = 'MAT', |
| 155 | + definition = function(object) { |
| 156 | + Original.Call = object@function.call |
| 157 | + Total.Time = object@runtime |
| 158 | + Average.Theta = mean(object@final.theta.estimate) |
| 159 | + Average.SEM = mean(object@final.theta.SEM, na.rm = T) |
| 160 | + Path.Taken = apply(object@modules.seen, 1, FUN = function(object) paste0(object, collapse = '-')) |
| 161 | + Most.Path = table(Path.Taken)[which(table(Path.Taken)==max(table(Path.Taken)))] |
| 162 | + |
| 163 | + line0 = c("Test Format: Mixed Adaptive Test") |
| 164 | + line1 = Original.Call |
| 165 | + line2 = paste0("Total Run Time: ", round(Total.Time[[1]], 3), " ", attr(Total.Time, "units")) |
| 166 | + line3 = paste0("Average Theta Estimate: ", round(Average.Theta, 3)) |
| 167 | + line4 = paste0("Average SEM: ", round(Average.SEM, 3)) |
| 168 | + line5 = paste0("Most Common Path(s) Taken: ", attr(Most.Path, 'names'), " taken by ", Most.Path, " subjects") |
| 169 | + |
| 170 | + cat(paste0(c(line0, line1, line2, line3, line4, line5), collapse = "\n")) |
| 171 | + }) |
| 172 | + |
0 commit comments