Package smile.plot.vega
Class RegressionTransform
java.lang.Object
smile.plot.vega.RegressionTransform
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 Summary
Modifier and TypeMethodDescriptionSets the output field names for the smoothed points generated by the loess transform.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.Sets the data fields to group by.Sets the functional form of the regression model.order
(int order) Sets the polynomial order (number of coefficients) for the "poly" method.params
(boolean flag) Sets if the transform should return the regression model parameters (one object per group), rather than trend line points.Returns the specification in pretty print.toString()
-
Method Details
-
toString
-
toPrettyString
Returns the specification in pretty print.- Returns:
- the specification in pretty print.
-
method
Sets the functional form of the regression model.- Parameters:
method
- "linear", "log", "exp", "pow", "quad", or "poly".- Returns:
- this object.
-
params
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
Sets the polynomial order (number of coefficients) for the "poly" method.- Parameters:
order
- The polynomial order (number of coefficients).- Returns:
- this object.
-
extent
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
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
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.
-