Skip to content

Improve curve-fit reports, uncertainty handling, and results layout - #9

Open
paulnord wants to merge 21 commits into
OpenSourcePhysics:masterfrom
paulnord:improve-curve-fit-reports
Open

Improve curve-fit reports, uncertainty handling, and results layout#9
paulnord wants to merge 21 commits into
OpenSourcePhysics:masterfrom
paulnord:improve-curve-fit-reports

Conversation

@paulnord

@paulnord paulnord commented Sep 5, 2026

Copy link
Copy Markdown

Curve-fit results now provide unit-bearing spreadsheet exports and experimental-physics fit statistics while keeping equal-weight least squares as the default. Expanding the report or changing the optional common measurement uncertainty does not change the best-fit coefficients.

Copy Fit Report now defaults to a compact classroom summary: model, equation, variable units, coefficients and errors, and the statistics shown on screen. The adjacent ... menu offers Copy Full Fit Report for the detailed analysis. Both retain full-precision spreadsheet cells.

The full report explicitly identifies X/Y variables and units, observations, editable parameter count, independent parameter rank, rank-aware degrees of freedom, residual statistics, centered R Square, chi-square, and one full-precision parameter table. For example, quadratic position-versus-time coefficients have m/s^2, m/s, and m units, following KnownPolynomial's verified descending-degree parameter order. UserFunction parameter units are not guessed.

DataTable exports obtain units from existing metadata, not column-name parsing. Raw and formatted copies share unit-bearing headers while retaining their numeric serialization and delimiters. ASCII expressions replace display superscripts, and copy/paste does not append duplicate unit suffixes. Unitless columns retain their previous subscript normalization.

The compact optional uncertainty controls support:

  • Estimated from residuals (default): sigma_y = sqrt(SSE/(n-rank)), chi-square = df and reduced chi-square = 1 by construction when defined; Q is N/A. The report explicitly states this is not an independent goodness-of-fit test.
  • A specified positive constant sigma_y: chi-square = SSE/sigma_y^2, reduced chi-square = chi-square/df, Q = the chi-square survival probability. The supplied scale is never recalibrated. Invalid input remains unavailable rather than falling back to estimated noise.
  • Fractional/custom pixels when a host supplies a valid direct-position conversion. OSP exposes a session-only FitMetadataProvider API; companion Tracker draft PR #74 supplies its existing calibration metadata. No project format change or general dimensional-analysis engine is introduced.

Coefficient standard errors retain Tracker's Bevington Eq. 8.13 profile/refit curvature method. Supplied sigma changes its scale; it does not replace the method with Jacobian covariance. Redundant parameters retain N/A errors and an explicit identifiability warning. Perfect residual-estimated fits report undefined chi-square rather than 0/0; a supplied positive sigma permits zero chi-square and Q=1.

Centered R Square remains descriptive variance explained, with the existing caution about Excel's uncentered convention for some through-zero fits. Rank is based on normalized derivative columns with tolerance 1e-7; nonlinear interpretation is local. Valid classical polynomial ANOVA remains supplemental. No coefficient p-values or confidence intervals were added.

Earlier improvements in this PR remain: two significant uncertainty digits with matching coefficient precision, full-precision values for computation/export, immediate fixed/free parameter updates in Autofit, manual-mode preservation, a Copy Fit Report button, context-menu gestures that preserve Autofit, and compact fit information/statistics with stable layout during selection and resizing.

Validation of this revision:

  • macOS desktop: 592 assertions across precision (19), report (118), popup (17), Data Tool layout (234), constraints (40), and physics/units (164); all pass. The fixture cleanup now clears its disposable tab’s changed flag before disposal to avoid a modal save prompt that previously caused intermittent timeouts.
  • Chrome, Firefox, and Playwright WebKit: 341 computational assertions per browser (19 precision, 118 report, 40 constraint, 164 physics).
  • Browser UI: resizing and point selection preserve layout; fixed parameters and supplied sigma update reporting correctly; coefficients stay unchanged when sigma changes; actual compact and full report copy gestures work. Chrome clipboard readback matches the expected TSV exactly. Firefox/WebKit clipboard contents were not read back.
  • The companion Tracker adapter builds against the new OSP classes and passes 17 calibration/column-identity checks; its four source files transpile with SwingJS. OSP changed classes and regression fixtures also transpile successfully.
  • Earlier revisions passed native Windows/Linux/macOS CI, but Windows/Linux were not rerun for this revision. These are targeted curve-fit tests, not comprehensive Tracker/installer/video-codec validation or native Safari testing.

Statistical definitions, metadata integration, limitations, and test instructions are in test/fit-report-physics.md and test/README.md. Dataset drawing error bars were inspected; a future per-point uncertainty column needs explicit selection-aligned mapping and is outside this change.

Uncertainty controls now explicitly label the default “Unweighted - estimate from residuals,” provide a wider separate value row, and distinguish pixel presets from physical units. Physical-unit starting values use one calibrated pixel (or residual scatter without calibration); switching supplied modes converts the current scale. Desktop layout tests check selector and value-field visibility and fractional-value entry width.

The display uses a single row for R-squared, SSE, and Residual SE; observation counts and degrees of freedom remain in copied reports. A scrolling fit panel preserves drawable graph space in small windows. The optional host position-versus-time metadata enables copied line-fit velocity and quadratic-fit velocity at t=0 and acceleration, with errors propagated by exact coefficient scaling. These derived results do not add duplicate on-screen rows. Arbitrary functions and unidentified column pairs do not receive physical labels.

Fit-uncertainty documentation is now arranged in three levels by audience:

  1. Understanding fit uncertainties is the short lab-facing guide: what the fitted value and +/- uncertainty mean, uncertainty choices, R-squared, reduced chi-square, and reporting. It begins from the principle that a number from a fit is not the answer; it is a measurement with assumptions attached.
  2. The statistics behind the result develops residual variance, degrees of freedom, profile curvature, nuisance-parameter refitting, rank, limitations, and the reproducible 2.000 +/- 0.063 m/s example.
  3. Bevington-style implementation note records the exact numerical procedure, code path, step heuristics, edge cases, and regression coverage. The inherited equation-number reference is explicitly distinguished from an edition-verified citation.

@paulnord paulnord changed the title Improve curve-fit uncertainty display, spreadsheet reports, and results layout Improve curve-fit reports, uncertainty handling, and results layout Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant