lf_censor.m 610 B

1234567891011121314151617181920212223242526272829
  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. lfc_y = y;
  11. unc = find(~cens);
  12. for i = 0:3
  13. fit = locfit(x,lfc_y,varargin{:});
  14. fh = fitted(fit);
  15. rs = rsum(fit);
  16. df0 = rs(1);
  17. df1 = rs(2);
  18. rdf = sum(1-cens) - 2*df0 + df1;
  19. sigma = sqrt(sum( (y-fh).*(lfc_y-fh) / rdf));
  20. sr = (y-fh)/sigma;
  21. lfc_y = fh + sigma*normpdf(sr)./normcdf(-sr);
  22. lfc_y(unc) = y(unc);
  23. end;
  24. return;