hi ineed to run this matlab program
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
i have an error run , the data is an (nx2) matrix
disp(' '); disp(' '); disp(' ');
disp(' This program computes the pointwise hazard rate by maximum likelihood,');
disp(' the survival function by KAPLAN-MEIR and the cumulative hazard rate');
disp(' by NELSON-AALEN.');
disp(' '); disp(' ');
disp(' Press any key to continue!');
pause;
clc;
disp(' ');disp(' ');disp(' ');
disp(' Are your data - not necessarily ordered - stored in a (n x 2) matrix');
disp(' named y in the workspace? The first column is for the observed times,');
disp(' the second column for the corresponding censoring indicator:');
disp(' 1 - for uncensored observation, 0 - for censored observation.');
disp(' '); disp(' ');
disp(' Type 1 if your data with the correct format are in the workspace, type 0 if not!');
disp(' ');
answer = input(' Answer = ');
if answer ~= 1
disp(' '); disp(' ');
disp(' Load the data with correct format and restart this program!');
disp(' Program stopped!');
return;
end
clear answer;
% Extracting of the uncensored observations
n = length(y); % sample size
xx = sort(selif(y(:,1),y(:,2)))'; % all uncensored observations in column vector
nn = length(xx); % number of uncensored observations
d = zeros(nn,1);
x = zeros(nn,1);
ii = 1;
jj = 1;
while ii <= nn
x(jj) = min(xx(ii:nn));
d(jj) = sum(x(jj) == xx(ii:nn));
ii = ii + d(jj);
jj = jj + 1;
end
x = x(1:jj-1); % vector of differing uncencensored observations
d = d(1:jj-1); % vector of the number of failures at x(jj)
% Determining the vector of the numbers at risk
k = length(x); % number of differing uncensored obeservations
z = sort(delif(y(:,1),y(:,2)))'; % all uncensored observations in column vector
ni = zeros(k,1); % vector of numbers at risk
c = sum(z < x(1)); % number of censored observations less than smallest uncens. obs.
ni(1) = n - c;
for ii = 2:k
ni(ii) = ni(ii-1) - d(ii-1) - sum( (z >= x(ii-1)) & (z < x(ii)));
end
% Estimates of the hazard rate and its variance
h = d ./ ni; % Hazard rate
varh = d .* (ni - d) ./ ni.^3; % Variance of the hazard rate
% KAPLAN-MEIER estimate of the survival function and its variance
S = cumprod(1 - h); % Survival function
varS = S.^2 .* cumsum(d ./ (ni .* (ni -d))); % Variance of the survival function
% NELSON--AALEN estimate of the cumulative hazard rate and its variance
H = cumsum(d ./ ni); % Cumulative hazard function
varH = cumsum(d .* (ni - d) ./ ni.^3); % Variance of the cumulative hazard function
% Tabular output
clc;
ii = (1:k)';
under = '----------------------------------------------------------------';
kopf = ' i x_i n_i d_i h(x_i) S(x_i) H(x_i) ';
tit = 'Estimation results';
res = [ ii x ni d h S H ];
fprintf('%s\n\n', tit);
fprintf('%s\n', kopf);
fprintf('%s\n', under);
fprintf('%3.0f %10.4g %4.0f %4.0f %10.4g %10.4g %10.4g\n', res');
% Graphical output
hup = h + 1.96 * sqrt(varh);
hlo = h - 1.98 * sqrt(varh);
Sup = S + 1.96 * sqrt(varS);
Slo = S - 1.96 * sqrt(varS);
Hup = H + 1.96 * sqrt(varH);
Hlo = H - 1.96 * sqrt(varH);
subplot(3,1,1);
plot(x,h,'k o','MarkerSize',5,'MarkerFaceColor','k');
hold on;
plot(x,hup,'r v','MarkerSize',5,'MarkerFaceColor','r');
plot(x,hlo,'r ^','MarkerSize',5,'MarkerFaceColor','r');
xlabel('x');
ylabel('est. h(x)');
title('Estimated hazard rate with 95% confidence limits');
axis([0.9*min(x) 1.1*max(x) min(hlo) 1.1*max(hup)]);
hold off;
subplot(3,1,2);
stairs(x,S,'Color', [0 0 0]);
hold on;
stairs(x,Sup,'Color', [1 0 0]);
stairs(x,Slo,'Color', [1 0 0]);
xlabel('x');
ylabel('est. S(x)');
axis([0.9*min(x) 1.1*max(x) min(Slo) 1.1*max(Sup)]);
title('Estimated survival function with 95% confidence limits');
hold off;
subplot(3,1,3);
stairs(x,H,'Color', [0 0 0]);
hold on;
stairs(x,Hup,'Color', [1 0 0]);
stairs(x,Hlo,'Color', [1 0 0]);
xlabel('x');
ylabel('est. H(x)');
axis([0.9*min(x) 1.1*max(x) min(Hlo) 1.1*max(Hup)]);
title('Estimated cumulative hazard rate with 95% confidence limits');
hold off;
2 Commenti
John D'Errico
il 11 Gen 2019
If you have an error, then show what the error is. The COMPLETE text of the error message. Otherwise, you force someone to guess what your data looks like. They need to guess how you responded to the various questions posed. So you probably need to provide more than just the information that your data is an nx2 matrix.
Image Analyst
il 11 Gen 2019
But John, no question was even asked - just an announcement was made by ali.
ali, if you decide to ask us a question, read this link, and then follow what it says, and then ask the question.
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!