Comments (6)
Cheers for the feedback - really useful!
-
Re: tsibble - the "alpha alpha" version of incidence2 was actually built on top of tsibble. It is a really nice package! However because each row of inputs we deal with can be considered a unique observation there was little need for the
key
used in tsibble. It felt like we were adding unnecessary dependencies for a small subset of the functionality. At this stage, with dplyr and tibble still refining how best to extend their functions/classes, I'm wary of relying on an intermediate package in the implementation. Having said that we're definitely not unwilling to change. The underlying implementation is such that we could swap out for tsibble in future if everyone felt that was the way to go! -
In regards to aweek, tsibble is implemented in a way which lets you use the aweek package for grouping should you wish but I agree it would be a useful function to be implemented directly. If it helps I can dig out my code that shows you how to use aweek with tsibble.
-
On naming - I will definitely look in to that. @thibautjombart and I were only discussing this morning how now was the time to change any names from the original package.
from incidence2.
@aspina7 here you go. Do you mind if I post this on the tsibble
issue as well in case others are interested?
library(outbreaks)
library(dplyr, warn.conflicts = FALSE)
library(tsibble)
library(aweek)
library(vctrs)
library(lubridate, warn.conflicts = FALSE)
# bits for tsibble --------------------------------------------------------
index_valid.aweek <- function(x) {
TRUE
}
interval_pull.aweek <- function(x) {
wk <- as.double((as_date(x) - as_date("1969-12-29")) / 7)
nweeks <- tsibble:::gcd_interval(wk)
new_interval(week = nweeks)
}
vec_cast.double.aweek <- function(x, to, ...) {
as.double((as_date(x) - as_date("1969-12-29")) / 7)
}
# load data ---------------------------------------------------------------
dat_raw <- ebola_sim_clean$linelist
dat_ts <-
dat_raw %>%
as_tsibble(key = case_id, index = date_of_onset)
# aweek epiweek version ---------------------------------------------------
dat_ts %>%
group_by(hospital, outcome) %>%
index_by(epiweek = ~ date2week(., week_start = "Sunday", floor_day = TRUE)) %>%
group_by(hospital, outcome) %>%
summarise(count = n())
#> # A tsibble: 849 x 4 [1W]
#> # Key: hospital, outcome [18]
#> # Groups: hospital [6]
#> hospital outcome epiweek count
#> <fct> <fct> <aweek> <int>
#> 1 Connaught Hospital Death 2014-W22-1 3
#> 2 Connaught Hospital Death 2014-W23-1 3
#> 3 Connaught Hospital Death 2014-W24-1 1
#> 4 Connaught Hospital Death 2014-W25-1 6
#> 5 Connaught Hospital Death 2014-W26-1 4
#> 6 Connaught Hospital Death 2014-W27-1 1
#> 7 Connaught Hospital Death 2014-W28-1 4
#> 8 Connaught Hospital Death 2014-W29-1 6
#> 9 Connaught Hospital Death 2014-W30-1 4
#> 10 Connaught Hospital Death 2014-W31-1 12
#> # … with 839 more rows
Created on 2020-07-03 by the reprex package (v0.3.0)
from incidence2.
awesome thanks!
Nay dont mind at all - go for it.
(will close this issue)
from incidence2.
The underlying implementation is such that we could swap out for tsibble in future if everyone felt that was the way to go!
Fair - makes sense the tsibble key (while functional) has been a bit annoying at times!
If it helps I can dig out my code that shows you how to use aweek with tsibble.
oo yes please that would be awesome!
from incidence2.
hey @tjtnew just circling back to this, based on the other discussion above and the fix done over in tsibble. Worth switching incidence2 to use lubridate rather than aweek?
from incidence2.
hey @aspina7 I was actually looking at this this, will summarise where I'm at below:
- I'm trying to work towards the v1.0 release of incidence2 and a major part of this is standardising how the intervals / date groups work. Currently, only the week groupings (due to aweek) generate a proper s3 class that you can work with independently from the incidence dataframes.
- Short term my plan is to standardise all of the date groupings (week, month, quarter and year) and implement them with the vctrs package. This will mean I move away from
aweek
but may not necessitate using lubridate (my current rough implementation only uses thewday
function from there which I think I can avoid by converting Dates to POSIXlt and getting the weekday from there). The months and quarters groupings will then be implemented in a way similar to the implementation here https://github.com/DavisVaughan/datea. - Longer term, it looks like Davis Vaughan is working on a very cool package called clock. Once this is released I think all our date grouping functionality will be replaced by this. It looks like it's going to be a really well thought out packages for dealing with dates and datetimes!
from incidence2.
Related Issues (20)
- Should we only provide getters for the variable names (not values)?
- Should a `find_peaks()` like function be in incidence HOT 1
- Restore some of the header information for incidence2 objects HOT 1
- Add minimal `new_incidence()` constructor
- Should `complete_dates()` use a different default `by` argument for POSIXct dates? HOT 7
- Consider warning when incidence objects are created with POSIXct dates HOT 1
- Error: object 'date_onset' not found HOT 1
- Error: show_cases dont work HOT 9
- reinstate `day` interval HOT 1
- Document `day` interval in vignettes.
- `plot.incidence2()` fails with `grates_period` dates HOT 3
- Make makefile more usable by others
- Ensure data.table uses 2 threads max in docs and examples
- NA values in observations cause a value of NA to be returned HOT 10
- Document how to handle grouped line list columns HOT 4
- Allow user to suppress NA warning in count variables
- vignette documentation on building upon incidence2 HOT 2
- Fix formatting of old news entries HOT 1
- Rework the devel news entry HOT 1
- 2.3.0 release TODO
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from incidence2.