📅  最后修改于: 2022-03-11 14:51:58.889000             🧑  作者: Mango
# Calculate the log-likelihood for each term
log_likelihoods <- log(y_pred) * y_actual + log(1 - y_pred) * (1 - y_actual)
# Calculate minus the sum of the log-likelihoods for each term
-sum(log_likelihoods)
#function
calc_neg_log_likelihood <- function(coeffs) {
intercept <- coeffs[1]
slope <- coeffs[2]
y_pred <- plogis(intercept + slope * x_actual)
log_likelihoods <- log(y_pred) * y_actual + log(1 - y_pred) * (1 - y_actual)
-sum(log_likelihoods)
}