0

I have data from a retrospective survey. The individuals who have not experienced a particular event of interest upto survey time are put into censored observation category and rest are uncensored. How to draw boxplot for this right censored data that shows the life table quartiles taking into account both censored and un-censored observations?

(My variable of interest 'fbi' is a duration variable, thus for uncensored obs durations are available and for censored I have replaced the duration 'fbi' with time interval between the origin to survey date and another dichotomous variable "cens" is there to recognize censored and uncensored cases.)

The data can be emulated with:

fbi <- rpois(100,12)
cens <- sample(0:1,100,replace=T) 
test <- data.frame(fbi,cens)

> head(test)
  fbi cens
1  18    0
2  14    0
3  17    1
4  11    1
5   9    0
6  10    1
thelatemail
  • 91,185
  • 12
  • 128
  • 188
Shruti
  • 1
  • 1
  • Could you provide some sample data that is reproducible? - http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – thelatemail Feb 02 '13 at 04:01
  • Sorry, I am really new here.. I am not getting how to right code here in textbox........ pls help me! – Shruti Feb 02 '13 at 05:10
  • but I can tell u that data emulates this: >fbi<-rpois(100,12) >cens<-sample(0:1,100,replace=T) >data<-data.frame(a,b) ,here in fbi, observations corresponding to cens=0 are those for whom duration fbi was not reported since they were still continuing, so I had replaced fbi corresponding to zero with the duration from origin to survey date. (!! sorry for badly written code) – Shruti Feb 02 '13 at 05:39
  • sorry!! it is data.frame(fbi,cens) – Shruti Feb 02 '13 at 05:52
  • Welcome to SO. I have edited the question to include the data you provided in the above comments. Next time around, just add this sort of (very useful!) information directly to the question so that potential answerers know how your data looks. – thelatemail Feb 02 '13 at 06:16

1 Answers1

0

Using the dummy data you suggested and which I added to the answer, the below line will plot 2 boxplots summarising the fbi variable including all cases, and using just the non-censored cases.

boxplot(test$fbi,test$fbi[test$cens==0],names=c("all cases","w/out censored"))

If you'd rather compare the censored to uncensored cases, you could do:

boxplot(fbi ~ cens,data=test,names=c("not censored","censored"))

edit

In response to the comment below, is the following piece of code using the NADA library what you are seeking?

library(NADA)
cenboxplot(test$fbi, as.logical(test$cen))

There is documentation on the cenboxplot function online here: http://rss.acs.unt.edu/Rdoc/library/NADA/html/cenboxplot.html

thelatemail
  • 91,185
  • 12
  • 128
  • 188
  • Thank you so much for the response! but i am looking for the censored boxplots... i.e. boxplots that show the life table quartiles. I have heard about the package "NADA", but don't know that will it work here or not for the right censored data. – Shruti Feb 02 '13 at 07:29
  • one more thing! can you pls explain me stepwise how did you write code here in the textbox? What should i do if i want to copy my code from R script in the comment box here? – Shruti Feb 02 '13 at 07:41
  • @Shruti - ok, I am not very familiar with this sort of thing, but have edited my answer to include a boxplot function using the `NADA` library. – thelatemail Feb 02 '13 at 07:41
  • @Shruti - if you paste your code into the textbox, then highlight the code and click the button that looks like `{}` you will get formatted code. – thelatemail Feb 02 '13 at 07:43
  • Thanku! but I can't find { } button. – Shruti Feb 02 '13 at 08:24