survData: Creates a data set for survival analysis

View source: R/survData.R

survDataR Documentation

Creates a data set for survival analysis

Description

This function creates a survData object from experimental data provided as a data.frame. The resulting object can then be used for plotting and model fitting. It can also be used to generate individual-time estimates.

The survDataCheck function can be used to check if an object containing survival data is formatted according to the expectations of the survData function.

Usage

survData(x)

survDataCheck(data, diagnosis.plot = FALSE)

Arguments

x

a data.frame containing the following four columns:

  • replicate: a vector of any class numeric, character or factor for replicate identification. A given replicate value should identify the same group of individuals followed in time

  • conc: a vector of class numeric with tested concentrations (positive values, may contain NAs)

  • time: a vector of class integer with time points, minimal value must be 0

  • Nsurv: a vector of class integer providing the number of alive individuals at each time point for each concentration and each replicate (may contain NAs)

data

any object

diagnosis.plot

if TRUE, the function may produce diagnosis plots

Details

Survival data sets can be under either constant or time-variable exposure profile. The resulting object, in addition to its survData class, inherits the class survDataCstExp or survDataVarExp respectively.

The x argument describes experimental results from a survival toxicity test. Each line of the data.frame corresponds to one experimental measurement, that is a number of alive individuals at a given concentration at a given time point and in a given replicate. Note that either the concentration or the number of alive individuals may be missing. The data set is inferred to be under constant exposure if the concentration is constant for each replicate and systematically available. The function survData fails if x does not meet the expected requirements. Please run survDataCheck to ensure x is well-formed.

Value

A dataframe of class survData and column replicate as factor.

The function returns a dataframe of class msgTable and data.frame with two columns: id and msg of character strings. When no error is detected the object is empty. Here is the list of possible error ids with their meaning:

dataframeExpected an object of class data.frame is expected
missingColumn at least one expected column heading is missing
firstTime0 the first time point for some (concentration, replicate) couples is not 0
concNumeric column conc contains a value of class other than numeric
timeNumeric column time contains a value of class other than numeric
NsurvInteger column Nsurv contains a value of class other than integer
tablePositive some data are negative
Nsurv0T0 Nsurv is 0 at time 0 for some (concentration, replicate)
duplicateID there are two identical (replicate, time) couples
NsurvIncrease Nsurv increases at some time point of some (concentration, replicate)
maxTimeDiffer maximum time for concentration is lower than maximum time for survival

Note

If an error of type dataframeExpected or missingColumn is detected, the function survDataCheck is stopped before looking for other errors.

See Also

survDataCheck

survData

Examples


# (1) Load the survival data set
data(zinc)

# (2) Create an objet of class 'survData'
dat <- survData(zinc)
class(dat)

# Run the check data function
data(zinc)
survDataCheck(zinc)

# Now we insert an error in the dataset, by artificially increasing the
# number of survivors at a given time point, in such a way that the number
# of indivuals increases in the corresponding replicate
zinc[25, "Nsurv"] <- as.integer(20)
survDataCheck(zinc, diagnosis.plot = TRUE)


morse documentation built on Oct. 29, 2022, 1:14 a.m.