From 3bf5fc32a7caa0dc8e578e3b746877bc05de14c5 Mon Sep 17 00:00:00 2001 From: swpease Date: Wed, 15 Jan 2025 22:34:32 -0800 Subject: [PATCH] `tidy.mvgam()` export; docs called `document()` to put it in the namespace and... documentation. --- NAMESPACE | 3 ++ man/augment.mvgam.Rd | 4 ++ man/reexports.Rd | 3 +- man/tidy.mvgam.Rd | 90 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 man/tidy.mvgam.Rd diff --git a/NAMESPACE b/NAMESPACE index cb8df574..281890ba 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -72,6 +72,7 @@ S3method(stancode,mvgam_prefit) S3method(standata,mvgam_prefit) S3method(summary,mvgam) S3method(summary,mvgam_prefit) +S3method(tidy,mvgam) S3method(update,jsdgam) S3method(update,mvgam) S3method(variables,mvgam) @@ -166,6 +167,7 @@ export(student_t) export(t2) export(te) export(ti) +export(tidy) export(tweedie) export(variables) importFrom(Rcpp,evalCpp) @@ -203,6 +205,7 @@ importFrom(brms,stancode) importFrom(brms,standata) importFrom(brms,student) importFrom(generics,augment) +importFrom(generics,tidy) importFrom(ggplot2,aes) importFrom(ggplot2,facet_wrap) importFrom(ggplot2,geom_bar) diff --git a/man/augment.mvgam.Rd b/man/augment.mvgam.Rd index 52a36440..d9b8fd43 100644 --- a/man/augment.mvgam.Rd +++ b/man/augment.mvgam.Rd @@ -62,4 +62,8 @@ augment(mod1, robust = TRUE, probs = c(0.25, 0.75)) } \seealso{ \code{\link{residuals.mvgam}}, \code{\link{fitted.mvgam}} + +Other tidiers: +\code{\link{tidy.mvgam}()} } +\concept{tidiers} diff --git a/man/reexports.Rd b/man/reexports.Rd index da19e2d5..6885fb7a 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -40,6 +40,7 @@ \alias{posterior_linpred} \alias{stancode} \alias{standata} +\alias{tidy} \alias{augment} \title{Objects exported from other packages} \keyword{internal} @@ -50,7 +51,7 @@ below to see their documentation. \describe{ \item{brms}{\code{\link[brms:conditional_effects.brmsfit]{conditional_effects}}, \code{\link[brms]{gp}}, \code{\link[brms:mcmc_plot.brmsfit]{mcmc_plot}}, \code{\link[brms:set_prior]{prior}}, \code{\link[brms:set_prior]{prior_}}, \code{\link[brms:set_prior]{prior_string}}, \code{\link[brms]{set_prior}}, \code{\link[brms]{stancode}}, \code{\link[brms]{standata}}} - \item{generics}{\code{\link[generics]{augment}}} + \item{generics}{\code{\link[generics]{augment}}, \code{\link[generics]{tidy}}} \item{insight}{\code{\link[insight]{get_data}}} diff --git a/man/tidy.mvgam.Rd b/man/tidy.mvgam.Rd new file mode 100644 index 00000000..e0c5a969 --- /dev/null +++ b/man/tidy.mvgam.Rd @@ -0,0 +1,90 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tidier_methods.R +\name{tidy.mvgam} +\alias{tidy.mvgam} +\title{Tidy an mvgam object's parameter posteriors} +\usage{ +\method{tidy}{mvgam}(x, probs = c(0.025, 0.5, 0.975), ...) +} +\arguments{ +\item{x}{An object of class \code{mvgam}.} + +\item{probs}{The desired probability levels of the parameters' posteriors. +Defaults to \code{c(0.025, 0.5, 0.975)}, i.e. 2.5\%, 50\%, and 97.5\%.} + +\item{...}{Unused, included for generic consistency only.} +} +\value{ +A \code{tibble} containing: +\itemize{ +\item "parameter": The parameter in question. +\item "type": The component of the model that the parameter belongs to (see details). +\item "mean": The posterior mean. +\item "sd": The posterior standard deviation. +\item percentile(s): Any percentiles of interest from these posteriors. +} +} +\description{ +Get parameters' posterior statistics, implementing the generic \code{tidy} from +the package \pkg{broom}. +} +\details{ +The parameters are categorized by the column "type". For instance, the +intercept of the observation model (i.e. the "formula" arg to \code{mvgam()}) has +the "type" "observation_beta". The possible "type"s are: +\itemize{ +\item observation_family_extra_param: any extra parameters for your observation +model, e.g. sigma for a gaussian observation model. These parameters are +not directly derived from the latent trend components (continuing the +gaussian example, contrast to mu). +\item observation_beta: betas from your observation model, excluding any smooths. +If your formula was \code{y ~ x1 + s(x2, bs='cr')}, then your intercept and +\code{x1}'s beta would be categorized as this. +\item random_effect_group_level: Group-level random effects parameters, i.e. +the mean and sd of the distribution from which the specific random +intercepts/slopes are considered to be drawn from. +\item random_effect_beta: betas for the individual random intercepts/slopes. +\item trend_model_param: parameters from your \code{trend_model}. +\item trend_beta: analog of "observation_beta", but for any \code{trend_formula}. +\item trend_random_effect_group_level: analog of "random_effect_group_level", +but for any \code{trend_formula}. +\item trend_random_effect_beta: analog of "random_effect_beta", +but for any \code{trend_formula}. +} + +Additionally, GP terms can be incorporated in several ways, leading to +different "type"s (or absence!): +\itemize{ +\item \code{s(bs = "gp")}: No parameters returned. +\item \code{gp()} in \code{formula}: "type" of "observation_param". +\item \code{gp()} in \code{trend_formula}: "type" of "trend_formula_param". +\item \code{GP()} in \code{trend_model}: "type" of "trend_model_param". +} +} +\examples{ +\dontrun{ +set.seed(0) +simdat <- sim_mvgam(T = 100, + n_series = 3, + trend_model = AR(), + prop_trend = 0.75, + family = gaussian()) +simdat$data_train$x = rnorm(nrow(simdat$data_train)) +simdat$data_train$year_fac = factor(simdat$data_train$year) + +mod <- mvgam(y ~ - 1 + s(time, by = series, bs = 'cr', k = 20) + x, + trend_formula = ~ s(year_fac, bs = 're') - 1, + trend_model = AR(cor = TRUE), + family = gaussian(), + data = simdat$data_train, + silent = 2) + +tidy(mod, probs = c(0.2, 0.5, 0.8)) +} + +} +\seealso{ +Other tidiers: +\code{\link{augment.mvgam}()} +} +\concept{tidiers}