This function calculates the predictive accuracy of linear or logistic regression models.

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

Examples

data(efc) fit <- lm(neg_c_7 ~ barthtot + c161sex, data = efc) # accuracy for linear model, with crossvalidation pred_accuracy(efc, fit)
#> #> # Accuracy of Model Predictions #> #> Accuracy: 41.12% #> SE: 6.56%-points #> Method: Correlation between observed and predicted
# accuracy for linear model, with bootstrapping pred_accuracy(efc, fit, method = "boot", n = 100)
#> #> # Accuracy of Model Predictions #> #> Accuracy: 41.30% #> SE: 2.78%-points #> Method: Correlation between observed and predicted
# 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)
#> #> # Accuracy of Model Predictions #> #> Accuracy: 58.38% #> SE: 3.92%-points #> Method: Area under Curve