From 57846334a66d468ea63f9d09d5bb20a2b83cd455 Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Mon, 22 Jul 2024 12:27:12 +1000 Subject: [PATCH] add eval_smooth general method --- DESCRIPTION | 1 + NAMESPACE | 10 +--------- R/monotonic.R | 13 +++++++++++-- man/eval_smooth.Rd | 16 ++++++++++++++++ src/mvgam.dll | Bin 1091584 -> 1091584 bytes 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 man/eval_smooth.Rd diff --git a/DESCRIPTION b/DESCRIPTION index f922c52b..18520031 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,6 +53,7 @@ Suggests: coda, runjags, tibble (>= 3.0.0), + gratia, usethis, testthat Additional_repositories: https://mc-stan.org/r-packages/ diff --git a/NAMESPACE b/NAMESPACE index cd56aaf9..e81fe1ac 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -78,6 +78,7 @@ export(code) export(compare_mvgams) export(dynamic) export(eval_mvgam) +export(eval_smooth) export(forecast) export(get_mvgam_priors) export(hindcast) @@ -157,14 +158,6 @@ importFrom(graphics,polygon) importFrom(graphics,rect) importFrom(graphics,rug) importFrom(graphics,title) -importFrom(gratia,by_level) -importFrom(gratia,by_variable) -importFrom(gratia,eval_smooth) -importFrom(gratia,is_factor_by_smooth) -importFrom(gratia,smooth_dim) -importFrom(gratia,smooth_label) -importFrom(gratia,smooths) -importFrom(gratia,spline_values) importFrom(insight,find_predictors) importFrom(insight,get_data) importFrom(insight,get_predictors) @@ -282,7 +275,6 @@ importFrom(stats,ts) importFrom(stats,update) importFrom(stats,update.formula) importFrom(stats,var) -importFrom(tibble,add_column) importFrom(utils,getFromNamespace) importFrom(utils,head) importFrom(utils,lsf.str) diff --git a/R/monotonic.R b/R/monotonic.R index 05185533..1818e7c7 100644 --- a/R/monotonic.R +++ b/R/monotonic.R @@ -413,10 +413,17 @@ add_mono_model_file = function(model_file, model_data = model_data)) } +#' S3 methods to evaluate individual smooths +#' @param smooth currently an object that inherits from class `mgcv.smooth` +#' @param ... arguments passed to other methods +#' @export +`eval_smooth` <- function(smooth, ...) { + UseMethod("eval_smooth") +} + #' Evaluation of a monotonically increasing function #' These evaluation functions are needed so that gratia::draw methods work with mvgam #' monotonic smooths -#' @importFrom gratia eval_smooth smooths by_variable smooth_label spline_values is_factor_by_smooth by_level smooth_dim #' @rdname monotonic #' @export eval_smooth.moi.smooth = function(smooth, @@ -429,6 +436,8 @@ eval_smooth.moi.smooth = function(smooth, overall_uncertainty = TRUE, dist = NULL, ...) { + + insight::check_if_installed("gratia") model$cmX <- model$coefficients ## deal with data if supplied @@ -511,6 +520,7 @@ eval_smooth.mod.smooth = function(smooth, overall_uncertainty = TRUE, dist = NULL, ...) { + insight::check_if_installed("gratia") model$cmX <- model$coefficients ## deal with data if supplied @@ -614,7 +624,6 @@ eval_smooth.mod.smooth = function(smooth, data } -#' @importFrom tibble add_column #' @noRd `add_by_var_column` <- function(object, by_var, n = NULL) { if (is.null(n)) { diff --git a/man/eval_smooth.Rd b/man/eval_smooth.Rd new file mode 100644 index 00000000..ede5c20a --- /dev/null +++ b/man/eval_smooth.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/monotonic.R +\name{eval_smooth} +\alias{eval_smooth} +\title{S3 methods to evaluate individual smooths} +\usage{ +eval_smooth(smooth, ...) +} +\arguments{ +\item{smooth}{currently an object that inherits from class \code{mgcv.smooth}} + +\item{...}{arguments passed to other methods} +} +\description{ +S3 methods to evaluate individual smooths +} diff --git a/src/mvgam.dll b/src/mvgam.dll index 0a9b1256ceeabada6f21bac60367358f9dcf5506..e41712403a7a1c7c4693e2e0ae3c3fa35d6a7981 100644 GIT binary patch delta 78 zcmV~$yA4240EW@H-fwf*Kzm!l0G6Tn6HzgY7~n1-%5M~vbC$<0k3BXsxpN=Q+pP#s h7~zXRgd!5LNJJ_!k&8lS-(5f#IT#t`bSV+v6@XS|y6YS!62=eG3bttW&d gjBte~d=ZFHL?RZ6NJS=cQHXNKR;{_uBk1fm{NPL^@c;k-