Create a censored time series object of cenTS class

Share:

Description

Create a censored time series response object of cenTS class. Default name of the response is "value", with the vectors of lower/upper censoring limits denoted by lcl and ucl respectively. The vector of censoring indicators, i.e., ci, is part of the cenTS object. Additional related variables can be stored and provided in the construction function, whose names are stored in xreg. All variable values are assumed to be of the same length of and thus aligned with the censored response time series. cenTS inherits from xts.

Usage

1
2
cenTS(value, order.by, lcl = NULL, ucl = NULL, ci = NULL,
  value.name = "value", ...)

Arguments

value

the value vector.

order.by

the index vector, must be a vector of time/date.

lcl

the vector of lower censoring limits, or a single numeric representing the constant limit. Default = NULL indicating no lower limit.

ucl

the vector of upper censoring limits, or a single numeric representing the constant limit. Default = NULL indicating no upper limit.

ci

the vector of censoring indicators whose value is -1 (0, 1) if the corresponding response is left censored (observed, right censored). Default = NULL, in which case, the function will compute ci by value, lcl and ucl. If ci is not NULL, the function will check the consistency of the data, assuming the observed values less (greater) than or equal to left (right) censoring limits are censored, and are observed otherwise. The function will stop if inconsistent results are found.

value.name

the name of the value, default = "value".

...

additional variables, must be able to be coerced to a data.frame.

Value

a cenTS object, any censored observation will be replaced by its corresponding censoring limit.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
strDates <- c("2000-01-01", "2000-01-02", "2000-01-03", "2000-01-04", "2000-01-05")
ts <- cenTS(value=c(1,-2,1,NA,0),
            order.by=as.Date(strDates,"%Y-%m-%d"),
            lcl=c(-3,-2,-1,-1,0),
            ucl=c(3,2,1,1,1),
            x=c(1,1,1,1,1),
            y=c(2,2,2,2,2))
 print(ts)
 print(xreg(ts))
 plot(ts)

## Not run: 
#wrong call, case 1
ts <- cenTS(value=c(1,-2,1,NA,0),
           order.by=as.Date(strDates,"%Y-%m-%d"),
           lcl=c(-3,-2,-1,-1,0),
           ucl=c(3,2,1,1,1),
           ci =c(-1,-1,1,NA,-1)
)
#wrong call, case 2
ts <- cenTS(value=c(1,-2,1,NA,0),
           order.by=as.Date(strDates,"%Y-%m-%d"),
           lcl=c(-3,-2,-1,-1,0),
           ucl=c(3,2,1,1,1),
           ci =c(1,-1,1,NA,-1)
)


#wrong call, case 3
ts <- cenTS(value=c(1,-2,1,NA,0),
           order.by=as.Date(strDates,"%Y-%m-%d"),
           lcl=c(-3,-2,-1,-1,0),
           ucl=c(3,2,1,1,1),
           ci =c(0,-1,0,NA,-1)
)

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.