Data Fitting and Regression

Least-squares data fitting, linear and nonlinear regression to extract physical parameters from measurements.

What it is

Curve fitting and statistical regression form the quantitative bridge connecting discrete experimental data points (xi,yi±σyi)(x_i, y_i \pm \sigma_{y_i}) with theoretical physical laws y=f(x;θ)y = f(x; \boldsymbol{\theta}), where θ=(θ1,…,θm)\boldsymbol{\theta} = (\theta_1, \dots, \theta_m) denotes the vector of unknown physical constants to determine (such as acceleration gg, Planck's constant hh, or internal resistance rr).

The gold standard in experimental physics is the weighted least-squares method, derived from maximum likelihood estimation under independent Gaussian errors. It consists of minimizing the goodness-of-fit chi-squared objective function (χ2\chi^2): χ2(θ)=∑i=1N(yi−f(xi;θ)σyi)2\chi^2(\boldsymbol{\theta}) = \sum_{i=1}^N \left( \frac{y_i - f(x_i; \boldsymbol{\theta})}{\sigma_{y_i}} \right)^2 Each data point enters the objective weighted inversely by its experimental variance: wi=1/σyi2w_i = 1/\sigma_{y_i}^2. High-precision data points exert strong mathematical pulling power on the fitted curve, while noisy points with broad error bars contribute marginally.

In the case of linear regression f(x)=mx+cf(x) = m x + c, analytical minimization yields exact weighted normal equations for slope mm and intercept cc, alongside their standard uncertainties and cross-covariance cov⁡(m,c)\operatorname{cov}(m, c).

Why it appears in physics

In physical science, no fundamental parameter is reliably measured from an isolated reading. Physical laws are confirmed by verifying whether functional relationships hold across decades of dynamic range:

  1. In Hooke's law (F=kΔxF = k \Delta x), spring stiffness kk is extracted as the slope of a linear fit between applied load and extension.
  2. In the photoelectric effect (V0e=hν−ΦV_0 e = h \nu - \Phi), the fundamental ratio h/eh/e is obtained from the slope of stopping potential versus incident photon frequency.
  3. In thermodynamics and nuclear physics, exponential and power laws are frequently linearized through logarithmic transformations (e.g. radioactive decay N(t)=N0e−λt  ⟹  ln⁡N=ln⁡N0−λtN(t) = N_0 e^{-\lambda t} \implies \ln N = \ln N_0 - \lambda t or Arrhenius activation energy ln⁡k=ln⁡A−Ea/RT\ln k = \ln A - E_a / RT).
  4. Goodness-of-fit evaluation via reduced chi-squared χν2=χ2/(N−m)\chi_\nu^2 = \chi^2 / (N - m) provides an objective arbiter: it certifies whether the physical model adequately describes the observations or if the hypothesis must be rejected.

Visual or geometric idea

Geometrically, the physical model f(x;θ)f(x; \boldsymbol{\theta}) traces a family of curves across the Cartesian plane (x,y)(x, y). Each data point carries a vertical error bar defining its uncertainty range ±σyi\pm \sigma_{y_i}.

The normalized residual ri=(yi−f(xi))/σyir_i = (y_i - f(x_i)) / \sigma_{y_i} measures the vertical distance between observation and curve in units of standard deviation. Weighted least squares deforms and shifts the curve to minimize the summed squared normalized distances. In a high-quality fit, the fitted line threads through approximately 68%68\% of the 1σ1\sigma error bars, with residuals scattered randomly above and below without coherent curvature or trend.

Minimal symbolic language

  1. Chi-squared loss function (χ2\chi^2): χ2=∑i=1Nwi[yi−f(xi)]2,wi=1σyi2\chi^2 = \sum_{i=1}^N w_i [y_i - f(x_i)]^2, \qquad w_i = \frac{1}{\sigma_{y_i}^2}
  2. Unweighted linear normal equations (wi=1w_i = 1): m=N∑xiyi−∑xi∑yiN∑xi2−(∑xi)2,c=yˉ−mxˉm = \frac{N \sum x_i y_i - \sum x_i \sum y_i}{N \sum x_i^2 - (\sum x_i)^2}, \qquad c = \bar{y} - m \bar{x}
  3. Reduced chi-squared (degrees of freedom ν=N−m\nu = N - m): χν2=χ2N−m\chi_\nu^2 = \frac{\chi^2}{N - m}
  4. Parameter covariance matrix (linear model y=Xθ\mathbf{y} = \mathbf{X} \boldsymbol{\theta}): Vθ=(XTWX)−1,σm=V11,σc=V22\mathbf{V}_{\boldsymbol{\theta}} = (\mathbf{X}^T \mathbf{W} \mathbf{X})^{-1}, \qquad \sigma_m = \sqrt{V_{11}}, \quad \sigma_c = \sqrt{V_{22}}
  5. Coefficient of determination (R2R^2): R2=1−∑(yi−y^i)2∑(yi−yˉ)2R^2 = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}

