Description Usage Arguments Details Value Author(s) Examples
k-fold cross-validation to select the polynomial degree and penalization
factor for a polywog
model.
1 2 |
formula |
model formula specifying the response and input variables. |
... |
other arguments to be passed to |
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
|
X |
logical: whether to include the raw model matrix (i.e., the
matrix of input variables prior to taking their polynomial expansion) in
the |
y |
logical: whether to include the response variable in the
|
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.
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.
Brenton Kenkel and Curtis S. Signorino
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)
|
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.