diff --git a/.Rbuildignore b/.Rbuildignore
index b4e86403..9b6ce103 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -11,3 +11,6 @@ LICENSE
.github/
cran-comments.md
^CRAN-SUBMISSION$
+^_pkgdown\.yml$
+^docs$
+^pkgdown$
diff --git a/Clarity.txt b/Clarity.txt
new file mode 100644
index 00000000..56b9166a
--- /dev/null
+++ b/Clarity.txt
@@ -0,0 +1,7 @@
+
\ No newline at end of file
diff --git a/DESCRIPTION b/DESCRIPTION
index 399f86c3..d3b39d6f 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -18,7 +18,7 @@ Description: Animal abundance estimation via conventional, multiple covariate
fitting is performed via maximum likelihood. Also included are diagnostics
and plotting for fitted detection functions. Abundance estimation is via a
Horvitz-Thompson-like estimator.
-Version: 3.0.0
+Version: 3.0.0.9000
URL: https://github.com/DistanceDevelopment/mrds/
BugReports: https://github.com/DistanceDevelopment/mrds/issues
Depends:
@@ -31,6 +31,7 @@ Imports:
nloptr,
Rsolnp
Suggests:
+ Distance,
testthat,
covr,
knitr,
diff --git a/NEWS b/NEWS.md
similarity index 72%
rename from NEWS
rename to NEWS.md
index ef380bd0..c392ef72 100644
--- a/NEWS
+++ b/NEWS.md
@@ -1,5 +1,4 @@
-mrds 3.0.0
-----------
+# mrds 3.0.0
New features
@@ -10,9 +9,7 @@ Bug Fixes
* The summary of the fitting object now correctly prints the optimiser used when monotonicity is enforced ('slsqp' or 'solnp').
* check.mono() now uses the same point locations as the optimiser. It also uses the same tolerance as the optimiser (1e-8) and applies this tolerance when checking (strict) monotonicity, and when checking 0 <= g(x) <= 1.
-
-mrds 2.3.0
-----------
+# mrds 2.3.0
New Features
@@ -24,12 +21,11 @@ Bug Fixes
* Ensure that the MCDS optimizer is not used for double observer models as this was generating errors. (Issue #89)
* Improved the documentation on initial values, lower and upper bounds in both the ddf and mrds_opt documentation (mrds_opt was renamed from mrds-opt which was not accessible via ?mrds-opt). (Issue #90)
-mrds 2.2.9
-----------
+# mrds 2.2.9
New Features
-* Users can now download the fortran MCDS.exe optimiser used in Distance for Windows and fit single observer models with both the optimisers in R via mrds and also MCDS.exe. For some datasets the optimisation with MCDS.exe is superior (giving a better likelihood) than the optimiser in R used with mrds. See ?MCDS for more details.
+* Users can now download the fortran MCDS.exe optimiser used in Distance for Windows and fit single observer models with both the optimisers in R via # mrds and also MCDS.exe. For some datasets the optimisation with MCDS.exe is superior (giving a better likelihood) than the optimiser in R used with mrds. See ?MCDS for more details.
Bug Fixes
@@ -38,8 +34,7 @@ Bug Fixes
* Fix bug when a uniform model was fitted with no adjustments. This caused an error when looking for the hessian. It also required that the covariance set to 0 when estimating the cluster size standard errors (Issue #79).
* fix bug with using binned data via cutpoints for prediction (#73)
-mrds 2.2.8
-----------
+# mrds 2.2.8
* Fix bug where plotting rem.fi models when truncation was used would lead to an error being thrown. (#58)
* Fix bugs when a uniform is fitted with no adjustments (#59)
@@ -51,8 +46,7 @@ mrds 2.2.8
* Make dht output tables consistent. Now always refers to Region in the display (rather than Region in summary and Label in N/D tables). Note this is only a display change so won't break code which looks to extract these values based on column names from the dht object which is unchanged.
* Fixed bug leading to erroneous zero totals in individuals N/D tables when there were no sightings in one or more strata. Bug was apparent when the data were sightings of clusters and the varflag 1 option (er_method = 1 in Distance ds function) was selected in the dht function.
-mrds 2.2.7
-----------
+# mrds 2.2.7
* Fix bug in check for # parameters < # data. Thanks to Anne Provencher St-Pierre.
* No longer display errors caused by solnp/gosolnp when doing constrained optimisation, these can be seen when showit>0 if necessary.
@@ -61,20 +55,18 @@ mrds 2.2.7
* Expected.S element of dht return now a data.frame not a list
* Fix total encounter rate and its variance in stratified analysis
-mrds 2.2.6
-----------
+# mrds 2.2.6
* Individuals summary table for dht now includes k (number of transects)
* Add effective detection radius (EDR) and its uncertainty to summary output
* Change default rounding of chi-squared test tables. This can be customized using print(ddf.gof(...), digits=?) for e.g., printing with knitr::kable
* New detection function: two-part normal ("tpn"), useful for aerial surveys in mountainous terrain, see Becker EF, Christ AM (2015) A Unimodal Model for Double Observer Distance Sampling Surveys. PLOS ONE 10(8): e0136403. https://doi.org/10.1371/journal.pone.0136403 and ?"two-part-normal".
-* To improve consistency in functions and arguments in the package, some functions will change from . separation to _. For now both versions exist but will be removed in mrds 2.2.7.
+* To improve consistency in functions and arguments in the package, some functions will change from . separation to _. For now both versions exist but will be removed in # mrds 2.2.7.
- add_df_covar_line -> add.df.covar.line
- p_dist_table -> p.dist.table
* Variable strip widths are now supported in dht. Users should supply an additional column to the sample data.frame ("CoveredArea") giving the total area covered in the given transect and set options=list(areas.supplied=TRUE). Thanks to Megan Ferguson for providing an example, code and feedback.
-mrds 2.2.5
-----------
+# mrds 2.2.5
* use "probabalists" definition of Hermite polynomials, as from Distance. More numerically stable
* remove setting of Hermite parameter to 1 (unclear why this was the case!)
@@ -93,30 +85,26 @@ mrds 2.2.5
* errors now thrown when more parameters than data (either unique distance values or bins)
-mrds 2.2.4
-----------
+# mrds 2.2.4
* add_df_covar_line now plots probability density functions for the point transect case
* warning is no longer raised when truncation is not set but bins are specified for binned data (it's assumed that the furthest cutpoint is the truncation)
* AIC/logLik functions now work for all methods
-mrds 2.2.3
-----------
+# mrds 2.2.3
* fix bug where region areas were not duplicated properly when density was estimated (using Area=0 in data)
* fix a bug in getting starting values for hazard-rate detection functions when point transect data is used
* fix issue with left truncation when estimating abundance/density in dht
-mrds 2.2.2
-----------
+# mrds 2.2.2
* fix issue in predict() when uniform key functions are used with new data.
* new function p_dist_table() to show the distribution of estimated probabilities of detection. Useful for covariate models to determine issues with very small ps.
* new function add_df_covar_line(), which can be used to add lines plots showing the detection function for a given covariate combination. Thanks to various members of the distance sampling mailing list for this suggestion.
* plots produced by plot.ds/plot.rem/plot.rem.fi/plot.trial/plot.trial.fi/plot.io/plot.io.fi/plot.det.tables now use same defaults as R 4.0.0 ("lightgrey" bars for histograms). Some deprecated arguments to plot.ds were removed.
-mrds 2.2.1
-----------
+# mrds 2.2.1
* hessian now returned when solnp (constrained optimisation) is used to fit the detection function
* Check for NA covariate values, thanks to Ana Cañadas for highlighting this issue.
@@ -126,16 +114,14 @@ mrds 2.2.1
* Fixed a bug in dht when left truncation is used. Previously left truncation was ignored. See https://github.com/DistanceDevelopment/mrds/issues/22 thanks to Carl Schwarz for finding this bug.
* Fix bug where two objects could have a missing observer and no error was thrown. Thanks to Ainars Aunins for reporting this bug and Eric Rexstad for diagnosing.
-mrds 2.2.0
------------
+# mrds 2.2.0
* fixed bug in calculation of Kolmogorov-Smirnov p-values. Previous methods did not take into account that parameters of the detection function were estimated, so a new bootstrap-based approach has been implemented. As this is time-consuming, the Kolmogorov-Smirnov test is no longer performed by default (use ks=TRUE to get the test).
-* Encounter rate variance for point transects when points were not all sampled an equal number of times was incorrect. mrds now uses the P3 estimator from Fewster et al (2009) for point transect encounter rate variance.
-* Bug in predicting when left truncation is used. Previously if the distance column in the new data was set to zero and left truncation was > 0 predictions were discarded, this was particularly problematic for io, etc MRDS models. Thanks to Natalie Kelly for spotting this and suggesting a fix.
+* Encounter rate variance for point transects when points were not all sampled an equal number of times was incorrect. # mrds now uses the P3 estimator from Fewster et al (2009) for point transect encounter rate variance.
+* Bug in predicting when left truncation is used. Previously if the distance column in the new data was set to zero and left truncation was > 0 predictions were discarded, this was particularly problematic for io, etc # mrds models. Thanks to Natalie Kelly for spotting this and suggesting a fix.
* Add errors when "P3" is used as an encounter rate variance estimator with non-point transect data, throws a warning and switches to P3 for points when it's not specified.
-mrds 2.1.18
------------
+# mrds 2.1.18
* fixed bug in parameter rescaling where scales were incorrectly entered as 1 due to an indexing bug
* Quantile-quantile plots now use an aspect ratio of 1
@@ -144,23 +130,20 @@ mrds 2.1.18
* Correctly specify distbegin/distend for predictions with binned data, thanks to Jason Roberts for spotting this bug.
* Let the user know that int.range was set in summary() results
-mrds 2.1.17
------------
+# mrds 2.1.17
* fixed starting value bug for hazard-rate models when distances are binned. Thanks to Natalia Schroeder and Eric Rexstad for discovering this.
* predict.ds now uses numerical integration to calculate integrals (rather than an approximation). Thanks to Eric Rexstad for spotting an issue with goodness of fit testing that highlighted this.
* plot.ds() now accepts an xlab="" argument to change the x axis label. Thanks to Steve Ahlswede for suggesting this.
-mrds 2.1.16
------------
+# mrds 2.1.16
* improved predict() method now does the Right Thing with factors
* Fixed bug in scaling of histograms for point transect pdf plots and points on those plots. Thanks to Erics Howe and Rexstad for reporting these issues.
* You can now set y axis limits when using plot.ds, defaults should be more sensible for pt+point models. Thanks to Eric Howe for the suggestion.
* Fixed bug when setting initial values that threw many errors. Thanks to Laura Marshall for spotting this.
-mrds 2.1.15
------------
+# mrds 2.1.15
* rescaling parameters were not correct, now fixed. Thanks to Laura Marshall for spotting this.
* coefficients are called coefficients (not a mixture of coefficients and parameters) in summary() results
@@ -169,194 +152,170 @@ mrds 2.1.15
* assign.par, create.ddfobj and detfct are now exported, so it can be used by dsm (though shouldn't be used by anything else!)
* fixed bug in left truncation where probability of detection was not calculated correctly. Thanks to Jason Roberts for pointing this out!
-mrds 2.1.14
------------
-
- * updated initialvalues calculation for hazard-rate -- now uses Beavers & Ramsay method to scale parameters for hazard-rate
- * automatic parameter rescaling for covariate models when covariates are poorly scaled. Now default for nlminb method
- * minor speed-up to logistic code when distance is a covariate
-
+# mrds 2.1.14
-mrds 2.1.13
------------
+* updated initialvalues calculation for hazard-rate -- now uses Beavers & Ramsay method to scale parameters for hazard-rate
+* automatic parameter rescaling for covariate models when covariates are poorly scaled. Now default for nlminb method
+* minor speed-up to logistic code when distance is a covariate
- * link to distance sampling Google Groups in help
- * duplicate non-convergence warning/error removed
- * warning of singular Hessian is now a warning()
- * re-wrote the debug output to be easier to read
- * dht now has an option (ci.width) to specify confidence interval width in output (thanks to David Pavlacky for the suggestion)
- * monotonicity now operates over left->right truncation for models that are left truncated and will fail with an error message if many integration intervals are used. Thanks to Tiago Marques for highlighting this issue.
-mrds 2.1.12
------------
+# mrds 2.1.13
- * \donttest{} examples are now \dontrun{}.
+* link to distance sampling Google Groups in help
+* duplicate non-convergence warning/error removed
+* warning of singular Hessian is now a warning()
+* re-wrote the debug output to be easier to read
+* dht now has an option (ci.width) to specify confidence interval width in output (thanks to David Pavlacky for the suggestion)
+* monotonicity now operates over left->right truncation for models that are left truncated and will fail with an error message if many integration intervals are used. Thanks to Tiago Marques for highlighting this issue.
-mrds 2.1.11
------------
+# mrds 2.1.12
- * Bug in unif+cos(1) models when using monotonicity constraints and randomised starting points. Since the model only has 1 parameter, there is a bug in selecting columns in Rsolnp starting value code that makes the result be a vector, which then doesn't work with an apply later. Workaround of not using randomised starting values in mrds for that model. Thanks to Nathalie Cavada for finding this bug.
+* \donttest{} examples are now \dontrun{}.
- * Fixed bug in pdot.dsr.integrate.logistic which was giving incorrect AIC values for FI models with binned data for points or lines.
+# mrds 2.1.11
- * Fixed issue where returned optimisation obejct got accessed without being checked to see if it's result was an error, causing problems when encapsulating ddf in other functions.
+* Bug in unif+cos(1) models when using monotonicity constraints and randomised starting points. Since the model only has 1 parameter, there is a bug in selecting columns in Rsolnp starting value code that makes the result be a vector, which then doesn't work with an apply later. Workaround of not using randomised starting values in # mrds for that model. Thanks to Nathalie Cavada for finding this bug.
+* Fixed bug in pdot.dsr.integrate.logistic which was giving incorrect AIC values for FI models with binned data for points or lines.
+* Fixed issue where returned optimisation obejct got accessed without being checked to see if it's result was an error, causing problems when encapsulating ddf in other functions.
-mrds 2.1.10
------------
+# mrds 2.1.10
- * added testing directory to .Rbuildignore, tests are now not included in built packages and are not run on CRAN. For tests use the source packages on github.
+* added testing directory to .Rbuildignore, tests are now not included in built packages and are not run on CRAN. For tests use the source packages on github.
-mrds 2.1.9
-----------
+# mrds 2.1.9
BUG FIXES
- * removed test that failed on CRAN's testing
-mrds 2.1.8
-----------
+* removed test that failed on CRAN's testing
+
+# mrds 2.1.8
CHANGES
- * removed doeachint/cgftab code, which used a spline approximation to the effective strip width/effective area when a half-normal detection function was used. This has been replaced with exact calculation via the error function (erf).
- * tests updated accordingly
- * monotonically constrained models now use a bunch of random start points -- uses gosolnp() from Rsolnp
- * re-fitting by jiggling parameters refined to multiply by a uniform variable with limits set as the upper and lower bounds (+/-1) so jiggling can go either way, on approximately the same scale as the parameters
- * corrected documentation for predict methods, which incorrectly stated what is returned for point transect models. Thanks to Thibault Dieuleveut for spotting this.
+* removed doeachint/cgftab code, which used a spline approximation to the effective strip width/effective area when a half-normal detection function was used. This has been replaced with exact calculation via the error function (erf).
+* tests updated accordingly
+* monotonically constrained models now use a bunch of random start points -- uses gosolnp() from Rsolnp
+* re-fitting by jiggling parameters refined to multiply by a uniform variable with limits set as the upper and lower bounds (+/-1) so jiggling can go either way, on approximately the same scale as the parameters
+* corrected documentation for predict methods, which incorrectly stated what is returned for point transect models. Thanks to Thibault Dieuleveut for spotting this.
BUG FIXES
* fixed 2 bugs in create.varstructure; the first was for removal method which was being treated as a trial method. The second was when obs.table was not specified (Region and sample labels in dataframe for each obs) and there was dual observers. In that case it was doubling the number of observations.
* fixed a bug in dht.deriv which had not been setup for removal; thanks to John Boulanger for noticing and reporting both of these bugs
-mrds 2.1.7
-----------
+# mrds 2.1.7
BUG FIXES
- * Standardisation was being applied to detection functions (such that g(0)=1) when there were no adjustments (which is uneccesary) but also caused issues when using gamma detection functions as this should be calculated at g(apex) instead. Standardisation code has been removed for when there are no adjustments and the correct scaling used for the gamma when there are. Thanks to Thomas Doniol-Valcroze for alerting us to this bug.
- * Partial name-matching in dht was fixed. Produced warning but not error.
+* Standardisation was being applied to detection functions (such that g(0)=1) when there were no adjustments (which is uneccesary) but also caused issues when using gamma detection functions as this should be calculated at g(apex) instead. Standardisation code has been removed for when there are no adjustments and the correct scaling used for the gamma when there are. Thanks to Thomas Doniol-Valcroze for alerting us to this bug.
+* Partial name-matching in dht was fixed. Produced warning but not error.
NEW FEATURES
- * Tests for gamma detection functions
- * Observations are automatically ordered by object and observer fields (if included) in ddf as expected by double observer analysis. A erroneous error message can be created if they are not ordered correctly or worse. Thanks to Ainars Aunins for bringing this to our attention.
- * Added function create_document() which will run a shiny application interface to mrds and will create a knitr document from a template. The template currently is only for a single observer analysis and is behind on all of the features for the app which is fairly complete.
-
+* Tests for gamma detection functions
+* Observations are automatically ordered by object and observer fields (if included) in ddf as expected by double observer analysis. A erroneous error message can be created if they are not ordered correctly or worse. Thanks to Ainars Aunins for bringing this to our attention.
+* Added function create_document() which will run a shiny application interface to # mrds and will create a knitr document from a template. The template currently is only for a single observer analysis and is behind on all of the features for the app which is fairly complete.
-mrds 2.1.6
-----------
+# mrds 2.1.6
BUG FIXES
- * some key+adjustment models failed to converge due to bugs in the optimisation code (mainly unif+cosine models)
+
+* some key+adjustment models failed to converge due to bugs in the optimisation code (mainly unif+cosine models)
NEW FEATURES
- * optimisation tips help page at ?"mrds-opt"
+* optimisation tips help page at ?"mrds-opt"
-mrds 2.1.5
-------------
+# mrds 2.1.5
CHANGES
- * models with both adjustment terms and covariates are now allowed
- * mono.check function checks that a detection function is monotonic over its range (at the observed covariate combinations if covariates are included)
+* models with both adjustment terms and covariates are now allowed
+* mono.check function checks that a detection function is monotonic over its range (at the observed covariate combinations if covariates are included)
-
-
-mrds 2.1.4-5
-------------
+# mrds 2.1.4-5
CHANGES
- * new testthat changes test locations etc, this has been sorted out.
- * which= argument in plot.* now sorts the which first, so plots will always be in order
- * plot.ds is now more friendly to par() users, thanks to Jason Roberts for the pointer
+* new `testthat` changes test locations etc, this has been sorted out.
+* which= argument in plot.* now sorts the which first, so plots will always be in order
+* plot.ds is now more friendly to par() users, thanks to Jason Roberts for the pointer
BUG FIXES
- * uniform+cosine detection functions were ignored when using monotonicity constraints, now they can be used together
- * mono.strict=TRUE didn't automatically turn on mono=TRUE, extra logic to correct this
- * montonicity constraints did not use standardised (g(x)/g(0) detection functions, so if g(x)>1 monotonicity constraints were voilated. Now standardised detection functions are used. Thanks to Len Thomas for noticing this bug.
-
+* uniform+cosine detection functions were ignored when using monotonicity constraints, now they can be used together
+* mono.strict=TRUE didn't automatically turn on mono=TRUE, extra logic to correct this
+* montonicity constraints did not use standardised (g(x)/g(0) detection functions, so if g(x)>1 monotonicity constraints were voilated. Now standardised detection functions are used. Thanks to Len Thomas for noticing this bug.
-
-mrds 2.1.4-3
-------------
+# mrds 2.1.4-3
BUG FIX
- * predict.io.fi did not work for new data (thanks to Len Thomas and Phil Hammond for pointing this out)
+* predict.io.fi did not work for new data (thanks to Len Thomas and Phil Hammond for pointing this out)
CHANGES
- * general documentation updates
- * simplication and re-structuring of internals
+* general documentation updates
+* simplication and re-structuring of internals
+
+# mrds 2.1.4-3
-mrds 2.1.4-3
-------------
CHANGES
- * internal re-structuring of summary methods
- * more tests
+* internal re-structuring of summary methods
+* more tests
+
+# mrds 2.1.4-2
-mrds 2.1.4-2
-------------
CHANGES
- * plot.ds now has a new argument, if TRUE (default) it will create a new window for each plot.
- * general janitorial work inside plotting methods, removing and simplifying old code; (hopefully) no new features.
+* plot.ds now has a new argument, if TRUE (default) it will create a new window for each plot.
+* general janitorial work inside plotting methods, removing and simplifying old code; (hopefully) no new features.
+
+# mrds 2.1.4-1
-mrds 2.1.4-1
-------------
CHANGES
- * Warning now issued when truncation is set to the largest distance by default.
-
- * updated dht documentation
+* Warning now issued when truncation is set to the largest distance by default.
+* updated dht documentation
+
+# mrds 2.1.4
-mrds 2.1.4
-----------
CHANGES
* modified det.tables and plot.det.tables so it does not create and plot some tables depending on observer configuration (io,trial,removal).
-
* to plot functions (other than plot.ds) added argument subtitle=TRUE (default). It can be either TRUE, FALSE. If TRUE it shows sub-titles for plot type. If FALSE, no subtitles are shown. With this argument it is possible to get subtitles without main title.
-
* set iterlimit=1 in call to rem.glm from ddf.rem.fi to prevent convergence issues in getting starting values.
+* created average.line.cond and it is now used in place of calcp.# mrds which was computing average line for conditional detection function by weighting values by estimated population proportions for each covariate value. It is now weighted by sample proportions (mean value).
-* created average.line.cond and it is now used in place of calcp.mrds which was computing average line for conditional detection function by weighting values by estimated population proportions for each covariate value. It is now weighted by sample proportions (mean value).
+# mrds 2.1.3-1
-mrds 2.1.3-1
-----------
BUG FIXES
* patched dht.se so if vc1=NA it will not fail
-
* patched plot.ds to only issue dev.new when not using another graphics device so it plays nice with Distance.
-mrds 2.1.3
-----------
+# mrds 2.1.3
+
BUG FIXES
* patched bug in dht which was returning incorrect values in bysample for sample.area and Dhat.
-
* patched code in dht.se so it would skip over variance component for p when key=unif and p=1.
CHANGES
* modified code in detfct.fit.opt and io and rem functions to adapt to changes in optimx
-
* removed old depends statements to optimx and Rsolnp; uses import
-mrds 2.1.2
-------------
+# mrds 2.1.2
+
BUG FIXES
* fixed usage and example lines that were too long
-mrds 2.1.1
-------------
+# mrds 2.1.1
+
BUG FIXES
* for full independence methods, the calculation for the distance sampling component was for unbinned data only. Code has been added to compute this component correctly for binned data. This required changes to each of the ddf.x.fi routines and for the logistic integration routines.
@@ -364,26 +323,23 @@ BUG FIXES
CHANGES
* Modified flpt.lnl code to set integrals to 1E-25 if <=0
-
* In integrate.pdf a vector argument for the integration range is converted to matrix if of length 2.
-
* ddf.gof will now use breaks set for binned data unless others are specified.
NEW FEATURES
* Added threshold detection functions ("th1" and "th2") which required some minor changes in other functions for summary/print.
-
* Added xlab and ylab arguments to plot functions to over-ride default labels
-mrds 2.1.0
-------------
+# mrds 2.1.0
+
CHANGES
* Modified DESCRIPTION so only R 2.15 or greater is allowed. Needed for optimHess jll(12/10/2012)
-mrds 2.0.9
-------------
+# mrds 2.0.9
+
NEW FEATURES
* New option plot=TRUE/FALSE in qqplot.ddf(), for when you only want the K-S and CvM test statistics, not plotting. dlm(11/13/2012)
@@ -392,67 +348,48 @@ BUG FIXES
* Fixed problem when obs dataframe in call to dht (which links observations to samples and regions) contained fields also in observation dataframe. Now only fields needed from obs are selected before merge. dlm(11/13/2012)
-mrds 2.0.8
-------------
+# mrds 2.0.8
+
* Unchanged version sent out with Distance in summer 2012
-mrds 2.0.7
-------------
+# mrds 2.0.7
NEW FEATURES
* Restructured likelihood/integration code for fitting ds models
-
* Adjustment functions will now work with binned data. Code was added to assure that fields distbegin and distend are available if binned=TRUE and breaks are set as well.
-
* Added argument adj.exp which if set to TRUE will use key*exp(adj) rather than key*adj to keep f(x)>0
-
* Added following restrictions for adjustments: if uniform key, adj.scale must be "width"; if non-uniform key and adj.scale="width", doeachint set to TRUE because scale integration will not work.
-
* Changed code in several functions so a uniform key with no adjustment functions could be used.
-
* New option plot=TRUE/FALSE in qqplot.ddf(), for when you only want the K-S and CvM test statistics, not plotting.
BUG FIXES
* Fixed inconsistencies in use and documentation of showit argument
-
* Fixed a bug where groups were not recognised in dht() when the size column occurred in both model data and observation table. (Thanks to Darren Kidney for spotting this.)
-mrds 2.0.6
-------------
+# mrds 2.0.6
NEW FEATURES
* Example code for binned point count data added to help for ddf
-
* Modified ddf.rem.fi and ddf.io.fi to use starting values from iterative offset glm to make optimization more robust
-
* Added a restriction so no one attempts fitting adjustment functions with covariates.
-
* Added some code to assure all of the necessary fields are available for binned data (binned=TRUE).
-
BUG FIXES
* Patched create.ddfobj so that point counts with binned data would work properly
-
* Patched ddf.ds such that stored data in object$data has detected=1
-
* Patched ddf.io.fi to throw an error when optimx() does not converge
-
* Patched ddf.io.fi and ddf.rem.fi so inclusion of factor(observer) will work in formula
-
* Patched dht, dht.se and covered.region.dht so it would handle 0 observations
-
* Suppress package messages from optimx
-
* Patched fpt.lnl, flt.lnl, print.ddf, model.description, summary.ds, print.summary.ds and coef.io, coef.trial, coef.rem, plot.io, plot.trial, and plot.rem to handle uniform key function.
-mrds 2.0.5
-------------
+# mrds 2.0.5
NEW FEATURES
@@ -461,22 +398,17 @@ NEW FEATURES
BUG FIXES
* Fixed code in dht.se such that it uses sample size from detection model in Satterthwaite approximation rather than size of selected subset of observations.
-
* Fixed coef functions so they would return parameter estimates for adjustment functions if any.
-mrds 2.0.4
-------------
+# mrds 2.0.4
BUG FIXES
* Changed flt.var to compute variance of average p correctly for point transects.
-
* Numerous changes by dlm to optimization code
-
* Changes to documentation to remove non-ASCII characters
-mrds 2.0.3
------------
+# mrds 2.0.3
NEW FEATURES
@@ -485,11 +417,9 @@ NEW FEATURES
BUG FIXES
* Changes to det.tables and gof functions to use include.lowest=TRUE in calls to cut function
-
* Changed all usage of T and F to TRUE and FALSE
-mrds 2.0.2
------------
+# mrds 2.0.2
* For changes in 2.0.2 and earlier see ONEWS
diff --git a/R/flnl.grad.R b/R/flnl.grad.R
index e162762e..5d387cbf 100644
--- a/R/flnl.grad.R
+++ b/R/flnl.grad.R
@@ -1,3 +1,5 @@
+#' Gradients of negative log likelihood function
+#'
#' This function derives the gradients of the negative log likelihood function,
#' with respect to all parameters. It is based on the theory presented in
#' Introduction to Distance Sampling (2001) and Distance Sampling: Methods and
diff --git a/_pkgdown.yml b/_pkgdown.yml
new file mode 100644
index 00000000..5e0319c6
--- /dev/null
+++ b/_pkgdown.yml
@@ -0,0 +1,43 @@
+url: ~
+template:
+ bootstrap: 5
+ bslib:
+ bg: "#fcfaf2"
+ fg: "#14059e"
+ primary: "#0542a3"
+ base_font: {google: "Roboto"}
+ includes:
+ in_header: |
+
+
+reference:
+
+navbar:
+ bg: primary
+ structure:
+ right: [twitter, github]
+ components:
+ twitter:
+ icon: fa-twitter
+ href: https://twitter.com/distancesamp
+ aria-label: Twitter
+ left:
+ - text: Function reference
+ href: reference/index.html
+ - text: Articles
+ menu:
+ - text: Point and full independence
+ href: articles/mrds-golftees.html
+ - text: News
+ href: news/index.html
+
+footer:
+ structure:
+ right: donate
+ left: clarity
+ components:
+ donate: "If you wish to donate to development and maintenance, please email us."
+ clarity: "We improve our site and software support by using Microsoft Clarity to see
+ how you use our website. By using our site, you agree that we and Microsoft
+ can collect and use this data. Clarity is GDPR compliant."
+
diff --git a/docs/404.html b/docs/404.html
new file mode 100644
index 00000000..eea0e2c6
--- /dev/null
+++ b/docs/404.html
@@ -0,0 +1,81 @@
+
+
+
GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>. ++ +
Estimating g(0) comparing full and point independence models
+vignettes/mrds-golftees.Rmd
+ mrds-golftees.RmdThis example looks at mark-recapture distance sampling (MRDS) models. The first part of this exercise involves analysis of a survey of a known number of golf tees. This is intended mainly to familiarise you with the double-platform data structure and analysis features in the R function mrds (Laake, Borchers, Thomas, Miller, & Bishop, 2019).
To help understand the terminology using in MRDS and the output produced by mrds, there is a guide available at this link called Interpreting MRDS output: making sense of all the numbers.
The aims of this practical are to learn how to model
+These data come from a survey of golf tees which conducted by statistics students at the University of St Andrews. The data were collected along transect lines, 210 metres in total. A distance of 4 metres out from the centre line was searched and, for the purposes of this exercise, we assume that this comprised the total study area, which was divided into two strata. There were 250 clusters of tees in total and 760 individual tees in total.
+The population was independently surveyed by two observer teams. The following data were recorded for each detected group: perpendicular distance, cluster size, observer (team 1 or 2), ‘sex’ (males are yellow and females are green and golf tees occur in single-sex clusters) and ‘exposure’. Exposure was a subjective judgment of whether the cluster was substantially obscured by grass (exposure=0) or not (exposure=1). The lengths of grass varied along the transect line and the grass was slightly more yellow along one part of the line compared to the rest.
+The golf tee dataset is provided as part of the mrds package.
Open R and load the mrds package and golf tee dataset (called book.tee.data). The elements required for an MRDS analysis are contained within the object dataset. These data are in a hierarchical structure (rather than in a ‘flat file’ format) so that there are separate elements for observations, samples and regions. In the code below, each of these tables is extracted to avoid typing long names.
+library(knitr)
+library(mrds)
+# Access the golf tee data
+data(book.tee.data)
+# Investigate the structure of the dataset
+str(book.tee.data)## List of 4
+## $ book.tee.dataframe:'data.frame': 324 obs. of 7 variables:
+## ..$ object : num [1:324] 1 1 2 2 3 3 4 4 5 5 ...
+## ..$ observer: Factor w/ 2 levels "1","2": 1 2 1 2 1 2 1 2 1 2 ...
+## ..$ detected: num [1:324] 1 0 1 0 1 0 1 0 1 0 ...
+## ..$ distance: num [1:324] 2.68 2.68 3.33 3.33 0.34 0.34 2.53 2.53 1.46 1.46 ...
+## ..$ size : num [1:324] 2 2 2 2 1 1 2 2 2 2 ...
+## ..$ sex : num [1:324] 1 1 1 1 0 0 1 1 1 1 ...
+## ..$ exposure: num [1:324] 1 1 0 0 0 0 1 1 0 0 ...
+## $ book.tee.region :'data.frame': 2 obs. of 2 variables:
+## ..$ Region.Label: Factor w/ 2 levels "1","2": 1 2
+## ..$ Area : num [1:2] 1040 640
+## $ book.tee.samples :'data.frame': 11 obs. of 3 variables:
+## ..$ Sample.Label: num [1:11] 1 2 3 4 5 6 7 8 9 10 ...
+## ..$ Region.Label: Factor w/ 2 levels "1","2": 1 1 1 1 1 1 2 2 2 2 ...
+## ..$ Effort : num [1:11] 10 30 30 27 21 12 23 23 15 12 ...
+## $ book.tee.obs :'data.frame': 162 obs. of 3 variables:
+## ..$ object : int [1:162] 1 2 3 21 22 23 24 59 60 61 ...
+## ..$ Region.Label: int [1:162] 1 1 1 1 1 1 1 1 1 1 ...
+## ..$ Sample.Label: int [1:162] 1 1 1 1 1 1 1 1 1 1 ...
+
+# Extract the list elements from the dataset into easy-to-access objects
+detections <- book.tee.data$book.tee.dataframe # detection information
+region <- book.tee.data$book.tee.region # region info
+samples <- book.tee.data$book.tee.samples # transect info
+obs <- book.tee.data$book.tee.obs # links detections to transects and regionsExamine the columns in the detections data because it has a particular structure.
+# Check detections
+head(detections)## object observer detected distance size sex exposure
+## 1 1 1 1 2.68 2 1 1
+## 21 1 2 0 2.68 2 1 1
+## 2 2 1 1 3.33 2 1 0
+## 22 2 2 0 3.33 2 1 0
+## 3 3 1 1 0.34 1 0 0
+## 23 3 2 0 0.34 1 0 0
+The structure of the detection is as follows:
+object column,object occurs twice - once for observer 1 and once for observer 2,detected column indicates whether the object was seen (detected=1) or not seen (detected=0) by the observer,distance column and cluster size is in the size column (the same default names as for the ds function).To ensure that the variables sex and exposure are treated correctly, define them as factor variables.
We will start by analysing these data assuming that Observer 2 was generating trials for Observer 1 but not vice versa, i.e. trial configuration where Observer 1 is the primary and Observer 2 is the tracker. (The data could also be analysed in independent observer configuration - you are welcome to try this for yourself). We begin by assuming full independence (i.e. detections between observers are independent at all distances): this requires only a mark-recapture (MR) model and, to start with, perpendicular distance will be included as the only covariate.
+
+# Fit trial configuration with full independence model
+fi.mr.dist <- ddf(method='trial.fi', mrmodel=~glm(link='logit',formula=~distance),
+ data=detections, meta.data=list(width=4))mrds output
+Having fitted the model, we can create tables summarizing the detection data. In the commands below, the tables are created using the det.tables function and saved to detection.tables.
+# Create a set of tables summarizing the double observer data
+detection.tables <- det.tables(fi.mr.dist)
+# Print these detection tables
+print(detection.tables)##
+## Observer 1 detections
+## Detected
+## Missed Detected
+## [0,0.4] 1 25
+## (0.4,0.8] 2 16
+## (0.8,1.2] 2 16
+## (1.2,1.6] 6 22
+## (1.6,2] 5 9
+## (2,2.4] 2 10
+## (2.4,2.8] 6 12
+## (2.8,3.2] 6 9
+## (3.2,3.6] 2 3
+## (3.6,4] 6 2
+##
+## Observer 2 detections
+## Detected
+## Missed Detected
+## [0,0.4] 4 22
+## (0.4,0.8] 1 17
+## (0.8,1.2] 0 18
+## (1.2,1.6] 2 26
+## (1.6,2] 1 13
+## (2,2.4] 2 10
+## (2.4,2.8] 3 15
+## (2.8,3.2] 4 11
+## (3.2,3.6] 2 3
+## (3.6,4] 1 7
+##
+## Duplicate detections
+##
+## [0,0.4] (0.4,0.8] (0.8,1.2] (1.2,1.6] (1.6,2] (2,2.4] (2.4,2.8] (2.8,3.2]
+## 21 15 16 20 8 8 9 5
+## (3.2,3.6] (3.6,4]
+## 1 1
+##
+## Observer 1 detections of those seen by Observer 2
+## Missed Detected Prop. detected
+## [0,0.4] 1 21 0.9545455
+## (0.4,0.8] 2 15 0.8823529
+## (0.8,1.2] 2 16 0.8888889
+## (1.2,1.6] 6 20 0.7692308
+## (1.6,2] 5 8 0.6153846
+## (2,2.4] 2 8 0.8000000
+## (2.4,2.8] 6 9 0.6000000
+## (2.8,3.2] 6 5 0.4545455
+## (3.2,3.6] 2 1 0.3333333
+## (3.6,4] 6 1 0.1428571
+The information in detection summary tables can be plotted, but, in the interest of space, only one (out of six possible plots) is shown (Figure 1).
+
+# Plot detection information, change number to see other plots
+plot(detection.tables, which=1)
+Figure 1: Detection distances for observer 1 +
+The plot numbers are:
+Note that if an independent observer configuration had been chosen, all plots would be available.
+A summary of the detection function model is available using the summary function. The Q-Q plot has the same interpretation as a Q-Q plot in a conventional, single platform analysis (Figure 2).
+# Produce a summary of the fitted detection function object
+summary(fi.mr.dist)##
+## Summary for trial.fi object
+## Number of observations : 162
+## Number seen by primary : 124
+## Number seen by secondary (trials) : 142
+## Number seen by both (detected trials): 104
+## AIC : 452.8094
+##
+##
+## Conditional detection function parameters:
+## estimate se
+## (Intercept) 2.900233 0.4876238
+## distance -1.058677 0.2235722
+##
+## Estimate SE CV
+## Average p 0.6423252 0.04069410 0.06335435
+## Average primary p(0) 0.9478579 0.06109656 0.06445750
+## N in covered region 193.0486185 15.84826582 0.08209469
+
+# Produce goodness of fit statistics and a qq plot
+gof.result <- ddf.gof(fi.mr.dist,
+ main="Full independence, trial configuration\ngoodness of fit Golf tee data")
+Figure 2: Fitted detection function for full independence, trial mode. +
+
+# Extract chi-square statistics for reporting
+chi.distance <- gof.result$chisquare$chi1$chisq
+chi.markrecap <- gof.result$chisquare$chi2$chisq
+chi.total <- gof.result$chisquare$pooled.chiAbbreviated \(\chi^2\) goodness-of-fit assessment shows the \(\chi^2\) contribution from the distance sampling model to be 11.5 and the \(\chi^2\) contribution from the mark-recapture model to be 3.4. The combination of these elements produces a total \(\chi^2\) of 14.9 with 17 degrees of freedom, resulting in a \(p\)-value of 0.604
+The (two) detection functions can be plotted (Figure 3).
+ +
+Figure 3: Observer 1 detection function (left) and conditional detection probabilty plot (right). +
+The plot labelled
+There is some evidence of unmodelled heterogeneity in that the fitted line in the left-hand plot declines more slowly than the histogram as the distance increases.
+Abundance is estimated using the dht function. In this function, we need to supply information about the transects and survey regions.
+# Calculate density estimates using the dht function
+tee.abund <- dht(model=fi.mr.dist, region.table=region, sample.table=samples, obs.table=obs)
+# Print out results in a nice format
+knitr::kable(tee.abund$individuals$summary, digits=2,
+ caption="Survey summary statistics for golftees")| Region | +Area | +CoveredArea | +Effort | +n | +k | +ER | +se.ER | +cv.ER | +mean.size | +se.mean | +
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | +1040 | +1040 | +130 | +229 | +6 | +1.76 | +0.12 | +0.07 | +3.18 | +0.21 | +
| 2 | +640 | +640 | +80 | +152 | +5 | +1.90 | +0.33 | +0.18 | +2.92 | +0.23 | +
| Total | +1680 | +1680 | +210 | +381 | +11 | +1.81 | +0.15 | +0.08 | +3.07 | +0.15 | +
+knitr::kable(tee.abund$individuals$N, digits=2,
+ caption="Abundance estimates for golftee population with two strata")| Label | +Estimate | +se | +cv | +lcl | +ucl | +df | +
|---|---|---|---|---|---|---|
| 1 | +356.52 | +32.35 | +0.09 | +294.54 | +431.53 | +17.13 | +
| 2 | +236.64 | +44.14 | +0.19 | +147.33 | +380.09 | +5.06 | +
| Total | +593.16 | +60.38 | +0.10 | +478.32 | +735.57 | +16.06 | +
The estimated abundance is 593 (recall that the true abundance is 760) and so this estimate is negatively biased. The 95% confidence interval does not include the true value.
+How about including the other covariates, size, sex and exposure, in the MR model? Which MR model would you use? In the command below, distance and sex are included in the detection function - remember sex was defined as a factor earlier on.
In the code below, all possible models (excluding interaction terms) are fitted.
+
+# Full independence model
+# Set up list with possible models
+mr.formula <- c("~distance","~distance+size","~distance+sex","~distance+exposure",
+ "~distance+size+sex","~distance+size+exposure","~distance+sex+exposure",
+ "~distance+size+sex+exposure")
+num.mr.models <- length(mr.formula)
+# Create dataframe to store results
+fi.results <- data.frame(MRmodel=mr.formula, AIC=rep(NA,num.mr.models))
+# Loop through all MR models
+for (i in 1:num.mr.models) {
+ fi.model <- ddf(method='trial.fi',
+ mrmodel=~glm(link='logit',formula=as.formula(mr.formula[i])),
+ data=detections, meta.data=list(width=4))
+ fi.results$AIC[i] <- summary(fi.model)$aic
+}
+# Calculate delta AIC
+fi.results$deltaAIC <- fi.results$AIC - min(fi.results$AIC)
+# Order by delta AIC
+fi.results <- fi.results[order(fi.results$deltaAIC), ]
+# Print results in pretty way
+knitr::kable(fi.results, digits=2)| + | MRmodel | +AIC | +deltaAIC | +
|---|---|---|---|
| 7 | +~distance+sex+exposure | +405.68 | +0.00 | +
| 8 | +~distance+size+sex+exposure | +407.40 | +1.72 | +
| 4 | +~distance+exposure | +433.72 | +28.04 | +
| 3 | +~distance+sex | +434.41 | +28.74 | +
| 6 | +~distance+size+exposure | +435.33 | +29.65 | +
| 5 | +~distance+size+sex | +436.02 | +30.34 | +
| 1 | +~distance | +452.81 | +47.13 | +
| 2 | +~distance+size | +454.58 | +48.91 | +
+# Fit chosen model
+fi.mr.dist.sex.exp <- ddf(method='trial.fi', mrmodel=~glm(link='logit',formula=~distance+sex+exposure),
+ data=detections, meta.data=list(width=4))We see that the preferred model contains distance + sex + exposure so check the goodness-of-fit statistics (Figure 4) and detection function plots (Figure 5).
+# Check goodness-of-fit
+ddf.gof(fi.mr.dist.sex.exp, main="FI trial mode\nMR=dist+sex+exp")
+Figure 4: Preferred model goodness of fit. +
+##
+## Goodness of fit results for ddf object
+##
+## Chi-square tests
+##
+## Distance sampling component:
+## [0,0.4] (0.4,0.8] (0.8,1.2] (1.2,1.6] (1.6,2] (2,2.4] (2.4,2.8]
+## Observed 25.000 16.000 16.000 22.000 9.000 10.000 12.000
+## Expected 20.276 19.341 18.074 16.345 14.083 11.511 9.046
+## Chisquare 1.101 0.577 0.238 1.957 1.834 0.198 0.964
+## (2.8,3.2] (3.2,3.6] (3.6,4] Total
+## Observed 9.000 3.000 2.000 124.000
+## Expected 6.915 5.044 3.366 124.000
+## Chisquare 0.629 0.828 0.554 8.881
+##
+## No degrees of freedom for test
+##
+## Mark-recapture component:
+## Capture History 01
+## [0,0.4] (0.4,0.8] (0.8,1.2] (1.2,1.6] (1.6,2] (2,2.4] (2.4,2.8]
+## Observed 1 2 2 6 5 2 6
+## Expected 1 2 2 6 4 4 6
+## Chisquare 0 0 0 0 0 1 0
+## (2.8,3.2] (3.2,3.6] (3.6,4] Total
+## Observed 6 2 6 38
+## Expected 7 2 5 38
+## Chisquare 0 0 0 2
+## Capture History 11
+## [0,0.4] (0.4,0.8] (0.8,1.2] (1.2,1.6] (1.6,2] (2,2.4] (2.4,2.8]
+## Observed 21 15 16 20 8 8 9
+## Expected 21 15 16 20 9 6 9
+## Chisquare 0 0 0 0 0 1 0
+## (2.8,3.2] (3.2,3.6] (3.6,4] Total
+## Observed 5 1 1 104
+## Expected 4 1 2 104
+## Chisquare 0 0 1 2
+##
+##
+## Total chi-square = 12.205 P = 0.66344 with 15 degrees of freedom
+##
+## Distance sampling Cramer-von Mises test (unweighted)
+## Test statistic = 0.0976947 p-value = 0.596294
+
+
+Figure 5: Detection functions for full independence model with distance, sex and exposure in MR component. +
+And produce abundance estimates.
+
+# Get abundance estimates
+tee.abund.fi <- dht(model=fi.mr.dist.sex.exp, region.table=region,
+ sample.table=samples, obs.table=obs)
+# Print results
+print(tee.abund.fi)## Abundance and density estimates from distance sampling
+## Variance : R2, N/L
+##
+## Summary statistics
+##
+## Region Area CoveredArea Effort n k ER se.ER cv.ER
+## 1 1 1040 1040 130 72 6 0.5538462 0.02926903 0.05284685
+## 2 2 640 640 80 52 5 0.6500000 0.08292740 0.12758061
+## 3 Total 1680 1680 210 124 11 0.5904762 0.03641856 0.06167659
+##
+## Summary for clusters
+##
+## Abundance:
+## Region Estimate se cv lcl ucl df
+## 1 1 119.28976 14.18666 0.1189260 91.64685 155.2704 10.12494
+## 2 2 98.17731 18.59356 0.1893876 63.58200 151.5961 7.83844
+## 3 Total 217.46707 26.05226 0.1197987 169.90391 278.3451 23.21368
+##
+## Density:
+## Region Estimate se cv lcl ucl df
+## 1 1 0.1147017 0.01364102 0.1189260 0.08812198 0.1492985 10.12494
+## 2 2 0.1534020 0.02905244 0.1893876 0.09934687 0.2368689 7.83844
+## 3 Total 0.1294447 0.01550730 0.1197987 0.10113328 0.1656816 23.21368
+##
+## Summary for individuals
+##
+## Abundance:
+## Region Estimate se cv lcl ucl df
+## 1 1 371.0397 37.86856 0.1020607 297.1733 463.2666 11.904084
+## 2 2 279.7141 67.25221 0.2404320 154.4960 506.4208 5.482654
+## 3 Total 650.7538 82.72649 0.1271241 493.7469 857.6875 11.907393
+##
+## Density:
+## Region Estimate se cv lcl ucl df
+## 1 1 0.3567690 0.03641208 0.1020607 0.2857436 0.4454487 11.904084
+## 2 2 0.4370533 0.10508158 0.2404320 0.2414000 0.7912825 5.482654
+## 3 Total 0.3873535 0.04924196 0.1271241 0.2938970 0.5105283 11.907393
+##
+## Expected cluster size
+## Region Expected.S se.Expected.S cv.Expected.S
+## 1 1 3.110407 0.2740170 0.08809682
+## 2 2 2.849071 0.2211204 0.07761141
+## 3 Total 2.992425 0.1758058 0.05875027
+This model incorporates the effect of more variables causing the heterogeneity. The estimated abundance is 651 which is less biased than the previous estimate and the 95% confidence interval (494, 858) contains the true value.
+The model is a reasonable fit to the data (i.e. non-significant \(\chi^2\) and Cramer von Mises tests). This model has a lower AIC (405.7) than the model with only distance (452.81) and so is to be preferred.
+A less restrictive assumption than full independence is point independence, which assumes that detections are only independent on the transect centre line i.e. at perpendicular distance zero (Buckland, Laake, & Borchers, 2010).
+Determine if a simple point independence model is better than a simple full independence one. This requires that a distance sampling (DS) model is specified as well a MR model. Here we try a half-normal key function for the DS model (Figure 6).
+
+# Fit trial configuration with point independence model
+pi.mr.dist <- ddf(method='trial',
+ mrmodel=~glm(link='logit', formula=~distance),
+ dsmodel=~cds(key='hn'),
+ data=detections, meta.data=list(width=4))
+# Summary pf the model
+summary(pi.mr.dist)##
+## Summary for trial.fi object
+## Number of observations : 162
+## Number seen by primary : 124
+## Number seen by secondary (trials) : 142
+## Number seen by both (detected trials): 104
+## AIC : 140.8887
+##
+##
+## Conditional detection function parameters:
+## estimate se
+## (Intercept) 2.900233 0.4876238
+## distance -1.058677 0.2235722
+##
+## Estimate SE CV
+## Average primary p(0) 0.9478579 0.02409996 0.02542571
+##
+##
+##
+## Summary for ds object
+## Number of observations : 124
+## Distance range : 0 - 4
+## AIC : 311.1385
+## Optimisation : mrds (nlminb)
+##
+## Detection function:
+## Half-normal key function
+##
+## Detection function parameters
+## Scale coefficient(s):
+## estimate se
+## (Intercept) 0.6632435 0.09981249
+##
+## Estimate SE CV
+## Average p 0.5842744 0.04637627 0.07937412
+##
+##
+## Summary for trial object
+##
+## Total AIC value = 452.0272
+## Estimate SE CV
+## Average p 0.5538091 0.04615832 0.08334697
+## N in covered region 223.9038534 22.99246338 0.10268900
+
+# Produce goodness of fit statistics and a qq plot
+gof.results <- ddf.gof(pi.mr.dist,
+ main="Point independence, trial configuration\n goodness of fit Golftee data")
+Figure 6: Point independence model in trial configuration goodness of fit. +
+The AIC for this point independence model is 452.03 which is marginally smaller than the first full independence model that was fitted and hence is to be preferred.
+
+# Get abundance estimates
+tee.abund.pi <- dht(model=pi.mr.dist, region.table=region,
+ sample.table=samples, obs.table=obs)
+# Print results
+print(tee.abund.pi)## Abundance and density estimates from distance sampling
+## Variance : R2, N/L
+##
+## Summary statistics
+##
+## Region Area CoveredArea Effort n k ER se.ER cv.ER
+## 1 1 1040 1040 130 72 6 0.5538462 0.02926903 0.05284685
+## 2 2 640 640 80 52 5 0.6500000 0.08292740 0.12758061
+## 3 Total 1680 1680 210 124 11 0.5904762 0.03641856 0.06167659
+##
+## Summary for clusters
+##
+## Abundance:
+## Region Estimate se cv lcl ucl df
+## 1 1 130.00869 12.83042 0.09868894 106.66570 158.4601 48.427773
+## 2 2 93.89516 14.30894 0.15239268 66.25307 133.0701 8.094137
+## 3 Total 223.90385 23.21562 0.10368567 181.78333 275.7840 44.038262
+##
+## Density:
+## Region Estimate se cv lcl ucl df
+## 1 1 0.1250084 0.01233694 0.09868894 0.1025632 0.1523655 48.427773
+## 2 2 0.1467112 0.02235771 0.15239268 0.1035204 0.2079220 8.094137
+## 3 Total 0.1332761 0.01381882 0.10368567 0.1082044 0.1641571 44.038262
+##
+## Summary for individuals
+##
+## Abundance:
+## Region Estimate se cv lcl ucl df
+## 1 1 413.4999 44.00744 0.1064267 332.9536 513.5313 30.289360
+## 2 2 274.4628 53.42626 0.1946576 171.1754 440.0740 5.987499
+## 3 Total 687.9626 79.79844 0.1159924 542.4532 872.5040 25.993175
+##
+## Density:
+## Region Estimate se cv lcl ucl df
+## 1 1 0.3975960 0.04231485 0.1064267 0.3201477 0.4937801 30.289360
+## 2 2 0.4288481 0.08347854 0.1946576 0.2674615 0.6876156 5.987499
+## 3 Total 0.4095016 0.04749907 0.1159924 0.3228888 0.5193476 25.993175
+##
+## Expected cluster size
+## Region Expected.S se.Expected.S cv.Expected.S
+## 1 1 3.180556 0.2114629 0.06648615
+## 2 2 2.923077 0.1750319 0.05987935
+## 3 Total 3.072581 0.1391365 0.04528327
+This results in an estimated abundance of 688. Can we do better if more covariates are included in the DS model?
+To include covariates in the DS detection function, we need to specify an MCDS model as follows:
+
+# Fit the PI-trial model - DS sex and MR distance
+pi.mr.dist.ds.sex <- ddf(method='trial',
+ mrmodel=~glm(link='logit',formula=~distance),
+ dsmodel=~mcds(key='hn',formula=~sex),
+ data=detections, meta.data=list(width=4))Use the summary function to check the AIC and decide if you are going to include any additional covariates in the detection function.
Now try a point independence model that has the preferred MR model from your full independence analyses.
+
+# Point independence model, Include covariates in DS model
+# Use selected MR model, iterate across DS models
+ds.formula <- c("~size","~sex","~exposure","~size+sex","~size+exposure","~sex+exposure",
+ "~size+sex+exposure")
+num.ds.models <- length(ds.formula)
+# Create dataframe to store results
+pi.results <- data.frame(DSmodel=ds.formula, AIC=rep(NA,num.ds.models))
+# Loop through ds models - use selected MR model from earlier
+for (i in 1:num.ds.models) {
+ pi.model <- ddf(method='trial', mrmodel=~glm(link='logit',formula=~distance+sex+exposure),
+ dsmodel=~mcds(key='hn',formula=as.formula(ds.formula[i])),
+ data=detections, meta.data=list(width=4))
+ pi.results$AIC[i] <- summary(pi.model)$AIC
+}
+# Calculate delta AIC
+pi.results$deltaAIC <- pi.results$AIC - min(pi.results$AIC)
+# Order by delta AIC
+pi.results <- pi.results[order(pi.results$deltaAIC), ]
+knitr::kable(pi.results, digits = 2)| + | DSmodel | +AIC | +deltaAIC | +
|---|---|---|---|
| 2 | +~sex | +399.26 | +0.00 | +
| 6 | +~sex+exposure | +400.28 | +1.02 | +
| 4 | +~size+sex | +401.06 | +1.80 | +
| 7 | +~size+sex+exposure | +401.94 | +2.69 | +
| 1 | +~size | +407.92 | +8.66 | +
| 3 | +~exposure | +407.97 | +8.72 | +
| 5 | +~size+exposure | +409.89 | +10.63 | +
This indicates that sex should be included in the DS model. We do this and check the goodness of fit and obtain abundance (Figure 7).
+# Fit chosen model
+pi.ds.sex <- ddf(method='trial', mrmodel=~glm(link='logit',formula=~distance+sex+exposure),
+ dsmodel=~mcds(key='hn',formula=~sex), data=detections,
+ meta.data=list(width=4))
+summary(pi.ds.sex)##
+## Summary for trial.fi object
+## Number of observations : 162
+## Number seen by primary : 124
+## Number seen by secondary (trials) : 142
+## Number seen by both (detected trials): 104
+## AIC : 94.89911
+##
+##
+## Conditional detection function parameters:
+## estimate se
+## (Intercept) 0.7870962 0.6774633
+## distance -1.9435496 0.3706866
+## sex1 2.8059863 0.6828331
+## exposure1 3.6094527 0.7332797
+##
+## Estimate SE CV
+## Average primary p(0) 0.9697357 0.02018875 0.02081882
+##
+##
+##
+## Summary for ds object
+## Number of observations : 124
+## Distance range : 0 - 4
+## AIC : 304.3594
+## Optimisation : mrds (nlminb)
+##
+## Detection function:
+## Half-normal key function
+##
+## Detection function parameters
+## Scale coefficient(s):
+## estimate se
+## (Intercept) 0.2525377 0.1327279
+## sex1 0.5832341 0.2041094
+##
+## Estimate SE CV
+## Average p 0.5605421 0.04616356 0.0823552
+##
+##
+## Summary for trial object
+##
+## Total AIC value = 399.2585
+## Estimate SE CV
+## Average p 0.5435777 0.04643912 0.08543235
+## N in covered region 228.1182656 24.21303261 0.10614245
+
+# Check goodness-of-fit
+ddf.gof(pi.ds.sex, main="PI trial configutation\nGolfTee DS model sex")
+Figure 7: Goodness of fit of point independence model with sex covariate in the distance sampling component and distance, sex and exposure in the mr component. +
+##
+## Goodness of fit results for ddf object
+##
+## Chi-square tests
+##
+## Distance sampling component:
+## [0,0.4] (0.4,0.8] (0.8,1.2] (1.2,1.6] (1.6,2] (2,2.4] (2.4,2.8]
+## Observed 25.000 16.000 16.000 22.000 9.000 10.000 12.000
+## Expected 21.917 20.740 18.630 15.976 13.181 10.553 8.261
+## Chisquare 0.434 1.083 0.371 2.272 1.326 0.029 1.692
+## (2.8,3.2] (3.2,3.6] (3.6,4] Total
+## Observed 9.000 3.000 2.000 124.000
+## Expected 6.354 4.810 3.579 124.000
+## Chisquare 1.102 0.681 0.697 9.687
+##
+## P = 0.20699 with 7 degrees of freedom
+##
+## Mark-recapture component:
+## Capture History 01
+## [0,0.4] (0.4,0.8] (0.8,1.2] (1.2,1.6] (1.6,2] (2,2.4] (2.4,2.8]
+## Observed 1 2 2 6 5 2 6
+## Expected 1 2 2 6 4 4 6
+## Chisquare 0 0 0 0 0 1 0
+## (2.8,3.2] (3.2,3.6] (3.6,4] Total
+## Observed 6 2 6 38
+## Expected 7 2 5 38
+## Chisquare 0 0 0 2
+## Capture History 11
+## [0,0.4] (0.4,0.8] (0.8,1.2] (1.2,1.6] (1.6,2] (2,2.4] (2.4,2.8]
+## Observed 21 15 16 20 8 8 9
+## Expected 21 15 16 20 9 6 9
+## Chisquare 0 0 0 0 0 1 0
+## (2.8,3.2] (3.2,3.6] (3.6,4] Total
+## Observed 5 1 1 104
+## Expected 4 1 2 104
+## Chisquare 0 0 1 2
+##
+## MR total chi-square = 3.3242 P = 0.76719 with 6 degrees of freedom
+##
+##
+## Total chi-square = 13.012 P = 0.44692 with 13 degrees of freedom
+##
+## Distance sampling Cramer-von Mises test (unweighted)
+## Test statistic = 0.081285 p-value = 0.684457
+
+# Get abundance estimates
+tee.abund.pi.ds.sex <- dht(model=pi.ds.sex, region.table=region,
+ sample.table=samples, obs.table=obs)
+print(tee.abund.pi.ds.sex)## Abundance and density estimates from distance sampling
+## Variance : R2, N/L
+##
+## Summary statistics
+##
+## Region Area CoveredArea Effort n k ER se.ER cv.ER
+## 1 1 1040 1040 130 72 6 0.5538462 0.02926903 0.05284685
+## 2 2 640 640 80 52 5 0.6500000 0.08292740 0.12758061
+## 3 Total 1680 1680 210 124 11 0.5904762 0.03641856 0.06167659
+##
+## Summary for clusters
+##
+## Abundance:
+## Region Estimate se cv lcl ucl df
+## 1 1 125.7678 12.50301 0.0994134 102.97968 153.5987 43.661605
+## 2 2 102.3504 17.53164 0.1712904 68.75816 152.3544 7.394232
+## 3 Total 228.1183 25.15313 0.1102635 182.12587 285.7252 28.045408
+##
+## Density:
+## Region Estimate se cv lcl ucl df
+## 1 1 0.1209306 0.01202212 0.0994134 0.09901892 0.1476911 43.661605
+## 2 2 0.1599226 0.02739319 0.1712904 0.10743463 0.2380538 7.394232
+## 3 Total 0.1357847 0.01497210 0.1102635 0.10840826 0.1700745 28.045408
+##
+## Summary for individuals
+##
+## Abundance:
+## Region Estimate se cv lcl ucl df
+## 1 1 395.0545 36.33887 0.09198445 329.0893 474.2422 79.293122
+## 2 2 299.7763 65.43246 0.21827099 175.5600 511.8809 5.685162
+## 3 Total 694.8307 84.25522 0.12126006 537.2149 898.6902 15.167148
+##
+## Density:
+## Region Estimate se cv lcl ucl df
+## 1 1 0.3798601 0.03494122 0.09198445 0.3164320 0.4560021 79.293122
+## 2 2 0.4684004 0.10223822 0.21827099 0.2743125 0.7998140 5.685162
+## 3 Total 0.4135897 0.05015192 0.12126006 0.3197708 0.5349347 15.167148
+##
+## Expected cluster size
+## Region Expected.S se.Expected.S cv.Expected.S
+## 1 1 3.141141 0.2081675 0.06627129
+## 2 2 2.928920 0.1866200 0.06371632
+## 3 Total 3.045923 0.1371508 0.04502767
+This model estimated an abundance of 695, which is closest to the true value of all the models - it is still less than the true value indicating, perhaps, some unmodelled heterogeneity on the trackline (or perhaps just bad luck - remember this was only one survey).
+Was this complex modelling worthwhile? In this case, the estimated \(p(0)\) for the best model was 0.97 (which is very close to 1). If we ran a conventional distance sampling analysis, pooling the data from the two observers, we should get a very robust estimate of true abundance.
+