lines.dfunc: lines.dfunc - Lines method for distance (detection) functions

View source: R/lines.dfunc.R

lines.dfuncR Documentation

lines.dfunc - Lines method for distance (detection) functions

Description

Lines method for objects of class 'dfunc'. Distance function line methods add distance functions to existing plots.

Usage

## S3 method for class 'dfunc'
lines(x, newdata = NULL, ...)

Arguments

x

An estimated distance function resulting from a call to dfuncEstim.

newdata

Data frame similar to the newdata parameter to lm containing new values for covariates in the distance function. One distance function is computed and plotted for each row in the data frame. If newdata is NULL, the routine computes the mean of all numeric covariates in the distance function and the mode of all factor covariates in the distance function. The new mean and mode vector is used to predict and plot a distance function.

...

Parameters to lines used to control attributes like color, line width, line type, etc.

Value

A data frame containing the x and y coordinates of the plotted line(s) is returned invisibly.

See Also

dfuncEstim, plot.dfunc, print.abund

Examples

set.seed(87654)
x <- rnorm(1000, mean=0, sd=20)
x <- x[x >= 0]
x <- units::set_units(x, "mi")
dfunc <- dfuncEstim(x~1, likelihood="halfnorm")
plot(dfunc, nbins = 40, col="lightgrey", border=NA, vertLines=FALSE)
lines(dfunc, col="grey", lwd=15)
lines(dfunc, col="black", lwd=5, lty = 2)

# Multiple lines 
data(sparrowDetectionData)
data(sparrowSiteData)
dfuncObs <- dfuncEstim(formula = dist ~ observer 
                     , likelihood = "halfnorm"
                     , detectionData = sparrowDetectionData
                     , siteData = sparrowSiteData)
plot(dfuncObs
   , vertLines = FALSE
   , lty = 0
   , col = c("grey","lightgrey")
   , border=NA
   , main="Detection by observer"
   , legend = FALSE)
y <- lines(dfuncObs
   , newdata = data.frame(observer = levels(sparrowSiteData$observer))
   , col = palette.colors(length(levels(sparrowSiteData$observer)))
   , lty = 1
   , lwd = 4)
head(y) # values returned, same as predict method


Rdistance documentation built on July 9, 2023, 6:46 p.m.