check_o: Check the fit for orthogonality of all points

View source: R/fit_functions.R

check_oR Documentation

Check the fit for orthogonality of all points

Description

Checks for orthogonality of all points by calculating the angle between the slope of the tangent at (x_{0i}, y_{0i}) and the slope of the Euclidean vector \|\vec{D}_i\| to (x_i, y_i), which should be 90^{\circ} if the Euclidean distance has been minimized. See 'Details'.

Usage

check_o(object, plot = TRUE) 

Arguments

object

an object returned from onls.

plot

logical. If TRUE, the α-values are plotted for a quick overview of orthogonality for all points.

Details

This is a validation method for checking the orthogonality between all (x_{0i}, y_{0i}) and (x_i, y_i). The function calculates the angle between the slope \mathrm{m}_i of the tangent obtained from the first derivative at (x_{0i}, y_{0i}) and the slope \mathrm{n}_i of the onls-minimized Euclidean distance between (x_{0i}, y_{0i}) and (x_i, y_i):

\tan(α_i) = ≤ft|\frac{\mathrm{m}_i - \mathrm{n}_i}{1 + \mathrm{m}_i \cdot \mathrm{n}_i}\right|, \,\, \mathrm{m}_i = \frac{df(x, β)}{dx_{0i}}, \,\, \mathrm{n}_i = \frac{y_i - y_{0i}}{x_i - x_{0i}}

=> α_i[^{\circ}] = \tan^{-1} ≤ft( ≤ft|\frac{\mathrm{m}_i - \mathrm{n}_i}{1 + \mathrm{m}_i \cdot \mathrm{n}_i}\right| \right) \cdot \frac{360}{2π}

Value

A dataframe containing x_i, x_{0i}, y_i, y_{0i}, α_i, \frac{df}{dx} and a logical for 89.95^\circ < α_i < 90.05^\circ. If plot = TRUE, a plot of the α-values in black if orthogonal, or red otherwise.

Author(s)

Andrej-Nikolai Spiess

Examples

## Compare 'data range extended' orthogonal model with a
## 'data range restricted' model by setting "extend = c(0, 0)"
## => some x may not be orthogonal!
x <- 1:20
y <- 10 + 3*x^2
y <- sapply(y, function(a) rnorm(1, a, 0.1 * a))
DAT <- data.frame(x, y)

mod1 <- onls(y ~ a + b * x^2, data = DAT, start = list(a = 1, b = 1))
check_o(mod1)

mod2 <- onls(y ~ a + b * x^2, data = DAT, start = list(a = 1, b = 1),
             extend = c(0, 0)) 
check_o(mod2)

onls documentation built on Oct. 31, 2022, 5:06 p.m.