-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovB_to_SE.m
30 lines (27 loc) · 975 Bytes
/
covB_to_SE.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function SE = covB_to_SE(covB)
% Compute standard error from variance-covariance matrix.
%
% Helper function to compute the standard errors of fixed effect estimates
% (Betas, B) from the variance-covariance matrix of B, covB. The full covB
% is required when performing a Wald test. The standard errors are
% sufficient for performing a t-test. The standard errors are computed as:
%
% SE = sqrt(diag(covB))
%
% SE has one row for each row in B or column in the design matrix X. When
% covB is a 3-dimensional matrix such that the third dimension corresponds
% to independent columns in the matrix of observations Y then SE will have
% one column for each column in Y.
%
% See also: SCAND
% Make sure argument is a square matrix.
assert(size(covB,1) == size(covB,2));
if ndims(covB) < 3 || size(covB,3) == 1
SE = sqrt(diag(covB));
else
SE = zeros(size(covB,1), size(covB,3));
parfor i=1:size(covB,3)
SE(:,i) = sqrt(diag(covB(:,:,i)));
end
end
end