if (interactive()) {
data(
plants_df,
plants_response,
plants_predictors,
plants_distance,
plants_rf
)
#subset to speed up example
idx <- 1:20
plants_df <- plants_df[idx, ]
plants_distance <- plants_distance[idx, idx]
#generate spatial predictors
mems <- mem_multithreshold(
distance.matrix = plants_distance,
distance.thresholds = 100
)
#rank them from higher to lower moran
mems.rank <- rank_spatial_predictors(
ranking.method = "moran",
spatial.predictors.df = mems,
reference.moran.i = plants_rf$residuals$autocorrelation$max.moran,
distance.matrix = plants_distance,
distance.thresholds = 100,
n.cores = 1
)
#select best subset via sequential addition
selection <- select_spatial_predictors_recursive(
data = plants_df,
dependent.variable.name = plants_response,
predictor.variable.names = plants_predictors,
distance.matrix = plants_distance,
distance.thresholds = 0,
spatial.predictors.df = mems,
spatial.predictors.ranking = mems.rank,
ranger.arguments = list(num.trees = 30),
n.cores = 1
)
#names of selected spatial predictors
selection$best.spatial.predictors
#optimization plot
plot_optimization(selection$optimization)
}
Run the code above in your browser using DataLab