Solved – Error bars and coefficient computation on linear regressions in Matlab

errorMATLABregression

I have a handful (~5) of values x I need to plot against a handful of values y (actually, log(x) vs. log(y)), in order to derive a linear equation used to derive an empiric power equation. However, I want to compute an error bar for the coefficient/power (e.g. x^(-3.5+-0.2)).

Here's the problem: Each value x, y has a unique error bar (However, the y error bars are the most important in this particular case). I'm only interested in the coefficient of the linear equation, so what I wonder is if there is a way to enter the set of error bars into the equation, and have matlab compute a good guess at the least and greatest plausible slope within the error range.

Otherwise, what would be a decent way to approximate this range of coefficients, for such a small set of values, assuming I know the relationship is linear? Simple slope between the extreme values of the least and greatest data point? Or is there perhaps a formula for computing the error range of a coefficient from the data set?

The problem I actually have is that while most of the mean values line up neatly, one deviates a bit; however, it is also the data point with the greatest error bar. And because there are large powers of variables with error bars involved, I want to get an idea of whether I can be at all confident in my coefficients. Carrying over error bars would seem like a decent way of doing it, if it is computationally feasible.

I hope the above makes sense. Thanks!

Best Answer

If sounds like you have some prior notion of the precision of your measurements. You can use

fitlm(x,y,'linear','weight',w)

to supply a vector of weights. It is common to use the inverse variance as a weight. So if the error bars are +/- 1 standard deviation, you might supply the reciprocal of the squares of these inverse standard deviations.

If you do that, the coefCI method will produce coefficient confidence intervals that take the weighting into account.

Related Question