aggregation of irregular interval time-series

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

aggregation of irregular interval time-series

Enrico Gabrielli
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: aggregation of irregular interval time-series

Rui Barradas
Hello,

I'm not getting your simple sum:


arvaia_catture_order[, week := as.integer(format(tempo, "%U"))]
aggregate(catture ~ week, arvaia_catture_order, sum)
#  week catture
#1   19      15
#2   20       5
#3   21      78
#4   22     120


Can you explain your result better?

Hope this helps,

Rui Barradas

Às 18:57 de 09/06/21, Enrico Gabrielli escreveu:

> Hello
> I just registered on the list.
> I am an agricultural technician and I am collaborating on a research
> project on agroforestry and Brown Marmorated Stink Bug (Halyomorpha
> halys, abbreviated BMSB).
>
> Through kobotoolbox we are collecting data of catches in traps on
> farms. Farms register inconsistently.
> I am trying to use packages for irregular time series.
>
> Here an exemple
> the data:
> # variable monitoring time as register an import from kobotoolbox
> 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"))
> # variable capture of BMSB
> catture <- c(25,92,23,2,5,30,23,3,15)
> # resulting table
> library(data.table)
> arvaia_catture <- data.table(tempo,catture)
> # order by time
> arvaia_catture_order <- arvaia_catture[order(arvaia_catture$tempo)]
>
> the catches refer to an interval, which goes from the previous
> monitoring up to the one recorded on the date
> our aim is to calculate the weekly catch
> also when a farmer, for example, enters the data on Thursday and
> Tuesday
> of the following week, on Tuesday in the trap he will find individuals
> who were also captured on Friday and Saturday, which formally are to be
> considered in the previous week.
>
> With the data of the example
> the results (with a spreadsheet) is
> two possibile solution
> week            simple SUM week         right SUM week
> 19      17      19,44027778
> 20      26      52,91388889
> 21      55      46,4375integrand_2 <- function(x) {0.62 * (1/x)}

integrate(integrand, lower = , upper = 5)

> 22      120     99,20833333
> The right SUM week is right!
>
> I have made several attempts
> with lubridate, padr, xts
> but the last one seems interesting to me
> with DTSg
> doing
> x_periodic <- alter(x,na.status = 'explicit',from="2021-05-15
> 12:00:00",by="min")
> colapply(x_periodic, fun = interpolateLinear)
> I managed to create a vector with all interpolated hours
> but with DTSg I still can't aggregate by week
>
> Has anyone on the list ever faced such a problem?
>
> Thank you
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: aggregation of irregular interval time-series

Bert Gunter-2
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: aggregation of irregular interval time-series

Enrico Gabrielli
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: aggregation of irregular interval time-series

Enrico Gabrielli
CONTENTS DELETED
The author has deleted this message.