ransac_nls {RANSAC}R Documentation

Robust Nonlinear Model Fitting via RANSAC

Description

Fits a robust nonlinear model ('nls') using the RANSAC algorithm.

Usage

ransac_nls(
  formula,
  data,
  start,
  n_min,
  n_iter = 100,
  tol = 0.2,
  verbose = FALSE
)

Arguments

formula

Model formula.

data

Data frame containing the model variables.

start

Named list of initial parameter estimates (as required by 'nls').

n_min

Minimum number of points to fit the model.

n_iter

Number of iterations (higher values make the model more robust).

tol

Absolute tolerance to consider a point as an inlier.

verbose

If 'TRUE', shows progress messages.

Value

An 'nls' model fitted only to the inliers, with an additional class '"ransac_nls"' and an '"inliers"' attribute.

Examples

set.seed(123)
D <- seq(10, 50, by = 5)
H <- seq(15, 30, length.out = length(D))
V <- 0.01 * D^2 * H + rnorm(length(D), sd = 5)
V[c(3, 7)] <- V[c(3, 7)] + 50  # add outliers
data <- data.frame(D = D, H = H, V = V)

model <- ransac_nls(V ~ a * D^b * H^c, data = data,
                    start = list(a = 0.01, b = 2, c = 1),
                    n_min = 4, n_iter = 100, tol = 10)
summary(model)


[Package RANSAC version 0.1.0 Index]