TNK LAB

Least-Squares Fitting & Chi-Square Analysis

Enter your own $(x, y)$ data with uncertainties $\sigma_x$ and $\sigma_y$, fit a model, and see whether the fit is actually consistent with your data via a $\chi^2$ goodness-of-fit test — the same workflow you'd use to check a lab measurement against a theoretical model.

Constant
Linear
Quadratic
x y σy σx

Leave σx / σy blank or 0 for "no known uncertainty" (that column's error bars and its contribution to the effective variance are then switched off for that point).

Fit Results

Where This Comes From

$$\chi^2 = \sum_{i=1}^{N} \frac{\left(y_i - f(x_i)\right)^2}{\sigma_{\mathrm{eff},i}^2}, \qquad \chi^2_\nu = \frac{\chi^2}{N-p}$$

$f(x)$ is the fitted polynomial with $p$ free parameters, and $\nu = N-p$ is the number of degrees of freedom. Parameters are found by minimizing $\chi^2$ (weighted least squares), and the $p$-value is the probability that $\chi^2$ this large (or larger) would arise from a correct model just by random chance.

How are x-errors handled, and what does the p-value mean?

Ordinary least squares only weighs $y$-uncertainty. When a point also has an $x$-uncertainty, this sim uses the effective-variance method: it projects $\sigma_x$ onto the $y$-axis using the fit's local slope, $\sigma_{\mathrm{eff}}^2 = \sigma_y^2 + \left(\frac{df}{dx}\right)^2\sigma_x^2$, then refits and repeats until the parameters stop changing.

Rule of thumb for the reduced chi-square $\chi^2_\nu$: values near 1 mean the scatter in your data matches your stated uncertainties. $\chi^2_\nu \gg 1$ means the model doesn't fit well or your error bars are too small; $\chi^2_\nu \ll 1$ usually means the error bars are overestimated (or the model has more free parameters than the data can justify).

The $p$-value turns that into a single probability: conventionally $p<0.05$ is called a "bad fit" (reject the model at 95% confidence), while $p>0.05$ means the data don't give you a reason to reject it — that is not the same as proving the model is correct, only that it isn't contradicted by this data.

Data & Best Fit

Normalized Residuals, (y − f(x)) / σeff