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

Description Usage Arguments Details Value Author(s) Examples

View source: R/cv.polywog.r

Description

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

Usage

1
2
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.

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.

Value

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

results

A table of each degree tested, the optimal penalization factor λ 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 λ. However, bootstrap results must be obtained by running bootPolywog on the "polywog.fit" element of the returned object, as in the examples below.

Author(s)

Brenton Kenkel and Curtis S. Signorino

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## 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)

Example output

Loading required package: miscTools
$results
     degree  lambda.min   cv.err
[1,]      1   0.0343371 57.67896
[2,]      2   0.8968497 46.41652
[3,]      3  14.2835751 47.43013
[4,]      4 400.3851894 49.55055

$degree.min
[1] 2

$polywog.fit

Call:
polywog(formula = prestige ~ education + income + type, data = Prestige, 
    degree = 2L, boot = 0, thresh = 1e-04, model = TRUE, X = FALSE, 
    y = FALSE)

Variables included in polynomial expansion of degree 2:
  education, income, type

Regularization method: Adaptive LASSO


attr(,"class")
[1] "cv.polywog"

Call:
polywog(formula = prestige ~ education + income + type, data = Prestige, 
    degree = 2L, boot = 0, thresh = 1e-04, model = TRUE, X = FALSE, 
    y = FALSE)

Coefficients:
                   Estimate Std. Error     2.5%  97.5%
(Intercept)         7.57728    9.10383  7.35204 29.718
education           1.59905    1.12345 -1.40998  1.445
income              0.86572    0.93904  0.08538  2.255
typebc              0.00000    4.60532 -9.59494  0.000
typeprof           21.95112    4.11805 16.44322 25.686
education^2         0.10467    0.02706  0.12462  0.192
education.income    0.00000    0.03372 -0.02919  0.051
education.typebc   -1.33758    0.90692 -2.10092 -0.036
education.typeprof -0.83993    0.40739 -0.83671 -0.001
income^2            0.00000    0.01554  0.00000  0.032
income.typebc       2.54421    1.40021  0.31858  3.451
income.typeprof    -0.24521    0.51859 -1.34342 -0.044

Regularization method: Adaptive LASSO
Adaptive weights: inverse linear model coefficients
Number of observations: 98
Polynomial expansion degree: 2
Model family: gaussian
Bootstrap iterations: 5
Penalization parameter (lambda): 0.8968

polywog documentation built on May 1, 2019, 9:15 p.m.