polywog (version 0.4-1)

cv.polywog: Cross-validation of polynomial degree and penalization factor

Description

k-fold cross-validation to select the polynomial degree and penalization factor for a polywog model.

Usage

cv.polywog(formula, ..., degrees.cv = 1:3, nfolds = 10, model = TRUE,
  X = FALSE, y = FALSE)

Arguments

formula

model formula specifying the response and input variables.

...

other arguments to be passed to polywog. Arguments related to the bootstrap will be ignored, as bootstrapping must be performed separately.

degrees.cv

vector of polynomial degrees to examine via cross-validation.

nfolds

number of folds to use in cross-validation.

model

logical: whether to include the model frame in the "polywog" object included in the output.

X

logical: whether to include the raw model matrix (i.e., the matrix of input variables prior to taking their polynomial expansion) in the "polywog" object included in the output.

y

logical: whether to include the response variable in the "polywog" object included in the output.

Value

An object of class "cv.polywog", a list containing:

results

A table of each degree tested, the optimal penalization factor \(\lambda\) for that degree, and its cross-validation error.

degree.min

The polynomial degree giving the lowest cross-validation error.

polywog.fit

A polywog model, fit at the polynomial degree giving the lowest cross-validation error.

Because the returned object contains the fitted polywog model for the optimal degree, no additional runs of polywog are necessary to estimate coefficients or the penalization factor \(\lambda\). However, bootstrap results must be obtained by running bootPolywog on the "polywog.fit" element of the returned object, as in the examples below.

Details

When fitting with method = "scad", different fold assignments are used for each polynomial degree specified, because cv.ncvreg does not allow for custom fold assignments. This may affect the accuracy of the estimated cross-validation error for each degree. When method = "scad", the calls to polywog made by cv.polywog will issue warnings that the foldid argument is being ignored.

Examples

Run this code
# NOT RUN {
## Using occupational prestige data
data(Prestige, package = "carData")
Prestige <- transform(Prestige, income = income / 1000)

## Examine degrees 1 through 4
## (note: using low convergence threshold to shorten computation time of the
## example, *not* recommended in practice!)
set.seed(39)
cv1 <- cv.polywog(prestige ~ education + income + type,
                  data = Prestige,
                  degrees.cv = 1:4,
                  nfolds = 10,
                  thresh = 1e-4)
print(cv1)

## Extract best model and bootstrap
fit1 <- cv1$polywog.fit
fit1 <- bootPolywog(fit1, nboot = 5)
summary(fit1)
# }

Run the code above in your browser using DataLab