Learn R Programming

sjstats (version 0.8.0)

pred_accuracy: Accuracy of predictions from model fit

Description

This function calculates the predictive accuracy of (generalized) linear models.

Usage

pred_accuracy(data, fit, method = c("cv", "boot"), k = 5, n = 1000)

Arguments

data
A data frame.
fit
Fitted model object of class lm or glm.
method
Character string, indicating whether crossvalidation (method = "cv") or bootstrapping (method = "boot") is used to compute the accuracy values.
k
The number of folds for the kfold-crossvalidation.
n
Number of bootstraps to be generated

Value

The accuracy of the model predictions, i.e. the proportion of accurately predicted values from the model.

Details

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).

Examples

Run this code
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