-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b85a473
commit 0199f6c
Showing
9 changed files
with
159 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#' @title Check Sample Size Limits | ||
#' | ||
#' @author | ||
#' Thomas Debray \email{tdebray@fromdatatowisdom.com} | ||
#' | ||
#' @description Validates that the upper and lower limits are numeric and that the upper limit is greater than the lower limit. | ||
#' | ||
#' @param lower Numeric. The initial lower limit for the search range. | ||
#' @param upper Numeric. The initial upper limit for the search range. | ||
#' | ||
#' @return NULL. If the checks pass, the function returns nothing. If the checks fail, it stops execution with an error message. | ||
validate_sample_size_limits <- function(lower, upper) { | ||
|
||
# Check if both lower and upper are numeric | ||
if (!is.numeric(upper) || !is.numeric(lower)) { | ||
stop("The upper and lower limits for the sample size must be numeric.") | ||
} | ||
|
||
# Check if both lower and upper are integers | ||
if (lower != as.integer(lower) || upper != as.integer(upper)) { | ||
stop("The upper and lower limits for the sample size must be integers.") | ||
} | ||
|
||
# Check lower is greater than 0 | ||
if (lower <= 0) { | ||
stop("The lower limit for the sample size must be greater than 0.") | ||
} | ||
|
||
# Check if upper is greater than or equal to lower | ||
if (upper < lower) { | ||
stop("The upper limit for the sample size must be greater than or equal to the lower limit.") | ||
} | ||
} | ||
|
||
|
||
#' @title Validate Positive Semi-Definite Matrices | ||
#' | ||
#' @author | ||
#' Thomas Debray \email{tdebray@fromdatatowisdom.com} | ||
#' | ||
#' @description Validates that all matrices in a list are symmetric and positive semi-definite. | ||
#' | ||
#' @param varcov_list List of matrices. Each matrix is checked to ensure it is symmetric and positive semi-definite. | ||
#' | ||
#' @return NULL. If all matrices pass, the function returns nothing. If any matrix fails, it stops with an error message. | ||
validate_positive_definite <- function(varcov_list) { | ||
# Function to check if a matrix is positive semi-definite | ||
is_positive <- function(x) { | ||
resp <- tryCatch({ | ||
matrixcalc::is.positive.semi.definite(round(x, 3)) | ||
}, error = function(e) { | ||
FALSE | ||
}) | ||
return(resp) | ||
} | ||
|
||
# Apply the check to each matrix in the list | ||
positive_definite_list <- unlist(lapply(varcov_list, is_positive)) | ||
|
||
# Stop if any matrix is not positive semi-definite | ||
if (!all(positive_definite_list)) { | ||
stop("All matrices in 'varcov_list' must be symmetric and positive semi-definite.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.