Message-ID: <461fe4f3a0b68ca81a105a055f5edf8a6b8d1581.camel@gmail.com>
Date: 2021-06-09T09:16:07Z
From: Enrico Gabrielli
Subject: Halyomorpha halys; observation time-series irregular: regularized weekly capture rates
In-Reply-To: <6f28db0e-527b-6e79-bf2c-be9dc09fd426@gmail.com>
Hi Micha
thanks to you I understood so many things!
But the result doesn't work.
So I tried padr
Here's how I worked, but unfortunately the pad function has problems,
it gives me an error:
> # variable monitoring time
> tempo <- as.POSIXct(c("2021-05-29 17:00:00 UTC","2021-06-05 10:52:00
> UTC","2021-06-01 17:00:00 UTC","2021-05-16 08:34:00 UTC","2021-06-05
> 17:00:00 UTC","2021-05-29 05:30:00 UTC","2021-05-23 06:30:00
> UTC","2021-05-20 13:00:00 UTC","2021-05-15 12:09:00 UTC","2021-06-06
> 19:18:00 UTC"))
> # variable capture of BMSB
> catture <- c(25,92,23,2,5,30,23,3,15,21,15,40,22)
>
> # resulting table
> library(data.table)
> arvaia_catture <- data.table(tempo,catture)
> # order by time
> arvaia_catture_order <- arvaia_catture[order(arvaia_catture$tempo)]
> # calculate the rate per hour of capture
> arvaia_catture_order$difftime_ora <-
> c(0,diff(arvaia_catture_order$tempo))
> arvaia_catture_order$catture_ora <-
> arvaia_catture_order$catture/arvaia_catture_order$difftime_ora
>
> # use of padr to fill the gap
> library(padr)
> arvaia_catture_ora <- thicken(arvaia_catture_order,interval = "hour")
> pad(arvaia_catture_ora,by=arvaia_catture_ora$tempo_hour)
I wrote to Edwin, the developer of padr.
He knows that in the end I will learn R! Since the money in the project
is scarce! Maybe I keep them for when more complex spatial-ecology
things have to be done
Il giorno lun, 07/06/2021 alle 13.37 +0300, Micha Silver ha scritto:
> Hi:
>
>
> On 6/7/21 11:44 AM, Enrico Gabrielli wrote:
> > Hello
> > I'm looking at if and how to find support with paid computer
> > scientists
> > because it is not possible for an agricultural technician in the
> > midst
> > of activities in the field, who does not know how to use R
> > solve this problem also through a mailing-list.
> > However it is right to complete the description of the problem,
> > maybe
> > you have ideas that I will give to the computer scientists that we
> > will
> > pay with the project
> > so I am not asking here for the solution, but only for ideas.
> >
> > This is an data example (really)
> > datetime capture
> > 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
> >
> > This is the results of two possibile solution
> > week simple SUM week right SUM week
> > 19 17 19,44027778
> > 20 26 52,91388889
> > 21 55 46,4375
> > 22 120 99,20833333
> >
> > simple is done with a simple sum by aggregate with weeknum
> > right is done with a it is done with the calculation of the ratio
> > between catches and time interval
>
> 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??
>
>
>
> > but this is done with a spreadsheet, but in order to automate the
> > generation of an html graph on the project server page, I need to
> > do
> > this with R
> >
> > I tested the xts package, and then I found lubridate and padr
> > interesting, but I stopped due to lack of time
> >