Filter löschen
Filter löschen

Confidence intervals given a vector and its variance-covariance matrix

11 Ansichten (letzte 30 Tage)
I have a kx1 vector b and its variance covariance matrix V. I would like to obtain 5% confidence intervals (CIs) for a linear combination of the elements of b, c = Hb, where H is 1xk and c a scalar. I know I can obtain p-values with linhyptest, but I can't get CIs with it. Thanks in advance!

Antworten (1)

Shivansh
Shivansh am 4 Okt. 2023
Hi Giulio,
I understand that you want to find the confidence intervals for the data using an inbuilt MATLAB function. As you have rightly mentioned, you can’t find the CIs using “linhyptest”.
To obtain confidence intervals (CIs) for a linear combination of the elements of vector b, c = Hb, you can use the `mvnrnd` function to generate random samples from a multivariate normal distribution. Here's an example code snippet that demonstrates this approach:
% Given inputs
b = [1; 2; 3]; % kx1 vector
V = [4, -1, 0; -1, 5, 2; 0, 2, 6]; % Variance-covariance matrix
H = [1, 2, 1]; % 1xk matrix
% Number of bootstrap samples
num_samples = 1000;
% Generate bootstrap samples
bootstrap_samples = mvnrnd(b', V, num_samples)';
% Calculate the linear combination for each bootstrap sample
c_samples = H * bootstrap_samples;
% Sort the samples
sorted_samples = sort(c_samples);
% Calculate the lower and upper bounds of the confidence interval
lower_index = round(num_samples * 0.025);
upper_index = round(num_samples * 0.975);
lower_bound = sorted_samples(lower_index);
upper_bound = sorted_samples(upper_index);
% Display the results
fprintf('Estimated linear combination: c = %.2f\n', H * b);
fprintf('Confidence interval: [%.2f, %.2f]\n', lower_bound, upper_bound);
In this code snippet, we generate bootstrap samples from a multivariate normal distribution with mean `b` and covariance matrix `V` using the `mvnrnd` function. We then calculate the linear combination `c` for each bootstrap sample. The bootstrap samples are sorted, and the lower and upper bounds of the confidence interval are determined by selecting the values corresponding to the 2.5th and 97.5th percentiles.
Adjust the inputs `b`, `V`, and `H` according to your specific problem. The code will output the estimated linear combination `c` and the corresponding confidence interval.
For more information on “mvrnd”, you can refer to the MATLAB documentation here https://in.mathworks.com/help/stats/mvnrnd.html?searchHighlight=mvrnd&s_tid=srchtitle_support_results_2_mvrnd.
Hope it helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by