View source: R/predict.mvTweedie.R
| predict.mvtweedie | R Documentation |
Predict proportions and associated standard errors using a standard S3 object interface
## S3 method for class 'mvtweedie'
predict(object, category_name = "group", newdata, se.fit = FALSE, ...)
object |
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. |
se.fit |
Whether to approximate the standard errors for predicted proportions |
... |
Not used |
After fitting Tweedie GLM using a log-link and multiple categories, we transform predicted densities to yield predicted proportions and associated SEs. This estimator for proportions arises naturally when analyzing a double-marked point process for diet samples, with marks for category and size.
predict.mvtweedie does this transformation for a model fitted using:
A generalized additive model (GAM) using gam
A generalized linear mixed model (GLMM) using glmmTMB
A spatio-temporal generalized linear mixed model (GLMM) using tinyVAST
It then also calculates an approximation to the standard error for this proportion.
Specifically, we calculate the proportion for each category as the density X
for that category, and the sum of densities Y for all other categories:
p_X = \frac{X}{X+Y}
Assuming we have an estimator for the standard error s(X) and s(Y),
and assuming that those estimators are independent such that
s(X+Y)^2 = s(X)^2 + s(Y)^2 , we then apply the
delta method to approximate the standard
error for the proportion as:
s(p_X)^2 = \frac{X^2}{(X+Y)^2} \left( \frac{s(X)^2}{X^2} -
2\frac{s(X)^2}{X(X+Y)}+
\frac{s(X)^2 + s(Y)^2}{(X+Y)^2} \right)
Predictions X and Y, and standard errors s(X) and s(Y)
are then supplied by the predict function that is native to the software
used when fitting the model.
predict.mvtweedie produces a vector of predicted proportions or a list containing predicted proportions and standard errors.
# Load packages
library(mvtweedie)
library(mgcv)
# load data set
data( Middleton_Island_TUPU, package="mvtweedie" )
# Run Tweedie GLM
gam0 = gam(
formula = Response ~ 0 + group,
data = Middleton_Island_TUPU,
family = tw
)
# Inspect results
class(gam0) = c( "mvtweedie", class(gam0) )
predict(
gam0,
se.fit = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.