rtrim
2.0 extensionsThis vignette describes the extenstions to the rtrim
package as per version 2.0:
See also the vignettes rtrim_confidence_intervals.html and taming_overdispersion.html for additional new features.
One of the major improvements in rtrim
2.0 with respect to 1.0 is the handling of monthly, or any other intra-annual, data. For example, where a classic TRIM model 3 looks like \[ \ln \mu_{ij} = \alpha_i + \beta_j \] where \(\mu_{ij}\) is an expected count, \(\alpha_i\) is a site parameter for site \(i\) and \(\beta_j\) is a time point parameter for year \(j\). the extension towards months looks like \[ \ln \mu_{ijm} = \alpha_i + \beta_j + \delta_m \] where \(\delta_m\) are month parameters for month \(m\).
Please take a look in TRIM_methods_v2.pdf for a full explanation, and application to other model formulations.
The general syntax to specify R-Trim models that use monthly data is as follows:
z <- trim(count ~ site + year, data=...) # simple annual data
z <- trim(count ~ site + year + habitat, data=...) # using covariates
z <- trim(count ~ site + (year+month), data=...) # using monthy data
z <- trim(count ~ site + (year+month) + habitat, data=...) # using both
Note the use of brackets to distinguish months from covariates.
Here is a full example for Oystercatcher data, which now comes with rtrim
2.0
rm(list=ls()) # always start with a clean slate
library(rtrim)
data(oystercatcher)
oc <- trim(count ~ site + (year+month), data=oystercatcher, model=3, overdisp=TRUE,
constrain_overdisp=0.999)
#> Warning in trim_estimate(count = count, site = site, year = year, month =
#> month, : Removed 15 sites without positive observations: (1, 30, 41, 48,
#> 66, 69, 78, 82, 83, 85, 86, 87, 88, 92, 104)
plot(index(oc))
#> [1] 873073.7 633285.0 615771.5 661340.2 833575.3 777598.0 791352.5
#> [8] 671946.8 664992.4 680107.0 733251.6 701182.6 574033.4 559199.2
#> [15] 494765.0 579944.7 538798.8 712040.1 609400.1 632065.0
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 517033351 92101885 87980958 92277504 115371246 104090085
#> [2,] 92101885 442230180 109847244 116683380 142993183 135714876
#> [3,] 87980958 109847244 477259597 125967234 151449592 139711091
#> [4,] 92277504 116683380 125967234 564360645 161431619 148720952
#> [5,] 115371246 142993183 151449592 161431619 633835300 190712327
#> [6,] 104090085 135714876 139711091 148720952 190712327 539960354
#> [7,] 107324487 135022617 144348675 152917872 193137323 185876591
#> [8,] 89179549 112638036 119159449 127844776 161196428 153333306
#> [9,] 87789858 112831394 118717232 126541266 162749409 155616030
#> [10,] 90651330 114151524 122756680 131966910 166121371 157653405
#> [11,] 96996074 126233514 133172358 141995052 180241390 174100577
#> [12,] 93376875 119597750 124963587 133875675 172362904 165299512
#> [13,] 76081210 97945997 103330783 109496492 140466798 134927984
#> [14,] 74258034 95375892 100537677 107042135 137558712 131421607
#> [15,] 65059022 84191283 89003681 94335671 120938384 116104101
#> [16,] 76644734 97451693 103381526 109350374 141176847 134779247
#> [17,] 70804161 90115923 95322773 100931261 130640483 124111931
#> [18,] 92780102 118542424 126136301 134740892 172116204 163518333
#> [19,] 79365278 104950811 109158081 116016104 148962054 144146616
#> [20,] 83384381 107132576 112645988 119949750 154785714 148073432
#> [,7] [,8] [,9] [,10] [,11] [,12]
#> [1,] 107324487 89179549 87789858 90651330 96996074 93376875
#> [2,] 135022617 112638036 112831394 114151524 126233514 119597750
#> [3,] 144348675 119159449 118717232 122756680 133172358 124963587
#> [4,] 152917872 127844776 126541266 131966910 141995052 133875675
#> [5,] 193137323 161196428 162749409 166121371 180241390 172362904
#> [6,] 185876591 153333306 155616030 157653405 174100577 165299512
#> [7,] 643739874 157732480 157927309 161811903 176438456 167015470
#> [8,] 157732480 451233033 129625326 133722809 144817929 136824002
#> [9,] 157927309 129625326 452641363 137817894 150509319 142617997
#> [10,] 161811903 133722809 137817894 463858208 152942407 145825902
#> [11,] 176438456 144817929 150509319 152942407 514906796 159220928
#> [12,] 167015470 136824002 142617997 145825902 159220928 498181534
#> [13,] 136649698 112407358 116432217 119253528 130365336 124835248
#> [14,] 132878980 109695978 113234634 116117403 126625415 121643637
#> [15,] 117812663 97410511 99767323 102435932 112287709 107190481
#> [16,] 137084895 112867273 116219107 119182770 129275804 124103340
#> [17,] 127102768 103761538 108370914 110573799 120000826 115552733
#> [18,] 166337039 137558620 142214693 146693891 158051384 152464410
#> [19,] 143797530 118734005 123477806 125514341 138514145 132222797
#> [20,] 149467025 122761466 127316078 130439447 142329053 137347696
#> [,13] [,14] [,15] [,16] [,17] [,18]
#> [1,] 76081210 74258034 65059022 76644734 70804161 92780102
#> [2,] 97945997 95375892 84191283 97451693 90115923 118542424
#> [3,] 103330783 100537677 89003681 103381526 95322773 126136301
#> [4,] 109496492 107042135 94335671 109350374 100931261 134740892
#> [5,] 140466798 137558712 120938384 141176847 130640483 172116204
#> [6,] 134927984 131421607 116104101 134779247 124111931 163518333
#> [7,] 136649698 132878980 117812663 137084895 127102768 166337039
#> [8,] 112407358 109695978 97410511 112867273 103761538 137558620
#> [9,] 116432217 113234634 99767323 116219107 108370914 142214693
#> [10,] 119253528 116117403 102435932 119182770 110573799 146693891
#> [11,] 130365336 126625415 112287709 129275804 120000826 158051384
#> [12,] 124835248 121643637 107190481 124103340 115552733 152464410
#> [13,] 362492398 99818363 88222753 101857634 94614057 125058710
#> [14,] 99818363 338657723 86236444 99498359 92530802 122197788
#> [15,] 88222753 86236444 326232850 88498680 82080423 108298757
#> [16,] 101857634 99498359 88498680 357147571 96117945 127078833
#> [17,] 94614057 92530802 82080423 96117945 322825460 118132687
#> [18,] 125058710 122197788 108298757 127078833 118132687 461971635
#> [19,] 108619583 106223299 94153023 109232954 101547744 134301740
#> [20,] 112373129 110041355 97287508 113510071 105741882 139910691
#> [,19] [,20]
#> [1,] 79365278 83384381
#> [2,] 104950811 107132576
#> [3,] 109158081 112645988
#> [4,] 116016104 119949750
#> [5,] 148962054 154785714
#> [6,] 144146616 148073432
#> [7,] 143797530 149467025
#> [8,] 118734005 122761466
#> [9,] 123477806 127316078
#> [10,] 125514341 130439447
#> [11,] 138514145 142329053
#> [12,] 132222797 137347696
#> [13,] 108619583 112373129
#> [14,] 106223299 110041355
#> [15,] 94153023 97287508
#> [16,] 109232954 113510071
#> [17,] 101547744 105741882
#> [18,] 134301740 139910691
#> [19,] 364350259 121185575
#> [20,] 121185575 400392895
#> [1] 0.0000000000 0.0007617459 0.0008007085 0.0009461736 0.0011608166
#> [6] 0.0010031791 0.0011465350 0.0008136608 0.0008118759 0.0008348462
#> [11] 0.0009401957 0.0008942946 0.0006375203 0.0005977485 0.0005490748
#> [16] 0.0006342448 0.0005671912 0.0008586752 0.0006631006 0.0007223828
While in the past TRIM was used to analyse count data with an annual resolution (i.e. one observation per site per year), the software package UIndex [Underhill, 1989; Underhill and Prŷs-Jones, 1995] was and is used to analyse count data with higher (e.g., monthly) resolution. As demonstrated above, rtrim
is extended to accept and analyse monthly data as well. This section demonstrates the application of rtrim
to monthly data, and compares the output with that of UIndex.
UIndex was used to analyse the monthly Oystercatcher counts, collected by SOVON Netherlands. Here we show the pre-saved output of UIndex, as the main trend, and the 90% `consistency intervals’. Note also the use of 2004 as base year.
load("UIndex_Oystercatcher_output.RData")
yrange <- range(uidx$index, uidx$lower, uidx$upper)
plot(uidx$year, uidx$index, type='l', xlab="Year", ylab="Index", ylim=yrange)
segments(uidx$year, uidx$lower, uidx$year,uidx$upper)
legend("topright", "UIndex", col="black", lty="solid")
# Add index=1 line for reference
abline(h=1.0, lty="dashed", col=gray(0.5))
# Mark the base year
ibase <- match(2004, uidx$year)
points(uidx$year[ibase], uidx$index[ibase], pch=16)
rtrim
Here we show the comparision with rtrim
, using the results computed above.
# Compute and plot an index for Oystercatcher counts, using 2004 as base year and
# adding 90% confidence intervals as well.
idx <- index(oc, level=0.9, base=2004)
#> [1] 873073.7 633285.0 615771.5 661340.2 833575.3 777598.0 791352.5
#> [8] 671946.8 664992.4 680107.0 733251.6 701182.6 574033.4 559199.2
#> [15] 494765.0 579944.7 538798.8 712040.1 609400.1 632065.0
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 517033351 92101885 87980958 92277504 115371246 104090085
#> [2,] 92101885 442230180 109847244 116683380 142993183 135714876
#> [3,] 87980958 109847244 477259597 125967234 151449592 139711091
#> [4,] 92277504 116683380 125967234 564360645 161431619 148720952
#> [5,] 115371246 142993183 151449592 161431619 633835300 190712327
#> [6,] 104090085 135714876 139711091 148720952 190712327 539960354
#> [7,] 107324487 135022617 144348675 152917872 193137323 185876591
#> [8,] 89179549 112638036 119159449 127844776 161196428 153333306
#> [9,] 87789858 112831394 118717232 126541266 162749409 155616030
#> [10,] 90651330 114151524 122756680 131966910 166121371 157653405
#> [11,] 96996074 126233514 133172358 141995052 180241390 174100577
#> [12,] 93376875 119597750 124963587 133875675 172362904 165299512
#> [13,] 76081210 97945997 103330783 109496492 140466798 134927984
#> [14,] 74258034 95375892 100537677 107042135 137558712 131421607
#> [15,] 65059022 84191283 89003681 94335671 120938384 116104101
#> [16,] 76644734 97451693 103381526 109350374 141176847 134779247
#> [17,] 70804161 90115923 95322773 100931261 130640483 124111931
#> [18,] 92780102 118542424 126136301 134740892 172116204 163518333
#> [19,] 79365278 104950811 109158081 116016104 148962054 144146616
#> [20,] 83384381 107132576 112645988 119949750 154785714 148073432
#> [,7] [,8] [,9] [,10] [,11] [,12]
#> [1,] 107324487 89179549 87789858 90651330 96996074 93376875
#> [2,] 135022617 112638036 112831394 114151524 126233514 119597750
#> [3,] 144348675 119159449 118717232 122756680 133172358 124963587
#> [4,] 152917872 127844776 126541266 131966910 141995052 133875675
#> [5,] 193137323 161196428 162749409 166121371 180241390 172362904
#> [6,] 185876591 153333306 155616030 157653405 174100577 165299512
#> [7,] 643739874 157732480 157927309 161811903 176438456 167015470
#> [8,] 157732480 451233033 129625326 133722809 144817929 136824002
#> [9,] 157927309 129625326 452641363 137817894 150509319 142617997
#> [10,] 161811903 133722809 137817894 463858208 152942407 145825902
#> [11,] 176438456 144817929 150509319 152942407 514906796 159220928
#> [12,] 167015470 136824002 142617997 145825902 159220928 498181534
#> [13,] 136649698 112407358 116432217 119253528 130365336 124835248
#> [14,] 132878980 109695978 113234634 116117403 126625415 121643637
#> [15,] 117812663 97410511 99767323 102435932 112287709 107190481
#> [16,] 137084895 112867273 116219107 119182770 129275804 124103340
#> [17,] 127102768 103761538 108370914 110573799 120000826 115552733
#> [18,] 166337039 137558620 142214693 146693891 158051384 152464410
#> [19,] 143797530 118734005 123477806 125514341 138514145 132222797
#> [20,] 149467025 122761466 127316078 130439447 142329053 137347696
#> [,13] [,14] [,15] [,16] [,17] [,18]
#> [1,] 76081210 74258034 65059022 76644734 70804161 92780102
#> [2,] 97945997 95375892 84191283 97451693 90115923 118542424
#> [3,] 103330783 100537677 89003681 103381526 95322773 126136301
#> [4,] 109496492 107042135 94335671 109350374 100931261 134740892
#> [5,] 140466798 137558712 120938384 141176847 130640483 172116204
#> [6,] 134927984 131421607 116104101 134779247 124111931 163518333
#> [7,] 136649698 132878980 117812663 137084895 127102768 166337039
#> [8,] 112407358 109695978 97410511 112867273 103761538 137558620
#> [9,] 116432217 113234634 99767323 116219107 108370914 142214693
#> [10,] 119253528 116117403 102435932 119182770 110573799 146693891
#> [11,] 130365336 126625415 112287709 129275804 120000826 158051384
#> [12,] 124835248 121643637 107190481 124103340 115552733 152464410
#> [13,] 362492398 99818363 88222753 101857634 94614057 125058710
#> [14,] 99818363 338657723 86236444 99498359 92530802 122197788
#> [15,] 88222753 86236444 326232850 88498680 82080423 108298757
#> [16,] 101857634 99498359 88498680 357147571 96117945 127078833
#> [17,] 94614057 92530802 82080423 96117945 322825460 118132687
#> [18,] 125058710 122197788 108298757 127078833 118132687 461971635
#> [19,] 108619583 106223299 94153023 109232954 101547744 134301740
#> [20,] 112373129 110041355 97287508 113510071 105741882 139910691
#> [,19] [,20]
#> [1,] 79365278 83384381
#> [2,] 104950811 107132576
#> [3,] 109158081 112645988
#> [4,] 116016104 119949750
#> [5,] 148962054 154785714
#> [6,] 144146616 148073432
#> [7,] 143797530 149467025
#> [8,] 118734005 122761466
#> [9,] 123477806 127316078
#> [10,] 125514341 130439447
#> [11,] 138514145 142329053
#> [12,] 132222797 137347696
#> [13,] 108619583 112373129
#> [14,] 106223299 110041355
#> [15,] 94153023 97287508
#> [16,] 109232954 113510071
#> [17,] 101547744 105741882
#> [18,] 134301740 139910691
#> [19,] 364350259 121185575
#> [20,] 121185575 400392895
#> [1] 0.0022672597 0.0013659905 0.0013733169 0.0016135102 0.0019964322
#> [6] 0.0016989249 0.0019353702 0.0013831943 0.0013546801 0.0000000000
#> [11] 0.0015659076 0.0014929217 0.0010628876 0.0009973079 0.0009138118
#> [16] 0.0010619011 0.0009485650 0.0014339095 0.0011065766 0.0012076265
plot(idx, band="ci")
# Plot UIndex on top
lines(uidx$year, uidx$index)
segments(uidx$year, uidx$lower, uidx$year,uidx$upper, lwd=2)
legend("bottom", c("UIndex","TRIM"), col=c("black","red"), lty="solid")
Note the computation and display of confidence intervals, which is new for rtrim
2.0, along with the standard errors of both classic TRIM and rtrim
1.0.
This plot demonstrates that the indices as computed by UIndex and rtrim
are virtually identical, and that the 90% confidence intervals of TRIM are well comparable to the 90% consistency intervals of TRIM, although both are estimated using completely different approaches. In the case of TRIM, confidence intervals are based on standard errors which are derived analytically as part of the GEE estimation process and ultimately are based on the variance within the orginal data. See the vignettes TRIM_methods_v2.pdf and rtrim_confidence_intervals.html for more information. Consistency intervals in UIndex are estimated by means of a bootstrap method. See Underhill [1989] and Underhill and Prŷs-Jones [1995] for more information.
rtrim
Sometimes it can be usefull to combine rtrim
results for different regions (‘strata’) into a single, larger scale (‘superstratum’) rtrim
analysis. One particular example is the case where individual EU countries use TRIM or rtrim
to compute indices for their own countries, and submit the results to the European Bird Census Counsil http://www.ebcc.info for aggregatation on the EU scale, see van Strien et al. [2001] for an example using the previous stand-alone version of TRIM. In this case, the output of the lower scale rtrim
runs, i.e., the time totals, are used as ‘observations’ in the higher scale run. Although this procedure works out well for the estimates and indices, it doesn’t work for the associated standard errors, because the time totals are not Poisson distributed, where the original counts are. To circumvent this problem, rtrim
has options to export the variances of the lower scale runs and to import these into the higher scale runs, to use instead.
The following example shows the associated workflow. Strictly for demonstration purposes, we split the Skylark dataset into two ‘regions’ associated with the habitats (heath and dunes).
# split data
data(skylark2)
heath <- subset(skylark2, habitat=="heath") # 208 records
dunes <- subset(skylark2, habitat=="dunes") # 232 records
heath$site <- factor(heath$site) # get rid of empty levels
dunes$site <- factor(dunes$site)
# run models
m1 <- trim(count ~ site + year, data=heath, model=3)
m2 <- trim(count ~ site + year, data=dunes, model=3)
# collect imputed time-totals (which is the default)
t1 <- totals(m1)
t2 <- totals(m2)
plot(t1,t2, names=c("heath", "dunes"))
Note the use of multiple time-totals in a single plot (new for
rtrim
2.0)
The next step is to use the time totals for the differente habitats (strata') as input data for an upscaled (
superstratum’) run. The habitat types now serve as site names, and imputed counts will be the input counts.
t1$region <- "heath"
t2$region <- "dunes"
t12 <- rbind(t1, t2)
head(t12)
#> time imputed se_imp region
#> 1 1984 376 33 heath
#> 2 1985 255 25 heath
#> 3 1986 339 22 heath
#> 4 1987 336 21 heath
#> 5 1988 389 23 heath
#> 6 1989 425 24 heath
The final preparation step is to extract the variance-covariance information for the different habitats, and combine them into a single list, using habitat/region names as identifier, enabling the correct match between the site identifiers in the data, and the variance-covariance matrices.
# Also collect the variance-covariance matrices for both runs
vcv1 <- vcov(m1)
vcv2 <- vcov(m2)
vcv3 <- list(heath=vcv1, dunes=vcv2)
and off we go with the superstratum run. Note the new argument covin
to use the variance-covariance data.
m3 <- trim(imputed ~ region + time, data=t12, model=3, covin=vcv3)
plot(totals(m3))
Now, just for comparison, we compare index plots for both the baseline run (where dunes and heath are taken together, but do act as covariates) and the upscaled `superstratum’ variant.
m0 <- trim(count ~ site + year + habitat, data=skylark2, model=3) # baseline
t0 <- totals(m0)
t3 <- totals(m3)
plot(t0,t3, names=c("baseline","superstrata"))
Which suggests that for this example the differences are small, if any.
In some cases, especially with clustering bird species, overdispersion can be huge, reaching unrealistic values of more than 500. rtrim now contains an option to constrain the computed value of overdispersion by detecting outliers, and removing them from the computation of overdispersion (but retaining them for all other calculations). The full rationale and methdology is described in taming_overdispersion.html, but the actual use is rather simple.
Take for example the Oystercatcher data, which results in a huge overdispersion of about 850
data(oystercatcher)
m1 <- trim(count ~ site + (year + month), data=oystercatcher, model=3, overdisp=TRUE)
#> Warning in trim_estimate(count = count, site = site, year = year, month =
#> month, : Removed 15 sites without positive observations: (1, 30, 41, 48,
#> 66, 69, 78, 82, 83, 85, 86, 87, 88, 92, 104)
overdispersion(m1)
#> [1] 850.7956
The inclusion of the option constrain_overdisp=0.999
triggers the detection of outliers that have a probability of 0.1%.
m2 <- trim(count ~ site + (year + month), data=oystercatcher, model=3, overdisp=TRUE,
constrain_overdisp=0.99)
#> Warning in trim_estimate(count = count, site = site, year = year, month =
#> month, : Removed 15 sites without positive observations: (1, 30, 41, 48,
#> 66, 69, 78, 82, 83, 85, 86, 87, 88, 92, 104)
overdispersion(m2)
#> [1] 102.6988
And so we get a much more reasonable result, with smaller standard errors.
t1 <- totals(m1)
t2 <- totals(m2)
plot(t1, t2, names=c("unconstrained","constrained"), leg.pos="bottom")
Once an rtrim
model has been estimated, one of the first steps of analysis schould be the plotting of time-totals. This is done by first calling the totals()
function, and then a custom plot()
function:
rm(list=ls()) # New section; time for a new blank slate
data(skylark2) # reload Skylark data
m1 <- trim(count ~ site + year, data=skylark2, model=3)
t1 <- totals(m1) # By default, the time-totals for the imputed data set
plot(t1)
Alternatively, one may compute the fitted time-totals. the next example shows the plotting of both the imputed and fitted time-totals, and also demonstrates how series can be named, and the plot can be decorated with a main title.
m2 <- trim(count ~ site + year, data=skylark2, model=2, changepoints=c(1,2))
ti <- totals(m2, "imputed")
tf <- totals(m2, "fitted")
plot(ti, tf, names=c("imputed","fitted"), main="Skylark", leg.pos="bottomright")
Since imputed totals are composed of both observed and estimated counts, it might be insightful to plot the observed counts as well.
m3 <- trim(count ~ site + year, data=skylark2, model=3)
t3 <- totals(m3, obs=TRUE) # Extract observations in addition to totals
plot(t3)
As can be seen, the amount of observed Skylarks is considerable smaller than the time totals suggest. Futhermore, it can be seen that while the observed counts decrease from 1989, the imputed counts continue to increase. It is thus suggested to look into more detail what is going on in different sites.
Once a TRIM model has been estimated, and indices are computed, these latter can be plotted using the generic plot command plot()
(which, behind the screens, calls plot.trim.index()
).
m <- trim(count ~ site + year, data=skylark2, model=3) # Run a fairly basic TRIM model
idx <- index(m) # By default, the indices for the imputed data set
#> [1] 510.6836 362.3937 429.4740 423.3654 468.9276 521.6995 561.7272 606.0412
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1477.92545 92.7689369 66.70285 36.7898412 70.51933 35.178440
#> [2,] 92.76894 936.9496647 22.65781 0.1722514 23.20863 -1.951136
#> [3,] 66.70285 22.6578114 653.25074 60.7162423 91.67497 67.316470
#> [4,] 36.78984 0.1722514 60.71624 602.0078455 69.75698 44.237315
#> [5,] 70.51933 23.2086252 91.67497 69.7569844 723.78329 78.045284
#> [6,] 35.17844 -1.9511360 67.31647 44.2373149 78.04528 745.141453
#> [7,] 54.92091 9.7404156 104.77364 77.9708130 118.51036 97.821352
#> [8,] 71.59978 10.8053142 91.77615 63.2329018 103.52698 81.446098
#> [,7] [,8]
#> [1,] 54.920910 71.59978
#> [2,] 9.740416 10.80531
#> [3,] 104.773636 91.77615
#> [4,] 77.970813 63.23290
#> [5,] 118.510362 103.52698
#> [6,] 97.821352 81.44610
#> [7,] 1025.804276 157.20899
#> [8,] 157.208992 1331.76321
#> [1] 0.000000000 0.005941472 0.006082549 0.005969154 0.007056803 0.008495630
#> [7] 0.010326455 0.012435740
plot(idx)
If required, the x-axis and y-axis labels as well as the tile can be defined, and the index can be expressed as a percentage, instead as a fraction. This example shows all these options:
plot(idx, xlab="Year AD", ylab="Index (%)", main="Skylark index", pct=TRUE)
When covariates are involved, it can be helpful to compute and plot indices for the various covariate categories as well. The next example demonstrates this.
m <- trim(count ~ site + year + habitat, data=skylark2, model=3) # Run a fairly basic TRIM model
idx <- index(m, covars=TRUE)
#> [1] 527.5958 377.2858 442.4999 429.1311 460.8150 515.0227 547.3168 593.6513
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1692.34791 192.96868 136.97952 88.66499 110.77219 30.65008
#> [2,] 192.96868 1110.88917 76.70122 35.39102 43.00598 -21.72407
#> [3,] 136.97952 76.70122 793.36085 90.03571 108.24950 57.54705
#> [4,] 88.66499 35.39102 90.03571 693.34798 86.41679 40.06895
#> [5,] 110.77219 43.00598 108.24950 86.41679 738.56689 75.26614
#> [6,] 30.65008 -21.72407 57.54705 40.06895 75.26614 731.73986
#> [7,] 83.43568 14.88130 107.84495 79.65669 115.06421 94.88576
#> [8,] 107.01019 16.97310 101.54848 69.34366 102.84031 85.46504
#> [,7] [,8]
#> [1,] 83.43568 107.01019
#> [2,] 14.88130 16.97310
#> [3,] 107.84495 101.54848
#> [4,] 79.65669 69.34366
#> [5,] 115.06421 102.84031
#> [6,] 94.88576 85.46504
#> [7,] 1008.52359 155.25222
#> [8,] 155.25222 1287.23926
#> [1] 0.000000000 0.006108429 0.006301413 0.005994897 0.006596219 0.008207252
#> [7] 0.009544005 0.011456737
#> [1] 151.42677 122.11216 103.17161 93.39996 71.96111 90.08915 81.15227
#> [8] 72.96652
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 768.80556 152.35917 76.44523 50.267785 42.232392 -33.8135511
#> [2,] 152.35917 617.78569 78.45822 51.710739 45.584741 -15.2138436
#> [3,] 76.44523 78.45822 608.45553 49.035767 39.366099 -10.7898593
#> [4,] 50.26779 51.71074 49.03577 565.412248 40.483816 -3.2616217
#> [5,] 42.23239 45.58474 39.36610 40.483816 516.361831 -1.6977481
#> [6,] -33.81355 -15.21384 -10.78986 -3.261622 -1.697748 487.5343846
#> [7,] 21.34101 28.10593 26.69336 26.003346 23.633078 0.5750175
#> [8,] 29.30087 33.37927 29.69921 28.009454 22.449232 3.8112388
#> [,7] [,8]
#> [1,] 21.3410079 29.300866
#> [2,] 28.1059281 33.379268
#> [3,] 26.6933647 29.699207
#> [4,] 26.0033461 28.009454
#> [5,] 23.6330781 22.449232
#> [6,] 0.5750175 3.811239
#> [7,] 568.0757726 36.184569
#> [8,] 36.1845687 503.451150
#> [1] 0.00000000 0.03802912 0.03755656 0.03470934 0.02834031 0.03488369
#> [7] 0.03340629 0.02850936
#> [1] 376.1690 255.1737 339.3283 335.7312 388.8538 424.9335 466.1646 520.6848
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1136.54235 40.609512 60.534286 38.39721 68.539801 64.463627
#> [2,] 40.60951 655.103478 -1.756992 -16.31972 -2.578762 -6.510225
#> [3,] 60.53429 -1.756992 511.905315 40.99994 68.883404 68.336907
#> [4,] 38.39721 -16.319719 40.999942 465.93573 45.932971 43.330572
#> [5,] 68.53980 -2.578762 68.883404 45.93297 579.205057 76.963886
#> [6,] 64.46363 -6.510225 68.336907 43.33057 76.963886 669.205472
#> [7,] 62.09467 -13.224629 81.151588 53.65335 91.431131 94.310738
#> [8,] 77.70932 -16.406163 71.849275 41.33420 80.391079 81.653802
#> [,7] [,8]
#> [1,] 62.09467 77.70932
#> [2,] -13.22463 -16.40616
#> [3,] 81.15159 71.84927
#> [4,] 53.65335 41.33420
#> [5,] 91.43113 80.39108
#> [6,] 94.31074 81.65380
#> [7,] 814.44782 119.06765
#> [8,] 119.06765 1123.78811
#> [1] 0.000000000 0.007936192 0.009381552 0.009206285 0.011674572 0.013949352
#> [7] 0.017002871 0.021810239
plot(idx)
As can be seen, indices for the various covariate categories are automatically plotted as well. This behaviour can be supressed by setting covar="none"
in the call to plot()
(note the use of plural covars' in the call to
index()--- because indices for multiple covariates can be computed, and the singular
covarin the call to
plot()` — because only one of them can be used for a single figure)
Indices for multiple TRIM runs can be combined in a single plot.
data(skylark2)
m0 = trim(count ~ site + year , data=skylark2, model=3)
m1 = trim(count ~ site + year + habitat, data=skylark2, model=3)
idx0 <- index(m0)
#> [1] 510.6836 362.3937 429.4740 423.3654 468.9276 521.6995 561.7272 606.0412
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1477.92545 92.7689369 66.70285 36.7898412 70.51933 35.178440
#> [2,] 92.76894 936.9496647 22.65781 0.1722514 23.20863 -1.951136
#> [3,] 66.70285 22.6578114 653.25074 60.7162423 91.67497 67.316470
#> [4,] 36.78984 0.1722514 60.71624 602.0078455 69.75698 44.237315
#> [5,] 70.51933 23.2086252 91.67497 69.7569844 723.78329 78.045284
#> [6,] 35.17844 -1.9511360 67.31647 44.2373149 78.04528 745.141453
#> [7,] 54.92091 9.7404156 104.77364 77.9708130 118.51036 97.821352
#> [8,] 71.59978 10.8053142 91.77615 63.2329018 103.52698 81.446098
#> [,7] [,8]
#> [1,] 54.920910 71.59978
#> [2,] 9.740416 10.80531
#> [3,] 104.773636 91.77615
#> [4,] 77.970813 63.23290
#> [5,] 118.510362 103.52698
#> [6,] 97.821352 81.44610
#> [7,] 1025.804276 157.20899
#> [8,] 157.208992 1331.76321
#> [1] 0.000000000 0.005941472 0.006082549 0.005969154 0.007056803 0.008495630
#> [7] 0.010326455 0.012435740
idx1 <- index(m1)
#> [1] 527.5958 377.2858 442.4999 429.1311 460.8150 515.0227 547.3168 593.6513
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1692.34791 192.96868 136.97952 88.66499 110.77219 30.65008
#> [2,] 192.96868 1110.88917 76.70122 35.39102 43.00598 -21.72407
#> [3,] 136.97952 76.70122 793.36085 90.03571 108.24950 57.54705
#> [4,] 88.66499 35.39102 90.03571 693.34798 86.41679 40.06895
#> [5,] 110.77219 43.00598 108.24950 86.41679 738.56689 75.26614
#> [6,] 30.65008 -21.72407 57.54705 40.06895 75.26614 731.73986
#> [7,] 83.43568 14.88130 107.84495 79.65669 115.06421 94.88576
#> [8,] 107.01019 16.97310 101.54848 69.34366 102.84031 85.46504
#> [,7] [,8]
#> [1,] 83.43568 107.01019
#> [2,] 14.88130 16.97310
#> [3,] 107.84495 101.54848
#> [4,] 79.65669 69.34366
#> [5,] 115.06421 102.84031
#> [6,] 94.88576 85.46504
#> [7,] 1008.52359 155.25222
#> [8,] 155.25222 1287.23926
#> [1] 0.000000000 0.006108429 0.006301413 0.005994897 0.006596219 0.008207252
#> [7] 0.009544005 0.011456737
plot(idx0, idx1)
As you see, a legend is inserted automatically. You can change the names of the series by using the
names
argument:
plot(idx0, idx1, names=c("Without covariates", "Using 'Habitat' as covariate"))
New in rtrim 2.0 is the possibility to express uncertainty as a confidence interval, in addition to the standard errors. Both the functions totals()
and index()
now accept the option level
that specifies the confidence level and triggers the computation.
m <- trim(count ~ site + year, data=skylark2, model=3)
tt <- totals(m, level=0.95) # Compute 95% confidence intervals
head(tt)
#> time imputed se_imp lo hi
#> 1 1984 511 38 434.9422 583.8739
#> 2 1985 362 31 299.7129 421.2013
#> 3 1986 429 26 376.8626 478.7599
#> 4 1987 423 25 372.8600 470.8378
#> 5 1988 469 27 414.9102 520.7285
#> 6 1989 522 27 467.9707 573.7910
So, the lower and upper bounds of the confidence interval is stored in columns lo
and hi
. These are automatically picked up by the plot()
function.
plot(tt)
If required, the uncertainty band, which is by default plotted using standard errors, can be plotted using the confidence intervals when the option band="ci"
is used.
plot(tt, band="ci")
See vignette rtrim_confidence_intervals.html for more information on the underlying methodology.
The detailed spatiotemporal structure of both the observed anf the imputed data can be inspected by means of the function heatmap()
that operates on the output of trim()
. The default behaviour of this function is to display a heat map of the observed counts only:
m <- trim(count ~ site + year, data=skylark2, model=3)
heatmap(m, main="Skylark, observations")
In this heatmap, site/time combinations are colored by (log) counts: lower counts are colored a pale red, and high counts a dark red. Consistent with the nature of count data, this color scale is proportional to the log counts. Observed counts of 0 cannot be represented this way and are colored white. Missing site/time combinations are marked as gray.
It can be seen that the observational coverage is not constant: most sites have incomplete records, especially in the earlier years. This is a typical patern for an expanding observation program, but may have consequences for the statistical analysis, because the imputation for these years will in fact be an extrapolation back in time.
The next example shows the TRIM estimated counts (using shades of blue, rather than red:
heatmap(m, "fitted", main="Skylark, TRIM estimates")
From this plot, it is clear that the variance between sites is much higher than the variance between years. In fact, the trend in time can hardly be seen.
The last example sows the heatmap for the imputed data, where estimates are used to fill up the missing observations. Again, red is for obervations, blue for estimates.
heatmap(m, "imputed", main="Skylark, imputed data")
For monthly data, heatmaps work slightly different, but in the same spirit:
data(oystercatcher)
m <- trim(count ~ site + (year + month), data=oystercatcher, model=3, overdisp=TRUE)
#> Warning in trim_estimate(count = count, site = site, year = year, month =
#> month, : Removed 15 sites without positive observations: (1, 30, 41, 48,
#> 66, 69, 78, 82, 83, 85, 86, 87, 88, 92, 104)
heatmap(m, "imputed", main="Oystercatcher (imputed)")
Again, observational coverage is extremely variable in both space and time. There appears to be a few sites that have sporadic, yet high, count observations, causing large amounts of estimated counts for this location for all other time points, which may effect the aggregated time-totals in a significant way.
Also note that in this example, many site/time combinations have registered a count of 0, which are colored white, as explained above.
van Strien, A. J., J. Pannekoek and D.W. Gibbons (2001) Indexing European bird population trends using results of national monitoring schemes: a trial of a new method, Bird Study, 48 (2), 200-213, DOI: 10.1080/00063650109461219
Underhill, LG, Prŷs-Jones, RP (1994) Index numbers for waterbird populations. I. Review and methodology. J Appl Ecol, 31, 463-480. doi: 10.2307/2404443
Underhill, L.G. (1989) Indices for Waterbird Populations. BTO Research Report 52, British Trust for Ornithology, Tring.