Class RegressionTransform

java.lang.Object
smile.plot.vega.RegressionTransform

public class RegressionTransform extends Object
The regression transform fits two-dimensional regression models to smooth and predict data. This transform can fit multiple models for input data (one per group) and generates new data objects that represent points for summary trend lines. Alternatively, this transform can be used to generate a set of objects containing regression model parameters, one per group.

This transform supports parametric models for the following functional forms:

linear (linear): y = a + b * x logarithmic (log): y = a + b * log(x) exponential (exp): y = a * e^(b * x) power (pow): y = a * x^b quadratic (quad): y = a + b * x + c * x^2 polynomial (poly): y = a + b * x + … + k * x^(order)

All models are fit using ordinary least squares. For non-parametric locally weighted regression, see the loess transform.

  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toPrettyString

      public String toPrettyString()
      Returns the specification in pretty print.
      Returns:
      the specification in pretty print.
    • method

      public RegressionTransform method(String method)
      Sets the functional form of the regression model.
      Parameters:
      method - "linear", "log", "exp", "pow", "quad", or "poly".
      Returns:
      this object.
    • params

      public RegressionTransform params(boolean flag)
      Sets if the transform should return the regression model parameters (one object per group), rather than trend line points. The resulting objects include a coef array of fitted coefficient values (starting with the intercept term and then including terms of increasing order) and an rSquared value (indicating the total variance explained by the model).
      Parameters:
      flag - a flag indicating if the transform should return the regression model parameters.
      Returns:
      this object.
    • order

      public RegressionTransform order(int order)
      Sets the polynomial order (number of coefficients) for the "poly" method.
      Parameters:
      order - The polynomial order (number of coefficients).
      Returns:
      this object.
    • extent

      public RegressionTransform extent(double min, double max)
      Sets a [min, max] domain over the independent (x) field for the starting and ending points of the generated trend line.
      Parameters:
      min - the minimum value of the independent field domain.
      max - the maximum value of the independent field domain.
      Returns:
      this object.
    • groupby

      public RegressionTransform groupby(String... fields)
      Sets the data fields to group by. If not specified, a single group containing all data objects will be used.
      Parameters:
      fields - The data fields to group by. If not specified, a single group containing all data objects will be used.
      Returns:
      this object.
    • as

      public RegressionTransform as(String... fields)
      Sets the output field names for the smoothed points generated by the loess transform.
      Parameters:
      fields - The output field names for the smoothed points generated by the loess transform.
      Returns:
      this object.