| add.df.covar.line {mrds} | R Documentation |
Add covariate levels detection function plots
Description
Add a line or lines to a plot of the detection function which correspond to a a given covariate combination. These can be particularly useful when there is a small number of factor levels or if quantiles of a continuous covariate are specified.
Usage
add.df.covar.line(ddf, data, ndist = 250, pdf = FALSE, breaks = "Sturges", ...)
add_df_covar_line(ddf, data, ndist = 250, pdf = FALSE, breaks = "Sturges", ...)
Arguments
ddf |
a fitted detection function object. |
data |
a |
ndist |
number of distances at which to evaluate the detection function. |
pdf |
should the line be drawn on the probability density scale; ignored for line transects. |
breaks |
required to ensure that PDF lines are the right size, should
match what is supplied to original |
... |
extra arguments to give to |
Details
All covariates must be specified in data. Plots can become quite busy
when this approach is used. It may be useful to fix some covariates at their
median level and plot set values of a covariate of interest. For example
setting weather (e.g., Beaufort) to its median and plotting levels of
observer, then creating a second plot for a fixed observer with levels of
weather.
Arguments to lines are supplied in ... and aesthetics like
line type (lty), line width (lwd) and colour (col) are
recycled. By default lty is used to distinguish between the lines. It
may be useful to add a legend to the plot (lines are plotted
in the order of data).
Value
invisibly, the values of detectability over the truncation range.
Author(s)
David L Miller
Examples
## Not run:
# fit an example model
data(book.tee.data)
egdata <- book.tee.data$book.tee.dataframe
result <- ddf(dsmodel = ~mcds(key = "hn", formula = ~sex),
data = egdata[egdata$observer==1, ], method = "ds",
meta.data = list(width = 4))
# make a base plot, showpoints=FALSE makes the plot less busy
plot(result, showpoints=FALSE)
# add lines for sex one at a time
add.df.covar.line(result, data.frame(sex=0), lty=2)
add.df.covar.line(result, data.frame(sex=1), lty=3)
# add a legend
legend(3, 1, c("Average", "sex==0", "sex==1"), lty=1:3)
# alternatively we can add both at once
# fixing line type and varying colour
plot(result, showpoints=FALSE)
add.df.covar.line(result, data.frame(sex=c(0,1)), lty=1,
col=c("red", "green"))
# add a legend
legend(3, 1, c("Average", "sex==0", "sex==1"), lty=1,
col=c("black", "red", "green"))
## End(Not run)