dataFrame.columns.stat — r2()

Description

The r2() method of the stat object computes the coefficient of determination between observed and predicted values.

Signature

dataFrame.columns(...columnNames).stat.r2({ predictorsCount: 0 })
Scope
columns
Family
stat
Returns
number

Arguments

...columnNames ( string[] )
The name of the columns from which to compute the coefficient of determination.
options (object)
R² computation options.

Option

predictorsCount (number)
The number of predictors used by the underlying model. When provided, the adjusted coefficient of determination is computed. (Default: 0.)

Returns

coef (number)
The computed coefficient of determination.

Notes

  • The method requires at least two selected columns.
  • The first selected column is interpreted as the observed values.
  • The second selected column is interpreted as the predicted values.
  • The coefficient of determination measures the proportion of variance explained by the model.
  • The value is generally between 0 and 1.
  • Higher values indicate a better fit between observed and predicted values.
  • predictorsCount is used to compute the adjusted R² when applicable.
  • A value of 1 indicates a perfect fit.

Example

// evaluate the coefficient of determination for 2 columns of the dataFrame
var coef = dataFrame.columns('groupA', 'groupB').stat.r2();

// log the stat details
notebook.log(coef);