This function generates a model frame for statistical or machine learning analysis from these objects:
: Dissimilarity data frame generated by
momentum()
,momentum_ls()
, ormomentum_dtw()
. The output model frame will have as many rows as this data frame.: Data frame with static descriptors of the time series. These descriptors are converted to distances between pairs of time series via
distance_matrix()
.: List defining composite predictors. This feature allows grouping together predictors that have a common meaning. For example,
composite_predictors = list(temperature = c("temperature_mean", "temperature_min", "temperature_max")
generates a new predictor named "temperature", which results from computing the multivariate distances between the vectors of temperature variables of each pair of time series. Predictors in one of such groups will be scaled before distance computation if their maximum standard deviations differ by a factor of 10 or more.
The resulting data frame contains the following columns:
x
andy
: names of the pair of time series represented in the row.response columns.
predictors columns: representing the distance between the values of the given static predictor between
x
andy
.(optional)
geographic_distance
: Ifpredictors_df
is ansf
data frame, then geographic distances are computed viasf::st_distance()
.
This function supports a parallelization setup via future::plan()
.
Usage
momentum_model_frame(
response_df = NULL,
predictors_df = NULL,
composite_predictors = NULL,
scale = TRUE,
distance = "euclidean"
)
Arguments
- response_df
(required, data frame) output of
momentum()
,momentum_ls()
, ormomentum_dtw()
. Default: NULL- predictors_df
(required, data frame or sf data frame) data frame with numeric predictors for the the model frame. Must have a column with the time series names in
response_df$x
andresponse_df$y
. Ifsf
data frame, the column "geographic_distance" with distances between pairs of time series is added to the model frame. Default: NULL- composite_predictors
(optional, list) list defining composite predictors. For example,
composite_predictors = list(a = c("b", "c"))
uses the columns"b"
and"c"
frompredictors_df
to generate the predictora
as the multivariate distance between"b"
and"c"
for each pair of time series inresponse_df
. Default: NULL- scale
(optional, logical) if TRUE, all predictors are scaled and centered with
scale()
. Default: TRUE- distance
(optional, string) Method to compute the distance between predictor values for all pairs of time series in
response_df
. Default: "euclidean".
See also
Other momentum_support:
momentum_aggregate()
,
momentum_boxplot()
,
momentum_spatial()
,
momentum_stats()
,
momentum_to_wide()
Examples
#Fagus sylvatica dynamics in Europe
tsl <- tsl_initialize(
x = fagus_dynamics,
name_column = "name",
time_column = "time"
)
#dissimilarity analysis
df <- momentum_ls(tsl = tsl)
#generate model frame
model_frame <- momentum_model_frame(
response_df = df,
predictors_df = fagus_coordinates,
scale = TRUE
)
head(model_frame)
#> x y psi most_similarity most_dissimilarity importance__evi
#> 1 Germany Spain 1.3962157 temperature rainfall -7.750367
#> 2 Germany Sweden 0.8364652 temperature evi 23.386800
#> 3 Spain Sweden 1.5703931 evi temperature -22.394882
#> importance__rainfall importance__temperature geographic_distance
#> 1 29.746952 -29.858647 -0.3958795
#> 2 17.288482 -17.462102 -0.7414534
#> 3 -3.892379 3.912167 1.1373329
#names of response and predictors
#and an additive formula
#are stored as attributes
attributes(model_frame)$predictors
#> [1] "geographic_distance"