This is a convenience function for performing multivariable polynomial regression. The degree of the polynomial fit and the degree of individual dimensions (as long as the latter does not exceed the former) is fully adjustable.
Takes Data, R, PW and PV as inputs.Data is a 2-D matrix of either row or column stacked data points. R is the response column vector. PW is the degree of the polynomial fit. PV(Optional) is a vector with the same length as the number of dimensions(Not to be confused with number of data points.), denoting the maximum allowed degree of each dimension on the polynomial fit. A PV of [2 1] would limit a 2-dimensional 2nd degree polynomial to the terms that have x^2, x and y, eliminating the terms with y^2.
The output is a struct composed of the coefficients vector, a Legend vector describing the corresponding polynomial term for each coefficient and the R-Square value of the fit.