Learn R Programming

onls (version 0.1-1)

check_o: 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 $\alpha$-values are plotted for a quick overview of orthogonality for all points.

Value

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

encoding

latin1

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(\alpha_i) = \left|\frac{\mathrm{m}_i - \mathrm{n}_i}{1 + \mathrm{m}_i \cdot \mathrm{n}_i}\right|, \,\, \mathrm{m}_i = \frac{df(x, \beta)}{dx_{0i}}, \,\, \mathrm{n}_i = \frac{y_i - y_{0i}}{x_i - x_{0i}}$$ $$=> \alpha_i[^{\circ}] = \tan^{-1} \left( \left|\frac{\mathrm{m}_i - \mathrm{n}_i}{1 + \mathrm{m}_i \cdot \mathrm{n}_i}\right| \right) \cdot \frac{360}{2\pi}$$

Examples

Run this code
## 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)

Run the code above in your browser using DataLab