Learn R Programming

sjstats (version 0.17.4)

pred_accuracy: Accuracy of predictions from model fit

Description

This function calculates the predictive accuracy of linear or logistic regression 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, the latter being a logistic regression model (binary response).

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

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.

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). The standard error is the standard deviation of the computed correlation resp. AUC-values.

See Also

cv_error

Examples

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