Covariance and Correlation

GX-TXT DEV112 P011-bis

Estimate covariance and correlation between variables and interpret the values given in the result matrices.

Prepare several measurements on the same rows

Create a Session Standalone with Session → New Session → Generate Session → Grouped Statistics Student Lab. Enable Covariance and Correlation from Configuration → Modules. The Dataset student.grouped.source contains 18 rows and measures both the voltage, in V and in mV, and the current in A. In Dataset → Canonical table check the column names and verify that the measurements in each row belong to the same observation.

Selection of Grouped Statistics Student Lab in Generate Session before the Session is created.
Selection of Grouped Statistics Student Lab in Generate Session before the Session is created.

Choose variables, interval and rows to exclude

  1. In Analysis → Covariance and Correlation set student.grouped.source as primary. In Variables select voltage_V and current_A. Press + Add to add voltage_mV. Remove removes the corresponding variable from the list.
  2. In Data selection uses None for all rows. To limit yourself to the lab window choose sel_001, defined on the axis sample from 3 to 18. The repetition with only the columns voltage_V and current_A recorded Selection: sel_001 in the report.
  3. Set Missing-pair policy on pairwise and NaN / Inf policy on omit. The first uses the valid rows for each single pair. listwise requires finite values in all the listed variables and uses the same rows for all pairs. With error the module rejects the presence of NaN or Inf after the selection.
  4. Set Pairwise results Dataset ID on covarianza.pairwise, leave on Create correlation heatmap and tick Run / recalculate now. In Run update the plan, then press Run enabled analyses. For the comparison repeat with listwise, ID covarianza.listwise and the map off.
Three variables configured with pairwise exclusion and the Pearson map on.
Three variables configured with pairwise exclusion and the Pearson map on.

Read covariance, Pearson and Spearman

Open the resulting Dataset from Results or from Dataset. Three variables produce nine rows, including the diagonal and the pairs in both orders. Check n_input, n_valid and n_excluded before comparing two coefficients. The sample covariance divides the sum of the products of the deviations by n−1, the population covariance by n. The units are the product of the two source units. Pearson measures the standardized linear relationship. Spearman applies the correlation to the ranks and measures monotonic association. Both are dimensionless and require useful variability. Check the status fields when a series is constant or the data are insufficient.

In the run with pairwise the V/A pair uses 16 of 18 rows, has a sample covariance of 0.417070833 V·A, Pearson 0.997264 and Spearman 0.998528. The voltage expressed in V and in mV uses 17 rows and gives Pearson 1 within numerical rounding. The value comes from the scale conversion of the same measurement. With listwise all elements use 16 rows. With more variables, pairwise exclusion can build coefficients from different samples. A high association alone does not identify a causal relationship.

Table of the pairs with covariances, units, coefficients and effective counts.
Table of the pairs with covariances, units, coefficients and effective counts.

Open the map and rename the variant

In Plots search for correlation_heatmap for the module plot and its variant plot.dataset for persistent presentation changes. The map shows Pearson between the variables in the same order on both axes. Choose the variant, use Presentation → Title and labels…, save the title and use Render → Rerender. Open the figure with Graph → Open PNG 1:1. Check the plot just produced by matching its title and source to the run: an existing figure may come from a previous run with the option on.

Pearson map in the Plots tab before the title change.
Pearson map in the Plots tab before the title change.
The map with the custom title Correlazioni fra misure di laboratorio.
The map with the custom title Correlazioni fra misure di laboratorio.
Presentation editor of the persistent variant.
Presentation editor of the persistent variant.