Description Usage Arguments Details Value Examples
View source: R/spatial_stats.R
Calculates spatial early warning statistics (spatial standard deviation and spatial autocorrelation = Moran's I) from a data frame of (optionally multiple) sampling events and variables. By default uses multiple cores to speed up spatial autocorrelation calculation, which can take quite a bit of time depending on how many data points you have.
1 2 3 4 5 6 7 8 9 | calc_spatial_stats(
spatial_data = flame_data,
lat_col = "latitude",
lon_col = "longitude",
var_cols = c("BGApc_ugL_tau", "ODO_percent_tau", "pH_tau"),
id_cols = c("Lake", "Year", "DOY"),
statistics = c("SD", "moransI"),
multiple_cores = TRUE
)
|
spatial_data |
data frame containing spatial locations and measurements of one or more variables; see |
lat_col |
character string, column name for latitude column |
lon_col |
character string, column name for longitude column |
var_cols |
character vector, column names that hold measurements of different variables |
id_cols |
character vector, columns that identify unique sampling events to separate data into before calculating stats independently on, defaults are "Lake", "Year", and "DOY" |
statistics |
character vector, statistics to run; options are "SD", "moransI", "skew", and "kurt" |
multiple_cores |
TRUE (default) or FALSE, should spatial autocorrelation calculations be run on multiple cores to speed up calculations? |
Note that time estimates printed out are very rough estimates and are based on using the default data and variables, and run on a AMD Ryzen 1800X with 8 cores/16 threads.
data frame with calculated spatial stats (SD and Moran's I) for each sample and variable
1 2 3 4 5 6 | spat_stats <- calc_spatial_stats(flame_data)
library(ggplot2)
ggplot(spat_stats %>% dplyr::filter(Stat == "SD"), aes(x = DOY, y = Value, color = Lake)) +
geom_line() +
facet_grid(rows = vars(Variable), cols = vars(Year), scales = "free_y") +
theme_bw()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.