View source: R/rank_spatial_predictors.R
rank_spatial_predictors | R Documentation |
Ranks spatial predictors generated by mem_multithreshold()
or pca_multithreshold()
by their effect in reducing the Moran's I of the model residuals (ranking.method = "effect"
), or by their own Moran's I (ranking.method = "moran"
).
In the former case, one model of the type y ~ predictors + spatial_predictor_X
is fitted per spatial predictor, and the Moran's I of this model's residuals is compared with the one of the model without spatial predictors (y ~ predictors
), to finally rank the spatial predictor from maximum to minimum difference in Moran's I.
In the latter case, the spatial predictors are ordered by their Moran's I alone (this is the faster option).
In both cases, spatial predictors that are redundant with others at a Pearson correlation > 0.5 and spatial predictors with no effect (no reduction of Moran's I or Moran's I of the spatial predictor equal or lower than 0) are removed.
This function has been designed to be used internally by rf_spatial()
rather than directly by a user.
rank_spatial_predictors( data = NULL, dependent.variable.name = NULL, predictor.variable.names = NULL, distance.matrix = NULL, distance.thresholds = NULL, ranger.arguments = NULL, spatial.predictors.df = NULL, ranking.method = c("moran", "effect"), reference.moran.i = 1, verbose = FALSE, n.cores = parallel::detectCores() - 1, cluster = NULL )
data |
Data frame with a response variable and a set of predictors. Default: |
dependent.variable.name |
Character string with the name of the response variable. Must be in the column names of |
predictor.variable.names |
Character vector with the names of the predictive variables. Every element of this vector must be in the column names of |
distance.matrix |
Squared matrix with the distances among the records in |
distance.thresholds |
Numeric vector with neighborhood distances. All distances in the distance matrix below each value in |
ranger.arguments |
List with ranger arguments. See rf or rf_repeat for further details. |
spatial.predictors.df |
Data frame of spatial predictors. |
ranking.method |
Character, method used by to rank spatial predictors. The method "effect" ranks spatial predictors according how much each predictor reduces Moran's I of the model residuals, while the method "moran" ranks them by their own Moran's I. Default: |
reference.moran.i |
Moran's I of the residuals of the model without spatial predictors. Default: |
verbose |
Logical, ff |
n.cores |
Integer, number of cores to use for parallel execution. Creates a socket cluster with |
cluster |
A cluster definition generated with |
A list with four slots:
method
: Character, name of the method used to rank the spatial predictors.
criteria
: Data frame with two different configurations depending on the ranking method. If ranking.method = "effect"
, the columns contain the names of the spatial predictors, the r-squared of the model, the Moran's I of the model residuals, the difference between the Moran's I of the model including the given spatial predictor, and the Moran's I of the model fitted without spatial predictors, and the interpretation of the Moran's I value. If ranking.method = "moran"
, only the name of the spatial predictor and it's Moran's I are in the output data frame.
ranking
: Ordered character vector with the names of the spatial predictors selected.
spatial.predictors.df
: data frame with the selected spatial predictors in the order of the ranking.
if(interactive()){ #loading distance matrix data(distance_matrix) #computing Moran's Eigenvector Maps mem.df <- mem( distance.matrix = distance_matrix[1:50, 1:50], distance.threshold = 0 ) #ranking by the Moran's I of the spatial predictor rank <- rank_spatial_predictors( distance.matrix = distance_matrix[1:50, 1:50], distance.thresholds = 0, spatial.predictors.df = mem.df, ranking.method = "moran", n.cores = 1 ) #checking Moran's I of MEMs rank$criteria #checking rank of MEMs rank$ranking }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.