View source: R/eval_classify.R
eval_classify | R Documentation |
After fitting GLM's with, set a classification rule, and obtain measures for classification effectiveness.
eval_classify(
num.class = 2,
classify.rule,
beta.hat,
x,
y,
family,
make.x0 = TRUE,
gamma.link = "log",
extra.measures = FALSE
)
num.class |
A scalar value defining the number of classes. Default value is two. |
classify.rule |
A vector of thresholds that determine assigned classes. |
beta.hat |
A vector of parameter estimates from some model fit. |
x |
A (numeric) design matrix whose number of columns is equal to
|
y |
A numeric vector of outcome measurements. The length of this
vector must equal |
family |
One of |
make.x0 |
Logical. When |
gamma.link |
Defines the link function in gamma GLM's. One of
|
extra.measures |
Logical. When |
Note that y
and x
may be the same outcomes/design
matrix used to generate beta.hat
, but they may also, and perhaps
more appropriately, be a held-out/independent data set on which to test the
classification performance of whatever model was used to obtain
beta.hat
.
A data frame with a single row containing columns for sensitivity, specificity, ppv, npv, and accuracy, where ppv is positive predictive value and npv is negative predictive value. When there are 3 or more classes, only accuracy, and possibly mse and mae, are returned.
set.seed(72874)
# sample size
n <- 10
# true betas
b <- c(1, 0.1, 0.5, 0, -0.1, -0.5)
# observed predictors
x <- matrix(rnorm(n * (length(b) - 1)), nrow = n, ncol = length(b) - 1)
x0 <- rep(1, n)
# observed outcomes
y <- cbind(x0, x) %*% b + rnorm(n, 0, 2.5)
y <- ifelse(y > 0, 1, 0)
# fitted model
yx.df <- data.frame(y, x)
beta.hat <- glm(y ~ ., data = yx.df , family = "binomial")$coefficients
# evaluate classification
eval_classify(classify.rule = 0.5, beta.hat = beta.hat,
x = x, y = y, family = "binomial",
extra.measures = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.