NR_logit: Newton-Raphson method for computing MLE under logistic...

Description Usage Arguments Details Value Examples

Description

For a simple logistic regression model with an intercept and one slope parameter, this function returns their respective MLE's. Iterations stop once the improvement in successive steps falls under a certain tolerance level.

Usage

1
NR_logit(x, y, n, tol = 1e-06, verbose = FALSE)

Arguments

x

vector of covariates (predictor)

y

vector of responses, each one distributed as a Binomial random variable

n

vector of number of trials for each observation.

tol

tolerance level governing when to stop the iterations. Here we use the larger absolute error for either parameter and compare it to tol. Iterations stop when the error is less than tol. Defaults to 1e-6.

verbose

Logical; if TRUE then function prints iterative feedback to the console, and if FALSE there is no printing. Defaults to FALSE.

Details

We can view y as the number of successes out of n trials, with probability of success p unknown. The linear predictor is related to p by the log odds ratio: log(p/(1-p)) = α + β x. It is known that in logsitic regression, we cannot obtain closed form solutions for α and β. This function uses the Newton-Raphson method to estimate these parameters. Our initial value is (α_0, β_0) = (0, 0), an intuitive choice that corresponds to the case of equally likely outcomes (p = 0.5).

In the function definition, the matrix L is the system of nonlinear score functions we need to solve, and L_prime is the derivative of L. Hence, each step of the iteration computes updated estimates via (α_{i+1}, β_{i+1}) = (α_{i}, β_{i}) + L_prime^-1 * L.

Value

A data.frame with two entries in one row, the first being the MLE of the intercept and the second being the MLE of the slope.

Examples

1
2
3
4
5
6
7
8
# Generate random covariates, responses, and trial totals
set.seed(547)
x <- runif(15, 6, 10)
n <- sample(1:15, replace = TRUE)
y <- rbinom(15, n, 0.6)
NR_logit(x, y, n)
NR_logit(x, y, n, verbose = TRUE)
NR_logit(x, y, n, tol = 1e-10, verbose = TRUE)

dchiu911/naim documentation built on May 15, 2019, 1:48 a.m.