Skip to content

How to predict detection probabilities for observations on specific distances? #189

@wlangera

Description

@wlangera

Hi

I want to get detection probabilities for observations on specific distances, but I only manage to predict average detection probabilities.

Is there any way to do this?
In this example you see that I get the same value for 50 m and 150 m although the detection probability clearly decreases over distance.

# Load required library
library(Distance)
#> Loading required package: mrds
#> This is mrds 3.0.0
#> Built: R 4.4.1; ; 2024-11-04 02:50:10 UTC; windows
#> 
#> Attaching package: 'Distance'
#> The following object is masked from 'package:mrds':
#> 
#>     create.bins

# Set seed for reproducibility
set.seed(123)

# Simulate dataset
n <- 200  # Number of observations
truncation_distance <- 250  # Maximum detection distance (truncation)

# Generate distances with a higher probability of being detected at shorter distances
distances <- rexp(n, rate = 0.01)  # Exponential distribution for decreasing probability
distances <- distances[distances <= truncation_distance]  # Truncate at 250 meters

# Add a categorical covariate (e.g., habitat type)
habitat <- sample(c("forest", "grassland"), length(distances), replace = TRUE)

# Combine into a data frame
data <- data.frame(
  distance = distances,
  habitat = habitat
)

# View the first few rows of the simulated data
head(data)
#>     distance   habitat
#> 1  84.345726    forest
#> 2  57.661027 grassland
#> 3 132.905487    forest
#> 4   3.157736    forest
#> 5   5.621098    forest
#> 6  31.650122    forest

# Fit a detection function using the Distance package
ds_model <- ds(
  data = data,
  truncation = truncation_distance,
  key = "hn",  # Half-normal key function
  adjustment = NULL,  # No adjustment terms
  formula = ~habitat  # Include habitat as a cov
)
#> Fitting half-normal key function
#> AIC= 1952.067
#> No survey area information supplied, only estimating detection function.

# Visualise detection curve
plot(ds_model)

# Predict detection probability for custom distance
predict(ds_model,
        newdata = data.frame(distance = 50, habitat = "forest"))
#> $fitted
#> [1] 0.4669516

predict(ds_model,
        newdata = data.frame(distance = 150, habitat = "forest"))
#> $fitted
#> [1] 0.4669516

predict(ds_model$ddf,
        newdata = data.frame(distance = 150, habitat = "forest"),
        integrate = FALSE)
#> $fitted
#> [1] 0.4669516

Created on 2024-11-28 with reprex v2.1.1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions