#' Controls for smooth terms
#'
#' @param sterm_default default function for creating univariate effects
#' @param teterm_default default function for creating bivariate effects
#' @param penalize_byterm if not NULL but positive value, the linear effect
#' in by-terms of smooth effects will be penalized
#' @return list of options
#'
#' @import mgcv
#' @export
#'
sterm_control <- function(
sterm_default = NULL,
teterm_default= function(x, y, la) paste0("sparse(ti(",x,", ", y, ", la = ", la, "))"),
penalize_byterm = NULL,
spline_type = c("tp", "ps")
)
{
spline_type = match.arg(spline_type)
default_sterm <- switch(spline_type,
tp = function(x, la)
paste0("sparse(s(", x, ", la = ", la, ", m=c(2,0)))"),
ps = function(x, la)
paste0("sparse(s(", x, ", la = ", la, ", m=c(3,2), type='ps'))")
)
if(is.null(sterm_default))
sterm_default <- default_sterm
ret_list <- list(
sterm_default = sterm_default,
teterm_default = teterm_default
)
if(!is.null(penalize_byterm))
ret_list$penalize_byterm = penalize_byterm
return(ret_list)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.