I would like to extract the lower and upper value of a survival curve fitted with the icenReg package in order to use it in a ggplot graph.
I know how to store these value in an object but I don't manage to extract them from this object :
library(icenReg)
data("IR_diabetes")
flatPrior_fit <- ic_bayes(cbind(left, right) ~ gender, data = IR_diabetes, model = "po", dist = "gamma")
invCDF_ests <- survCIs(flatPrior_fit)
How do I extract these values, and how can I use them to obtain the confidence interval of the curve in ggplot ?
Look at its structure:
str(invCDF_ests)
Reference class 'surv_cis' [package "icenReg"] with 4 fields
$ cis :List of 1
..$ baseline: num [1:20, 1:5] 0.025 0.075 0.125 0.175 0.225 0.275 0.325 0.375 0.425 0.475 ...
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : NULL
.. .. ..$ : chr [1:5] "Percentile" "estimate (mean)" "estimate (median)" "lower" ...
$ call : language ic_bayes(formula = cbind(left, right) ~ gender, data = IR_diabetes, model = "po", dist = "gamma")
$ newdata :Formal class 'uninitializedField' [package "methods"] with 2 slots
.. ..@ field : chr "newdata"
.. ..@ className: chr "ANY"
$ ci_level: num 0.95
and 19 methods, of which 5 are possibly relevant:
all_lines, fit_one_row, initialize, one_lines, show#envRefClass
Then notice that the cis
element of that structure appears to be a regular R list that contains a matrix named baseline
and the cis
element is along side three other elements as well as a slew of non-displayed methods. It is, however, a reference class object commonly referred to as R6. I don't have a lot of experience with R6 structures and methods, but naively tried to extract it with "$" since that was being shown by the str
output, .... and had immediate success:
invCDF_ests$cis$baseline
Percentile estimate (mean) estimate (median) lower upper
[1,] 0.025 6.953697 6.955755 6.485497 7.393824
[2,] 0.075 8.874299 8.878339 8.415723 9.295514
[3,] 0.125 10.089455 10.091384 9.638875 10.514400
[4,] 0.175 11.068418 11.069332 10.627237 11.488847
[5,] 0.225 11.929793 11.928560 11.490618 12.344999
[6,] 0.275 12.724884 12.722080 12.283112 13.136176
[7,] 0.325 13.482080 13.482863 13.042530 13.897173
[8,] 0.375 14.219952 14.220951 13.783115 14.639034
[9,] 0.425 14.952450 14.953364 14.509479 15.379580
[10,] 0.475 15.691488 15.693712 15.245050 16.129615
[11,] 0.525 16.448540 16.449714 15.992385 16.895773
[12,] 0.575 17.235948 17.236388 16.759356 17.703037
[13,] 0.625 18.068360 18.069621 17.566506 18.563556
[14,] 0.675 18.964750 18.964280 18.439468 19.492435
[15,] 0.725 19.951830 19.954490 19.392602 20.516102
[16,] 0.775 21.070620 21.072578 20.464390 21.676400
[17,] 0.825 22.391076 22.390087 21.730446 23.057110
[18,] 0.875 24.051236 24.051829 23.313166 24.814614
[19,] 0.925 26.398369 26.391658 25.537376 27.296126
[20,] 0.975 30.982438 30.972453 29.838112 32.221068
I'm assuming that you know how to use "[" to extract results from R matrices, so I consider the question fully answered.