This function calculates the predictive accuracy of linear or logistic regression models.
pred_accuracy(data, fit, method = c("cv", "boot"), k = 5, n = 1000)
A data frame.
Fitted model object of class lm
or glm
, the latter
being a logistic regression model (binary response).
Character string, indicating whether crossvalidation
(method = "cv"
) or bootstrapping (method = "boot"
)
is used to compute the accuracy values.
The number of folds for the kfold-crossvalidation.
Number of bootstraps to be generated.
A list with two values: The accuracy
of the model predictions, i.e.
the proportion of accurately predicted values from the model and
its standard error, std.error
.
For linar models, the accuracy is the correlation coefficient
between the actual and the predicted value of the outcome. For
logistic regression models, the accuracy corresponds to the
AUC-value, calculated with the auc
-function.
The accuracy is the mean value of multiple correlation resp.
AUC-values, which are either computed with crossvalidation
or nonparametric bootstrapping (see argument method
).
The standard error is the standard deviation of the computed
correlation resp. AUC-values.
# NOT RUN {
data(efc)
fit <- lm(neg_c_7 ~ barthtot + c161sex, data = efc)
# accuracy for linear model, with crossvalidation
pred_accuracy(efc, fit)
# accuracy for linear model, with bootstrapping
pred_accuracy(efc, fit, method = "boot", n = 100)
# accuracy for logistic regression, with crossvalidation
efc$services <- sjmisc::dicho(efc$tot_sc_e, dich.by = 0, as.num = TRUE)
fit <- glm(services ~ neg_c_7 + c161sex + e42dep,
data = efc, family = binomial(link = "logit"))
pred_accuracy(efc, fit)
# }
Run the code above in your browser using DataLab