opoly {Momocs} | R Documentation |
Calculate orthogonal polynomial fits on open outlines
Description
Calculates orthogonal polynomial coefficients, through a linear model fit (see lm), from a matrix of (x; y) coordinates or a Opn object
Usage
opoly(x, ...)
## Default S3 method:
opoly(x, degree, ...)
## S3 method for class 'Opn'
opoly(
x,
degree,
baseline1 = c(-0.5, 0),
baseline2 = c(0.5, 0),
nb.pts = 120,
...
)
## S3 method for class 'list'
opoly(x, ...)
Arguments
x |
a matrix (or a list) of (x; y) coordinates |
... |
useless here |
degree |
polynomial degree for the fit (the Intercept is also returned) |
baseline1 |
numeric the |
baseline2 |
numeric the |
nb.pts |
number of points to sample and on which to calculate polynomials |
Value
a list with components when applied on a single shape:
-
coeff
the coefficients (including the intercept) -
ortho
whether orthogonal or natural polynomials were fitted -
degree
degree of the fit (could be retrieved throughcoeff
though) -
baseline1
the first baseline point (so far the first point) -
baseline2
the second baseline point (so far the last point) -
r2
the r2 from the fit -
mod
the raw lm model
otherwise an OpnCoe object.
Note
Orthogonal polynomials are sometimes called Legendre's polynomials. They are preferred over natural polynomials since adding a degree do not change lower orders coefficients.
See Also
Other polynomials:
npoly()
,
opoly_i()
Examples
data(olea)
o <- olea[1]
op <- opoly(o, degree=4)
op
# shape reconstruction
opi <- opoly_i(op)
coo_plot(o)
coo_draw(opi)
lines(opi, col='red')
# R2 for degree 1 to 10
r <- numeric()
for (i in 1:10) { r[i] <- opoly(o, degree=i)$r2 }
plot(2:10, r[2:10], type='b', pch=20, col='red', main='R2 / degree')