View source: R/fit_functions.R
| check_o | R Documentation |
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'.
check_o(object, plot = TRUE)
object |
an object returned from |
plot |
logical. If |
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}
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.
Andrej-Nikolai Spiess
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.