getLinearRegressions: Get Linear Regressions BioTIME

View source: R/slopesBioTIME.R

getLinearRegressionsR Documentation

Get Linear Regressions BioTIME

Description

Fits linear regression models to getAlphaMetrics or getBetaMetrics outputs

Usage

getLinearRegressions(x, divType, pThreshold = 0.05)

Arguments

x

('data.frame') BioTIME data table in the format of the output of getAlphaMetrics or getBetaMetrics functions

divType

('character') string specifying the nature of the metrics in the data; either 'divType = "alpha"' or 'divType = "beta"' are supported

pThreshold

('numeric') P-value threshold for statistical significance

Details

The function 'getLinearRegressions' fits simple linear regression models (see lm for details) for a given output ('data') of either getAlphaMetrics or getBetaMetrics function. 'divType' needs to be specified in agreement with x. The typical model has the form 'metric ~ year'. Note that assemblages with less than 3 time points and/or single species time series are removed.

Value

Returns a single long 'data.frame' with results of linear regressions (slope, p-value, significance, intercept) for each 'assemblageID'.

Examples

  library(BioTIMEr)
  x <- data.frame(
    resamp = 1L,
    YEAR = rep(rep(2010:2015, each = 4), times = 4),
    Species = c(replicate(n = 8L * 6L, sample(letters[1L:10L], 4L, replace = FALSE))),
    ABUNDANCE = rpois(24 * 8, 10),
    assemblageID = rep(LETTERS[1L:8L], each = 24)
  )
  alpham <- getAlphaMetrics(x, "ABUNDANCE")
  getLinearRegressions(x = alpham, divType = "alpha", pThreshold = 0.01)
  betam <- getBetaMetrics(x = x, "ABUNDANCE")
  getLinearRegressions(x = betam, divType = "beta")


BioTIMEr documentation built on Sept. 14, 2024, 9:09 a.m.