survival analysis - fminsearch censored MATLAB -
edit found y(c) in script gives error:
subscript indices must either real positive integers or logicals.
but in example script y(c) prints values of y censored.
i trying use script found analysis of censored data. script works fine when try use own data error.
this example code:
% have (x,y) data n = 100; x = 10*rand(n,1); y = 5 + .5*x + randn(n,1); plot(x,y,'o','color',[.8 .8 .8]); % it's censored, can't observe values larger 8 c = y>8 o = min(y,8); line(x,o,'marker','o','color','b','linestyle','none') % if fit line data observe, no b = polyfit(x,o,1) s = norm(o-polyval(b,x))/sqrt(n) xx = linspace(0,10); line(xx,polyval(b,xx),'color','r') % instead need likelihood function taket censoring account nloglik = @(p) - sum(log(normpdf(o(~c),p(1)*x(~c)+p(2),p(3)))) ... - sum(log(1-normcdf(o(c),p(1)*x(c)+p(2),p(3)))); nloglik = @(p) - sum(log(normpdf(tof(~c),p(1)*z(~c)+p(2),p(3)))) ... - sum(log(1-normcdf(tof(c),p(1)*z(c)+p(2),p(3)))); p = fminsearch(nloglik,[b,s])
here code:
load('uv.mat') % 18 column array = 1 : length(uv{1,7}) if uv{1,7}(i) ~= 0 x(i)=log10(uv{1,4}(i)); y(i) = uv{1,7}(i); end end c=zeros(length(y),1); % c stands censored i=1:length(y) if uv{1,8}{i} == 'u' % u stands upper limit c(i)=1; end end b = polyfit(x,y,1) s = norm(y-polyval(b,x))/sqrt(length(x)) nloglik = @(p) - sum(log(normpdf(y(~c),p(1)*x(~c)+p(2),p(3)))) ... - sum(log(1-normcdf(y(c),p(1)*x(c)+p(2),p(3)))); p = fminsearch(nloglik,[b,s])
the error is:
subscript indices must either real positive integers or logicals. error in @(p)-sum(log(normpdf(y(~c),p(1)*x(~c)+p(2),p(3))))-sum(log(1-normcdf(y(c),p(1)*x(c)+p(2),p(3)))) error in fminsearch (line 191) fv(:,1) = funfcn(x,varargin{:}); error in zwithcensoring (line 22) %zwithcensoring name of script p = fminsearch(nloglik,[b,s])
i tried debug p seems called before defined. found nloglik function input parameter p.
how script give error not example script? , how past error?
change variable c logical, i.e.:
c = logical(c)
before use indexing.
alternatively, create 'c' logical begin with:
c= false(length(y),1); % c stands censored i=1:length(y) if uv{1,8}{i} == 'u' % u stands upper limit c(i)=true; end end
if not work, posting working code fix problem.
Comments
Post a Comment