Skip to contents

(1/m) X^T (p_hat - y) with the PSD Hessian (1/m) X^T diag(p(1-p)) X, which is what makes the cost convex.

Usage

morie_geron_logistic_gradient(X, y, theta, add_bias = FALSE)

Arguments

X, y, theta

Design, 0/1 labels, coefficients.

add_bias

Prepend a ones column.

Value

List with gradient, hessian, p_hat, residuals, estimate, n.

Examples

set.seed(4)
X <- cbind(1, rnorm(30))
y <- rbinom(30, 1, plogis(X %*% c(-0.5, 1.5)))
morie_geron_logistic_gradient(X, y, theta = c(0, 0))
#> $gradient
#> [1]  0.06666667 -0.07309471
#> 
#> $hessian
#>           [,1]      [,2]
#> [1,] 0.2500000 0.1217968
#> [2,] 0.1217968 0.2169862
#> 
#> $p_hat
#>  [1] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
#> [20] 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5
#> 
#> $residuals
#>  [1] -0.5  0.5  0.5  0.5 -0.5 -0.5  0.5  0.5 -0.5  0.5 -0.5 -0.5 -0.5  0.5 -0.5
#> [16] -0.5 -0.5  0.5  0.5  0.5  0.5 -0.5 -0.5  0.5  0.5  0.5 -0.5  0.5  0.5  0.5
#> 
#> $estimate
#> [1] 0.09893069
#> 
#> $n
#> [1] 30
#> 
#> $method
#> [1] "Logistic regression cost gradient"
#>