Skip to content

Commit

Permalink
Updated from ifelse to if else to support NULL return
Browse files Browse the repository at this point in the history
  • Loading branch information
LHBO committed Dec 8, 2023
1 parent 6a391b2 commit b9728d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @return Matrix of dimension \code{ncol(X)*ncol(X)}
#' @author Martin Jullum
hat_matrix_cpp <- function(X, mcov, S_scale_dist, h) {
.Call(`_shapr_hat_matrix_cpp`, X, mcov, S_scale_dist, h)
.Call(`_shapr_hat_matrix_cpp`, X, mcov, S_scale_dist, h)
}

#' sigma_hat_sq-function
Expand All @@ -29,7 +29,7 @@ hat_matrix_cpp <- function(X, mcov, S_scale_dist, h) {
#'
#' @author Martin Jullum
rss_cpp <- function(H, y) {
.Call(`_shapr_rss_cpp`, H, y)
.Call(`_shapr_rss_cpp`, H, y)
}

#' correction term with trace_input in AICc formula
Expand All @@ -42,7 +42,7 @@ rss_cpp <- function(H, y) {
#' @return Scalar
#' @author Martin Jullum
correction_matrix_cpp <- function(tr_H, n) {
.Call(`_shapr_correction_matrix_cpp`, tr_H, n)
.Call(`_shapr_correction_matrix_cpp`, tr_H, n)
}

#' Temp-function for computing the full AICc with several X's etc
Expand All @@ -59,7 +59,7 @@ correction_matrix_cpp <- function(tr_H, n) {
#' @return Scalar with the numeric value of the AICc formula
#' @author Martin Jullum
aicc_full_single_cpp <- function(X, mcov, S_scale_dist, h, y) {
.Call(`_shapr_aicc_full_single_cpp`, X, mcov, S_scale_dist, h, y)
.Call(`_shapr_aicc_full_single_cpp`, X, mcov, S_scale_dist, h, y)
}

#' AICc formula for several sets, alternative definition
Expand All @@ -77,7 +77,7 @@ aicc_full_single_cpp <- function(X, mcov, S_scale_dist, h, y) {
#'
#' @author Martin Jullum
aicc_full_cpp <- function(h, X_list, mcov_list, S_scale_dist, y_list, negative) {
.Call(`_shapr_aicc_full_cpp`, h, X_list, mcov_list, S_scale_dist, y_list, negative)
.Call(`_shapr_aicc_full_cpp`, h, X_list, mcov_list, S_scale_dist, y_list, negative)
}

#' (Generalized) Mahalanobis distance
Expand All @@ -97,12 +97,12 @@ aicc_full_cpp <- function(h, X_list, mcov_list, S_scale_dist, y_list, negative)
#' @return Array of three dimensions. Contains the squared distance for between all training and test observations for all feature combinations passed to the function.
#' @author Martin Jullum
mahalanobis_distance_cpp <- function(featureList, Xtrain_mat, Xtest_mat, mcov, S_scale_dist) {
.Call(`_shapr_mahalanobis_distance_cpp`, featureList, Xtrain_mat, Xtest_mat, mcov, S_scale_dist)
.Call(`_shapr_mahalanobis_distance_cpp`, featureList, Xtrain_mat, Xtest_mat, mcov, S_scale_dist)
}

#' @keywords internal
sample_features_cpp <- function(m, n_features) {
.Call(`_shapr_sample_features_cpp`, m, n_features)
.Call(`_shapr_sample_features_cpp`, m, n_features)
}

#' Get imputed data
Expand Down Expand Up @@ -141,7 +141,7 @@ sample_features_cpp <- function(m, n_features) {
#'
#' @author Nikolai Sellereite
observation_impute_cpp <- function(index_xtrain, index_s, xtrain, xtest, S) {
.Call(`_shapr_observation_impute_cpp`, index_xtrain, index_s, xtrain, xtest, S)
.Call(`_shapr_observation_impute_cpp`, index_xtrain, index_s, xtrain, xtest, S)
}

#' Calculate weight matrix
Expand All @@ -160,7 +160,7 @@ observation_impute_cpp <- function(index_xtrain, index_s, xtrain, xtest, S) {
#' @return Matrix of dimension n x m + 1
#' @author Nikolai Sellereite
weight_matrix_cpp <- function(subsets, m, n, w) {
.Call(`_shapr_weight_matrix_cpp`, subsets, m, n, w)
.Call(`_shapr_weight_matrix_cpp`, subsets, m, n, w)
}

#' Get feature matrix
Expand All @@ -174,5 +174,6 @@ weight_matrix_cpp <- function(subsets, m, n, w) {
#' @return Matrix
#' @author Nikolai Sellereite
feature_matrix_cpp <- function(features, m) {
.Call(`_shapr_feature_matrix_cpp`, features, m)
.Call(`_shapr_feature_matrix_cpp`, features, m)
}

4 changes: 2 additions & 2 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ make_waterfall_plot <- function(dt_plot,
plot_MSEv_eval_crit <- function(explanation_list,
index_x_explain = NULL,
id_combination = NULL,
CI_level = ifelse(length(explanation_list[[1]]$pred_explain) < 20, NULL, 0.95),
CI_level = if (length(explanation_list[[1]]$pred_explain) < 20) NULL else 0.95,
geom_col_width = 0.9,
plot_type = "overall") {
# Setup and checks ----------------------------------------------------------------------------
Expand Down Expand Up @@ -1008,7 +1008,7 @@ plot_MSEv_eval_crit <- function(explanation_list,
# Get the number of observations and combinations and the quantile of the T distribution
n_explain <- explanation_list[[1]]$internal$parameters$n_explain
n_combinations <- explanation_list[[1]]$internal$parameters$n_combinations
tfrac <- ifelse(is.null(CI_level), NULL, qt((1 + CI_level) / 2, n_explain - 1))
tfrac <- if (is.null(CI_level)) NULL else qt((1 + CI_level) / 2, n_explain - 1)

# Create data.tables of the MSEv values
MSEv_dt_list <- MSEv_extract_MSEv_values(
Expand Down

0 comments on commit b9728d7

Please sign in to comment.