How to Perform a Weighted Fit to a Constant?

  • Context: Undergrad 
  • Thread starter Thread starter f95toli
  • Start date Start date
  • Tags Tags
    Constant Fit
Click For Summary
SUMMARY

This discussion addresses the challenge of performing a weighted fit to a constant using experimental data with known variances for each data point. The user seeks to fit the dataset to the equation y=a, while also obtaining goodness of fit parameters such as standard error and R² value. The solution involves calculating the weighted mean, utilizing weights defined as 1/sqrt(variance) for each point. The user notes that while Matlab's curve fitting toolbox is effective for linear fits, it does not support fitting to constants directly.

PREREQUISITES
  • Understanding of weighted averages and their calculation
  • Familiarity with statistical concepts such as standard error and R² value
  • Basic knowledge of Matlab and its curve fitting toolbox
  • Experience with experimental data analysis
NEXT STEPS
  • Research the calculation of weighted means in statistical analysis
  • Explore Matlab's capabilities for custom fitting functions
  • Learn about goodness of fit metrics in regression analysis
  • Investigate alternative software tools for statistical fitting, such as Python's SciPy library
USEFUL FOR

Researchers, data analysts, and statisticians who are working with experimental data and require methods for fitting constants while accounting for variance in their datasets.

f95toli
Science Advisor
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
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 28 ·
Replies
28
Views
3K
  • · Replies 16 ·
Replies
16
Views
3K
Replies
24
Views
3K
Replies
28
Views
4K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
8
Views
2K
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K