ptrend | R Documentation |
The function estimates a trend from count survey data.
ptrend(
formula,
data = list(),
family = quasipoisson(),
nGrid = 500,
nBoot = 500,
bootType = "hessian",
gamModel = TRUE,
engine = "gam",
...
)
formula |
A trend formula. This is a GAM formula with an extra term |
data |
A data frame containing response variables and covariates. |
family |
The distributional family of the response. The family most use a log-link, it defaults to a quasi-Poisson. |
nGrid |
The number of grid points over which to compute the trend. If the length of the argument is one, an equally spaced grid over the survey period of length nGrid is set up. nGrid can also be a vector of length 3, in which case the first element is the number of grid points and the second and third elements give, respectively, the start and endpoints of the grid. |
nBoot |
The number of bootstrap samples to draw. |
bootType |
Only one method, "hessian", currently implemented. Type "hessian", draws bootstrap samples using the Bayesian
covariance matrix of the parameters (see |
gamModel |
If true, the fit of the underlying gam model is saved in the output. May be set to FALSE to save memory, but with the side effect that the fit of the gam model cannot be checked. |
engine |
If 'gam', the default, model fitting is done via |
... |
Further arguments passed to |
The function estimates smooth or loglinear population trends, or indexes from simple design count survey data.
It is essentially a wrapper around a call to gam
, processing its output using predict.gam
to produce a trend estimate.
For smooth trends, cubic regression splines for the temporal variable are set up by the term s(var, k = k, fx = fx , bs = "cr")
where var
is the first argument to trend
in the formula.
For loglinear trends, the identity of var
is used, and for index models a factor variable is constructed from var
.
Temporal random effects are set up by converting the temporal variable supplied to trend
to a factor variable
and adding this factor variable to the data supplied to gam
.
Bootstrap confidence intervals are computed by drawing normally distributed random variable with means equal to the estimated coefficients and covariance matrix equal to the Bayesian posterior covariance matrix (see vcov.gam).
An object of class trend.
Jonas Knape
## Simulate a data set with 15 sites and 25 years
data = simTrend(15, 25)
## Fit a smooth trend with fixed site effects, random time effects,
## and automatic selection of degrees of freedom
trFit = ptrend(count ~ trend(year, tempRE = TRUE, type = "smooth") + site, data = data)
## Check the model fit
checkFit(trFit)
## Plot the trend
plot(trFit)
summary(trFit)
## Check the estimated percent change from year 8 to 25
change(trFit, 8, 25)
## Fit a loglinear trend model with random site effects and random time effects
## to the same data set.
trLin = ptrend(count ~ trend(year, tempRE = TRUE, type = "loglinear") +
s(site, bs = "re"), data = data)
plot(trLin)
summary(trLin)
## Fit an index model with fixed site effects and an (unrelated) continous covariate
## as a smooth effect.
# Simulate mock covariate unrelated to data.
cov = rnorm(nrow(data))
trInd = ptrend(count ~ trend(year, type = "index") + site + s(cov), data = data)
plot(trInd)
summary(trInd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.