Description Usage Arguments Details Value Examples
Shrink regression coefficients using a bootstrap-derived shrinkage factor.
1 |
dataset |
a dataset for regression analysis. Data should be in the form
of a matrix, with the outcome variable as the final column.
Application of the |
model |
type of regression model. Either "linear" or "logistic". |
N |
the number of times to replicate the bootstrapping process |
sdm |
a shrinkage design matrix. For examples, see |
int |
logical. If TRUE the model will include a regression intercept. |
int.adj |
logical. If TRUE the regression intercept will be re-estimated after shrinkage of the regression coefficients. |
This function applies bootstrapping to a dataset in order to derive a shrinkage factor and apply it to the regression coefficients. Regression coefficients are estimated in a bootstrap sample, and then a shrinkage factor is estimated using the input data. The mean of N shrinkage factors is then applied to the original regression coeffients, and the regression intercept may be re-estimated.
This process can currently be applied to linear or logistic regression models.
bootval
returns a list containing the following:
raw.coeff |
the raw regression model coefficients, pre-shrinkage. |
shrunk.coeff |
the shrunken regression model coefficients |
lambda |
the mean shrinkage factor over N bootstrap replicates |
N |
the number of bootstrap replicates |
sdm |
the shrinkage design matrix used to apply the shrinkage factor(s) to the regression coefficients |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## Example 1: Linear regression using the iris dataset
data(iris)
iris.data <- as.matrix(iris[, 1:4])
iris.data <- cbind(1, iris.data)
sdm1 <- matrix(c(0, 1, 1, 1), nrow = 1)
set.seed(777)
bootval(dataset = iris.data, model = "linear", N = 200, sdm = sdm1,
int = TRUE, int.adj = TRUE)
## Example 2: logistic regression using a subset of the mtcars data
data(mtcars)
mtc.data <- cbind(1,datashape(mtcars, y = 8, x = c(1, 6, 9)))
head(mtc.data)
set.seed(777)
bootval(dataset = mtc.data, model = "logistic", N = 500)
|
$raw.coeff
[,1]
-0.2403074
Sepal.Length -0.2072661
Sepal.Width 0.2228285
Petal.Length 0.5240831
$shrunk.coeff
[,1]
[1,] -0.2403263
[2,] -0.2072688
[3,] 0.2228315
[4,] 0.5240900
$lambda
[1] 1.000013
$N
[1] 200
$sdm
[,1] [,2] [,3] [,4]
[1,] 0 1 1 1
mpg wt am vs
[1,] 1 21.0 2.620 1 0
[2,] 1 21.0 2.875 1 0
[3,] 1 22.8 2.320 1 1
[4,] 1 21.4 3.215 0 1
[5,] 1 18.7 3.440 0 0
[6,] 1 18.1 3.460 0 1
$raw.coeff
[,1]
2.396504
mpg 0.421866
wt -2.948354
am -4.868638
$shrunk.coeff
[,1]
[1,] 1.1664241
[2,] 0.2303914
[3,] -1.6101684
[4,] -2.6588825
$lambda
[1] 0.5461245
$N
[1] 500
$sdm
[,1] [,2] [,3] [,4]
[1,] 0 1 1 1
There were 50 or more warnings (use warnings() to see the first 50)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.