Learn R Programming

riskRegression (version 2018.04.21)

discreteRoot: Dichotomic search for monotone function

Description

Find the root of a monotone function on a discrete grid of value using dichotomic search

Usage

discreteRoot(fn, grid, increasing = TRUE, check = TRUE,
  tol = .Machine$double.eps^0.5)

Arguments

fn

[function] objective function to minimize in absolute value.

grid

[vector] possible minimizers.

increasing

[logical] is the function fn increasing?

check

[logical] should the program check that fn takes a different sign for the first vs. the last value of the grid?

tol

[numeric] the absolute convergence tolerance.

Examples

Run this code
# NOT RUN {
### find the position of a value in a vector
f <- function(x){abs(vec[x]-1)}
discreteRoot(function(x){x},grid = seq(-20,10,1))

# }

Run the code above in your browser using DataLab