Be the first to rate this file! 27 Downloads (last 30 days) File Size: 30.1 KB File ID: #38226

Fit distributions to censored data

by

 

Fits distributions to data when left and/or right and/or interval censoring is present

| Watch this File

File Information
Description

Fits a distribution to the data x based on maximum likelihood. The data can be left and/or right and/or interval censored.

The following distributions are supported:

1. Normal (normfitc)
2. Log-Normal (lognfitc)
3. Logistic (logistfitc)
4. Log-logistic (loglogistfitc)
5. Extreme value (evfitc)
6. Weibull (wblfitc)
7. Exponential (expfitc)
8. Gamma (gamfitc)
9. Rayleigh (raylfitc)

INPUT ARGUMENTS:
x: a two column matrix of the data. For example, (for a real-line supported distribution):

  -Inf 5.0000--> left censored
7.0000 Inf--> right censored
5.0000 9.0000--> interval censored
8.0000 8.0000--> exactly observed

that is, if all data are exactly observed then the two columns must be identical. See also the "examples" file for an illustration.

If a distribution with positive support is to be chosen then the above example turns out to be:

     0 5.0000--> left censored
7.0000 Inf--> right censored
5.0000 9.0000--> interval censored
8.0000 8.0000--> exactly observed

OPTIONAL INPUT ARGUMENTS: (These can be either not be reached at all,
or set as [] to proceed to the next optional input argument)

minimizer: Can be set equal to 1 or 2 or 3. That is 1: the fminsearchbnd routine is used for minimization, 2: the fmincon with Largescale set to off and the ‘spq’ algorithm is employed. 3. the fmincon with Largescale set to off and the ‘interior-point’ algorithm is employed. If set to [] or not reached at all then minimizer 1 is chosen by default (for no particular reason). If convergence problems occur be sure to explore all three minimizers first. Then you may explore other initial values in the next input argument.

init: A row vector of initial values defined by the user. If you do not want to define this and move on to the next optional input arguments set it as []. If initial values are not provided by the user then they are derived based on exactly observed data or right censored based on built in MATLAB functions. If only interval data are available then the midpoints are considered as exactly observed and built in funtions are used to obtain initial values.

options: The options that will be used in the optimset of fminsearchbnd or fmincon depending which minimizer is selected by the previous input argument. That is, if the minimizer is set to 1, then the options will refer to the fminsearchbnd. If the minimizer is set to 2 or 3, then the options will refer to fmincon. The options set in this argument will replace the default options mentioned in the minimizer input argument. The default will take place if this input argument is set to [] or not reached at all. See also MATLAB documentation for the "options" of fmincon or fminsearch.

OUTPUT ARGUMENTS:

pars: estimated parameters

covars: variance covariance matrix of the estimated parameters. This is evaluated based on John D'erricos "Adaptive Robust Numerical Differentiation" tools throughout all distributions.

SE: standard error of the estimated parameters

gval: value of the loglikelihood

exitflag: depends on the minimizer selected. In the case where only exactly observed data and/or right censored data are available then exitflag is set to NaN since the estimation is done based on the built in fitting routines.

The purpose of this routine is to provide a useful tool to MATLAB users to fit some distributions (many of which are primarily used in Survival Analysis) when left and/or right and/or interval censored are available.

This routine uses John D'Erricos fminsearchbnd or built in "fmincon" for minimization.

The covariance matrix is calculated
numerically using also John D'Erricos “Adaptive Robust Numerical Differentiation” tools. These can be found here:

http://www.mathworks.com/matlabcentral/fileexchange/8277

http://www.mathworks.com/matlabcentral/fileexchange/13490-adaptive-robust-numerical-differentiation

%See also the "examples" file for an illustration

Acknowledgements

Fminsearchbnd, Fminsearchcon and Adaptive Robust Numerical Differentiation inspired this file.

Required Products Optimization Toolbox
Statistics Toolbox
MATLAB release MATLAB 7.10 (R2010a)
Other requirements The user may choose to use either John D'erricos fminsearchbnd or built in fmincon. The tools "Adaptive Robust Numerical Differentiation" of John D'errico are also needed.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
19 Aug 2013 K H

My mistake-works great

14 Aug 2013 K H

Thank you for the helpful code. I am getting this error message, any help is greatly appreciated as I am new to Matlab.

I used [pars covars SE gval exitflag]=lognfitc(mydatamatrix,2)

Undefined function 'hessian' for input arguments of type 'function_handle'.

Error in lognfitc (line 160)
hess = hessian(logL,pars);

Contact us