Contents
- Description
- Input
- Output
- Remarks
- Example of use
- set independent variables to column vectors,
- t = reshape(t, max(size(t)), 1);
- y = reshape(y, max(size(y)), 1);
- eval([ 'f = ', func, '(p(:,1), t, y);']);
- prob = reshape(f - [f(2:nt,:);zeros(1,ny)], nty, 1);
function [cov, cor, sd, dev] = psurv2(func, p, t, y, N)
Description
Calculates covariance matrix and standard deviations of parameters in survivor models, like psurv, but for 2 independent variables.
Input
func: string with name of user-defined function
f = func (p, t, y) with p: np-vector; t: nt-vector; y: ny-vector
f: (nt,ny)-matrix with model-predictions for surviving numbers
p: (np,2) matrix with
p(:,1) initial guesses for parameter values
p(:,2) binaries with yes or no iteration (optional)
t: (nt,1)-vector with first independent variable (time)
y: (ny,1)-vector with second independent variable
N: (nt,ny)-matrix with surviving numbers
Output
cov: (np,np) matrix with covariances
cor: (np,np) matrix with correlation coefficients
sd: (np,1) matrix with standard deviations
dev: scalar with deviance
Remarks
calls scdsurv2, and user-defined function 'func'
Example of use
assuming that function_name, pars, tvalues, yvalues, numbers are defined properly:
[cov, cor, sd, ss] = pregr2('function_name', pars, tvalues, yvalues, numbers).
set independent variables to column vectors,
t = reshape(t, max(size(t)), 1);
y = reshape(y, max(size(y)), 1);
global nt ny l index;
[np, k] = size(p);
cov = zeros(np,np);
cor = zeros(np,np);
index = 1:np;
if k>1
index = index(1 == p(:,2));
end
l = max(size(index));
if (l == 0)
return;
end
[nt ny] = size(N);
nty = nt*ny;
D = N - [N(2:nt,:); zeros(1,ny)]; D = reshape(D, nty, 1);
n0 = ones(nt,1) * N(1,:); n0 = reshape(n0, nty, 1);
likmax = D' * log(max(1e-10, D./ n0));
eval([ 'f = ', func, '(p(:,1), t, y);']);
prob = reshape(f - [f(2:nt,:);zeros(1,ny)], nty, 1);
[prob, Dprob] = scdsurv2(func, p(:,1), t, y);
dprob = zeros(nty,np);
dprob(:,index) = Dprob;
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./(1e-10 + sd*sd');