Skip to content

Commit

Permalink
document and update name
Browse files Browse the repository at this point in the history
  • Loading branch information
mkapur-noaa committed Dec 11, 2024
1 parent 908b332 commit 5a753a7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
28 changes: 18 additions & 10 deletions R/check_Deriv.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#' Check whether the CI of the derivative includes zero or not
#' @param x vector of values over which derivatives were evaluated
#' @param d vector output of {Deriv()}
#' @param upper upper confidence interval; output of {confint_Deriv()}
#' @param lower lower confidence interval; output of {confint_Deriv()}
#' @param eval the value that you would like to examine. default 0

signifMK <- function(x, d, upper, lower, eval = 0, crit.eval){
#' @return vector of confidence intervals of same length as object.
#' @export
check_Deriv <- function(x, d, upper, lower, eval = 0, crit.eval){
miss <- upper > eval & lower < eval ## check if CI contains fail value
rej <- x ## save evaluated point
# want <- d > eval | d < eval ## T/F if derivative is greater or less than 0
Expand All @@ -12,15 +20,15 @@ signifMK <- function(x, d, upper, lower, eval = 0, crit.eval){

## hand it pdats, derivatives, intervals, and value to compare
## this will simply reject derivatives that equal zero or fall outside the CI
signifD <- function(x, d, upper, lower, eval = 0) {
miss <- upper > eval & lower < eval
incr <- decr <- x
want <- d > eval
incr[!want | miss] <- NA
want <- d < eval
decr[!want | miss] <- NA
list(incr = incr, decr = decr)
}
# signifD <- function(x, d, upper, lower, eval = 0) {
# miss <- upper > eval & lower < eval
# incr <- decr <- x
# want <- d > eval
# incr[!want | miss] <- NA
# want <- d < eval
# decr[!want | miss] <- NA
# list(incr = incr, decr = decr)
# }
## mk function -- see if derivative CI contains 0
# signifCI <- function(x, upper, lower, eval = 0){
# rej <- x ## print in terms of evaluated quantities
Expand Down
10 changes: 9 additions & 1 deletion R/confint_Deriv.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#' Calculate confidence interval of derivative, adapted from
#' \href{https://gist.githubusercontent.com/gavinsimpson/e73f011fdaaab4bb5a30/raw/82118ee30c9ef1254795d2ec6d356a664cc138ab/Deriv.R}{Gavin Simpson}.
#' @param object vector output of {Deriv()}
#' @param term string smooth name, i.e. "year". must match values in mod and newdata
#' @param alpha confidence threshold. default 0.05 (for 95% CI)

confint.Deriv <- function(object, term, alpha = 0.05, ...) {
#' @return vector of confidence intervals of same length as object.
#' @export

confint_Deriv <- function(object, term, alpha = 0.05, ...) {
l <- length(object) - 3
term.labs <- names(object[seq_len(l)])
if(missing(term)) {
Expand Down

0 comments on commit 5a753a7

Please sign in to comment.