Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
timbeechey committed Mar 9, 2024
1 parent edf1c55 commit 4db2d42
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 130 deletions.
12 changes: 0 additions & 12 deletions R/accuracy.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ plot.clubproaccuracy <- function(x, ...) {
}


#' Print prediction accuracy.
#'
#' @details
#' Print a table of prediction accuracy by category
#'
#' @param x an object of class "clubproaccuracy"
#' @param ... ignored
#' @return called for side-effects only
#' @examples
#' mod <- club(rate ~ dose, data = caffeine)
#' z <- accuracy(mod)
#' print(z)
#' @export
print.clubproaccuracy <- function(x, ...) {
print(unclass(x))
Expand Down
7 changes: 0 additions & 7 deletions R/classify.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,6 @@ club.formula <- function(f, data, imprecision = 0, nreps = 1000L, normalise_cols
}


#' Print the model call.
#' @param x an object of class "clubprofit"
#' @param ... ignored
#' @return No return value, called for side effects.
#' @examples
#' mod <- club(rate ~ dose, data = caffeine)
#' print(mod)
#' @export
print.clubprofit <- function(x, ...) {
print(x$call)
Expand Down
26 changes: 10 additions & 16 deletions R/compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ compare.clubprofit <- function(m1, m2) {
pcc_diff <- abs(pcc(m1) - pcc(m2))
diff_dist <- pcc_replicates(m1) - pcc_replicates(m2)
cval <- length(abs(diff_dist)[abs(diff_dist) >= pcc_diff]) / m1$nreps
structure(
list(pcc_diff = pcc_diff,
diff_dist = diff_dist,
cval = cval),
class = "clubprocomparison")
structure(list(pcc_diff = pcc_diff,
diff_dist = diff_dist,
cval = cval),
class = "clubprocomparison")
}


Expand All @@ -66,13 +65,11 @@ compare.clubprofit <- function(m1, m2) {
#' @export
summary.clubprocomparison <- function(object, ...) {
structure(
list(
pcc_diff = object$pcc_diff,
min_pcc_difference = min(object$diff_dist),
max_pcc_difference = max(object$diff_dist),
nreps = length(object$diff_dist),
cval = object$cval
),
list(pcc_diff = object$pcc_diff,
min_pcc_difference = min(object$diff_dist),
max_pcc_difference = max(object$diff_dist),
nreps = length(object$diff_dist),
cval = object$cval),
class = "summary.clubprocomparison"
)
}
Expand All @@ -84,7 +81,7 @@ print.summary.clubprocomparison <- function(x, ..., digits = 2L) {
stopifnot("digits cannot be negative"= digits >= 0)
stopifnot("digits must be a single number"= length(digits) == 1)

cat("********** Model Comparison **********\n\n")
cat("********** Model Comparison **********\n")
cat("Absolute PCC difference: ", round(x$pcc_diff, 2), "\n")
cat("Minimum random PCC difference: ", round(x$min_pcc_difference, digits), "\n")
cat("Maximum random PCC difference: ", round(x$max_pcc_difference, digits), "\n")
Expand All @@ -98,9 +95,6 @@ print.clubprocomparison <- function(x, ...) {
}


# plot.clubprocomparison


#' Plot model comparison.
#'
#' @details
Expand Down
12 changes: 0 additions & 12 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ plot.clubpropredictions <- function(x, ...) {
}


#' Print predictions.
#'
#' @details
#' Print a table of observed versus predicted categories
#'
#' @param x an object of class "clubpropredictions"
#' @param ... ignored
#' @return called for side-effects only
#' @examples
#' mod <- club(rate ~ dose, data = caffeine)
#' z <- predict(mod)
#' print(z)
#' @export
print.clubpropredictions <- function(x, ...) {
print(unclass(x))
Expand Down
27 changes: 0 additions & 27 deletions man/print.clubproaccuracy.Rd

This file was deleted.

23 changes: 0 additions & 23 deletions man/print.clubprofit.Rd

This file was deleted.

27 changes: 0 additions & 27 deletions man/print.clubpropredictions.Rd

This file was deleted.

11 changes: 5 additions & 6 deletions src/cpp_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <RcppArmadilloExtensions/sample.h>
#include <progress.hpp>
#include <progress_bar.hpp>
using namespace arma;
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::depends(RcppProgress)]]

Expand All @@ -38,7 +37,7 @@ arma::mat to_indicator_matrix(arma::vec v) {
// [[Rcpp::export]]
arma::mat normalise_columns(arma::mat A) {
for (size_t j {0}; j < A.n_cols; j++) {
auto colfactor = sqrt(accu(square(A.col(j))));
auto colfactor = std::sqrt(arma::accu(arma::square(A.col(j))));
for (size_t i {}; i < A.n_rows; i++) {
A(i, j) = colfactor == 0.0 ? 0.0 : A(i, j) / colfactor;
}
Expand All @@ -50,7 +49,7 @@ arma::mat normalise_columns(arma::mat A) {
// [[Rcpp::export]]
arma::mat normalise_rows(arma::mat A) {
for (size_t i {0}; i < A.n_rows; i++) {
auto rowfactor = sqrt(accu(square(A.row(i))));
auto rowfactor = std::sqrt(arma::accu(arma::square(A.row(i))));
for (size_t j {0}; j < A.n_cols; j++) {
A(i, j) = rowfactor == 0.0 ? 0.0 : A(i, j) / rowfactor;
}
Expand All @@ -62,7 +61,7 @@ arma::mat normalise_rows(arma::mat A) {
// [[Rcpp::export]]
arma::mat dichotemise_matrix(arma::mat A) {
for (size_t i {0}; i < A.n_rows; i++) {
auto m = max(A.row(i));
auto m = arma::max(A.row(i));
for(size_t j {0}; j < A.n_cols; j++) {
A(i, j) = ((A(i, j) == m) && (m > 0)) ? 1.0 : 0.0;
}
Expand All @@ -74,7 +73,7 @@ arma::mat dichotemise_matrix(arma::mat A) {
// [[Rcpp::export]]
arma::mat binary_procrustes_rotation(arma::vec obs, arma::mat target_mat, bool normalise_cols) {
arma::mat obs_mat = to_indicator_matrix(obs);
arma::mat T = trans(obs_mat) * target_mat;
arma::mat T = arma::trans(obs_mat) * target_mat;
arma::mat A = normalise_cols ? obs_mat * normalise_rows(normalise_columns(T)) : obs_mat * normalise_rows(T);
return A;
}
Expand All @@ -95,7 +94,7 @@ double c_pcc(arma::vec obs, arma::mat target_indicator_mat, int imprecision, boo
arma::mat binary_matrix = dichotemise_matrix(binary_procrustes_rotation(obs, target_indicator_mat, normalise_cols));
double matches{0.0};
for (size_t i {0}; i < binary_matrix.n_rows; i++) {
if (accu(binary_matrix.row(i)) == 1.0) {
if (arma::accu(binary_matrix.row(i)) == 1.0) {
if (std::abs(int(binary_matrix.row(i).index_max()) - int(target_indicator_mat.row(i).index_max())) <= imprecision) {
matches += 1.0;
}
Expand Down

0 comments on commit 4db2d42

Please sign in to comment.