95% confidence bands around fit from fminunc - matlab

I have performed a MLE fit to some data that I have using the fminunc function in matlab and estimated the parameter confidence intervals from the Hessian output. Does anyone have a method for generating 95% confidence bands around the fitted curve?

A crude way to do this is generate parameters grid on the intervals that you have obtained, and plot the curve for every point of this grid. This works only if the number of parameters is low. You should keep in mind that the resulting confidence interval for curve is lower than that of the parameters, i.e. if you have 2 parameters with 95% confidence, you will obtain 95%*95%=90% confidence interval
If the curve depends on the parameters monotonically at every point, you can generate the interval just by taking boundary values of parameter intervals.

Related

Calculate 95% Confidence Interval from Diagnostic Test Data

I'm trying to calculate the 95% confidence intervals based off a series of matrices based in Matlab:
I know how to calculate the required sensitivity, specificity, negative predictive value and positive predictive value, however I'm not sure, given these data, how to calculate the 95% confidence interval.
Any help would be greatly appreciated.
You need the whole distribution to calculate your confidence intervals.
Once you have it, call it "data" and run the following code.
The code works with nans in the data, with vectors (Nx1) or matrices (NxM). As long as each distribution is represented by a column
%%% calculate CI
alpha_lvl = [2.5 97.5]; % lower and upper boundaries for the CI
SEM = nanstd(data)./sqrt(sum(~isnan(data ))); % Standard Error
ts = tinv(alpha_lvl/100,length(data)-1); % T-Score
CI = bsxfun(#plus,nanmean(data ),bsxfun(#times,SEM,ts')); % confidence intervals

How can I validate my estimated covariance matrix?

I have two covariances of size 6*6, one is supposed be the true covariance and the other is the Maximum likelihood estimate for my covariance. Is there any way I could validate my estimated covariance?
I don't know how exactly you determined your covariance matrix, but generally it is a good first step to check the confidence intervals of your estimators.
Heuristically speaking a wide confidence interval suggests that your estimator has a lot of uncertainty.
Take a look at the Matlab function corrcoef, which also gives lower and upper bounds for the estimated correlation coefficients,
cf. https://uk.mathworks.com/help/matlab/ref/corrcoef.html#bunkanr .
Maybe using this function on your data gives you a good starting point. If you use your own function to estimate the ML estimators, you will have to add the confidence intervals yourself.

Confidence intervals on the derivative of a polynomial surface

My problem is the following:
I have fit a surface to some xyz coordinate data to obtain a polynomial surface. That's a polynomial in the variables x and y giving a surface of z-values. I know how to compute 95 percent condidence intervals on the mean response and also new predicition intervals (the standard stuff). Having obtained the surface function it's also easy to determine the derivative at a certain point on the the surface however, what I'm looking for is:
How do I compute confidence levels on the derivative value dS/dx, the (partial) derivative in the x direction at a certain point?
Are there expressions for calculating such intervals similar to the intervals for the 95 percent confidence intervals on the mean response?
(Please don't bother to post an answer on the confidence interval for the slope of a simple regression line. That's not the answer to this question. Anyway, I think it isn't.)

Calculating confidence intervals from the empirical distribution obtained with the bootstrap method

I have calculated the empirical distribution of the sample mean using the bootstrap method, but now I would also need to calculate the confidence interval for the population mean using the empirical distribution I found.
Is there a way to do it automatically in Matlab given my state? If not, how would you find the 95% confidence interval for population mean?
The bootstrapped confidence intervals for the mean as you have calculated it are the quantiles of the distribution. So, it can be as simple as
quantile(myBootstrappedMeans, [0.05, 0.95])
That will give a 90% confidence interval for the vector myBootstrappedMeans. For reference, http://math.usask.ca/~longhai/doc/talks/slide-bootstrap.pdf
0.05 and 0.95 are for the 90% confidence interval (the middle 90% of the data). For a different confidence interval, you would just need to choose the middle quantiles of that data. So, for 95% you would use 0.025 and 0.975. To generalize, you would use (1-level)/2 and (0.5 + level/2) where level is the confidence interval (or confidence level) that you want.

Methodology of FFT for Matlab spectrogram / short time Fourier transform functions

I'm trying to figure out how MATLAB does the short time Fourier transforms for its spectrogram function (and related functions like specgram, or stft in Octave). What is curious to me is that you can apparently specify the length of the window and the FFT length (number of output frequencies) independently, whereas I would have expected that these two should be equal (since the length of an FFT'd signal is the same as the length of the original signal). To illustrate what I mean, here is the function call:
[S,F,T]=spectrogram(signal,winSize,overlapSize,fftSize,rate);
winSize is the length of subintervals which are to be (individually) FFT'd, and fftSize is the number of frequency components given in the output. When these are not equal, does Matlab do interpolation to produce the required number of frequency bins?
Ultimately the reason I want to know is so that I can determine the proper units and scaling for the frequencies.
Cheers
A windowed segment of a signal can be zero-padded to a longer length vector to use a longer FFT. The frequency scaling will be determined by the length of the FFT (and the signals sample rate). The window size and window formula will determine the effective resolution, in terms of peak separation ability.
Why do this? Some FFT sizes can be computed more efficiently than others (slightly or a lot, depending on the FFT library used). Also, a longer FFT will calculate more points or bins, thus producing a higher density of interpolated points in a potentially smoother spectrum result.