| pred_accuracy {sjstats} | R Documentation |
This function calculates the predictive accuracy of linear or logistic regression models.
pred_accuracy(data, fit, method = c("cv", "boot"), k = 5, n = 1000)
data |
A data frame. |
fit |
Fitted model object of class |
method |
Character string, indicating whether crossvalidation
( |
k |
The number of folds for the kfold-crossvalidation. |
n |
Number of bootstraps to be generated. |
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.
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.
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)