Given some count observations, estimate a TRIM model and use these to impute the data set if nescessary.
trim(object, ...)# S3 method for data.frame
trim(
object,
count_col = "count",
site_col = "site",
year_col = "year",
month_col = NULL,
weights_col = NULL,
covar_cols = NULL,
model = 2,
changepoints = ifelse(model == 2, 1L, integer(0)),
overdisp = FALSE,
serialcor = FALSE,
autodelete = TRUE,
stepwise = FALSE,
covin = list(),
...
)
# S3 method for formula
trim(object, data = NULL, weights = NULL, ...)
# S3 method for trimcommand
trim(object, ...)
Either a data.frame
, a formula
or a trimcommand
.
If object
is a formula
, the dependent variable (left-hand-side)
is treated as the 'counts' variable. The first and second independent variable
are treated as the 'site' and 'time' variable, in that specific order. All
other variables are treated as covariates.
More parameters, see below in the details
[character]
name of the column holding species counts
[character]
name of the column holding the site id
[character]
name of the column holding the time of counting
[character]
optional name of the column holding the season of counting
[numeric]
Optional vector of site weights. The length of
[character]
name(s) of column(s) holding covariates
[numeric]
TRIM model type 1, 2, or 3.
[numeric]
Indices for changepoints (`Models').
[logical]
Take overdispersion into account (See `Estimation options').
[logical]
Take serial correlation into account (See `Estimation details')
[logical]
Auto-delete changepoints when number of observations is too small. (See
`Demands on data').
[logical]
Perform stepwise refinement of changepoints.
a list of variance-covariance matrices; one per pseudo-site.
[data.frame]
Data frame containing at least counts, sites, and times
[character]
name of the column in data
which respresents weights (optional)
The purpose of trim
is to estimate population totals over time,
based on a set of counts
In Model 1, the imputed values are modeled as
where
In Model 2, the imputed values are modeled as
Here, changepoints
that indicate at what times the growth
rate is allowed to change. Using a wald
test
one can investigate whether the changes in slope at the changepoints are
significant. Setting stepwise=TRUE
makes trim
automatically
remove changepoints where the slope does not change significantly.
In Model 3, the imputed values are modeled as
where wald
test, one can estimate whether the collection
of deviations
The parameters coefficients
function. (See also the examples
below).
Other model parameters can be extracted using functions such as
gof
(for goodness of fit), summary
or totals
. Refer to the `See also' section for an overview.
In many data sets will use use only yearly count data, in which case the
time trim
is to use monthly (or any other sub-yearly) count data,
in combination with index computations on the yearly time scale.
In this case, counts are given as
The contibution of month factors to the model is always similar to the way year factors are used in Model 3, that is,
For the same reason why
In the basic case of Models 2 and 3, the growth parameter
For Model 2 with covariates the growth factor
Here, coefficients
function will report every
individual value of wald
test,
the significance of contributions of covariates can be tested.
For Model 3 with covariates the parameter
Again, the coefficients
and the significance of covariates can
be investigated with the wald
test.
In the simplest case, the counts at different times and sites are considered
independently Poisson distributed. The (often too strict) assumption that
counts are independent over time may be dropped, so correlation between time
points at a certain site can be taken into account. The assumption of being
Poisson distributed can be relaxed as well. In general, the
variance-covariance structure of counts
where
If overdispersion = TRUE
makes trim
relax this
condition. Setting serialcor=TRUE
allows trim
to assume a
non-zero correlation between adjacent time points, thus relaxing the
assumption of independence over time.
The data set must contain sufficient counts to be able to estimate the model. In particular
For model 2 without covariates there must be at least one observation for each time segment defined by the change points.
For model 2 with covariates there must be at least one observation for every value of each covariate, at each time segment defined by the change points.
For model 3 without covariates there must be at least one observation for each time point.
For model 3 with covariates there must be at least one observation for every value of each covariate, at each time point.
For montly data, there must be at least one observation for every month.
The function check_observations
identifies cases where too few
observations are present to compute a model. Setting the option
autodelete=TRUE
(Model 2 only) makes trim
remove changepoints
such that at each time piece sufficient counts are available to estimate the
model.
All versions of trim
support additional 'experts only' arguments:
verbose
Logical switch to temporarily enable verbose output. (use option(trim_verbose=TRUE)
) for permanent verbosity.
constrain_overdisp
Numerical value to control overdispersion.
A value in the range 0..1 uses a Chi-squared oulier detection method.
A value >1 uses Tukey's Fence.
A value of 1.0 (which is the default) results in unconstrained overdispersion.
conv_crit
Convergence criterion.
Used within the iterative emodel estimation algorithm.
The default value is 1e-5
.).
May be set to higher values in case models don't converge.
max_iter
Number of iterations. Default value is 200
. May be set to higher values in case models don't converge.
premove
Probability of removal of changepoints (default value: 0.2). Parameter used in stepwise refinement of models. See the vignette 'Models and statistical methods in rtrim'.
penter
Probability of re-entering of changepoints (default value: 0.15). Similar use as premove
.
rtrim by example for a gentle introduction, rtrim for TRIM users for users of the classic Delphi-based TRIM implementation, and rtrim 2 extensions for the major changes from rtrim v.1 to rtrim v.2
Other analyses:
coef.trim()
,
confint.trim()
,
gof()
,
index()
,
now_what()
,
overall()
,
overdispersion()
,
plot.trim.index()
,
plot.trim.overall()
,
results()
,
serial_correlation()
,
summary.trim()
,
totals()
,
vcov.trim()
,
wald()
Other modelspec:
check_observations()
,
read_tcf()
,
read_tdf()
,
set_trim_verbose()
,
trimcommand()
# NOT RUN {
data(skylark)
m <- trim(count ~ site + time, data=skylark, model=2)
summary(m)
coefficients(m)
# An example using weights
# set up some random weights (one for each site)
w <- runif(55, 0.1, 0.9)
# match weights to sites
skylark$weights <- w[skylark$site]
# run model
m <- trim(count ~ site + time, data=skylark, weights="weights", model=3)
# An example using change points, a covariate, and overdispersion
# 1 is added as cp automatically
cp <- c(2,6)
m <- trim(count ~ site + time + Habitat, data=skylark, model=2, changepoints=cp, overdisp=TRUE)
coefficients(m)
# check significance of changes in slope
wald(m)
plot(overall(m))
# }
Run the code above in your browser using DataLab