spp_trend: Individual trend analysis

View source: R/spp_trend.R

spp_trendR Documentation

Individual trend analysis

Description

Estimates the species-specific temporal trends for each selected response variable and statistically compares them with the overall temporal trend derived from the complete dataset. It compares individual species' trajectories against the OT using the interaction term of the lm().

Usage

spp_trend(data, spp, predictor, responses, n_min = 50)

Arguments

data

A ⁠data frame⁠ containing the variables for the model, including species, year, month, lon, lat, tme and/or ele.

spp

A character vector of unique species names.

predictor

A character vector of predictor variable names representing a temporal variable (year_month).

responses

A character vector of response variable names to analyze.

n_min

Minimum numeric number of presences required for a species in each hemisphere (or globally for species in both hemispheres) to perform the analysis.

Details

The function fits linear models for each species and compares them to the general trend using an interaction model (response ~ predictor * group). Longitude (lon) values are transformed to a 0-360 range to ensure statistical consistency near the antimeridian. A key feature of this function is its specialized handling of latitude. Because the Equator is set at 0, latitude values in the Southern Hemisphere are negative. To ensure that a direction shift is interpreted consistently across the globe (where a negative increase in the South corresponds to a positive increase in the North), the function employs two complementary approaches: Hemispheric split: It divides the records based on their location (lat < 0 for South and lat > 0 for North) and performs separate analyses for each. Global analysis: It performs an analysis using the complete dataset (Global) by transforming all latitudes into absolute values (abs(lat)). This allows for a unified global trend estimation. Note that this hemispheric division and absolute transformation logic is applied exclusively to the latitude (lat) variable.

Value

A data frame with trend statistics, including:

  • species: Name of the analyzed species.

  • responses: Name of the variable analyzed.

  • trend: Slope of the linear model (rate of change over time).

  • t: t-statistic for the species-specific trend.

  • pvalue: Statistical significance of the species trend.

  • ci_95_max, ci_95_min: 95% confidence interval bounds for the slope.

  • dif_t: t-statistic of the interaction term (species vs. baseline).

  • dif_pvalue: p-values of the interaction term. A low value indicates a significant deviation from the general trend.

  • n: Sample size for the specific species/hemisphere subset

  • hemisphere: Geographic context (North, South, or Global for global comparison).

Examples


data <- data.frame(
   species = sample(paste0("spp_", 1:10), 500, replace = TRUE),
   year = sample(1950:2020, 500, replace = TRUE),
   month = sample(1:12, 500, replace = TRUE),
   lon = runif(500, -10, 20),
   lat = runif(500, 30, 70),
   tme = rnorm(500, 15, 10)
)

data$year_month <- data$year + data$month * 0.075

predictor <- "year_month"
responses <- c("lat", "lon", "tme")

spp <- unique(data$species)

spp_trend_result <- spp_trend(data, spp, predictor, responses, n_min = 50)

print(spp_trend_result)


SppTrend documentation built on Feb. 7, 2026, 5:07 p.m.