Calculating error from parameter distribution
3 次查看(过去 30 天)
显示 更早的评论
I have a distribution. It is a multi-peaked distribution of signal magnitude over a range of frequencies. This distribution is made up of discrete measurements. I have error associated with each point in the distribution obtained from the covariance matrix of my data.
What I want to do, I've calculated the mean-log frequency for the distribution, and now I want to calculate the error associated with this value. How would I propagate the error from the points of the frequency distribution to the mean-log value.
0 个评论
回答(1 个)
the cyclist
2023-4-4
I don't know if there is a way to do this analytically, but I believe you should be able to calculate the error using Monte Carlo simulation. (This is a common method for error estimation of statistics that are not analytically tractable.)
You should definitely thoroughly check the following code, which I threw together rather quickly, especially if this is for something important!
% Your measurement
f_meas = [10; 20];
% Covariance array
f_err = [0.1 0.0;
0.0 0.2];
% Number of simulations
NSIM = 10000;
% Generate the Monte Carlo simulations of errored measurements
f_sim = mvnrnd(f_meas,f_err,NSIM);
% Define some function of the inputs that you care about
func = @(x) mean(log(x));
% For each simulation, apply the function.
% (You can probably do this step more efficiently that a loop, but it might depend on the function)
func_val = zeros(NSIM,1);
for ns = 1:NSIM
func_val(ns) = func(f_sim(ns,:));
end
% Take the mean (over the simulations)
mean_func_val = mean(func_val)
% Error in the statistic is the standard deviation over the simulations
err_func_val = std(func_val)
% Plot histograms of the simulated values, as a sanity check
figure
tiledlayout(3,1)
ax1=nexttile;
histogram(f_sim(:,1))
ax2=nexttile;
histogram(f_sim(:,2))
nexttile
histogram(func_val)
xline(mean_func_val,"Color","red")
xline(mean_func_val-err_func_val,"Color","red","LineStyle","--")
xline(mean_func_val+err_func_val,"Color","red","LineStyle","--")
linkaxes([ax1 ax2],"x")
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!