| 0 | 1 function fit = lf_censor(x,y,cens,varargin) | 
|  | 2 % | 
|  | 3 % Censored local regression using normal assumption. | 
|  | 4 % Must provide x, y and cens. | 
|  | 5 % All other arguments to locfit() can be provided, with the | 
|  | 6 % exception of weights. | 
|  | 7 % | 
|  | 8 % NEED: Kaplan Meier Estimate. Iterations are fixed. | 
|  | 9 % | 
|  | 10 | 
|  | 11 lfc_y = y; | 
|  | 12 unc = find(~cens); | 
|  | 13 | 
|  | 14 for i = 0:3 | 
|  | 15   fit = locfit(x,lfc_y,varargin{:}); | 
|  | 16   fh = fitted(fit); | 
|  | 17 | 
|  | 18   rs = rsum(fit); | 
|  | 19   df0 = rs(1); | 
|  | 20   df1 = rs(2); | 
|  | 21 | 
|  | 22   rdf = sum(1-cens) - 2*df0 + df1; | 
|  | 23   sigma = sqrt(sum( (y-fh).*(lfc_y-fh) / rdf)); | 
|  | 24   sr = (y-fh)/sigma; | 
|  | 25   lfc_y = fh + sigma*normpdf(sr)./normcdf(-sr); | 
|  | 26   lfc_y(unc) = y(unc); | 
|  | 27 end; | 
|  | 28 | 
|  | 29 return; |