| Title: | Fit multivariate logit Tweedie model using mgcv or glmmTMB |
|---|---|
| Description: | Defines predict function that transforms output from a Tweedie GLM fitted using mgcv or glmmTMB, and returns predictions of an equivalent multivariate logit Tweedie model. This can then be used for standard plotting and diagnostics. |
| Authors: | James Thorson [aut, cre] (ORCID: <https://orcid.org/0000-0001-7415-1010>) |
| Maintainer: | James Thorson <[email protected]> |
| License: | GPL-3 |
| Version: | 1.1.0 |
| Built: | 2026-06-02 00:35:13 UTC |
| Source: | https://github.com/james-thorson-noaa/mvtweedie |
Data sufficient to demonstrate how to use a Tweedie GLM to provide inference about proportions e.g. in food habits analysis, where the model output is processed to represent a multivariate logit Tweedie model.
data(Middleton_Island_TUPU)data(Middleton_Island_TUPU)
Specifically includes Tufted Puffin bill loads sampled at Middleton Island.
Response Numeric prey biomass in bill load samples
Year Numeric year
group factor representing prey species or category
SampleID factor with a level for every sampling occasion, e.g., for use in row normalization
Mayumi Arimitsu
It returns a tibble with predicted proportions from a Tweedie GAM model.
predict_mvtweedie( model, exclude_terms = NULL, length_out = 50, values = NULL, ... )predict_mvtweedie( model, exclude_terms = NULL, length_out = 50, values = NULL, ... )
The created tibble can then be plotted using ggplot2
Predict proportions and associated standard errors using a standard S3 object interface
## S3 method for class 'mvtweedie' predict( x, category_name = "group", newdata, origdata = x$frame, se.fit = FALSE )## S3 method for class 'mvtweedie' predict( x, category_name = "group", newdata, origdata = x$frame, se.fit = FALSE )
x |
output from |
category_name |
name of column that indicates grouping variable |
newdata |
An optional data frame in which to look for variables with which to predict. If omitted, the fitted values are used. |
origdata |
original data used when fitting |
se.fit |
A switch indicating if standard errors are required. |
A Tweedie GLM using a log-link and multiple categories can be transformed to yield predicted proportions and associated SEs, where the model is interpreted as a multivariate logit Tweedie distribution. This function does this transformation for a model fitted using:
It then also calculates an approximation to the standard error for this proportion
## Not run: # Load packages library(mvtweedie) # load data set data( Middleton_Island_TUPU, package="mvtweedie" ) DF = Middleton_Island_TUPU # Run Tweedie GLM gam0 = gam( formula = Response ~ 0 + group, data = DF, family = tw ) # Inspect results class(gam0) = c( "mvtweedie", class(gam0) ) predict(gam0, se.fit=TRUE, origdata = DF) ## End(Not run)## Not run: # Load packages library(mvtweedie) # load data set data( Middleton_Island_TUPU, package="mvtweedie" ) DF = Middleton_Island_TUPU # Run Tweedie GLM gam0 = gam( formula = Response ~ 0 + group, data = DF, family = tw ) # Inspect results class(gam0) = c( "mvtweedie", class(gam0) ) predict(gam0, se.fit=TRUE, origdata = DF) ## End(Not run)