Clear Filters
Clear Filters

Empirical CDF with data containing left censored, exact and right censored failures.

7 views (last 30 days)
My data consists of left censored, exact failures and right censored points. I am trying ecdf by considering data in two different forms.:
  1. I create data as two column matrix. for left censored i use [-Inf, observed value], for exact failures i use [observed value, observed value] and for right censored i use [observed value, Inf] as per the documentation. and now I do [f,x] = ecdf[Data]
  2. Next I create a single column vector of my Data, and I create a second vector as censoring data and use -1 for left censored, 0 for exact and 1 for right censored. I calculate the cdf using [f,x] = ecdf[Data1,'Censoring',censoring_data_vector;
According to documention, ecdf ignores if the data is two colum matrix and performs cdf calculations, other wise uses the censoring information. Both should be exactly same but i get totally different answers and i believe the first one is giving more reasonable answers than the second one. Please help what am I doing wrong in my second method? Thanks in advance. I can provide the data if someone wants to try it.

Answers (1)

Aditya
Aditya on 24 Jan 2024
Edited: Aditya on 24 Jan 2024
Hi Pappu,
I understand that you are facing some issues with using ecdf function.
The MATLAB function ecdf can handle censored data when provided with a censoring vector, where the censoring information is given as -1 for left-censored, 0 for exact, and 1 for right-censored data points. However, the way you are describing the use of ecdf with a two-column matrix is not standard and may not be supported directly by the function. The typical usage of ecdf for censored data is with a single column vector of data and a corresponding censoring vector.
Here is the correct way to use ecdf with censoring:
% Data1 is a single column vector of observed values.
Data1 = [ ... ]; % Replace with your data
% Censoring_data_vector is a vector of the same length as Data1 where:
% -1 corresponds to a left-censored observation
% 0 corresponds to an exact failure (uncensored observation)
% 1 corresponds to a right-censored observation
censoring_data_vector = [ ... ]; % Replace with your censoring data
% Convert censoring vector to logical where 0 is uncensored and 1 is censored
censoring_logical = censoring_data_vector ~= 0;
% Use ecdf with the censoring vector
[f, x] = ecdf(Data1, 'Censoring', censoring_logical, 'Function', 'survivor');
Please ensure that you are using the 'Censoring' option correctly with a logical vector, where true (1) indicates a censored observation and false (0) indicates an exact failure. The 'Function' option set to 'survivor' will compute the survivor function, which is 1 minus the empirical CDF, a common choice when dealing with censored data.
If you are still getting different results between the two methods you described, it's likely due to a misunderstanding of how ecdf handles the two-column matrix input. The function does not natively support a two-column matrix where the columns represent left and right censoring limits. Instead, it expects a single column of data points and an optional logical censoring vector.
If you provide the data, I can help you debug the issue further. However, I can only give you guidance and cannot run the code myself. Please make sure that the censoring vector is correctly specified as a logical vector, where true indicates a censored observation, and that you are using the 'Censoring' option correctly in the ecdf function call.
Hope this helps.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!