You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a suggestion to make assess_temporal_independence() faster using more vectorial approach and more basic R functions. It's a slightly modified version with only a vector timestamp rather than the whole data.frame for increased modularity.
Let me know if you're intrested and I can create a PR.
#' Assess temporal independence#'#' @param timestamp A vector of datetime (or numeric in minutes)#' @param minDeltaTime_dur: Duration in minutes between records of the same#' species at the same station to be considered independent.#' @param deltaTimeComparedTo: Character, `"lastIndependentRecord"` or#' `"lastRecord"`.#' For two records to be considered independent, must the second one be at#' least `minDeltaTime` minutes after the last independent record of the same#' species (`deltaTimeComparedTo = "lastIndependentRecord"`), or#' `minDeltaTime` minutes after the last record (`deltaTimeComparedTo =#' "lastRecord"`)?#' If `minDeltaTime` is 0, `deltaTimeComparedTo` should be NULL.#' @noRdassess_temporal_independence<-function(timestamp, minDeltaTime_dur=60, deltaTimeComparedTo="lastRecord") {
# Convert to numerict<- as.numeric(timestamp)
# Compute for lastRecord:# Are idpt if the duration since last record is greater than minDeltaTime_dur. First record is always a new eventindependent<- c(T, diff(t) >minDeltaTime_dur*60)
# For lastIndependentRecord, it's a bit more complicatedif (deltaTimeComparedTo=="lastIndependentRecord") {
# keep a copy to compare later in case.independent_old<-independent# lastIndependentRecord can only have more sequence/event than lastRecord, so we start from lastRecord sequence and split new sequences within if required.# cumsum(independent) allow to create groups based on the independent vectorindependent<- split(t, cumsum(independent), drop=FALSE) %>%
lapply(\(tt){
idpt<- rep(F, length(tt))
continue<-Ti<-1while (continue) {
idpt[i] <-T# findInterval is a fast way to compute the next index of the +minDeltaTime_dur record which will make the new sequence.e<- findInterval(tt[i] +minDeltaTime_dur*60, tt)
if (e== length(idpt)) {
continue<-F
} else {
i<-e+1
}
}
return(idpt)
}) %>%
unlist() %>%
unname()
# Should always be zero# sum(independent_old & !independent)# New group/event/sequence# sum(!independent_old & independent)
}
return(independent)
}
The text was updated successfully, but these errors were encountered:
camtraptor/R/get_record_table.R
Line 372 in 0559ca0
Here is a suggestion to make
assess_temporal_independence()
faster using more vectorial approach and more basic R functions. It's a slightly modified version with only a vectortimestamp
rather than the whole data.frame for increased modularity.Let me know if you're intrested and I can create a PR.
The text was updated successfully, but these errors were encountered: