How to Perform a Weighted Fit to a Constant?

  • Context: Undergrad 
  • Thread starter Thread starter f95toli
  • Start date Start date
  • Tags Tags
    Constant Fit
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
Messages
3,510
Reaction score
1,073
I have the following silly problem I don't know how to get round:cry:

I have a set of datapoints, each point has known variance (this is experimental data).

I now want to fit this dataset using a constant, meaning I have an equation y=a, i.e. there is no independent variable.
I also want to know some goodness of fit parameters for my fit, i.e. the standard error and ideally also the R^2 value.

This would obviously be trivial if all the points had the same variance, but I don't know how to handle the fact that I need a weighted fit (presumably with 1/sqrt(variance) as weight for each point)

I do know how to do this for linear fits (Matlab's curve fitting toolbox etc), but Matlab doesn't seem to like fitting to constants. Hence, I might have to do it manually.
 
Physics news on Phys.org
After writing my question...I realized that all I need to do is to calculate the weighted mean:blushing:

Problem solved