What the result means

The optimal parameters θ^\hat{\boldsymbol{\theta}} yield the best unbiased estimate of the underlying physical constants. Interpreting the reduced chi-squared χν2\chi_\nu^2 is crucial:

  • χν2≈1\chi_\nu^2 \approx 1: The model fits the data well, and estimated error bars accurately reflect true random experimental scatter.
  • χν2≫1\chi_\nu^2 \gg 1 (e.g. χν2>3\chi_\nu^2 > 3): Poor fit. Either the physical model is invalid (e.g. linear model applied to quadratic physics), unmodeled systematic errors exist, or uncertainties were severely underestimated.
  • χν2≪1\chi_\nu^2 \ll 1 (e.g. χν2<0.2\chi_\nu^2 < 0.2): Suspicious. Experimental uncertainties were grossly overestimated, or data points were artificially smoothed.

When not to use it

  1. Ordinary least squares when errors exist on both variables (xx and yy): If horizontal uncertainties σxi\sigma_{x_i} are significant relative to σyi\sigma_{y_i}, standard OLS underestimates slope mm (attenuation bias). Orthogonal distance regression (ODR) or the York estimator must be used.
  2. Unweighted linear regression on transformed non-linear equations: When linearizing y=AeBxy = A e^{B x} via logarithms, transformed variances scale as σln⁡y≈σy/y\sigma_{\ln y} \approx \sigma_y / y. Unweighted regression on ln⁡y\ln y assigns excessive weight to tiny values of yy carrying massive relative uncertainties, distorting parameter extraction. Weighted regression with wi=yi2/σyi2w_i = y_i^2 / \sigma_{y_i}^2 or direct nonlinear optimization (Levenberg-Marquardt) is mandatory.
  3. Overfitting: Fitting an (N−1)(N-1)-degree polynomial to NN data points forces χ2=0\chi^2 = 0 but destroys predictive insight, producing wild oscillations between points (Runge's phenomenon). Model complexity must be rooted in physical mechanisms.

Operational summary

  • Plot experimental data on a scatter plot displaying explicit error bars σyi\sigma_{y_i} (and σxi\sigma_{x_i} where applicable).
  • Formulate the model function and determine linearity in parameters.
  • For linear models, solve the weighted least-squares normal equations with weights wi=1/σi2w_i = 1/\sigma_i^2.
  • Extract standard parameter errors σm\sigma_m and σc\sigma_c from the diagonal elements of the covariance matrix.
  • Evaluate reduced chi-squared χν2\chi_\nu^2 and inspect normalized residuals for systematic trends.

Weighted Linear Regression and Curve Fitting Procedure

Before calculating

Tabulate experimental observations in three columns: independent coordinate xix_i, dependent coordinate yiy_i, and standard experimental uncertainty σyi\sigma_{y_i}. Ensure all σyi>0\sigma_{y_i} > 0. If measurement uncertainties are identical across all points (homoscedasticity), ordinary unweighted least squares may be used; if uncertainties vary between data points (heteroscedasticity), statistical weights wi=1/σyi2w_i = 1/\sigma_{y_i}^2 must be calculated.

Step 1: identify the mathematical object

Formulate the linear mathematical model linking physical quantities: y=mx+cy = m x + c Map the fit parameters (m,c)(m, c) to underlying physical constants:

  • Ohm's law (V=RIV = R I): dependent variable y=Vy = V, independent variable x=Ix = I, slope m=Rm = R, theoretical intercept c=0c = 0.
  • Linear thermal expansion (L=L0+L0αΔTL = L_0 + L_0 \alpha \Delta T): slope m=L0αm = L_0 \alpha, intercept c=L0c = L_0.

Step 2: choose the operation

Compute the fundamental weighted moments of the dataset: S=∑i=1Nwi,Sx=∑i=1Nwixi,Sy=∑i=1NwiyiS = \sum_{i=1}^N w_i, \quad S_x = \sum_{i=1}^N w_i x_i, \quad S_y = \sum_{i=1}^N w_i y_i Sxx=∑i=1Nwixi2,Sxy=∑i=1Nwixiyi,Syy=∑i=1Nwiyi2S_{xx} = \sum_{i=1}^N w_i x_i^2, \quad S_{xy} = \sum_{i=1}^N w_i x_i y_i, \quad S_{yy} = \sum_{i=1}^N w_i y_i^2 Compute the linear system determinant: Δ=S⋅Sxx−(Sx)2\Delta = S \cdot S_{xx} - (S_x)^2

Step 3: preserve units and signs

  • Statistical weights wi=1/σyi2w_i = 1/\sigma_{y_i}^2 carry physical dimensions [y]−2[y]^{-2}.
  • The fitted slope mm carries units of [y]/[x][y] / [x].
  • The intercept cc carries units of [y][y].
  • The determinant Δ\Delta has units [y]−4[x]2[y]^{-4} [x]^2. Preserve algebraic signs strictly in all cross-products SxyS_{xy}.

Step 4: calculate

  1. Optimal fit parameters: m=S⋅Sxy−Sx⋅SyΔm = \frac{S \cdot S_{xy} - S_x \cdot S_y}{\Delta} c=Sxx⋅Sy−Sx⋅SxyΔc = \frac{S_{xx} \cdot S_y - S_x \cdot S_{xy}}{\Delta}
  2. Standard parameter uncertainties: σm=SΔ\sigma_m = \sqrt{\frac{S}{\Delta}} σc=SxxΔ\sigma_c = \sqrt{\frac{S_{xx}}{\Delta}} cov⁡(m,c)=−SxΔ\operatorname{cov}(m, c) = -\frac{S_x}{\Delta}
  3. Goodness of fit (Chi-squared and residuals): χ2=∑i=1Nwi(yi−mxi−c)2\chi^2 = \sum_{i=1}^N w_i (y_i - m x_i - c)^2 Degrees of freedom: ν=N−2\nu = N - 2. χν2=χ2N−2\chi_\nu^2 = \frac{\chi^2}{N - 2}

Step 5: interpret the result

  • Physical inference: Derive the target constant from mm or cc, propagating uncertainties via σm\sigma_m or σc\sigma_c.
  • Validation criterion χν2\chi_\nu^2:
    • If 0.8≤χν2≤1.50.8 \leq \chi_\nu^2 \leq 1.5: the model is valid and experimental uncertainties are well-estimated.
    • If χν2>2\chi_\nu^2 > 2: inspect normalized residuals ri=yi−(mxi+c)r_i = y_i - (m x_i + c). Parabolic residual patterns indicate missing nonlinear physics (e.g. x2x^2 term).
  • Final reporting: Report parameters with clear physical units and consistent decimal rounding matching uncertainty: m=(mˉ±σm) [units]m = (\bar{m} \pm \sigma_m) \text{ [units]}, c=(cˉ±σc) [units]c = (\bar{c} \pm \sigma_c) \text{ [units]}.

Self-check checklist

  • Is determinant Δ>0\Delta > 0? (If Δ=0\Delta = 0, all xix_i values are identical, making a slope mathematically undefined).
  • Do units of slope match [y]/[x][y]/[x] and intercept match [y][y]?
  • Did I verify that residuals do not show systematic curvature?
  • Is reduced chi-squared χν2\chi_\nu^2 close to unity?
  • If theoretical physics requires c=0c = 0 (e.g. Ohm's law), is the fitted intercept consistent with zero within [−σc,+σc][-\sigma_c, +\sigma_c]?

Guided Example: Determining Planck's Constant via the Photoelectric Effect

Physical Situation

In Millikan's classic photoelectric experiment, a cesium photocathode is illuminated with monochromatic light across 4 distinct optical frequencies ν\nu. For each frequency, the stopping potential V0V_0 required to quench the electronic photocurrent is recorded, alongside an experimental measurement uncertainty σV=0.02 V\sigma_V = 0.02 \text{ V} across all data points:

  • Point 1: ν1=5.50×1014 Hz\nu_1 = 5.50 \times 10^{14} \text{ Hz}, V0,1=0.36±0.02 VV_{0,1} = 0.36 \pm 0.02 \text{ V}
  • Point 2: ν2=6.20×1014 Hz\nu_2 = 6.20 \times 10^{14} \text{ Hz}, V0,2=0.65±0.02 VV_{0,2} = 0.65 \pm 0.02 \text{ V}
  • Point 3: ν3=6.90×1014 Hz\nu_3 = 6.90 \times 10^{14} \text{ Hz}, V0,3=0.94±0.02 VV_{0,3} = 0.94 \pm 0.02 \text{ V}
  • Point 4: ν4=7.60×1014 Hz\nu_4 = 7.60 \times 10^{14} \text{ Hz}, V0,4=1.23±0.02 VV_{0,4} = 1.23 \pm 0.02 \text{ V}

The fundamental elementary charge is e=1.602×10−19 Ce = 1.602 \times 10^{-19} \text{ C}. The goal is to estimate Planck's constant hh and the cathode work function Φ\Phi.

Mathematical Translation

Einstein's photoelectric equation is: eV0=hν−Φ  ⟹  V0=(he)ν−Φee V_0 = h \nu - \Phi \implies V_0 = \left( \frac{h}{e} \right) \nu - \frac{\Phi}{e} This maps to a straight line y=mx+cy = m x + c where y=V0y = V_0, x=νx = \nu, slope m=h/em = h/e, and intercept c=−Φ/ec = -\Phi/e. Since all measurement uncertainties are identical (σi=0.02 V\sigma_i = 0.02 \text{ V}), statistical weights are uniform: wi=1/(0.02)2=2500 V−2w_i = 1/(0.02)^2 = 2500 \text{ V}^{-2}. Using scaled coordinates xx in units of 1014 Hz10^{14} \text{ Hz}: x=[5.50,6.20,6.90,7.60]x = [5.50, 6.20, 6.90, 7.60], y=[0.36,0.65,0.94,1.23]y = [0.36, 0.65, 0.94, 1.23].

Step-by-Step Calculation

  1. Sample Means: N=4N = 4 xˉ=5.50+6.20+6.90+7.604=6.55×1014 Hz\bar{x} = \frac{5.50 + 6.20 + 6.90 + 7.60}{4} = 6.55 \times 10^{14} \text{ Hz} yˉ=0.36+0.65+0.94+1.234=0.795 V\bar{y} = \frac{0.36 + 0.65 + 0.94 + 1.23}{4} = 0.795 \text{ V}
  2. Centered Summations: ∑(xi−xˉ)2=(−1.05)2+(−0.35)2+(0.35)2+(1.05)2=2.45\sum (x_i - \bar{x})^2 = (-1.05)^2 + (-0.35)^2 + (0.35)^2 + (1.05)^2 = 2.45 ∑(xi−xˉ)(yi−yˉ)=(−1.05)(−0.435)+(−0.35)(−0.145)+(0.35)(0.145)+(1.05)(0.435)=1.015\sum (x_i - \bar{x})(y_i - \bar{y}) = (-1.05)(-0.435) + (-0.35)(-0.145) + (0.35)(0.145) + (1.05)(0.435) = 1.015
  3. Slope and Intercept: m=1.0152.45≈0.4142857 V/(1014 Hz)=4.143×10−15 V⋅sm = \frac{1.015}{2.45} \approx 0.4142857 \text{ V}/(10^{14} \text{ Hz}) = 4.143 \times 10^{-15} \text{ V}\cdot\text{s} c=yˉ−mxˉ=0.795−(0.4142857×6.55)=−1.9186 Vc = \bar{y} - m \bar{x} = 0.795 - (0.4142857 \times 6.55) = -1.9186 \text{ V}
  4. Statistical Uncertainties: σm=σ∑(xi−xˉ)2=0.022.45×1014≈0.128×10−15 V⋅s\sigma_m = \frac{\sigma}{\sqrt{\sum (x_i - \bar{x})^2}} = \frac{0.02}{\sqrt{2.45} \times 10^{14}} \approx 0.128 \times 10^{-15} \text{ V}\cdot\text{s} σc=σ1N+xˉ2∑(xi−xˉ)2=0.020.25+17.511≈0.084 V\sigma_c = \sigma \sqrt{\frac{1}{N} + \frac{\bar{x}^2}{\sum (x_i - \bar{x})^2}} = 0.02 \sqrt{0.25 + 17.511} \approx 0.084 \text{ V}
  5. Recovering Physical Parameters: h=m⋅e=(4.143×10−15 V⋅s)×(1.602×10−19 C)=6.637×10−34 J⋅sh = m \cdot e = (4.143 \times 10^{-15} \text{ V}\cdot\text{s}) \times (1.602 \times 10^{-19} \text{ C}) = 6.637 \times 10^{-34} \text{ J}\cdot\text{s} σh=σm⋅e=0.205×10−34 J⋅s\sigma_h = \sigma_m \cdot e = 0.205 \times 10^{-34} \text{ J}\cdot\text{s} Work function: Φ=−c⋅e=1.919 eV±0.084 eV\Phi = -c \cdot e = 1.919 \text{ eV} \pm 0.084 \text{ eV}.

Reading the Result

The computed value for Planck's constant is h=(6.64±0.21)×10−34 J⋅sh = (6.64 \pm 0.21) \times 10^{-34} \text{ J}\cdot\text{s}. The CODATA accepted reference value hCODATA=6.62607015×10−34 J⋅sh_{\text{CODATA}} = 6.62607015 \times 10^{-34} \text{ J}\cdot\text{s} falls cleanly within the 68%68\% confidence interval.

Common Error Avoided

Forcing the regression line through the origin (c=0c=0). Imposing c=0c=0 would erroneously assume electrons require zero binding energy to escape the photocathode, corrupting the slope and yielding an inaccurate value for hh.


Inverse Example: Diagnosing Newton's Law of Cooling from Structured Residuals

Physical Situation

A student investigates the thermal cooling of a heated metallic sample in ambient air at Tamb=20.0∘CT_{\text{amb}} = 20.0^\circ\text{C}. The student fits temperature T(t)T(t) directly to a linear model T(t)=mt+cT(t) = m t + c, obtaining m=−0.50∘C/minm = -0.50^\circ\text{C/min} and c=80.0∘Cc = 80.0^\circ\text{C} with a high correlation coefficient R2=0.94R^2 = 0.94. However, the residual plot shows negative residuals for t<20 mint < 20 \text{ min}, strongly positive residuals for 20<t<60 min20 < t < 60 \text{ min}, and negative residuals again for t>60 mint > 60 \text{ min}.

Given Result

Linear fit with an inverted parabolic residual signature (systematic deterministic curvature).

Analytical Reconstruction

Systematic curvature in residuals proves the linear model violates the underlying continuum physics. Newton's law of cooling governs the process: dTdt=−k(T−Tamb)  ⟹  T(t)−Tamb=(T0−Tamb)e−kt\frac{dT}{dt} = -k (T - T_{\text{amb}}) \implies T(t) - T_{\text{amb}} = (T_0 - T_{\text{amb}}) e^{-k t} Linearizing by taking the natural logarithm of excess temperature ΔT=T(t)−Tamb\Delta T = T(t) - T_{\text{amb}}: y∗=ln⁡(T(t)−20.0)=ln⁡(T0−20.0)−kty^* = \ln(T(t) - 20.0) = \ln(T_0 - 20.0) - k t Plotting ln⁡(T−20.0)\ln(T - 20.0) against time tt eliminates all residual curvature, scattering points randomly around zero and dropping reduced χν2\chi_\nu^2 from 18.418.4 down to 1.051.05.

What Physical Question It Can Answer

Why is a high R2=0.94R^2 = 0.94 insufficient proof of linearity? The coefficient of determination R2R^2 measures explained variance but cannot detect systematic model bias. Residual analysis and reduced χν2\chi_\nu^2 are mandatory to reveal whether the true physics is exponential rather than linear.

Boundary Verification

As t→∞t \to \infty, the false linear model predicts T→−∞T \to -\infty (violating absolute zero and thermal equilibrium), whereas the exponential model properly asymptotes to T(t)→Tamb=20∘CT(t) \to T_{\text{amb}} = 20^\circ\text{C}.

Common Mistakes in Data Fitting and Regression

1. Relying solely on R2R^2 to assess linearity

It seems reasonable because an R2>0.98R^2 > 0.98 delivers a deceptive sense of mathematical perfection. It fails because R2R^2 only measures variance reduction relative to a horizontal mean line; it is completely blind to systematic residual curvature (Anscombe's quartet demonstrates four datasets sharing identical R2=0.67R^2 = 0.67 where one is linear, one is a clean parabola, and another has an extreme outlier). It is detected by plotting residuals or computing χν2\chi_\nu^2. It is corrected by always graphing residuals ri=yi−f(xi)r_i = y_i - f(x_i) and demanding χν2≈1\chi_\nu^2 \approx 1. Mini-example: fitting y=x2y = x^2 for x∈[10,20]x \in [10, 20] to a straight line yields R2>0.99R^2 > 0.99, yet residuals form an obvious parabolic arch disproving physical linearity.

2. Using ordinary least squares when uncertainties exist on both coordinates

It seems reasonable because standard software routines only take single XX and YY columns. It fails because ordinary least squares assumes XX is perfectly known with all variance localized in YY. When XX carries experimental error σx\sigma_x, the estimated slope suffers attenuation bias and is systematically shifted toward zero. It is detected whenever horizontal error bars are visible on the scatter plot. It is corrected by employing Deming orthogonal distance regression or the York weighted algorithm. Mini-example: if true physics is y=2xy = 2 x but xx contains substantial random noise, standard OLS regression of yy on xx returns a slope near 1.61.6 instead of 2.02.0.

3. Neglecting variance weighting when linearizing physical equations

It seems reasonable because transforming y=AeBxy = A e^{B x} into ln⁡y=ln⁡A+Bx\ln y = \ln A + B x looks like simple algebra. It fails because logarithmic transformations warp error bars nonlinearly: σln⁡y=σy/y\sigma_{\ln y} = \sigma_y / y. Data points with small physical values of yy experience massive uncertainty expansion on the logarithmic scale. It is detected when running unweighted linear fits on logarithmic data spanning several orders of magnitude. It is corrected by assigning statistical weights wi=1/σln⁡yi2=yi2/σyi2w_i = 1/\sigma_{\ln y_i}^2 = y_i^2 / \sigma_{y_i}^2. Mini-example: in radioactive decay curves, tail points near background may have σln⁡y=2.0\sigma_{\ln y} = 2.0, while initial points have σln⁡y=0.01\sigma_{\ln y} = 0.01. Equal weighting lets background noise corrupt the half-life determination.

4. Forcing zero intercept without physical justification

It seems reasonable because elementary textbooks write physical laws as y=mxy = m x with zero intercept (e.g. V=RIV = R I or F=maF = m a). It fails because physical experiments feature amplifier offsets, zero-drift calibration shifts, or static friction thresholds. Forcing c=0c=0 distorts the slope to absorb unmodeled instrument offsets. It is detected when software is configured with "intercept = 0" without testing whether an unrestricted fit yields an intercept compatible with zero within [−σc,+σc][-\sigma_c, +\sigma_c]. It is corrected by fitting two unconstrained parameters (m,c)(m, c) and performing a statistical hypothesis test on cc. Mini-example: an ammeter with +0.1 A+0.1 \text{ A} zero-shift will cause a 10%10\% error in resistance if the fit is forced through the origin.

5. Polynomial overfitting of noisy measurements

It seems reasonable because adding polynomial degrees monotonically lowers residual sum of squares χ2\chi^2. It fails because higher polynomial degrees model noise rather than underlying physics, producing violent unphysical oscillations between data coordinates. It is detected when reduced chi-squared drops below 0.2 (χν2<0.2\chi_\nu^2 < 0.2) and the fitted curve ripples between points. It is corrected by choosing models grounded in physical differential equations or applying model selection metrics like AIC or BIC. Mini-example: fitting 6 free-fall observations with a 5th-degree polynomial yields χ2=0\chi^2 = 0, but interpolates negative or infinite local accelerations violating gravity.

Quick detection rule

  • After every fit, plot normalized residuals ri=yi−f(xi)r_i = y_i - f(x_i) against xix_i.
  • If residuals trace a "U" or "S" shape, the model is not linear, no matter how close R2R^2 is to 1.

Physical Applications of Data Fitting and Regression

1. Classical mechanics: verification of Newton's second law and inertial mass

Appears when testing F=maF = m a on dynamic linear tracks using load cells and optical photogates, varying applied force and measuring chariot acceleration. It is calculated by running weighted linear regression of acceleration aa versus force FF: a=(1mtotal)F−ffricmtotala = \left(\frac{1}{m_{\text{total}}}\right) F - \frac{f_{\text{fric}}}{m_{\text{total}}}. The result gives total system inertial mass from the reciprocal of slope (mtotal=1/slopem_{\text{total}} = 1/\text{slope}) and friction force from the vertical intercept. The critical danger is forcing zero intercept; unavoidable friction introduces a finite negative intercept which, if omitted, artificially overestimates true inertial mass. As a final sanity check, regression-derived mass is cross-checked against gravitational mass measured statically on an analytical balance to verify the equivalence principle.

2. Thermodynamics: absolute zero determination via Charles's law

Appears in constant-volume gas thermometry, measuring pressure PP of a trapped ideal gas sample across known temperatures TT in Celsius (ice bath, steam, oil baths). It is calculated by fitting P(T)=mT+cP(T) = m T + c, where ideal gas physics dictates P=nRV(TC+273.15)P = \frac{n R}{V} (T_C + 273.15). The result derives experimental absolute zero by extrapolating the fitted line to zero pressure (P=0P=0): Tzero=−c/mT_{\text{zero}} = -c / m. The critical danger is extrapolating from a narrow temperature span (e.g. 20∘C20^\circ\text{C} to 40∘C40^\circ\text{C}), where tiny slope uncertainties σm\sigma_m drastically magnify extrapolation error bars at −273∘C-273^\circ\text{C}. As a final sanity check, propagated extrapolation uncertainty σTzero=∣Tzero∣(σc/c)2+(σm/m)2−2cov⁡(m,c)/(mc)\sigma_{T_{\text{zero}}} = |T_{\text{zero}}| \sqrt{(\sigma_c/c)^2 + (\sigma_m/m)^2 - 2\operatorname{cov}(m, c)/(m c)} is verified to enclose −273.15∘C-273.15^\circ\text{C}.

3. Electromagnetism: internal resistance and open-circuit EMF

Appears when testing terminal voltage VV of a battery across varying load currents II. It is calculated via linear fit V=E−rIV = \mathcal{E} - r I, where the vertical intercept delivers open-circuit electromotive force (EMF) E\mathcal{E} and slope magnitude provides internal resistance rr. The result establishes the maximum power transfer point (achieved when load matches internal resistance RL=rR_L = r). The critical danger is ignoring internal heating at high currents, which causes internal resistance to drift upwards during testing, curving data points at the high-current limit. As a final sanity check, high-current points subject to thermal drift are excluded and residual linearity is confirmed.

4. Optics and atomic physics: Rydberg constant from hydrogen Balmer series

Appears in emission spectroscopy when measuring wavelengths λ\lambda of visible hydrogen Balmer lines (Hα,Hβ,HγH_\alpha, H_\beta, H_\gamma) using a diffraction grating spectrometer. It is calculated via Rydberg's formula 1λ=RH(14−1n2)\frac{1}{\lambda} = R_H \left( \frac{1}{4} - \frac{1}{n^2} \right). Defining y=1/λy = 1/\lambda and x=(0.25−1/n2)x = (0.25 - 1/n^2) for n=3,4,5,6n = 3, 4, 5, 6, linear regression extracts slope RHR_H. The result provides the Rydberg constant RH≈1.097×107 m−1R_H \approx 1.097 \times 10^7 \text{ m}^{-1}, linking atomic spectra to fundamental constants me,e,ℏ,cm_e, e, \hbar, c. The critical danger is propagating diffraction angles θ\theta to wavelengths λ=dsin⁡θ\lambda = d \sin\theta without accounting for the cos⁡θ\cos\theta non-uniform uncertainty stretch, assigning improper weights to violet lines. As a final sanity check, fitted intercept is tested against zero and reduced chi-squared confirms Bohr model validity.

5. Astrophysics: Hubble constant determination (H0H_0)

Appears in observational cosmology when mapping radial recession velocity vv (via Doppler redshift zz) against luminosity distance dd (via Type Ia supernovae or Cepheid variable stars). It is calculated by applying weighted regression to the Hubble-Lemaître law: v=H0dv = H_0 d. The result determines cosmic expansion rate H0≈70 (km/s)/MpcH_0 \approx 70 \text{ (km/s)/Mpc} and estimates the age of the observable universe as t0∼1/H0t_0 \sim 1/H_0. The critical danger is neglecting local galaxy peculiar velocities induced by gravitational clustering (such as the Great Attractor), which distorts the slope unless the sample is restricted to deep Hubble flow (d>50 Mpcd > 50 \text{ Mpc}), or failing to use the York estimator when both axes carry large relative uncertainties. As a final sanity check, residuals are inspected and compared with cosmic microwave background parameters (Planck satellite).

Guided Practice: Data Fitting and Regression

Level 1: recognition

Propose the variable transformation (X,Y)(X, Y) that linearizes each physical law into Y=mX+cY = m X + c:

  1. Inverse-square law: y=Ax2y = \frac{A}{x^2}.
  2. Simple pendulum period: T=2πLgT = 2\pi \sqrt{\frac{L}{g}}.
  3. Capacitor discharge current: I(t)=I0e−t/RCI(t) = I_0 e^{-t/RC}.
  4. Stefan-Boltzmann blackbody radiation: P(T)=σAT4P(T) = \sigma A T^4.

Solution:

  1. Set Y=yY = y and X=1/x2X = 1/x^2 (or ln⁡y=ln⁡A−2ln⁡x\ln y = \ln A - 2\ln x with Y=ln⁡yY = \ln y and X=ln⁡xX = \ln x).
  2. Square both sides: T2=(4π2g)LT^2 = \left(\frac{4\pi^2}{g}\right) L. Set Y=T2Y = T^2 and X=LX = L (slope m=4π2/gm = 4\pi^2/g).
  3. Take natural logs: ln⁡I=ln⁡I0−(1RC)t\ln I = \ln I_0 - \left(\frac{1}{RC}\right) t. Set Y=ln⁡IY = \ln I and X=tX = t (slope m=−1/RCm = -1/RC, intercept c=ln⁡I0c = \ln I_0).
  4. Set Y=PY = P and X=T4X = T^4 (slope m=σAm = \sigma A).

Level 2: direct application

Three data pairs of force versus elongation are recorded for an elastic spring:

  • x1=0.02 m,F1=1.95 Nx_1 = 0.02 \text{ m}, F_1 = 1.95 \text{ N}
  • x2=0.04 m,F2=4.05 Nx_2 = 0.04 \text{ m}, F_2 = 4.05 \text{ N}
  • x3=0.06 m,F3=5.98 Nx_3 = 0.06 \text{ m}, F_3 = 5.98 \text{ N}

Assuming uniform uncertainty σF=0.05 N\sigma_F = 0.05 \text{ N}, compute spring constant kk via linear fit F=kx+cF = k x + c and test if intercept cc is consistent with zero.

Solution:

  1. Sample means: xˉ=(0.02+0.04+0.06)/3=0.04 m\bar{x} = (0.02 + 0.04 + 0.06)/3 = 0.04 \text{ m}. Fˉ=(1.95+4.05+5.98)/3=3.9933 N\bar{F} = (1.95 + 4.05 + 5.98)/3 = 3.9933 \text{ N}.
  2. Deviations: xi−xˉ=[−0.02,0.00,+0.02]x_i - \bar{x} = [-0.02, 0.00, +0.02]. Fi−Fˉ=[−2.0433,+0.0567,+1.9867]F_i - \bar{F} = [-2.0433, +0.0567, +1.9867].
  3. Sums: ∑(xi−xˉ)2=0.0008 m2\sum (x_i - \bar{x})^2 = 0.0008 \text{ m}^2. ∑(xi−xˉ)(Fi−Fˉ)=0.0806 N⋅m\sum (x_i - \bar{x})(F_i - \bar{F}) = 0.0806 \text{ N}\cdot\text{m}.
  4. Slope (kk): k=0.08060.0008=100.75 N/mk = \frac{0.0806}{0.0008} = 100.75 \text{ N/m}
  5. Intercept cc: c=Fˉ−kxˉ=3.9933−(100.75×0.04)=−0.0367 Nc = \bar{F} - k \bar{x} = 3.9933 - (100.75 \times 0.04) = -0.0367 \text{ N}
  6. Standard parameter uncertainties: σk=0.050.0008≈1.77 N/m\sigma_k = \frac{0.05}{\sqrt{0.0008}} \approx 1.77 \text{ N/m} σc=0.0513+(0.04)20.0008=0.052.3333≈0.076 N\sigma_c = 0.05 \sqrt{\frac{1}{3} + \frac{(0.04)^2}{0.0008}} = 0.05 \sqrt{2.3333} \approx 0.076 \text{ N} Result: k=(100.8±1.8) N/mk = (100.8 \pm 1.8) \text{ N/m}. Intercept c=(−0.04±0.08) Nc = (-0.04 \pm 0.08) \text{ N} is fully consistent with zero (∣c∣<σc|c| < \sigma_c).

Level 3: tool selection

You record 50 data points of electrical resistivity versus temperature ρ(T)\rho(T) of a superconductor. Between 100 K100\text{ K} and 150 K150\text{ K} behavior is linear, but below 95 K95\text{ K} resistance abruptly vanishes to zero. How should you extract the normal-state linear temperature coefficient?

Solution: You must truncate the regression domain:

  1. Never perform a single global regression across phase transitions.
  2. Restrict data to T≥105 KT \geq 105\text{ K} where the metallic normal state is rigorously established.
  3. Perform weighted linear regression solely on that sub-domain.
  4. Inspect residuals to ensure no superconducting fluctuation tail contaminates the selected linear window.

Level 4: physical interpretation

A linear fit of velocity versus time v(t)=at+v0v(t) = a t + v_0 on an air track with N=20N=20 points yields R2=0.998R^2 = 0.998 but reduced chi-squared χν2=4.8\chi_\nu^2 = 4.8. Explain this physical discrepancy.

Solution: R2=0.998R^2 = 0.998 merely indicates that 99.8%99.8\% of overall variance follows the general acceleration trend. However, χν2=4.8≫1\chi_\nu^2 = 4.8 \gg 1 proves that point-by-point deviations from the straight line are nearly 5 times larger than expected from random statistical noise alone. Physical reasons:

  1. Quadratic air drag Fd=−bv2F_d = -b v^2 introduces subtle downward curvature.
  2. The air track has a slight physical sag or tilt variation along its length.
  3. Photogate timer uncertainties were underestimated.

Level 5: intentional mistake

To linearize y=Ae−Bxy = A e^{-B x}, a student takes logarithms Y=ln⁡yY = \ln y and applies ordinary unweighted regression to: y1=100.0±1.0  ⟹  Y1=4.605y_1 = 100.0 \pm 1.0 \implies Y_1 = 4.605 y2=10.0±1.0  ⟹  Y2=2.303y_2 = 10.0 \pm 1.0 \implies Y_2 = 2.303 y3=1.0±1.0  ⟹  Y3=0.000y_3 = 1.0 \pm 1.0 \implies Y_3 = 0.000 The student weights all three transformed points equally. Explain why this creates massive bias.

Conceptual blunder: By error propagation, logarithmic uncertainty is σY=σy/y\sigma_Y = \sigma_y / y.

  • Point 1: σY1=1.0/100.0=0.01  ⟹  w1=10 000\sigma_{Y_1} = 1.0 / 100.0 = 0.01 \implies w_1 = 10\,000.
  • Point 2: σY2=1.0/10.0=0.10  ⟹  w2=100\sigma_{Y_2} = 1.0 / 10.0 = 0.10 \implies w_2 = 100.
  • Point 3: σY3=1.0/1.0=1.00  ⟹  w3=1\sigma_{Y_3} = 1.0 / 1.0 = 1.00 \implies w_3 = 1.

In unweighted regression, point 3 (with 100%100\% relative uncertainty) receives the identical weight as point 1 (with 0.010.01 uncertainty). Point 1 is actually 10,000 times more reliable. Equal weighting lets noise in the tail corrupt the slope calculation.