
Fit polynomial regression using a linear or logistic model; predict new data.
polyFit(xy, deg, maxInteractDeg=deg, use = "lm", pcaMethod=NULL,
pcaLocation='front', pcaPortion=0.9, glmMethod="one", cls=NULL)
# S3 method for polyFit
predict(object, newdata, ...)
Data frame with response variable in the last column. In the classification case, response is class ID, stored in a vector, not as a factor. Categorical variables (> 2 levels) should be passed as factors, not dummy variables or integers, to ensure the polynomial matrix is constructed properly.
The max degree for polynomial terms.
The max degree of interaction terms.
Set to 'lm' for linear regression, 'glm' for
logistic regression, or 'mvrlm' for multivariate-response lm
.
NULL for no PCA. For PCA, can be either 'prcomp'
(use the prcomp
function) or 'RSpectra' (use
the eigs
function in the RSpectra package.
In case PCA is applied, specify 'front' to have PCA calculated before forming polynomials, otherwise 'back.
If less than 1.0, use as many principal components so as to achieve this portion of total variance. Otherwise, use this many components. In the 'RSpectra' case, this value must be an integer of 1 or more.
Defaults to "one."
Virtual cluster, for parallel computation (One Vs. All case).
Data frame, one row for each "X" to be predicted. Must
have the same column names as in xy
(without "Y").
An item of class 'polyFit' containing output. Can be used with predict().
Additional arguments for getPoly().
The return value of polyFit()
is an polyFit
object. The
orginal arguments are retained, along with the fitted models and so on.
The prediction function predict.polyFit
returns the predicted
value(s) for newdata
. In the classification case, these will be
the predicted class labels, 1,2,3,...
The polyFit
function calls getPoly
to generate
polynomial terms from predictor variables, then fits the generated
data to a linear or logistic regression model. (Powers of dummy
variables will not be generated, other than degree 1, but interaction
terms will calculated.
If pcaMethod
is not NULL
, a principal component
analysis is performed before or after generating the polynomials.
When logistic regression for classification is indicated, with more
than two classes, All-vs-All or One-vs-All methods, coded
'all'
and 'one'
, can be applied to deal with multiclass
problem. Multinomial logit ('multilog'
) is also available.
Under the 'mvrlm' option in a classification problem, lm
is
called with multivariate response, using cbind
and dummy
variables for class membership as the response. Since predictors are
used to form polynomials, this should be a reasonable model, and is
much faster than 'glm'.
# NOT RUN {
#getPE(Dummies = TRUE) # prgeng data from library(regtools)
#pe1 <- pe[,c(1,2,4,6,7,12:16,3)] # select some predictors
#pfout <- polyFit(pe1,2)
# predict worker like pe1[1,] but age 42 with MS degree
#newdata <- pe1[1,-11]
#newdata[1,1] <- 42
#newdata[1,4] <- 1
#predict(pfout,newdata[,-11]) # 81022.27
# }
Run the code above in your browser using DataLab