Title: | Count Transformation Models |
---|---|
Description: | Count transformation models featuring parameters interpretable as discrete hazard ratios, odds ratios, reverse-time discrete hazard ratios, or transformed expectations. An appropriate data transformation for a count outcome and regression coefficients are simultaneously estimated by maximising the exact discrete log-likelihood using the computational framework provided in package 'mlt', technical details are given in Siegfried & Hothorn (2020) <DOI:10.1111/2041-210X.13383>. The package also contains an experimental implementation of multivariate count transformation models with an application to multi-species distribution models <DOI:10.48550/arXiv.2201.13095>. |
Authors: | Sandra Siegfried [aut, cre] , Luisa Barbanti [aut] , Torsten Hothorn [aut] |
Maintainer: | Sandra Siegfried <[email protected]> |
License: | GPL-2 |
Version: | 0.5-2 |
Built: | 2024-11-19 19:20:39 UTC |
Source: | https://github.com/r-forge/ctm |
Confidence bands for transformation, distribution, survivor or cumulative hazard functions
## S3 method for class 'cotram' confband(object, newdata, level = 0.95, type = c("trafo", "distribution", "survivor", "cumhazard"), smooth = FALSE, q = NULL, K = 20, cheat = K, ...)
## S3 method for class 'cotram' confband(object, newdata, level = 0.95, type = c("trafo", "distribution", "survivor", "cumhazard"), smooth = FALSE, q = NULL, K = 20, cheat = K, ...)
object |
an object of class |
newdata |
a data frame of observations. |
level |
the confidence level. |
type |
the function to compute the confidence band for. |
smooth |
logical; if |
q |
quantiles at which to evaluate the model. |
K |
number of grid points the function is evaluated at
(in the absence of |
cheat |
number of grid points the function is evaluated at when
using the quantile obtained for |
... |
additional arguments to |
The function is evaluated at the count response or at K
grid points
and simultaneous confidence intervals are then interpolated in order to
construct the band.
For each row in newdata
the function and corresponding confidence
band evaluated at the count response (or K
or cheat
grid points)
is returned.
op <- options(digits = 4) data("birds", package = "TH.data") ### fit count transformation model with cloglog link m_birds <- cotram(SG5 ~ AOT + AFS + GST + DBH + DWC + LOG, data = birds, method = "cloglog") ### compute asymptotic confidence bands for the distribution function ### for the first oberservation confband(m_birds, newdata = birds[1, ], type = "distribution") options(op)
op <- options(digits = 4) data("birds", package = "TH.data") ### fit count transformation model with cloglog link m_birds <- cotram(SG5 ~ AOT + AFS + GST + DBH + DWC + LOG, data = birds, method = "cloglog") ### compute asymptotic confidence bands for the distribution function ### for the first oberservation confband(m_birds, newdata = birds[1, ], type = "distribution") options(op)
Likelihood-based count transformation models for fully parameterised discrete conditional distribution functions. The link function governing the interpretation of the predictor can be chosen and results in discrete hazard ratios, odds ratios, reverse time hazard ratios or conditional expectation of transformed counts.
cotram(formula, data, method = c("logit", "cloglog", "loglog", "probit"), log_first = TRUE, prob = 0.9, subset, weights, offset, cluster, na.action = na.omit, ...)
cotram(formula, data, method = c("logit", "cloglog", "loglog", "probit"), log_first = TRUE, prob = 0.9, subset, weights, offset, cluster, na.action = na.omit, ...)
formula |
an object of class |
data |
an optional data frame, list or environment (or object
coercible by |
method |
character specifying the choice of the link function, mapping the transformation function into probabilities. Available choices include the logit, complementary log-log, log-log or probit link. The different link functions govern the interpretation of the linear predictor. Details of the interpretation can be found in the package vignette. |
prob |
probability giving the quantile of the response defining the upper limit of the support of a smooth Bernstein polynomial (with the lower limit being set to 0). If a vector of two probabilites is specified, the corresponding quantiles of the response define the lower and upper limit of the support, respectively. Note, that the support is rounded to integer values. |
log_first |
logical; if |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
offset |
this can be used to specify an _a priori_ known component to
be included in the linear predictor during fitting. This
should be |
cluster |
optional factor with a cluster ID employed for computing clustered covariances. |
na.action |
a function which indicates what should happen when the data
contain |
... |
additional arguments to |
Likelihood-based estimation of a fully parameterised conditional discrete
distribution function for count data, while ensuring interpretability of
the linear predictors. The models are defined with a negative shift term
relating positive predictors to larger values of the conditional mean.
For the model with logistic or cloglog link exp(-coef())
is the multiplicative change of discrete odds-ratios or hazard ratios. For
the model with loglog link exp(coef())
is the multiplicative change of
the reverse time hazard ratios. Applying a transformation model with probit link
coef()
gives the conditional expectation of the transformed counts,
with transformation function estimated from data.
An object of class cotram
and tram
, with corresponding coef
,
vcov
, logLik
, summary
,
print
, plot
and predict
methods.
Sandra Siegfried, Torsten Hothorn (2020), Count Transformation Models, Methods in Ecology and Evolution, 11(7), 818–827, doi:10.1111/2041-210X.13383.
Torsten Hothorn, Lisa Möst, Peter Bühlmann (2018), Most Likely Transformations, Scandinavian Journal of Statistics, 45(1), 110–134, doi:10.1111/sjos.12291.
Torsten Hothorn (2020), Most Likely Transformations: The mlt Package, Journal of Statistical Software, 92(1), 1–68, doi:10.18637/jss.v092.i01.
op <- options(digits = 2) data("birds", package = "TH.data") cotram(SG5 ~ AOT + AFS + GST + DBH + DWC + LOG, data = birds) options(op)
op <- options(digits = 2) data("birds", package = "TH.data") cotram(SG5 ~ AOT + AFS + GST + DBH + DWC + LOG, data = birds) options(op)
Methods for objects inheriting from class cotram
## S3 method for class 'cotram' predict(object, newdata = model.frame(object), type = c("lp", "trafo", "distribution", "survivor", "density", "logdensity", "hazard", "loghazard", "cumhazard", "logcumhazard", "odds", "logodds", "quantile"), smooth = FALSE, q = NULL, K = 20, prob = 1:(10-1)/10, ...) ## S3 method for class 'cotram' plot(x, newdata, type = c("distribution", "survivor","density", "logdensity", "cumhazard", "quantile", "trafo"), confidence = c("none", "band"), level = 0.95, smooth = FALSE, q = NULL, K = 20, cheat = K, prob = 1:(10-1)/10, col = "black", fill = "lightgrey", lty = 1, lwd = 1, add = FALSE, ...) ## S3 method for class 'cotram' as.mlt(object) ## S3 method for class 'cotram' logLik(object, parm = coef(as.mlt(object), fixed = FALSE), newdata, ...)
## S3 method for class 'cotram' predict(object, newdata = model.frame(object), type = c("lp", "trafo", "distribution", "survivor", "density", "logdensity", "hazard", "loghazard", "cumhazard", "logcumhazard", "odds", "logodds", "quantile"), smooth = FALSE, q = NULL, K = 20, prob = 1:(10-1)/10, ...) ## S3 method for class 'cotram' plot(x, newdata, type = c("distribution", "survivor","density", "logdensity", "cumhazard", "quantile", "trafo"), confidence = c("none", "band"), level = 0.95, smooth = FALSE, q = NULL, K = 20, cheat = K, prob = 1:(10-1)/10, col = "black", fill = "lightgrey", lty = 1, lwd = 1, add = FALSE, ...) ## S3 method for class 'cotram' as.mlt(object) ## S3 method for class 'cotram' logLik(object, parm = coef(as.mlt(object), fixed = FALSE), newdata, ...)
object , x
|
a fitted linear count transformation model inheriting
from class |
newdata |
an optional data frame of observations. |
parm |
model parameters. |
type |
type of prediction, current options include
linear predictors ( |
confidence |
whether to plot a confidence band (see |
level |
the confidence level. |
smooth |
logical; if |
q |
quantiles at which to evaluate the model. |
prob |
probabilities for the evaluation of the quantile function |
K |
number of grid points the function is evaluated at
(for |
cheat |
number of grid points the function is evaluated at when
using the quantile obtained for |
col |
color for the lines to plot. |
fill |
color for the confidence band. |
lty |
line type for the lines to plot. |
lwd |
line width. |
add |
logical; indicating if a new plot shall be generated (the default). |
... |
additional arguments to the underlying methods for |
predict
and plot
can be used to inspect the model on
different scales.
predict.cotram
, confband.cotram
,
tram-methods
, mlt-methods
, plot.ctm
op <- options(digits = 4) data("birds", package = "TH.data") ### fit count transformation model with cloglog link m_birds <- cotram(SG5 ~ AOT + AFS + GST + DBH + DWC + LOG, data = birds, method = "cloglog") logLik(m_birds) ### classical likelihood inference summary(m_birds) ### coefficients of the linear predictor (discrete hazard ratios) exp(-coef(m_birds)) ### compute predicted median along with 10% and 90% quantile for the first ### three observations nd <- birds[1:3,] round(predict(m_birds, newdata = nd, type = "quantile", prob = c(.1, .5, .9), smooth = TRUE), 3) ### plot the predicted distribution for these observations plot(m_birds, newdata = nd, type = "distribution", col = c("skyblue", "grey", "seagreen")) options(op)
op <- options(digits = 4) data("birds", package = "TH.data") ### fit count transformation model with cloglog link m_birds <- cotram(SG5 ~ AOT + AFS + GST + DBH + DWC + LOG, data = birds, method = "cloglog") logLik(m_birds) ### classical likelihood inference summary(m_birds) ### coefficients of the linear predictor (discrete hazard ratios) exp(-coef(m_birds)) ### compute predicted median along with 10% and 90% quantile for the first ### three observations nd <- birds[1:3,] round(predict(m_birds, newdata = nd, type = "quantile", prob = c(.1, .5, .9), smooth = TRUE), 3) ### plot the predicted distribution for these observations plot(m_birds, newdata = nd, type = "distribution", col = c("skyblue", "grey", "seagreen")) options(op)
Abundance of six spider species on 190 plots in the Bavarian Forest National Park
data("spiders")
data("spiders")
A data frame with 190 observations on the following 9 variables.
Plot
experimental plot id
Elevation
elevation of the plot
Canopy_openess
openess of canopy at plot
Pardosa_ferruginea
number of Pardosa ferruginea observed
Harpactea_lepida
number of Harpactea lepida observed
Callobius_claustrarius
number of Callobius claustrarius observed
Coelotes_terrestris
number of Coelotes terrestris observed
Pardosa_lugubris
number of Pardosa lugubris observed
Pardosa_riparia
number of Pardosa riparia observed
To untangle effects of dead-wood addition and canopy openness on non-saproxylic epigeal arthropods, Seibold et al (2016) exposed different amounts of logs and branches on 190 0.1-ha plots located in sunny or shady mixed montane forests and sampled epigeal arthropods over three years. The data contain abundances of six spider species for all 190 plots, along with plot elevation and canopy openess.
Sebastian Seibold, Claus Bässler, Petr Baldrian, Lena Reinhard, Simon Thorn, Michael D. Ulyshen, Ingmar Weiß and Jörg Müller (2016). Dead-wood addition promotes non-saproxylic epigeal arthropods but effects are mediated by canopy openness. Biological Conservation, 204, 181–188, doi:10.1016/j.biocon.2016.09.031.