Skip to content
Prev 6312 / 7420 Next

Halyomorpha halys; observation time-series irregular: regularized weekly capture rates

Hi:
On 6/7/21 11:44 AM, Enrico Gabrielli wrote:
It's still not clear. time interval in hours? or days?


Have a look at this code, using your example data:


library(dplyr)


Hh <- read.table(header = FALSE, text="2021-05-15 14:09:00??? 15
2021-05-16 10:34:00??? 2
2021-05-20 15:00:00??? 3
2021-05-23 08:30:00??? 23
2021-05-29 07:30:00??? 30
2021-05-29 19:00:00??? 25
2021-06-01 19:00:00??? 23
2021-06-05 12:52:00??? 92
2021-06-05 19:00:00??? 5")
colnames(Hh) <- c("Date", "Time", "Captures")

Hh$DateTime <- as.POSIXct(paste(Hh$Date, Hh$Time),
 ???????????????????????? format = "%Y-%m-%d %H:%M:%S",
 ???????????????????????? tz = "UTC") ??? ??? # What time zone??

# I assume time interval in days

# The first row must have timediff=0, since there is no previous DateTime

Hh$Timediff <- c(0, diff(Hh$DateTime)/24)
# Captures per hour
Hh$Capt.per.Day <- ifelse(Hh$Timediff == 0, 0, Hh$Captures/Hh$Timediff)

# Week number:
Hh$Weeknum <- strftime(Hh$DateTime, "%Y%W")
Hh
 ??????? Date???? Time Captures??????????? DateTime? Timediff 
Capt.per.Day Weeknum
1 2021-05-15 14:09:00?????? 15 2021-05-15 14:09:00 0.0000000 0.0000000? 
202119
2 2021-05-16 10:34:00??????? 2 2021-05-16 10:34:00 0.8506944 2.3510204? 
202119
3 2021-05-20 15:00:00??????? 3 2021-05-20 15:00:00 4.1847222 0.7168935? 
202120
4 2021-05-23 08:30:00?????? 23 2021-05-23 08:30:00 2.7291667 8.4274809? 
202120
5 2021-05-29 07:30:00?????? 30 2021-05-29 07:30:00 5.9583333 5.0349650? 
202121
6 2021-05-29 19:00:00?????? 25 2021-05-29 19:00:00 0.4791667 52.1739130? 
202121
7 2021-06-01 19:00:00?????? 23 2021-06-01 19:00:00 3.0000000 7.6666667? 
202122
8 2021-06-05 12:52:00?????? 92 2021-06-05 12:52:00 3.7444444 24.5697329? 
202122
9 2021-06-05 19:00:00??????? 5 2021-06-05 19:00:00 0.2555556 19.5652174? 
202122


# Now sum by wekknum

Hh_weekly <- Hh %>%

 ? group_by(Weeknum) %>%
 ? summarise(Hourly.Capt.per.Week = sum(Capt.per.Day)) %>%
 ? ungroup()

Hh_weekly
# A tibble: 4 x 2
 ? Weeknum Hourly.Capt.per.Week
 ? <chr>????????????????? <dbl>
1 202119????????????????? 2.35
2 202120????????????????? 9.14
3 202121???????????????? 57.2
4 202122???????????????? 51.8



Does that bring you any closer??