Description Usage Arguments References Examples
testGlmnet
specifies a penalized logistic regression as the classifier to test. It returns a function that can be taken as the input of ‘testModel’. R package ‘glmnet’ is required.
1 | testGlmnet(formula, alpha = 1)
|
formula |
an object of class |
alpha |
the elasticnet mixing parameter, with 0≤α≤ 1. The penalty is defined as (1-α)/2||β||_2^2+α||β||_1.
|
Zhang, Ding and Yang (2021) "Is a Classification Procedure Good Enough?-A Goodness-of-Fit Assessment Tool for Classification Learning" arXiv preprint arXiv:1911.03063v2 (2021).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | ## Not run:
###################################################
# Generate a sample dataset.
###################################################
# set the random seed
set.seed(20)
# set the number of observations
n <- 200
# set the number of covariates
p <- 20
# generate covariates data
Xdat <- matrix(runif((n*p), -5,5), nrow = n, ncol = p)
colnames(Xdat) <- paste("x", c(1:p), sep = "")
# generate random coefficients
betaVec <- rnorm(6)
# calculate the linear predictor data
lindat <- 3 * (Xdat[,1] < 2 & Xdat[,1] > -2) + -3 * (Xdat[,1] > 2 | Xdat[,1] < -2) +
0.5 * (Xdat[,2] + Xdat[, 3] + Xdat[,4] + Xdat[, 5])
# calculate the probabilities
pdat <- 1/(1 + exp(-lindat))
# generate the response data
ydat <- sapply(pdat, function(x) rbinom(1, 1, x))
# generate the dataset
dat <- data.frame(y = ydat, Xdat)
###################################################
# Obtain the testing result
###################################################
# 50 percent training set
testRes1 <- BAGofT(testModel = testGlmnet(formula = y~., alpha = 1),
data = dat,
ne = n*0.5,
nsplits = 20,
nsim = 40)
# 75 percent training set
testRes2 <- BAGofT(testModel = testGlmnet(formula = y~., alpha = 1),
data = dat,
ne = n*0.75,
nsplits = 20,
nsim = 40)
# 90 percent training set
testRes3 <- BAGofT(testModel = testGlmnet(formula = y~., alpha = 1),
data = dat,
ne = n*0.9,
nsplits = 20,
nsim = 40)
# print the testing result.
print(c(testRes1$p.value, testRes2$p.value, testRes3$p.value))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.