Need a function that gets correlation scores - perhaps get_correlation()?
Closed this issue · 2 comments
vjjan91 commented
show_correlation() currently only plots the correlation scores against one another, but I need a way to remove variables that are highly correlated to one another.
mhesselbarth commented
There now is a function called calculate_correlation()
which works similar to show_correlation()
, but returns a tibble
with all the correlations. This can be used easily to remove all highly correlated metrics.
Please use devtools::install_github("r-spatialecology/landscapemetrics", ref = "get_correlation")
to install the development version of the package. Please be aware that the function might still contain bugs.
library(landscapemetrics)
metrics <- landscapemetrics::calculate_lsm(landscape, level = "class")
#> Warning: Please use check_landscape() to ensure the input data is valid.
#> Warning: Class 1: PAFRAC = NA for class with < 10 patches
#> Warning: Class 3: PAFRAC = NA for class with < 10 patches
correlations <- landscapemetrics::calculate_correlation(metrics, method = "pearson",
simplify = TRUE, diag = FALSE)
correlations[correlations$value > -0.1 & correlations$value < 0.1, ]
#> metric_1 metric_2 value
#> 22 dcore_cv ai -0.046163683
#> 90 gyrate_sd area_cv 0.064254227
#> 91 iji area_cv 0.092523768
#> 96 nlsi area_cv 0.075073518
#> 105 shape_cv area_cv 0.070463638
#> 107 shape_sd area_cv -0.070501797
#> 154 para_cv area_mn -0.025259591
#> 187 dcore_cv area_sd -0.063030919
#> 209 para_cv area_sd -0.094066851
#> 288 cohesion cai_cv -0.080549709
#> 305 frac_cv cai_cv 0.004467640
#> 317 np cai_cv 0.020446896
#> 322 pd cai_cv 0.020446896
#> 373 pafrac cai_mn 0.045093237
#> 483 pafrac circle_cv -0.057790673
#> 538 pafrac circle_mn 0.086432943
#> 648 pafrac clumpy 0.092574740
#> 758 pafrac contig_cv -0.006872416
#> 912 frac_sd core_cv -0.005155770
#> 979 para_cv core_mn -0.035027459
#> 1012 dcore_cv core_sd -0.059738849
#> 1034 para_cv core_sd -0.097350000
#> 1089 para_cv cpland 0.085957749
#> 1143 pafrac dcad -0.082199494
#> 1192 lpi dcore_cv -0.025369803
#> 1196 nlsi dcore_cv -0.004253198
#> 1207 shape_sd dcore_cv 0.008836981
#> 1254 para_cv dcore_mn 0.002660876
#> 1309 para_cv dcore_sd -0.041593737
#> 1364 para_cv division 0.036600895
#> 1693 pafrac frac_mn 0.079193939
#> 1795 gyrate_sd gyrate_cv 0.053902381
#> 1796 iji gyrate_cv 0.082193455
#> 1801 nlsi gyrate_cv 0.085410038
#> 1810 shape_cv gyrate_cv 0.060115806
#> 1812 shape_sd gyrate_cv -0.080842022
#> 1859 para_cv gyrate_mn 0.001317579
#> 2134 para_cv mesh -0.036600895
#> 2188 pafrac ndca -0.082199494
#> 2413 pladj para_cv 0.009455186
#> 2416 shape_mn para_cv -0.037520916
#> 2419 tca para_cv 0.085957749
Created on 2019-05-14 by the reprex package (v0.2.1)
Feel free to re-open at any time, but will close this for now.