cancor_eof {stxplore} | R Documentation |
Performs CCA using Empirical Orthogonal Functions (EOFs) from a lagged dataset
Description
Performs Canonical Correlation Analysis (CCA) using Empirical Orthogonal Function analysis using in a dataframe or a stars object. The autoplot function can plot the outputs.
The variations are * 'cancor_eof.data.frame()' if the input is a dataframe * 'cancor_eof.stars()' if the input is a stars object * 'autoplot.cancoreof()' to plot the outputs.
Usage
cancor_eof(x, lag, n_eof, ...)
## S3 method for class 'data.frame'
cancor_eof(x, lag = 7, n_eof = 10, values_df, ...)
## S3 method for class 'stars'
cancor_eof(x, lag = 7, n_eof = 10, ...)
## S3 method for class 'cancoreof'
autoplot(
object,
line_plot = TRUE,
space_plot = TRUE,
palette = "Spectral",
xlab = "Time",
...
)
Arguments
x |
The dataframe or stars object. If it is a dataframe, then it should have the locations. |
lag |
Specifies the lag to be used. |
n_eof |
The number of EOFs to be used. |
... |
Other arguments currently ignored. |
values_df |
For dataframes: the dataframe of dimension |
object |
autoplot parameter: the output of the function ‘cancor_eof’. |
line_plot |
autoplot parameter: if set to |
space_plot |
autoplot parameter: if set to |
palette |
autoplot parameter: the color palette to use for plotting. |
xlab |
autoplot parameter:: he label on the x-axis for the line plot. |
Value
A cancoreof object with CCA output, EOF output, original data and cancor object from 'stats'.
Examples
# Dataframe example
data(SSTlonlatshort)
data(SSTdatashort)
cancor_df <- cancor_eof(x = SSTlonlatshort,
lag = 7,
n_eof = 8,
values_df = SSTdatashort)
autoplot(cancor_df)
# Stars example
library(dplyr)
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-28")
precip <- precip_df[ ,c('lat', 'lon', 'date', 'z')]
st_precip <- st_as_stars(precip, dims = c("lon", "lat", "date"))
cancor_st <- cancor_eof(st_precip)
autoplot(cancor_st, line_plot = TRUE, space_plot = FALSE)