Extended dfuncEstim examples

Following is a series of dfuncEstim calls that show the calling parameters for popular distance sampling options.

library(Rdistance)
## Rdistance (version 3.1.2)
data("sparrowDetectionData")
data("sparrowSiteData")

Half-normal function with right truncation

dfunc <- dfuncEstim(formula = dist ~ 1
                  , detectionData = sparrowDetectionData
                  , w.hi = units::set_units(100, "m"))
dfunc
## Call: dfuncEstim(formula = dist ~ 1, detectionData =
##    sparrowDetectionData, w.hi = units::set_units(100, "m"))
## Coefficients:
##        Estimate  SE        z        p(>|z|)     
## Sigma  46.3587   2.549913  18.1805  7.365789e-74
plot(dfunc, col="grey")

Half-normal function, truncation, group sizes

dfunc <- dfuncEstim(formula = dist ~ groupsize(groupsize)
                  , detectionData = sparrowDetectionData
                  , w.hi = units::set_units(100, "m"))
dfunc
## Call: dfuncEstim(formula = dist ~ groupsize(groupsize), detectionData =
##    sparrowDetectionData, w.hi = units::set_units(100, "m"))
## Coefficients:
##        Estimate  SE        z        p(>|z|)     
## Sigma  46.3587   2.549913  18.1805  7.365789e-74
plot(dfunc, col="grey")

Half-normal function with factor covariate

Increase the maximum number of iterations if distance function convergence is an issue. The observer covariate is constant within transects and appears in the site data frame (sparrowSiteData), so the site data frame must be included in the call to dfuncEstim. Otherwise, the site data frame is not needed until abundance is estimated (in abundEstim).

dfuncObs <- dfuncEstim(formula = dist ~ observer
                     , detectionData = sparrowDetectionData
                     , siteData = sparrowSiteData
                     , w.hi = units::set_units(100, "m")
                     , control=RdistanceControls(maxIter=1000))
dfuncObs
## Call: dfuncEstim(formula = dist ~ observer, detectionData =
##    sparrowDetectionData, siteData = sparrowSiteData, w.hi =
##    units::set_units(100, "m"), control = RdistanceControls(maxIter =
##    1000))
## Coefficients:
##               Estimate    SE         z           p(>|z|)      
## (Intercept)    3.9157276  0.1325055  29.5514280  6.295424e-192
## observerobs2   0.0368698  0.2121217   0.1738144   8.620113e-01
## observerobs3  -0.0508131  0.1747992  -0.2906941   7.712853e-01
## observerobs4  -0.2904761  0.1718375  -1.6904117   9.094923e-02
## observerobs5  -0.1025525  0.1758776  -0.5830903   5.598325e-01
plot(dfuncObs, col="grey")

Hazard-rate function with covariate, truncation, and variable group sizes

Group sizes do not influence the estimated distance function. Only distance to the group is used. But, group sizes are associated with individual detections and are used to estimate abundance in function abundEstim. If abundance will be estimate and group sizes vary, Rdistance requires specification of a group size variable in the call to dfuncEstim. Here, groupsize is a column in the detection data frame and group sizes are specified using groupsize() in the formula.

dfuncObs <- dfuncEstim(formula = dist ~ observer + groupsize(groupsize)
                     , likelihood = "hazrate"
                     , detectionData = sparrowDetectionData
                     , siteData = sparrowSiteData
                     , w.hi = units::set_units(100, "m"))
dfuncObs
## Call: dfuncEstim(formula = dist ~ observer + groupsize(groupsize),
##    detectionData = sparrowDetectionData, siteData = sparrowSiteData,
##    likelihood = "hazrate", w.hi = units::set_units(100, "m"))
## Coefficients:
##               Estimate     SE         z           p(>|z|)      
## (Intercept)    3.86255658  0.1796040  21.5059637  1.369123e-102
## observerobs2   0.06544074  0.2884028   0.2269074   8.204957e-01
## observerobs3   0.05675877  0.2383286   0.2381534   8.117621e-01
## observerobs4  -0.39338347  0.2242432  -1.7542718   7.938394e-02
## observerobs5  -0.09897167  0.2135483  -0.4634627   6.430327e-01
## k              2.26440055  0.4846781   4.6719680   2.983274e-06
plot(dfuncObs, col="grey")

Hazard rate, covariate, group sizes, left and right truncation

Right truncation at 100 meters, left truncation at 20 meters. If x.scl is not specified as greater than w.lo, a warning is issued.

dfunc <- dfuncEstim(formula = dist ~ observer + groupsize(groupsize)
                     , likelihood = "hazrate"
                     , detectionData = sparrowDetectionData
                     , siteData = sparrowSiteData
                     , w.lo = units::set_units(20, "m")
                     , x.scl = units::set_units(20, "m")
                     , w.hi = units::set_units(100, "m"))
dfunc
## Call: dfuncEstim(formula = dist ~ observer + groupsize(groupsize),
##    detectionData = sparrowDetectionData, siteData = sparrowSiteData,
##    likelihood = "hazrate", w.lo = units::set_units(20, "m"), w.hi =
##    units::set_units(100, "m"), x.scl = units::set_units(20, "m"))
## Coefficients:
##               Estimate    SE          z            p(>|z|)     
## (Intercept)    3.8931772   0.2295965  16.95660259  1.720067e-64
## observerobs2   0.4785896   0.3884430   1.23207169  2.179223e-01
## observerobs3   0.2821896   0.2923237   0.96533261  3.343782e-01
## observerobs4  -3.1637197  47.3803897  -0.06677277  9.467626e-01
## observerobs5  -0.3483488   0.3284465  -1.06059519  2.888739e-01
## k              2.2649669   0.3463928   6.53872489  6.204553e-11
plot(dfunc, col="grey")

Hazard rate, covariate, group sizes, specify g(0)

Specify g(0) at the intercept by setting g.x.scl. This scales the entire distance function. Here, probability of detection on the transect is known to be 0.8.

dfunc <- dfuncEstim(formula = dist ~ observer + groupsize(groupsize)
                     , likelihood = "hazrate"
                     , detectionData = sparrowDetectionData
                     , siteData = sparrowSiteData
                     , g.x.scl = 0.8)
dfunc
## Call: dfuncEstim(formula = dist ~ observer + groupsize(groupsize),
##    detectionData = sparrowDetectionData, siteData = sparrowSiteData,
##    likelihood = "hazrate", g.x.scl = 0.8)
## Coefficients:
##               Estimate      SE         z            p(>|z|)      
## (Intercept)    3.999741284  0.1316422  30.38342405  9.095471e-203
## observerobs2   0.140084714  0.1737914   0.80605073   4.202136e-01
## observerobs3   0.004448866  0.1452435   0.03063039   9.755643e-01
## observerobs4  -0.423433582  0.1612356  -2.62617956   8.634925e-03
## observerobs5  -0.151863042  0.1508744  -1.00655270   3.141498e-01
## k              3.117839044  0.3313693   9.40895644   5.010870e-21
plot(dfunc, col="grey")