Learn R Programming

polyreg (version 0.4.0)

xvalPoly,xvalKf,xvalDnet: Cross validation on Polynomial regression

Description

Separate the dataset to training and test set, and obtain the mean absolute error (for linear regression) or accuracy (for logistic regression).

Usage

xvalPoly(xy, maxDeg, maxInteractDeg = maxDeg, use = "lm",
               pcaMethod = NULL, pcaPortion = 0.9,
               glmMethod = "one",
               nHoldout = min(10000, round(0.2*nrow(xy))),
               pcaLocation='front',
               yCol = NULL, cls=NULL, startDeg=1)

Arguments

xy

Data matrix or dataframe with response variable in the last column.

maxDeg

Max degree for power terms.

maxInteractDeg

Max degree of interaction terms.

startDeg

Starting degree. Enables user to skip lower degree models. (But defaults to 1.)

use

Can be "lm" for using linear regreesion, and "glm" for using logistic regression.

pcaMethod

Should be either NULL (no PCA), "prcomp" (base R implementation of PCA), or "RSpectra" (recent implementation of PCA).

pcaPortion

If pcaMethod is provided, use components up to this proportion of total variance.

pcaLocation

Is PCA performed before or after the (polynomial) model matrix is constructed?

glmMethod

For classification problems. If there are more than two classes, this can be "all" for All-vs-All method, or "one" for One-vs-All method.

nHoldout

Size of test test.

yCol

If provided, the column where y is found (i.e., other than the last colum, where it is expected).

cls

cluster (for clusterEvalQ()).

Value

The return value of xvalPoly is an R vector of mean absolute error (for lm) or probability of correct classification (for glm). The i-th element of the vector is for degree i.

Details

The xvalPoly function divides the data to training and test sets, and use polyFit to generate models using training data and use polyFit.predict to generate results on test set, and compare the results. The xvalKf does the same for kerasformula neural networks package.

Examples

Run this code
# NOT RUN {
y <- mtcars[,1] # make mpg the outcome
Xy <- as.data.frame(cbind(mtcars[,-1], y)) # make y column the last column
xvalPoly(Xy,2,use="lm") # not using pca
xvalPoly(Xy,2, use="lm", pcaMethod="prcomp", 0.8) # using pca on X first
# }

Run the code above in your browser using DataLab