Getting regression weights from histogram
2 views (last 30 days)
Show older comments
Matthias Schiedeck
on 9 Jun 2022
Edited: Alan Stevens
on 9 Jun 2022
Hello!
I have generated several data points from a given function in order to fit another curve. Although the input (concentrations) is always different, some output values (temperatures) seem to occur more frequently (see histogram). When fitting my new curve with these temperature values, frequently occurring values (e.g. 350 - 400 °C) are more heavily weighted than others (e.g. 500 - 550 °C).
Therefore I want to do a weighted regression/fit, where I give a little more weight to less frequently occurring values and less weight to more frequently occuring values (since it's not experimental data but just calculation results). I'm looking for something like the red curve drawn on the histogram. Unfortunately, I can't do this by hand since it's too many data points.
Is there a way to get something like the red curve from histogram data?
Thanks,
Matthias
0 Comments
Accepted Answer
Alan Stevens
on 9 Jun 2022
Edited: Alan Stevens
on 9 Jun 2022
Something like this perhaps?
% Dummy data
N = 1000;
M = N/40;
T = randn(N,1);
h = histogram(T,M);
W = max(h.Values)-h.Values;
x = min(T):(max(T)-min(T))/(M-1):max(T);
hold on
plot(x,W)
xlabel('T')
NB You will probably want to scale the weights as obtained above, so that you don't get a zero weight.
You could use interp1 if you need a separate weight for each temperature.
0 Comments
More Answers (0)
See Also
Categories
Find more on Fit Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!