set.seed(87654)
x <- rnorm(1000, mean=0, sd=20)
x <- x[x >= 0]
x <- units::set_units(x, "mi")
Df <- data.frame(transectID = "A"
, distance = x
) |>
dplyr::nest_by( transectID
, .key = "detections") |>
dplyr::mutate(length = units::set_units(100,"km"))
attr(Df, "detectionColumn") <- "detections"
attr(Df, "obsType") <- "single"
attr(Df, "transType") <- "line"
attr(Df,'effortColumn') <- "length"
is.RdistDf(Df) # TRUE
dfunc <- Df |> dfuncEstim(distance ~ 1, likelihood="halfnorm")
plot(dfunc, nbins = 40, col="lightgrey", border=NA, vertLines=FALSE)
lines(dfunc, col="grey30", lwd=15)
lines(dfunc, col="grey90", lwd=5, lty = 2)
# Multiple lines
data(sparrowDfuncObserver)
obsLevs <- levels(sparrowDfuncObserver$data$observer)
plot(sparrowDfuncObserver
, vertLines = FALSE
, lty = 0
, plotBars = FALSE
, main="Detection by observer"
, legend = FALSE)
y <- lines(sparrowDfuncObserver
, newdata = data.frame(observer = obsLevs)
, col = palette.colors(length(obsLevs))
, lty = 1
, lwd = 4)
head(y) # values returned, with distances as column
Run the code above in your browser using DataLab