conversions: Conversion of incidence objects

Description Usage Arguments Details Author(s) See Also Examples

Description

These functions convert incidence objects into other classes.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## S3 method for class 'incidence'
as.data.frame(x, ..., long = FALSE)

as.incidence(x, ...)

## S3 method for class 'matrix'
as.incidence(x, dates = NULL, interval = NULL,
  isoweeks = TRUE, ...)

## S3 method for class 'data.frame'
as.incidence(x, dates = NULL, interval = NULL,
  isoweeks = TRUE, ...)

## S3 method for class 'numeric'
as.incidence(x, dates = NULL, interval = NULL,
  isoweeks = TRUE, ...)

Arguments

x

An incidence object, or an object to be converted as incidence (see details).

...

Further arguments passed to other functions (no used).

long

A logical indicating if the output data.frame should be 'long', i.e. where a single column containing 'groups' is added in case of data computed on several groups.

dates

A vector of dates, each corresponding to the (inclusive) lower limit of the bins.

interval

An integer indicating the time interval used in the computation of the incidence. If NULL, it will be determined from the first time interval between provided dates. If only one date is provided, it will trigger an error.

isoweeks

A logical indicating whether isoweeks should be used in the case of weekly incidence; defaults to TRUE.

Details

Conversion to incidence objects should only be done when the original dates are not available. In such case, the argument x should be a matrix corresponding to the $counts element of an incidence object, i.e. giving counts with time intervals in rows and named groups in columns. In the absence of groups, a single unnamed columns should be given. data.frame and vectors will be coerced to a matrix.

Author(s)

Thibaut Jombart [email protected], Rich Fitzjohn

See Also

the incidence() function to generate the 'incidence' objects.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## create fake data
data <- c(0,1,1,2,1,3,4,5,5,5,5,4,4,26,6,7,9)
sex <- sample(c("m","f"), length(data), replace=TRUE)

## get incidence per group (sex)
i <- incidence(data, groups = sex)
i
plot(i)

## convert to data.frame
as.data.frame(i)

## same, 'long format'
as.data.frame(i, long = TRUE)



## conversion from a matrix of counts to an incidence object
i$counts
new_i <- as.incidence(i$counts, i$dates)
new_i
all.equal(i, new_i)

incidence documentation built on Nov. 30, 2018, 4:23 p.m.