Learn R Programming

spatialEco (version 2.0-2)

poly_trend: Polynomial trend

Description

Fits a polynomial trend using specified order

Usage

poly_trend(x, y, degree, ci = 0.95, plot = TRUE, ...)

Value

A poly.trend class (list) containing

  • trend data.frame of fit polynomial and upper/lower confidence intervals

  • model Class lm model object fit with poly term

  • prameterCI Intercept confidence intervals of Nth order polynomials

  • order Specified polynomial order

Arguments

x

Vector of x

y

Vector of y

degree

Polynomial order (default 3)

ci

+/- confidence interval (default 0.95)

plot

Plot results (TRUE/FALSE)

...

Additional arguments passed to plot

Author

Jeffrey S. Evans jeffrey_evans@tnc.org

Details

A fit using a lm(y ~ x + I(X^2) + I(X^3)) form will be correlated which, can cause problems. The function avoids undue correlation using orthogonal polynomials

Examples

Run this code
 set.seed(42)
 x <- seq(from=0, to=20, by=0.1)
 y <- (500 + 0.4 * (x-10)^3)
 noise <- y + rnorm(length(x), mean=10, sd=80) 
 
 p <- poly_trend(x, noise, degree = 3, ci = 0.95,
                 main="3rd degree polynomial")
 
 dev.new(height=6, width=12)
   layout(matrix(c(1,2), 1, 2, byrow = TRUE))
   p <- poly_trend(x, noise, degree = 3, 
                   main="3rd degree polynomial")
   p <- poly_trend(x, noise, degree = 6, 
                   main="6th degree polynomial")

cat("Confidence intervals for", "1 -", p$order, "polynomials",  "\n")
  p$prameterCI

Run the code above in your browser using DataLab