popTime: Population Time Plot

Description Usage Arguments Details Value See Also Examples

View source: R/plots.R

Description

plot method for objects of class popTime and popTimeExposure

Create a data frame for population time plots to give a visual representation of incidence density

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## S3 method for class 'popTime'
plot(x, ..., xlab = "Follow-up time", ylab = "Population",
  line.width = 1, line.colour = "grey80", point.size = 1,
  point.colour = "red", legend = FALSE, legend.position = c("bottom",
  "top", "left", "right"))

## S3 method for class 'popTimeExposure'
plot(x, ..., ncol = 1, xlab = "Follow-up time",
  ylab = "Population", line.width = 1, line.colour = "grey80",
  point.size = 1, point.colour = "red", legend = FALSE,
  legend.position = c("bottom", "top", "left", "right"))

popTime(data, time, event, censored.indicator, exposure)

checkArgsTimeEvent(data, time, event)

Arguments

x

an object of class popTime or popTimeExposure.

...

Ignored.

xlab, ylab, line.width, line.colour, point.size, point.colour, legend, legend.position

See par.

ncol

Number of columns.

data

a data.frame or data.table containing the source dataset.

time

a character string giving the name of the time variable. See Details.

event

a character string giving the name of the event variable contained in data. See Details. If event is a numeric variable, then 0 needs to represent a censored observation, 1 needs to be the event of interest. Integers 2, 3, ... and so on are treated as competing events. If event is a factor or character and censored.indicator is not specified, this function will assume the reference level is the censored indicator

censored.indicator

a character string of length 1 indicating which value in event is the censored. This function will use relevel to set censored.indicator as the reference level. This argument is ignored if the event variable is a numeric

exposure

a character string of length 1 giving the name of the exposure variable which must be contained in data. Default is NULL. This is used to produced exposure stratified plots. If an exposure is specified, popTime returns an object of class popTimeExposure

Details

It is assumed that data contains the two columns corresponding to the supplied time and event variables. If either the time or event argument is missing, the function looks for columns that contain the words "time", "event", or "status" in them (case insensitive). The function first looks for the time variable, then it looks for the event variable. This order of operation is important if for example the time variable is named "event time" and the event variable is named "event indicator". This function will first (automatically) find the time variable and remove this as a possibility from subsequent searches of the event variable. The following regular expressions are used for the time and event variables:

time

"[\s\W_]+time|^time\b"

event

"[\s\W_]+event|^event\b|[\s\W_]+status|^status\b"

This allows for "time" to be preceded or followed by one or more white space characters, one or more non-word characters or one or more underscores. For example, the following column names would be recognized by the function as the "time" variable: "time of death", "death_time", "Time", "time", "diagnosis_time", "time.diag", "diag__time". But the following will not be recognized: "diagtime","eventtime", "Timediag"

Value

The methods for plot return a population time plot, stratified by exposure status in the case of popTimeExposure.

The methods for plot return a population time plot, stratified by exposure status in the case of popTimeExposure.

An object of class popTime (or popTimeExposure if exposure is specified), data.table and data.frame in this order! The output of this function is to be used with the plot method for objects of class popTime or of class popTimeExposure, which will produce population time plots

See Also

plot.popTime, plot.popTimeExposure

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
data(bmtccr)
popTimeData <- popTime(data = bmtccr, time = "ftime", exposure = "D")
# p is an object of class gg and ggplot
p <- plot(popTimeData)
# you can further modify the object using all ggplot2 functions
# here we modify the number of y-tick labels
p + scale_y_continuous(breaks = seq(0, max(popTimeData$data$ycoord), 10))

## End(Not run)

casebase documentation built on May 29, 2017, 1:40 p.m.