emp_spatial_cov {stxplore} | R Documentation |
Computes empirical spatial covariance using a dataframe or a stars object
Description
Computes empirical spatial covariance by removing trends and examining residuals. It can compute lag-0 or log-1 empirical covariance either by latitude or longitude. You can split up the spatial domain by latitude or longitude and plot the covariance for each longitudinal/latitudinal strips.
Usage
emp_spatial_cov(
x,
lat_or_lon_strips = "lon",
quadratic_time = FALSE,
quadratic_space = FALSE,
num_strips = 1,
lag = 0,
...
)
## S3 method for class 'data.frame'
emp_spatial_cov(
x,
lat_or_lon_strips = "lon",
quadratic_time = FALSE,
quadratic_space = FALSE,
num_strips = 1,
lag = 0,
lat_col,
lon_col,
t_col,
z_col,
...
)
## S3 method for class 'stars'
emp_spatial_cov(
x,
lat_or_lon_strips = "lon",
quadratic_time = FALSE,
quadratic_space = FALSE,
num_strips = 1,
lag = 0,
...
)
## S3 method for class 'spatialcov'
autoplot(object, xlab = "Latitude", ...)
Arguments
x |
A stars object or a dataframe. Arguments differ according to the input type. |
lat_or_lon_strips |
Takes the values |
quadratic_time |
If |
quadratic_space |
If |
num_strips |
The number of latitudinal/longitudinal strips to produce. This is used when plotting using autoplot. |
lag |
Lag can be either 0 or 1. |
... |
Other arguments currently ignored. |
lat_col |
For dataframes: the column or the column name giving the latitude. The y coordinate can be used instead of latitude. |
lon_col |
For dataframes: the column or the column name giving the longitude. The x coordinate can be used instead of longitude. |
t_col |
For dataframes: the time column. Time must be a set of discrete integer values. |
z_col |
For dataframes: the The quantity of interest that will be plotted. Eg. temperature. |
object |
For autoplot: the output of the function ‘emp_spatial_cov’. |
xlab |
For autoplot: the label for x-axis. |
Value
A spatialcov object with empirical covariance data organised spatially according to the number of strips and the lagged covariance.
Examples
# Dataframe example
library(dplyr)
data(NOAA_df_1990)
Tmax <- filter(NOAA_df_1990,
proc == "Tmax" &
month %in% 5:6 &
year == 1993)
Tmax$t <- Tmax$julian - min(Tmax$julian) + 1
emp_df <- emp_spatial_cov(Tmax,
lat_col = "lat",
lon_col = "lon",
t_col ="t",
z_col = "z",
lat_or_lon_strips = "lon",
num_strips = 4,
lag = 1)
autoplot(emp_df)
# Stars example
library(stars)
# Create a stars object from a data frame
precip_df <- NOAA_df_1990[NOAA_df_1990$proc == 'Precip', ] %>%
filter(date >= "1992-02-01" & date <= "1992-02-05")
precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')]
st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date"))
emp_spatial_cov(st_precip)