Regression

GX-TXT DEV112 P011-bis

Configure regressions and compare coefficients, fit indicators and outputs of linear and polynomial examples.

Generate the measurements and check the units

Create a Session Standalone with Session → New Session → Generate Session → Weighted Regression. The public Generator prepares regression.linear and regression.polynomial. In Configuration → Modules enable Regression. Open the polynomial Dataset and check in Canonical table the columns x, y, sigma_y and weight_inv_variance. When a choice requires the ID, you can get it from Dataset → Variables or Technical Details.

Selection of Weighted Regression in Generate Session before the Session is created.
Selection of Weighted Regression in Generate Session before the Session is created.

In the tested release, the column x has no unit in either Generator Dataset and the run is rejected (bug 149). In Dataset → Variables choose x, open the variable editor, assign 1 to Unit and save. This exercise treats x as dimensionless. For a physical axis always use its actual unit. y and sigma_y have unit V.

Correcting the Unit metadata of the x variable before the run.
Correcting the Unit metadata of the x variable before the run.
Samples, uncertainties and weights of the polynomial Dataset.
Samples, uncertainties and weights of the polynomial Dataset.

Set X, Y, model, weights and numerical validity

  1. In Analysis → Regression set the source to primary and give Independent X variable and Measured Y variable. Data selection can restrict the samples to an already saved X interval. None uses all available rows.
  2. Choose linear in Regression model for intercept and slope. polynomial uses the degree given in Polynomial degree. The cubic test uses degree 3 with 61 valid rows. Check that there are enough distinct X values.
  3. In Statistical weight or measurement uncertainty gives the column required by Explicit weight semantics. With none leaves the field empty. With statistical_weight choose a dimensionless, non-negative relative weight. A zero weight excludes the row from the estimate. For inverse_variance_uncertainty pass the known standard deviation of Y, for example sigma_y in V. The module computes 1/σ². Passing the already weighted field weight_inv_variance as a statistical weight is rejected because it carries the unit V⁻².
  4. Set Measurement noise assumption on unspecified when the assumption is not justified. Use independent_gaussian_known_sigma to interpret the reduced χ² only if the errors are independent and Gaussian and the σ are known in an absolute sense.
  5. In NaN / Inf policy, omit excludes the rows made incompatible by non-finite values. error stops the estimate. With Rank-deficient fit policy → error a rank-deficient design is rejected. minimum_norm can publish the minimum-norm solution when the coefficients are not uniquely identifiable. Read Numerical rank and do not interpret the individual coefficients as identified estimates when the rank is deficient.
  6. Choose Output Dataset ID prefix distinct for each model. Turn on or off Create fit and residual graphs according to the exercise. Tick Run / recalculate now, update the plan in Run, start and check the state and the Datasets in Results.
Cubic fit with known uncertainties in the same unit as Y.
Cubic fit with known uncertainties in the same unit as Y.

Check coefficients, predictions, residuals and quality

In Results open .fit for the observed, fitted and residual values on the input rows, and .curve for the curve produced by the model. .coefficients gives the powers in order and the physical units of the coefficients. .covariance describes the covariance of the coefficients when applicable. .metrics and the report include counts, errors, rank, conditioning, degrees of freedom and the state of the conditional metrics.

The cubic with known σ has terms from degree 3 to degree 0 of about 0.49710, −1.99483, 1.51102 and 2.98601. R² is 0.999774, the rank is 4 and the reduced χ² is 1.18082 with 57 residual degrees of freedom. Interpret R² together with the residuals to check for systematic structure or poor coverage of the domain. The reduced χ² compares the normalized residuals with the known σ. With only relative weights the absolute reference for this interpretation is missing. Check the labels and the weighting semantics of the metrics before comparing numbers between reports and tables.

In Plots choose the fit or residuals plot of the regression concerned and open it with Graph → Open PNG 1:1. The fit allows a visual comparison between data and curve. In the residuals look for a trend with X, changing spread and influential points. The data of .fit let you check them by original index.

Observations, predicted value and residuals on the rows of the cubic fit.
Observations, predicted value and residuals on the rows of the cubic fit.
Table of the cubic fit metrics, with rank and degrees of freedom.
Table of the cubic fit metrics, with rank and degrees of freedom.

Compare ordinary and weighted linear fits

In a new Session with the public Generator Statistics, use statistics.source. Check the units of sample, value and weight and set 1 for sample if it is missing. In the module assign X=sample and Y=value. First run linear with weights none, the weight variable field empty and prefix regressione.ordinaria. Repeat with statistical_weight, column weight and prefix regressione.statistica. Both use omit for non-finite values.

The ordinary regression has 11 valid observations and R² about 0.92372. The weighted comparison has 10 valid observations, a slope of about 1.44245 V per unit of sample, R² about 0.88810; the report declares the reduced χ² not applicable. The two models minimize different objective functions. The relative weights change the contribution of the rows to the estimate.

To isolate the rank deficiency, use Descriptive Statistics Student Lab with X=constant_V and Y=voltage_V. The mode error reports that X has too few distinct values for degree 1. Set minimum_norm, sel_001, omit and turn off the plots. The test publishes the solution on 9 observations and rank 1. With constant X, slope and intercept are not separately identifiable.

Metrics of the linear regression with ordinary weighting.
Metrics of the linear regression with ordinary weighting.
Metrics of the linear regression with relative statistical weights.
Metrics of the linear regression with relative statistical weights.