diff rDiff/src/locfit/m/lf_censor.m @ 0:0f80a5141704

version 0.3 uploaded
author vipints
date Thu, 14 Feb 2013 23:38:36 -0500
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rDiff/src/locfit/m/lf_censor.m	Thu Feb 14 23:38:36 2013 -0500
@@ -0,0 +1,29 @@
+function fit = lf_censor(x,y,cens,varargin)
+%
+% Censored local regression using normal assumption.
+% Must provide x, y and cens.
+% All other arguments to locfit() can be provided, with the
+% exception of weights.
+%
+% NEED: Kaplan Meier Estimate. Iterations are fixed.
+%
+
+lfc_y = y;
+unc = find(~cens);
+
+for i = 0:3
+  fit = locfit(x,lfc_y,varargin{:});
+  fh = fitted(fit);
+
+  rs = rsum(fit);
+  df0 = rs(1);
+  df1 = rs(2);
+
+  rdf = sum(1-cens) - 2*df0 + df1;
+  sigma = sqrt(sum( (y-fh).*(lfc_y-fh) / rdf));
+  sr = (y-fh)/sigma;
+  lfc_y = fh + sigma*normpdf(sr)./normcdf(-sr);
+  lfc_y(unc) = y(unc);
+end;
+
+return;