Skip to content

Commit

Permalink
add eval_smooth general method
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Clark committed Jul 22, 2024
1 parent 65c0687 commit 5784633
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Suggests:
coda,
runjags,
tibble (>= 3.0.0),
gratia,
usethis,
testthat
Additional_repositories: https://mc-stan.org/r-packages/
Expand Down
10 changes: 1 addition & 9 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions R/monotonic.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
16 changes: 16 additions & 0 deletions man/eval_smooth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified src/mvgam.dll
Binary file not shown.

0 comments on commit 5784633

Please sign in to comment.