Question

I'm trying to create confidence interval for a set of data not randomly distributed and very skewed at right. Surfing, I discovered a pretty rude method that consists in using the 97.5% percentile (of my data) for the upperbound CL and 2.5% percentile for your lower CL. Unfortunately, I need a more sophisticated way!

Then I discovered the bootstrap, precisley the MATLAB bootci function, but I'm having hard time to undestand how to used it properly.

Let's say that M is my matrix containing my data (19x100), and let's say that:

Mean = mean(M,2);
StdDev = sqrt(var(M'))';

How can I compute the asymmetrical CI for every row of the Mean vector using bootci?

Note: earlier, I was computing the CI in this very wrong way: Mean +/- 2 * StdDev, shame on me!

Was it helpful?

Solution

Let's say you have a 100x19 data set. Each column has a different distribution. We'll choose the log normal distribution, so that they skew to the right.

means  = repmat(log(1:19), 100, 1);
stdevs = ones(100, 19);
X = lognrnd(means, stdevs);

Notice that each column is from the same distribution, and the rows are separate observations. Most functions in MATLAB operate on the rows by default, so it's always preferable to keep your data this way around.

You can compute bootstrap confidence intervals for the mean using the bootci function.

ci = bootci(1000, @mean, X);

This does 1000 resamplings of your data, calculates the mean for each resampling and then takes the 2.5% and 97.5% quantiles. To show that it's an asymmetric confidence interval about the mean, we can plot the mean and the confidence intervals for each column

plot(mean(X), 'r')
hold on
plot(ci')

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top