Dear Distance Sampling Group,
I am encountering an error when running the dht() function in R using the Distance package. Here is my code:
dht_results
<- dht(
model = ds.site,
sample.table = sample_table,
obs.table = obs_table,
region.table = region_table
)
However, I get the following error message:
Error in !model$meta.data$point : invalid argument type.
summary(ds.site) runs well. It shows:
str(ds.site) shows the structure as
..$ meta.data :List of 7 .. ..$ width : num 1000 .. ..$ point : logi FALSE
But, print(ds.site$meta.data) returns NULL
I tried reworking from start. Distance sampling analysis works well if I don't account effort. But I need to include effort. I am unsure how to resolve it.
My model (ds.site) was created using the ds() function. R version is R-4.4.1. I wanted to perform density-based effort calculation.
Any guidance on troubleshooting this error, re;iab;e website to study about working on this would be greatly
appreciated!
Thank you in advance for your help.
Sincerely
Sabi
Dear Eric,
Thank you so much.
I wanted to include the transect length information in the distance
sampling analysis as effort-based density estimation. For that I could not find
way to include it within the function for distanceSampling. There were errors
when included as effort = effort. So, I followed the way which used sample
table, observation table and region table (as below). summary(ds.site) does not
show density by below process. I wonder I should be missing or incorrect
somewhere.
Following other resources, I am trying all the ways; things work if
"dht" is not included in the process.
Alternately, I worked step by step (long process) by fitting detection function
with adjustments, then extracting N in covered region from the model,
calculating density using area of study site, calculating total effort (total
transect length) and then calculating density based on the effort. This results
Density (per km² per km
effort), identify model with lowest AIC. Is this correct process?
However,
I wanted to work on below R work flow which I reviewed in R documents for
distance sampling. While working for effort-based density estimation (in
distance sampling), I set function as below: I wonder if issue with transect id
(Sample.Label) might also cause error in this process, or my process of working
with dht function is wrong here. I have tried to include as much as possible below thinking if that would help more to figure out, and suggest anything I could do.
Thank you in advance for your time in guiding me. It means a lot to me to learn
this analysis in R.
distanceSampling <- function(survey) {
KEY <- c("hn", "unif", "hr")
ADJ <- c("cos", "herm", "poly")
AICs <- data.frame(ID = 1:9,
Key = NA,
Adjustment = NA,
AIC = NA)
N <- 0
for (i in 1:length(KEY)) {
for (j in 1:length(ADJ)) {
N <- N + 1
AICs$Key[N] <- KEY[i]
AICs$Adjustment[N] <- ADJ[j]
ds.fit <- ds(survey,
key = KEY[i],
adjustment = ADJ[j],
convert_units = 0.001)
AICs$AIC[N] <- as.numeric(AIC(ds.fit)[2])
print(paste('Finished ', round(N / 9 * 100, 2), "%", sep = ''))
}
}
AICs <- AICs[order(AICs$AIC), ]
return(AICs)
}
AICs <- distanceSampling(distance_sampling_data)
My distance_sampling_data has study_site_name, year, transect_id, species, perpendicular_distance( in meter), number_of_animal observed, and transect_length (in km).
# Calculated total effort as below
total_effort <- distance_sampling_data %>%
group_by(transect_id, study_site, year) %>%
summarise(Effort = sum(transect_length, na.rm = TRUE)) %>%
ungroup()
# Created sample table
sample_table <- data.frame(
Region.Label = total_effort$study_site,
Sample.Label = total_effort$transect_id,
Effort = total_effort$Effort
)
# Created observation table
obs_table <- data.frame(
Sample.Label = distance_sampling_data$transect_id,
Region.Label = distance_sampling_data$study_site,
distance = distance_sampling_data$perpendicular_distance
)
# Created region table
region_table <- data.frame(
Region.Label = unique(distance_sampling_data$study_site),
Area = 336
)
# Fitted the best model
ds.site <- ds(
distance_sampling_data,
key = AICs$Key[1],
adjustment = AICs$Adjustment[1],
truncation = 1000
)
summary(ds.site)
# Summary for distance analysis
# Number of observations : 182
# Distance range : 0 - 1000
#
# Model : Hazard-rate key function
# AIC : 2447.217
# Optimisation: mrds (nlminb)
#
# Detection function parameters
# Scale coefficient(s):
# estimate se
# (Intercept) 6.010397 0.142116
#
# Shape coefficient(s):
# estimate se
# (Intercept) 0.8206267 0.2156811
#
# Estimate SE CV
# Average p 0.5477412 0.04640994 0.08472968
# N in covered region 332.2737007 32.66447626 0.09830593
# Perform effort based density estimation
dht_results <- dht(
model = ds.site,
sample.table = sample_table,
obs.table = obs_table,
region.table = region_table
)
Error in !model$meta.data$point : invalid argument type