Contents
function [cov, cor, sd, dev] = psurv (func, p, ...
Description
calculates covariance and correlation matrix of parameters standard deviation and sum of squared deviations
of model predictions with respect to observations
Input
func: string with name of user-defined function
f = func (p, tn) with
p: k-vector with parameters; tn: (n,c)-matrix; f: n-vector
[f1, f2, ...] = func (p, tn1, tn2, ...) with p: k-vector and
tni: (ni,k)-matrix; fi: ni-vector with model predictions
The dependent variable in the output f; For tn see below.
Output
p: (k,2) matrix with
p(:,1) initial guesses for parameter values
p(:,2) binaries with yes or no iteration (optional)
tni (read as tn1, tn2, .. ): (ni,2) matrix with
tni(:,1) time: must be increasing with rows
tni(:,2) number of survivors: must be non-increasing with rows
tni(:,3, 4, ... ) data-pont specific information data (optional)
The number of data matrices tn1, tn2, ... is optional but >0
cov: (np,np) matrix with covariances
cor: (np,np) matrix with correlation coefficients
sd: (np,1) matrix with standard deviations
dev: scalar with deviance
Example of use
assuming that function_name, pars, and tn1 (and possibly more data matrices) are defined properly:
[cov, cor, sd, ss] = psurv('function_name', pars, tn1, tn2, ...).
Code
global index l n ntn listt listtn listf listg
i = 1;
ci = num2str(i);
nntn = nargin -1;
ntn = nntn -1;
va_start ();
while (--nntn)
eval(['tn', ci, ' = va_arg();']);
eval(['[n(', ci, ') k] = size(tn', ci, ');']);
if i == 1
obtain time intervals and numbers of death
D = tn1(:,2) - [tn1(2:n(i),2);0];
n0 = tn1(1,2)*ones(n(1),1);
listtn = ['tn', ci,','];
listt = ['tn', ci];
listf = ['f', ci,','];
listg = ['g', ci,','];
else
eval(['D = [D; tn', ci,'(:,2) - [tn', ci, '(2:n(i),2);0];']);
eval(['n0 = [n0; tn', ci, '(1,2)*ones(n(', ci,'),1)];']);
listtn = [listtn, ' tn', ci,','];
listt = [listt, ' tn', ci];
listf = [listf, ' f', ci,','];
listg = [listg, ' g', ci,','];
end
i++;
ci = num2str(i);
end
[i nl] = size(listtn); listtn = listtn(1:(nl-1));
[i nl] = size(listf); listf = listf(1:(nl-1));
[i nl] = size(listg); listg = listg(1:(nl-1));
eval(['global ', listt,';']);
likmax = D'*log(max(1e-10,D./ n0));
[np, k] = size(p);
index = 1:np;
if k>1
index = index(1 == p(:,2));
end
l = max(size(index));
if (l == 0)
return;
end
[prob, dprob] = scdsurv(func, p(:,1));
dev = 2 * (likmax - D' * log(max(1e-10,prob)));
cov(index, index) = inv((n0./prob * ones(1,l).*dprob)'*dprob);
sd = sqrt(diag(cov));
cor = cov./(sd*sd');