id = 1;
rng('default'); rng(8*id)
n = 5e3;
q = 10;
p = 4;
inds = 1:p;
betas = zeros(q,1); betas(inds) = [0.5, 0.5, 0.35, -0.35]';
Z = binornd(1, 0.5, [n,q]);
mu = Z*betas;
labs = ones(1,n);
lambda0 = 29.2672; k0 = 0.8178; C0 = 1.57;
eps = log(wblrnd(lambda0, k0,[n,1]))/C0;
eps = exp(-0.5*mu.^2).*eps;
K = 78;
T = exp(1 + mu + eps);
C = Z(:,1) + Z(:,2) + unifrnd(0,K,[n,1]);
V = min(T,C);
Delta = (T<=C);
fprintf('The proportion of non-censoring: %3.4f\n', mean(Delta))
n0 = 4;
Z0 = zeros(n0, q);
Z0(1, 1:p) = [1,1,1,0];
Z0(2, 1:p) = [1,0,1,1];
Z0(3, 1:p) = [1,1,1,1];
Z0(4, 1:p) = [0,0,0,1];
t0 = 0:0.2:60; len = numel(t0); trueY = zeros(len, n0);
for i = 1:n0
trueMu = Z0(i,:)*betas;
x = exp(0.5*trueMu^2)*(log(t0)-1-trueMu);
trueY(:,i) = exp(- (exp(C0*x)/lambda0).^k0);
end
Trues.eps = eps; Trues.T = T; Trues.C = C;
Trues.beta = betas; Trues.inds = inds;
Trues.labs = labs;
tot = 200; burn = 100;
N =150;
nch = 3;
myseeds = [1,2,3];
ngammas = 2;
niter = tot-burn;
nsample = niter*nch;
matpara = zeros(nsample, q*2+1+ngammas+1 + 1);
Ps = zeros(nsample, N);
Theta = zeros(nsample, N*2);
initBetas = Trues.beta;
for ch = 1:nch
i0 = (ch-1)*niter + (1:niter);
fprintf('\nMCMC chain %d: ',ch)
[matpara(i0,:), Theta(i0,:), Ps(i0,:)] = AFT_Bayes_LASSO(V, Delta, Z, N, tot, burn, initBetas, myseeds(ch));
end
betaSamples = matpara(:, 1:q)';
lb = quantile(betaSamples,0.025,2); ub = quantile(betaSamples,0.975,2);
fprintf('\nTrue, posterior mean, lower and upper bound of 95%% credible interval, coverage of the true:\n')
disp(num2str([Trues.beta,mean(betaSamples,2), lb, ub, (lb<Trues.beta).*(ub>Trues.beta)==1], 3))
mu0 = Z0*betaSamples;
nu0 = zeros(n0, nsample);
spm = nan(len, n0); spl = nan(len, n0); spu = nan(len, n0);
fprintf('\nThe design matrix for some example groups for survival probability:\n')
disp(Z0)
for i = 1:n0
for j = 1:nsample
nu0(i, j) = exp( [mu0(i,j), mu0(i,j).^2]*matpara(j, (2*q+1)+(1:ngammas))' );
end
for t = 1:len
t1 = t0(t);
tmp = 1 - sum(Ps.*normcdf(...
( repmat( ((log(t1) - mu0(i,:))./sqrt(nu0(i,:)))', [1,N]) - Theta(:,1:N) )./sqrt(Theta(:,N+(1:N)))...
), 2);
spm(t, i) = mean(tmp); spl(t, i) = quantile(tmp, .025); spu(t, i) = quantile(tmp, .975);
end
subplot(2,2,i); plot(t0, trueY(:,i), 'r-')
xlim([Z0(i,:)*betas+1, 60])
hold on,
for j = t0
plot(j, mean(V(~( sum((Z(:,1:p) - repmat(Z0(i,1:p), [n,1])).^2, 2) ))>=j), 'k.')
end
plot(t0, spm(:,i), 'b-')
plot(t0, spl(:,i), 'b--')
plot(t0, spu(:,i), 'b--')
hold off
end
disp('Demo completed. For full results, need to increase tot for achieving reasonable mixing rates and convergence')
The proportion of non-censoring: 0.7090
MCMC chain 1: 200 iterations are done with elapsed time 0.14 minutes.
MCMC chain 2: 200 iterations are done with elapsed time 0.14 minutes.
MCMC chain 3: 200 iterations are done with elapsed time 0.13 minutes.
True, posterior mean, lower and upper bound of 95% credible interval, coverage of the true:
0.5 0.499 0.494 0.503 1
0.5 0.499 0.494 0.503 1
0.35 0.349 0.342 0.356 1
-0.35 -0.352 -0.357 -0.347 1
0 0.00363 -0.00462 0.0115 1
0 -0.000818 -0.00794 0.0036 1
0 -0.00223 -0.00764 0.00244 1
0 -0.000749 -0.00521 0.0048 1
0 -0.00105 -0.00609 0.00368 1
0 0.0019 -0.00144 0.00574 1
The design matrix for some example groups for survival probability:
1 1 1 0 0 0 0 0 0 0
1 0 1 1 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
Demo completed. For full results, need to increase tot for achieving reasonable mixing rates and convergence