poly_trend: Polynomial trend

View source: R/poly_trend.R

poly_trendR Documentation

Polynomial trend

Description

Fits a polynomial trend using specified order

Usage

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

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

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

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

Author(s)

Jeffrey S. Evans jeffrey_evans@tnc.org

Examples

 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


spatialEco documentation built on Nov. 18, 2023, 1:13 a.m.