|
23 | 23 | # data structures used in weighted parametric group sequential designs. |
24 | 24 |
|
25 | 25 | #' @importFrom S7 new_class new_object class_data.frame class_integer class_character new_S3_class S7_inherits S7_object method |
| 26 | +NULL |
26 | 27 |
|
27 | 28 | #' EventTable S7 Class |
28 | 29 | #' |
|
56 | 57 | #' |
57 | 58 | #' # Create valid event data |
58 | 59 | #' event_data <- tibble( |
59 | | -#' H1 = c(1L, 1L, 2L, 2L), |
60 | | -#' H2 = c(1L, 2L, 2L, 2L), |
61 | | -#' Analysis = c(1L, 1L, 1L, 2L), |
62 | | -#' Event = c(155.5, 85.2, 160.7, 170.3) |
| 60 | +#' H1 = c(1L, 2L, 1L, 1L, 2L, 1L), |
| 61 | +#' H2 = c(1L, 2L, 2L, 1L, 2L, 2L), |
| 62 | +#' Analysis = c(1L, 1L, 1L, 2L, 2L, 2L), |
| 63 | +#' Event = c(155, 160, 85, 305, 320, 170) |
63 | 64 | #' ) |
64 | 65 | #' |
65 | 66 | #' # Create EventTable object |
|
69 | 70 | #' print(event_table@n_hypotheses) # Number of hypotheses |
70 | 71 | #' print(event_table@n_analyses) # Number of analyses |
71 | 72 | #' |
72 | | -#' # Use with existing wpgsd functions |
73 | | -#' correlation_matrix <- generate_corr(event_table@data) |
74 | | -#' |
| 73 | +#' @name EventTable |
75 | 74 | #' @export |
76 | 75 | # Define the EventTable S7 class |
77 | 76 | EventTable <- S7::new_class( |
@@ -200,43 +199,6 @@ as_event_table <- function(data) { |
200 | 199 | EventTable(data = data) |
201 | 200 | } |
202 | 201 |
|
203 | | -#' Core Event Data Validation Function |
204 | | -#' |
205 | | -#' @description |
206 | | -#' Comprehensive validation function for event data used across the package. |
207 | | -#' This is the single source of truth for event data validation logic. |
208 | | -#' |
209 | | -#' @param data A data.frame or tibble to validate |
210 | | -#' @param validation_level Character string specifying validation level: |
211 | | -#' - "basic": Check required columns, data types, and basic constraints |
212 | | -#' - "strict": Include advanced mathematical requirements for correlation computation |
213 | | -#' - "s7": Full validation for S7 EventTable objects |
214 | | -#' @param return_errors Logical. If TRUE, return error messages instead of stopping. |
215 | | -#' Used for S7 validators which expect error messages. |
216 | | -#' |
217 | | -#' @return If `return_errors = FALSE`: `TRUE` if validation passes (invisible), |
218 | | -#' otherwise stops with descriptive error message. |
219 | | -#' If `return_errors = TRUE`: `TRUE` if validation passes, otherwise |
220 | | -#' first error message as character string. |
221 | | -#' |
222 | | -#' @details |
223 | | -#' Validation checks performed: |
224 | | -#' |
225 | | -#' **Basic level:** |
226 | | -#' - Required columns (H1, H2, Analysis, Event) are present |
227 | | -#' - All columns are numeric |
228 | | -#' - Hypothesis indices (H1, H2) are positive |
229 | | -#' - Analysis numbers are positive |
230 | | -#' - Event counts are non-negative |
231 | | -#' |
232 | | -#' **Strict level (includes basic plus):** |
233 | | -#' - H1 <= H2 for all rows (correlation computation requirement) |
234 | | -#' - Unique combinations of H1, H2, Analysis |
235 | | -#' - Sequential hypothesis and analysis indices starting from 1 |
236 | | -#' - Diagonal entries exist for all off-diagonal entries |
237 | | -#' |
238 | | - |
239 | | - |
240 | 202 | #' Validate EventTable Data Format |
241 | 203 | #' |
242 | 204 | #' @description |
@@ -279,53 +241,6 @@ validate_event_table_data <- function(data) { |
279 | 241 | validate_event_data_core(data, validation_level = "basic") |
280 | 242 | } |
281 | 243 |
|
282 | | -#' Create EventTable S7 Object |
283 | | -#' |
284 | | -#' @description |
285 | | -#' Create a type-safe S7 EventTable object that represents event count data |
286 | | -#' structure used in `generate_corr()` and `generate_event_table()`. This class |
287 | | -#' provides validation and computed properties for hypothesis and analysis counts. |
288 | | -#' |
289 | | -#' @param data A tibble or data.frame containing the required columns: |
290 | | -#' - `H1`: First hypothesis index (numeric, positive integers) |
291 | | -#' - `H2`: Second hypothesis index (numeric, positive integers) |
292 | | -#' - `Analysis`: Analysis number (numeric, positive integers) |
293 | | -#' - `Event`: Event count (numeric, non-negative) |
294 | | -#' |
295 | | -#' @details |
296 | | -#' The EventTable class automatically validates the input data and computes: |
297 | | -#' - `n_hypotheses`: Maximum hypothesis index across H1 and H2 columns |
298 | | -#' - `n_analyses`: Maximum analysis number |
299 | | -#' |
300 | | -#' The class ensures data integrity by validating that: |
301 | | -#' - All required columns are present |
302 | | -#' - H1, H2, Analysis, and Event are numeric |
303 | | -#' - Hypothesis indices are positive integers |
304 | | -#' - Analysis numbers are positive integers |
305 | | -#' - Event counts are non-negative |
306 | | -#' |
307 | | -#' @return An EventTable S7 object with validated data and computed properties |
308 | | -#' |
309 | | -#' @examples |
310 | | -#' library(tibble) |
311 | | -#' |
312 | | -#' # Create sample event data |
313 | | -#' event_data <- tibble( |
314 | | -#' H1 = c(1, 2, 1, 1, 2, 1), |
315 | | -#' H2 = c(1, 2, 2, 1, 2, 2), |
316 | | -#' Analysis = c(1, 1, 1, 2, 2, 2), |
317 | | -#' Event = c(155, 160, 85, 305, 320, 170) |
318 | | -#' ) |
319 | | -#' |
320 | | -#' # Create EventTable object |
321 | | -#' event_table <- EventTable(data = event_data) |
322 | | -#' |
323 | | -#' # Access properties |
324 | | -#' print(event_table@n_hypotheses) # Number of hypotheses |
325 | | -#' print(event_table@n_analyses) # Number of analyses |
326 | | -#' |
327 | | -#' # Use with existing wpgsd functions |
328 | | -#' correlation_matrix <- generate_corr(event_table@data) |
329 | 244 | # CorrelationMatrix S7 Class ==== |
330 | 245 |
|
331 | 246 | #' CorrelationMatrix S7 Class |
@@ -361,6 +276,7 @@ validate_event_table_data <- function(data) { |
361 | 276 | #' |
362 | 277 | #' print(corr_obj) |
363 | 278 | #' |
| 279 | +#' @name CorrelationMatrix |
364 | 280 | #' @export |
365 | 281 | CorrelationMatrix <- S7::new_class("CorrelationMatrix", |
366 | 282 | properties = list( |
|
0 commit comments