| spp_trend | R Documentation |
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().
spp_trend(data, spp, predictor, responses, n_min = 50)
data |
A |
spp |
A |
predictor |
A |
responses |
A |
n_min |
Minimum |
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.
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).
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.