Skip to content

Commit 7743218

Browse files
authored
Merge pull request #44 from bbuchsbaum/codex/add-full-roxygen-blocks-for-functions
Add documentation for generics
2 parents 10d7928 + aa8be8d commit 7743218

7 files changed

+122
-29
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export(get_nfolds)
145145
export(get_samples)
146146
export(get_searchlight)
147147
export(group_means)
148+
export(has_crossval)
148149
export(has_test_set)
149150
export(kfold_cross_validation)
150151
export(load_model)
@@ -186,6 +187,7 @@ export(second_order_similarity)
186187
export(select_features)
187188
export(sequential_blocked_cross_validation)
188189
export(strip_dataset)
190+
export(tune_grid)
189191
export(sub_result)
190192
export(test_design)
191193
export(train_indices)

R/allgeneric.R

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -407,30 +407,61 @@ fit_model <- function(obj, roi_x, y, wts, param, lev=NULL, last=FALSE, classProb
407407
UseMethod("fit_model")
408408
}
409409

410-
#' Tune Grid Extraction
410+
#' Extract Tuning Grid
411411
#'
412-
#' Extract the parameter grid to optimize for a model.
412+
#' Returns the parameter grid used to tune a model.
413413
#'
414-
#' @param obj The model object.
415-
#' @param x The training data.
416-
#' @param y The response vector.
417-
#' @param len The number of elements in the tuning grid.
418-
tune_grid <- function(obj, x,y,len) {
414+
#' @param obj A model or model specification.
415+
#' @param x Training data.
416+
#' @param y Response variable.
417+
#' @param len Number of parameter sets to generate.
418+
#'
419+
#' @return A data frame of tuning parameter combinations.
420+
#' @rdname tune_grid-methods
421+
#' @export
422+
#'
423+
#' @examples
424+
#' ds <- gen_sample_dataset(D = c(5, 5, 5), nobs = 10)
425+
#' mdl <- load_model("sda_notune")
426+
#' tune_grid(mdl, ds$dataset$train_data, ds$design$y_train, len = 1)
427+
tune_grid <- function(obj, x, y, len) {
419428
UseMethod("tune_grid")
420429
}
421430

422431
#' Test Set Availability
423432
#'
424-
#' Check if an object has a test set available.
433+
#' Determine whether the object contains a separate test set.
434+
#'
435+
#' @param obj Object to query.
425436
#'
426-
#' @param obj The object to check for a test set.
437+
#' @return Logical indicating if a test set exists.
438+
#' @rdname has_test_set-methods
427439
#' @export
440+
#'
441+
#' @examples
442+
#' ds <- gen_sample_dataset(D = c(4, 4, 4), nobs = 10, external_test = TRUE)
443+
#' has_test_set(ds$design)
428444
has_test_set <- function(obj) {
429445
UseMethod("has_test_set")
430446
}
431447

432-
#' Requires cross-validation to be performed
433-
#' @param obj The model object.
448+
#' Cross-Validation Availability
449+
#'
450+
#' Determine whether cross-validation is specified for the object.
451+
#'
452+
#' @param obj Model specification object.
453+
#'
454+
#' @return Logical indicating if cross-validation will be performed.
455+
#' @rdname has_crossval-methods
456+
#' @export
457+
#'
458+
#' @examples
459+
#' ds <- gen_sample_dataset(D = c(4, 4, 4), nobs = 10)
460+
#' cval <- blocked_cross_validation(ds$design$block_var)
461+
#' mdl <- load_model("sda_notune")
462+
#' mspec <- mvpa_model(mdl, ds$dataset, ds$design,
463+
#' "classification", crossval = cval)
464+
#' has_crossval(mspec)
434465
has_crossval <- function(obj) {
435466
UseMethod("has_crossval")
436467
}
@@ -442,25 +473,37 @@ has_crossval.default <- function(obj) {
442473

443474
#' Compute Performance Metrics
444475
#'
445-
#' Compute performance metrics (accuracy, AUC, RMSE, etc.) for classification/regression results.
476+
#' Generic function to compute performance metrics from result objects.
446477
#'
447-
#' @param x The classification/regression result object to evaluate.
448-
#' @param ... Additional arguments passed to method-specific performance functions.
478+
#' @param x Result object from a classification or regression analysis.
479+
#' @param ... Additional arguments passed to methods.
449480
#'
450-
#' @return A list of performance metrics.
481+
#' @return Named numeric vector of performance metrics.
482+
#' @rdname performance-methods
451483
#' @export
452-
performance <- function(x,...) {
484+
#'
485+
#' @examples
486+
#' cres <- binary_classification_result(
487+
#' observed = factor(c("a", "b")),
488+
#' predicted = factor(c("a", "b")),
489+
#' probs = matrix(c(0.8, 0.2, 0.3, 0.7), ncol = 2,
490+
#' dimnames = list(NULL, c("a", "b")))
491+
#' )
492+
#' performance(cres)
493+
performance <- function(x, ...) {
453494
UseMethod("performance")
454495
}
455496

456497
#' Compute Performance for an Object
457498
#'
458499
#' Delegates calculation of performance metrics to the appropriate method.
459500
#'
460-
#' @param obj The input object.
461-
#' @param result The classification/regression result object to evaluate.
501+
#' @param obj Model specification or object capable of computing performance.
502+
#' @param result The classification/regression result to evaluate.
462503
#'
463-
#' @return A list of performance metrics.
504+
#' @return Named numeric vector of performance metrics.
505+
#' @rdname compute_performance-methods
506+
#' @export
464507
#'
465508
#' @examples
466509
#' cres <- binary_classification_result(
@@ -472,7 +515,6 @@ performance <- function(x,...) {
472515
#' dummy <- list(performance = performance)
473516
#' class(dummy) <- "mvpa_model"
474517
#' compute_performance(dummy, cres)
475-
#' @export
476518
compute_performance <- function(obj, result) {
477519
UseMethod("compute_performance")
478520
}

man/compute_performance.Rd

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

man/has_crossval.Rd

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

man/has_test_set.Rd

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/performance.Rd

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

man/tune_grid.Rd

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

0 commit comments

Comments
 (0)