Closed GISilvia closed 4 months ago
Same problem here.
My code works well in the part of the data (present modeling), but when I tried to model to the future the output is full of 0 or 1 in binary.
`## current projections niche_models_proj_current <- BIOMOD_Projection( bm.mod = niche_models, new.env = bioclim, models.chosen = 'all', metric.binary = 'all', metric.filter = 'all', proj.name = "current", build.clamping.mask = TRUE, compress = FALSE)
ensemble_models_proj_current <- BIOMOD_EnsembleForecasting( bm.em = ensemble_models, bm.proj = niche_models_proj_current, models.chosen = 'all', metric.binary = 'TSS', metric.filter = 'all') `
But when I tried to model this data for the future:
`ProLau_models_proj_e_4.5_2041 <- BIOMOD_Projection( bm.mod = niche_models, proj.name = "bio_45_2041", new.env = bio_45_2041, models.chosen = 'all', metric.binary = 'all', metric.filter = 'all', build.clamping.mask = TRUE, compress = FALSE)
ProLau_ensemble_models_proj_e_4.5_2041 <- BIOMOD_EnsembleForecasting( bm.em = ensemble_models, bm.proj = ProLau_models_proj_e_4.5_2041, models.chosen = 'all', metric.binary = 'all', metric.filter = 'all') `
Everything is 1.
I'm calling this image using:
eproj_e_4.5_2041_bin <- raster(ProLau_ensemble_models_proj_e_4.5_2041@proj.out@link[2]) plot(eproj_e_4.5_2041_bin)
Hello to both of you,
Thanks a lot for all your information! I'm sorry but I will need a little bit more to be able to help you. Your code seems nice, so I'll take a closer look at your data.
Can you send me (if you haven't already) :
modformat
with your cross validation table plot(modformat, calib.lines = DataSplitTable.b)You can also check whether the variables in the current and the new environment have the same range and whether you are on the same coordinates reference.
Thank you, Hélène
Hello Hélène,
Sending the files that you ask previously:
Variables of current and new environment have the same crs and range
Current environment:
summary(bioclim)
bio13 bio17 bio18 bio19 bio2
Min. : 53 Min. : 0.00 Min. : 5.0 Min. : 0.0 Min. : 48.0
1st Qu.:215 1st Qu.: 19.00 1st Qu.:174.0 1st Qu.: 48.0 1st Qu.:102.0
Median :282 Median : 44.00 Median :280.0 Median : 106.0 Median :117.0
Mean :273 Mean : 69.73 Mean :302.8 Mean : 315.2 Mean :114.6
3rd Qu.:332 3rd Qu.: 93.00 3rd Qu.:413.0 3rd Qu.: 671.0 3rd Qu.:128.0
Max. :641 Max. :465.00 Max. :839.0 Max. :1672.0 Max. :157.0
NA's :24927 NA's :24927 NA's :24927 NA's :24927 NA's :24927
bio3 bio8
Min. :57.00 Min. :185.0
1st Qu.:69.00 1st Qu.:244.0
Median :71.00 Median :253.0
Mean :72.79 Mean :251.7
3rd Qu.:77.00 3rd Qu.:262.0
Max. :90.00 Max. :285.0
NA's :24927 NA's :24927
New environment:
bio13 bio17 bio18 bio19 bio2
Min. : 54.56 Min. : 0.00 Min. : 16.0 Min. : 0.00 Min. : 4.917
1st Qu.:214.94 1st Qu.: 18.75 1st Qu.:186.4 1st Qu.: 42.25 1st Qu.:10.164
Median :284.75 Median : 44.19 Median :294.5 Median : 122.31 Median :11.814
Mean :270.58 Mean : 67.21 Mean :295.1 Mean : 378.27 Mean :11.509
3rd Qu.:324.44 3rd Qu.: 93.19 3rd Qu.:392.6 3rd Qu.: 817.94 3rd Qu.:12.722
Max. :590.31 Max. :424.69 Max. :690.7 Max. :1647.06 Max. :16.023
NA's :24907 NA's :24907 NA's :24907 NA's :24907 NA's :24907
bio3 bio8
Min. :58.20 Min. :20.19
1st Qu.:67.19 1st Qu.:25.59
Median :70.15 Median :26.41
Mean :70.94 Mean :26.29
3rd Qu.:74.51 3rd Qu.:27.14
Max. :86.67 Max. :30.58
NA's :24907 NA's :24907
projection current:
projection future (error?!)
binary
Variables importance
I also uploaded my .RData to mega if you need it.
R version 4.3.1 (2023-06-16 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22631)
biomod2_4.2-4
Dear Hélène,
here the information you asked.
Summary of my current environment (data I used to train the model):
as.data.frame(summary(explvar))
Var1 Var2 Freq
1 bio7 Min. : 2.00
2 bio7 1st Qu.:19.90
3 bio7 Median :26.60
4 bio7 Mean :28.15
5 bio7 3rd Qu.:36.80
6 bio7 Max. :70.50
7 bio7 NA's :588
8 bio10 Min. :264.2
9 bio10 1st Qu.:289.5
10 bio10 Median :293.7
11 bio10 Mean :293.9
12 bio10 3rd Qu.:298.9
13 bio10 Max. :312.0
14 bio10 NA's :588
15 bio16 Min. : 0.4
16 bio16 1st Qu.: 216.6
17 bio16 Median : 304.6
18 bio16 Mean : 415.7
19 bio16 3rd Qu.: 513.3
20 bio16 Max. :6263.1
21 bio16 NA's :588
22 bio17 Min. : 0.0
23 bio17 1st Qu.: 31.4
24 bio17 Median : 77.7
25 bio17 Mean : 107.8
26 bio17 3rd Qu.: 145.0
27 bio17 Max. :4258.0
28 bio17 NA's :588
29 soil_bulk_density Min. : 23.88
30 soil_bulk_density 1st Qu.: 96.91
31 soil_bulk_density Median :122.43
32 soil_bulk_density Mean :116.03
33 soil_bulk_density 3rd Qu.:135.11
34 soil_bulk_density Max. :170.85
35 soil_bulk_density NA's :588
36 pop_density Min. :0.0000
37 pop_density 1st Qu.:0.0309
38 pop_density Median :0.1425
39 pop_density Mean :0.1966
40 pop_density 3rd Qu.:0.3245
41 pop_density Max. :1.1410
42 pop_density NA's :588
Summary of the new environment (It is actually the current environment, but in the form of raster stack, I used this as new.env, to project the models, but the result of this projection give the error):
as.data.frame(summary(preseu))
Var1 Var2 Freq
1 bio7 Min. : 6.30
2 bio7 1st Qu.:28.00
3 bio7 Median :31.40
4 bio7 Mean :31.04
5 bio7 3rd Qu.:35.30
6 bio7 Max. :43.90
7 bio7 NA's :66441
8 bio10 Min. :-2.35
9 bio10 1st Qu.:15.15
10 bio10 Median :18.35
11 bio10 Mean :20.16
12 bio10 3rd Qu.:25.75
13 bio10 Max. :38.75
14 bio10 NA's :66441
15 bio16 Min. : 0.3
16 bio16 1st Qu.: 100.5
17 bio16 Median : 225.7
18 bio16 Mean : 212.6
19 bio16 3rd Qu.: 272.7
20 bio16 Max. :1794.8
21 bio16 NA's :66441
22 bio17 Min. : 0.00
23 bio17 1st Qu.: 18.50
24 bio17 Median :101.50
25 bio17 Mean : 94.78
26 bio17 3rd Qu.:123.80
27 bio17 Max. :916.20
28 bio17 NA's :66441
29 soil_bulk_density Min. : 446.5
30 soil_bulk_density 1st Qu.: 882.9
31 soil_bulk_density Median :1188.6
32 soil_bulk_density Mean :1156.4
33 soil_bulk_density 3rd Qu.:1438.7
34 soil_bulk_density Max. :1591.2
35 soil_bulk_density NA's :67337
36 pop_density Min. :0.00
37 pop_density 1st Qu.:0.42
38 pop_density Median :1.45
39 pop_density Mean :1.80
40 pop_density 3rd Qu.:2.94
41 pop_density Max. :9.19
42 pop_density NA's :66960
Messaggio di avvertimento:
[summary] used a sample
Projection with the current environment (it is wrong, all 0 values):
plot(ppreseu)
Variable importance plot:
bm_PlotVarImpBoxplot(mod_output, group.by = c("run", "expl.var", "algo"), do.plot = TRUE)
$tab full.name PA run algo expl.var rand var.imp 1 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio7 1 0.710284 2 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio10 1 0.425987 3 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio16 1 0.079090 4 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio17 1 0.138658 5 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM soil_bulk_density 1 0.117066 6 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM pop_density 1 0.063259 7 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio7 2 0.708930 8 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio10 2 0.420378 9 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio16 2 0.078378 10 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio17 2 0.139604 11 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM soil_bulk_density 2 0.116540 12 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM pop_density 2 0.063863 13 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio7 3 0.707577 14 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio10 3 0.423276 15 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio16 3 0.078538 16 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM bio17 3 0.138586 17 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM soil_bulk_density 3 0.118723 18 Acacia.dealbata_allData_RUN1_GLM allData RUN1 GLM pop_density 3 0.063159 19 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio7 1 0.654626 20 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio10 1 0.230004 21 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio16 1 0.103142 22 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio17 1 0.110407 23 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM soil_bulk_density 1 0.119644 24 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM pop_density 1 0.013109 25 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio7 2 0.657607 26 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio10 2 0.231492 27 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio16 2 0.102554 28 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio17 2 0.110365 29 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM soil_bulk_density 2 0.120174 30 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM pop_density 2 0.013056 31 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio7 3 0.657290 32 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio10 3 0.232859 33 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio16 3 0.103279 34 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM bio17 3 0.111368 35 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM soil_bulk_density 3 0.119644 36 Acacia.dealbata_allData_RUN1_GAM allData RUN1 GAM pop_density 3 0.013098 37 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio7 1 0.692433 38 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio10 1 0.440718 39 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio16 1 0.040623 40 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio17 1 0.040095 41 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM soil_bulk_density 1 0.070191 42 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM pop_density 1 0.059520 43 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio7 2 0.693898 44 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio10 2 0.436268 45 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio16 2 0.040577 46 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio17 2 0.039983 47 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM soil_bulk_density 2 0.070667 48 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM pop_density 2 0.059504 49 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio7 3 0.697554 50 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio10 3 0.438521 51 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio16 3 0.040531 52 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM bio17 3 0.039402 53 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM soil_bulk_density 3 0.070369 54 Acacia.dealbata_allData_RUN2_GLM allData RUN2 GLM pop_density 3 0.059378 55 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio7 1 0.652602 56 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio10 1 0.292217 57 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio16 1 0.052917 58 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio17 1 0.025047 59 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM soil_bulk_density 1 0.080371 60 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM pop_density 1 0.031365 61 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio7 2 0.652233 62 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio10 2 0.288683 63 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio16 2 0.053752 64 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio17 2 0.024678 65 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM soil_bulk_density 2 0.080489 66 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM pop_density 2 0.031262 67 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio7 3 0.651987 68 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio10 3 0.289184 69 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio16 3 0.053540 70 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM bio17 3 0.023993 71 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM soil_bulk_density 3 0.080436 72 Acacia.dealbata_allData_RUN2_GAM allData RUN2 GAM pop_density 3 0.031217 73 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio7 1 0.642398 74 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio10 1 0.579409 75 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio16 1 0.024214 76 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio17 1 0.075697 77 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM soil_bulk_density 1 0.088577 78 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM pop_density 1 0.096496 79 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio7 2 0.639281 80 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio10 2 0.579038 81 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio16 2 0.024187 82 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio17 2 0.076497 83 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM soil_bulk_density 2 0.086787 84 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM pop_density 2 0.096225 85 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio7 3 0.646850 86 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio10 3 0.582162 87 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio16 3 0.023156 88 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM bio17 3 0.075019 89 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM soil_bulk_density 3 0.087925 90 Acacia.dealbata_allData_RUN3_GLM allData RUN3 GLM pop_density 3 0.095470 91 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio7 1 0.585054 92 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio10 1 0.325883 93 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio16 1 0.037746 94 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio17 1 0.045873 95 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM soil_bulk_density 1 0.106897 96 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM pop_density 1 0.069914 97 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio7 2 0.583427 98 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio10 2 0.324823 99 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio16 2 0.037908 100 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio17 2 0.045986 101 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM soil_bulk_density 2 0.106925 102 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM pop_density 2 0.070179 103 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio7 3 0.585427 104 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio10 3 0.327569 105 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio16 3 0.037886 106 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM bio17 3 0.044779 107 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM soil_bulk_density 3 0.106508 108 Acacia.dealbata_allData_RUN3_GAM allData RUN3 GAM pop_density 3 0.070562 109 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio7 1 0.702648 110 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio10 1 0.506200 111 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio16 1 0.039105 112 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio17 1 0.040939 113 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM soil_bulk_density 1 0.116300 114 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM pop_density 1 0.067271 115 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio7 2 0.699033 116 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio10 2 0.511444 117 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio16 2 0.039173 118 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio17 2 0.041648 119 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM soil_bulk_density 2 0.115755 120 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM pop_density 2 0.068246 121 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio7 3 0.704411 122 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio10 3 0.504875 123 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio16 3 0.038259 124 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM bio17 3 0.041248 125 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM soil_bulk_density 3 0.116127 126 Acacia.dealbata_allData_RUN4_GLM allData RUN4 GLM pop_density 3 0.067425 127 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio7 1 0.616569 128 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio10 1 0.305258 129 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio16 1 0.056746 130 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio17 1 0.024795 131 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM soil_bulk_density 1 0.065617 132 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM pop_density 1 0.040434 133 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio7 2 0.610435 134 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio10 2 0.308497 135 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio16 2 0.056379 136 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio17 2 0.024806 137 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM soil_bulk_density 2 0.064984 138 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM pop_density 2 0.039240 139 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio7 3 0.614173 140 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio10 3 0.307203 141 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio16 3 0.056091 142 Acacia.dealbata_allData_RUN4_GAM allData RUN4 GAM bio17 3 0.024128 [ reached 'max' / getOption("max.print") -- omitted 218 rows ]
$plot
The plot of modformat with my cross validation table:
plot(modformat, calib.lines = DataSplitTable.b)
Caricamento dei namespace richiesti: ggtext
$data.vect
class : SpatVector
geometry : points
dimensions : 1248407, 2 (geometries, attributes)
extent : -178.8293, 179.454, -55.55431, 83.12069 (xmin, xmax, ymin, ymax)
coord. ref. :
names : resp dataset
type :
$data.label 9 10 "Presences" "Presences (calibration)" 11 12 "Presences (validation)" "Presences (evaluation)" 19 20 "True Absences" "True Absences (calibration)" 21 22 "True Absences (validation)" "True Absences (evaluation)" 29 30 "Pseudo-Absences" "Pseudo-Absences (calibration)" 31 1 "Pseudo-Absences (validation)" "Background"
$data.plot
thank you so much
Hello to both of you,
I will answer @karolceron first.
Thanks a lot for your data: it helps a lot to find the problem. 🙏
So first, it doesn't come from the code but more from the models.
If you have a look at the response curves, it has a strange behavior. For example, RF is almost binary. If you look at the evaluation table, you see that RF is often one of the only models selected. So it leads to a prediction with only 1
. Classification models can be tricky. 😅
I will advise you to look at the response curves before selecting the models for the ensemble model. You could also look at the importance variable (you will need to set the var.import
parameter to a number >= 2) and pay attention if there is not a variable with much greater importance than the others.
I hope it helps! Don't hesitate if you still notice strange behavior. Hélène
Hi @GISilvia,
Thanks for the additional information! 🙏 I think the problem comes first from the fact that your variables are not in the same range. For example, for bio10, in the current environment ranges from 264,2 to 312 but in your raster, bio10 ranges from -2,35 to 38,75. As the model is not trained on this range, it sets the predictions to zero.
Hope it will solve your problem. Hélène
Hi @GISilvia,
I'm not sure I follow you. You've found why the variables are not in the same range and you've corrected it: but you've given me the summary of the old environment ? One of the things you can do is project with your training environment, so it will help to find where the error is coming from. Don't hesitate, if you have the possibility, to send us your data as it can be sometimes easier. (by mail if you prefer helene.blancheteau@univ-grenoble-alpes.fr)
Hélène
Dear Hélène,
I'm sorry, I deleted my last reply just after posting because I realised it wasn't clear, although you could read it. I'll better explain now: Your last observation was very useful for me, and it allowed me to understand the source of the problem! Here's what happened:
Thank you so much for your help!!!
What could it be the reason why my models give only the value of 0 in each cell of the projection images? I have built some stacks of bioclimatic variables from Chelsa Climate, population and soil values for the present and different future scenarious, I used the present ones as esplicative variables, I have built a dataframe of presences and pseudo-absences with their environmental explicative variables. I also did a stratified cross validation. I run GLM and GAM models for different set of points, and all seem to work. As a result I plotted nice resonse curves. But when I project the single models with BIOMOD_Projection, for some environmental stacks my projection results include only the value of 0 for all the models. I processed all the environmental stacks in the same way (I tried both raster and terra pakcages), but I always have this problem. This is my code:
modformat <- BIOMOD_FormatingData(resp.var= as.data.frame(b[ ,myRespName]) , resp.xy = b[,c("x_centroid","y_centroid")], resp.name = myRespName, expl.var=b[ , raster_names], PA.nb.rep =3, PA.nb.absences=10000, na.rm=T)
modOption <- BIOMOD_ModelingOptions( GLM = list( type = 'quadratic', interaction.level = 1 ), GAM = list( algo = 'GAM_mgcv' , k=1, select=T) )
DataSplitTable.b <- bm_CrossValidation(bm.format = modformat, balance = 'presences', k = 5, strategy = "strat", nb.rep = 3)
mod_output <- BIOMOD_Modeling( bm.format = modformat, modeling.id = paste(myRespName, "ModTest", sep = ""), models = c("GLM", "GAM"), bm.options = modOption, CV.do.full.models = FALSE, prevalence = 0.5, var.import = 3, metric.eval = c('TSS', 'ROC'), nb.cpu = 1, seed.val = NULL, do.progress = TRUE, CV.strategy = "user.defined", CV.user.table = DataSplitTable.b )
Projection
preseu <- rast("preseu.tif") names(preseu) <- c("bio7", "bio10", "bio16", "bio17", "soil_bulk_density", "pop_density") ppreseu <- BIOMOD_Projection(bm.mod=mod_output, new.env = preseu , proj.name="_modelOut_ppreseu_projection", build.clamping.mask=T, output.format = ".img", metric.filter = "ROC", metric.binary="ROC")
Outoputs:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.formated.data -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
dir.name = .
sp.name = Acacia.dealbata
Min. : 20.0 Min. :2642 Min. : 4 Min. : 0 Min. : 238.8 Min. : 0.0000
1st Qu.:199.0 1st Qu.:2895 1st Qu.: 2166 1st Qu.: 314 1st Qu.: 969.1 1st Qu.: 0.3089
Median :266.0 Median :2937 Median : 3046 Median : 777 Median :1224.3 Median : 1.4252
Mean :281.5 Mean :2939 Mean : 4157 Mean : 1078 Mean :1160.3 Mean : 1.9656
3rd Qu.:368.0 3rd Qu.:2989 3rd Qu.: 5133 3rd Qu.: 1450 3rd Qu.:1351.1 3rd Qu.: 3.2447
Max. :705.0 Max. :3120 Max. :62631 Max. :42580 Max. :1708.5 Max. :11.4100
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.models.options -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
GLM = list( type = 'quadratic', interaction.level = 1, myFormula = NULL, test = 'AIC', family = binomial(link = 'logit'), mustart = 0.5, control = glm.control(epsilon = 1e-08, maxit = 50, trace = FALSE) ),
GBM = list( distribution = 'bernoulli', n.trees = 2500, interaction.depth = 7, n.minobsinnode = 5, shrinkage = 0.001, bag.fraction = 0.5, train.fraction = 1, cv.folds = 3, keep.data = FALSE, verbose = FALSE, perf.method = 'cv', n.cores = 1),
GAM = list( algo = 'GAM_mgcv', type = 's_smoother', k = 1, interaction.level = 0, myFormula = NULL, family = binomial(link = 'logit'), method = 'GCV.Cp', optimizer = c('outer','newton'), select = TRUE, knots = NULL, paraPen = NULL, control = list(nthreads = 1, ncv.threads = 1, irls.reg = 0, epsilon = 1e-07, maxit = 200 , trace = FALSE, mgcv.tol = 1e-07, mgcv.half = 15, rank.tol = 1.49011611938477e-08 , nlm = list(ndigit=7, gradtol=1e-06, stepmax=2, steptol=1e-04, iterlim=200, check.analyticals=0) , optim = list(factr=1e+07), newton = list(conv.tol=1e-06, maxNstep=5, maxSstep=2, maxHalf=30, use.svd=0) , outerPIsteps = 0, idLinksBases = TRUE, scalePenalty = TRUE, efs.lspmax = 15, efs.tol = 0.1, keepData = FALSE , scale.est = fletcher, edge.correct = FALSE) ),
CTA = list( method = 'class', parms = 'default', cost = NULL, control = list(xval = 5, minbucket = 5, minsplit = 5, cp = 0.001, maxdepth = 25) ),
ANN = list( NbCV = 5, size = NULL, decay = NULL, rang = 0.1, maxit = 200),
SRE = list( quant = 0.025),
FDA = list( method = 'mars', add_args = NULL),
MARS = list( type = 'simple', interaction.level = 0, myFormula = NULL, nk = NULL, penalty = 2, thresh = 0.001, nprune = NULL, pmethod = 'backward'),
RF = list( do.classif = TRUE, ntree = 500, mtry = 'default', sampsize = NULL, nodesize = 5, maxnodes = NULL),
MAXENT = list( path_to_maxent.jar = 'D:/Silvia', memory_allocated = 512, initial heap size = NULL, maximum heap size = NULL, background_data_dir = 'default', maximumbackground = 'default', maximumiterations = 200, visible = FALSE, linear = TRUE, quadratic = TRUE, product = TRUE, threshold = TRUE, hinge = TRUE, lq2lqptthreshold = 80, l2lqthreshold = 10, hingethreshold = 15, beta_threshold = -1, beta_categorical = -1, beta_lqp = -1, beta_hinge = -1, betamultiplier = 1, defaultprevalence = 0.5),
MAXNET = list( myFormula = NULL, regmult = 1, regfun = ),
XGBOOST = list( max.depth = 5, eta = 0.1, nrounds = 512, objective = binary:logistic, nthread = 1 ) ) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
[100,] TRUE TRUE TRUE FALSE TRUE TRUE FALSE _allData_RUN8 _allData_RUN9 _allData_RUN10 [1,] FALSE TRUE TRUE [2,] TRUE TRUE FALSE [3,] TRUE TRUE TRUE [4,] FALSE TRUE TRUE [5,] TRUE TRUE TRUE [6,] FALSE TRUE TRUE [7,] TRUE TRUE FALSE [8,] TRUE TRUE TRUE [9,] TRUE TRUE FALSE [10,] TRUE TRUE FALSE [11,] FALSE TRUE TRUE [12,] TRUE FALSE TRUE [13,] TRUE FALSE TRUE [14,] TRUE TRUE TRUE [15,] TRUE FALSE TRUE [16,] TRUE FALSE TRUE [17,] TRUE TRUE FALSE [18,] TRUE TRUE FALSE [19,] TRUE FALSE TRUE [20,] TRUE TRUE TRUE [21,] TRUE TRUE TRUE [22,] TRUE TRUE TRUE [23,] TRUE TRUE TRUE [24,] TRUE TRUE TRUE [25,] TRUE FALSE TRUE [26,] FALSE TRUE TRUE [27,] TRUE TRUE FALSE [28,] TRUE TRUE TRUE [29,] TRUE FALSE TRUE [30,] TRUE TRUE FALSE [31,] TRUE FALSE TRUE [32,] TRUE TRUE TRUE [33,] FALSE TRUE TRUE [34,] FALSE TRUE TRUE [35,] FALSE TRUE TRUE [36,] TRUE FALSE TRUE [37,] TRUE TRUE FALSE [38,] TRUE TRUE TRUE [39,] FALSE TRUE TRUE [40,] TRUE TRUE FALSE [41,] FALSE TRUE TRUE [42,] TRUE TRUE TRUE [43,] TRUE TRUE TRUE [44,] TRUE TRUE TRUE [45,] TRUE TRUE TRUE [46,] TRUE TRUE TRUE [47,] TRUE TRUE TRUE [48,] FALSE TRUE TRUE [49,] TRUE TRUE TRUE [50,] FALSE TRUE TRUE [51,] FALSE TRUE TRUE [52,] TRUE TRUE FALSE [53,] TRUE TRUE FALSE [54,] TRUE FALSE TRUE [55,] TRUE TRUE FALSE [56,] TRUE TRUE TRUE [57,] TRUE TRUE TRUE [58,] TRUE FALSE TRUE [59,] TRUE TRUE FALSE [60,] TRUE TRUE FALSE [61,] TRUE TRUE FALSE [62,] TRUE TRUE TRUE [63,] FALSE TRUE TRUE [64,] TRUE TRUE TRUE [65,] TRUE FALSE TRUE [66,] TRUE TRUE FALSE [67,] TRUE TRUE TRUE [68,] TRUE TRUE FALSE [69,] TRUE TRUE TRUE [70,] TRUE TRUE TRUE [71,] FALSE TRUE TRUE [72,] TRUE FALSE TRUE [73,] TRUE TRUE TRUE [74,] FALSE TRUE TRUE [75,] TRUE TRUE FALSE [76,] TRUE TRUE FALSE [77,] TRUE TRUE FALSE [78,] TRUE TRUE FALSE [79,] TRUE TRUE TRUE [80,] TRUE TRUE TRUE [81,] FALSE TRUE TRUE [82,] TRUE TRUE FALSE [83,] TRUE FALSE TRUE [84,] TRUE FALSE TRUE [85,] TRUE FALSE TRUE [86,] FALSE TRUE TRUE [87,] TRUE TRUE TRUE [88,] TRUE FALSE TRUE [89,] TRUE FALSE TRUE [90,] TRUE FALSE TRUE [91,] TRUE TRUE TRUE [92,] TRUE FALSE TRUE [93,] TRUE TRUE FALSE [94,] TRUE TRUE FALSE [95,] TRUE TRUE TRUE [96,] TRUE TRUE TRUE [97,] TRUE TRUE TRUE [98,] TRUE TRUE TRUE [99,] TRUE TRUE FALSE [100,] TRUE TRUE TRUE [ reached getOption("max.print") -- omitted 122481 rows ]
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.models.out -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Modeling folder : .
Species modeled : Acacia.dealbata
Modeling id : Acacia.dealbata_Mod_Test
Considered variables : bio7 bio10 bio16 bio17 soil_bulk_density pop_density
Computed Models : Acacia.dealbata_allData_RUN1_GLM Acacia.dealbata_allData_RUN1_GAM Acacia.dealbata_allData_RUN2_GLM Acacia.dealbata_allData_RUN2_GAM Acacia.dealbata_allData_RUN3_GLM Acacia.dealbata_allData_RUN3_GAM Acacia.dealbata_allData_RUN4_GLM Acacia.dealbata_allData_RUN4_GAM Acacia.dealbata_allData_RUN5_GLM Acacia.dealbata_allData_RUN5_GAM Acacia.dealbata_allData_RUN6_GLM Acacia.dealbata_allData_RUN6_GAM Acacia.dealbata_allData_RUN7_GLM Acacia.dealbata_allData_RUN7_GAM Acacia.dealbata_allData_RUN8_GLM Acacia.dealbata_allData_RUN8_GAM Acacia.dealbata_allData_RUN9_GLM Acacia.dealbata_allData_RUN9_GAM Acacia.dealbata_allData_RUN10_GLM Acacia.dealbata_allData_RUN10_GAM
Failed Models : none
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= BIOMOD.projection.out -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Projection directory : ./Acacia.dealbata/_modelOut_ppreseu_projection
sp.name : Acacia.dealbata
expl.var.names : bio7 bio10 bio16 bio17 soil_bulk_density pop_density
modeling.id : Acacia.dealbata_Mod_Test ( ./Acacia.dealbata/Acacia.dealbata.Acacia.dealbata_Mod_Test.models.out )
models.projected : Acacia.dealbata_allData_RUN1_GLM, Acacia.dealbata_allData_RUN1_GAM, Acacia.dealbata_allData_RUN2_GLM, Acacia.dealbata_allData_RUN2_GAM, Acacia.dealbata_allData_RUN3_GLM, Acacia.dealbata_allData_RUN3_GAM, Acacia.dealbata_allData_RUN4_GLM, Acacia.dealbata_allData_RUN4_GAM, Acacia.dealbata_allData_RUN5_GLM, Acacia.dealbata_allData_RUN5_GAM, Acacia.dealbata_allData_RUN6_GLM, Acacia.dealbata_allData_RUN6_GAM, Acacia.dealbata_allData_RUN7_GLM, Acacia.dealbata_allData_RUN7_GAM, Acacia.dealbata_allData_RUN8_GLM, Acacia.dealbata_allData_RUN8_GAM, Acacia.dealbata_allData_RUN9_GLM, Acacia.dealbata_allData_RUN9_GAM, Acacia.dealbata_allData_RUN10_GLM, Acacia.dealbata_allData_RUN10_GAM
available binary projection : ROC
available filtered projection : ROC
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This is the result of the projection, where I have the problem:
plot(ppreseu)
This is the raster stack of environmental variables for model projections, that gave me the problem:
class : SpatRaster dimensions : 7545, 12025, 6 (nrow, ncol, nlyr) resolution : 0.008333333, 0.008333333 (x, y) extent : -31.27514, 68.93319, 18.97486, 81.84986 (xmin, xmax, ymin, ymax) coord. ref. : lon/lat WGS 84 (EPSG:4326) source : preseu.tif names : bio7, bio10, bio16, bio17, soil_~nsity, pop_density min values : 5.5, -7.15, 0.2, 0.0, 299.6515, 0.00000 max values : 44.7, 39.15, 4063.8, 1750.8, 1675.9122, 11.53112
These are the response curves from the models:
Session info:
R version 4.3.0 (2023-04-21 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 11 x64 (build 22631)
Matrix products: default
locale: [1] LC_COLLATE=Italian_Italy.utf8 [2] LC_CTYPE=Italian_Italy.utf8
[3] LC_MONETARY=Italian_Italy.utf8 [4] LC_NUMERIC=C
[5] LC_TIME=Italian_Italy.utf8
time zone: Europe/Rome tzcode source: internal
attached base packages: [1] stats graphics grDevices utils datasets [6] methods base
other attached packages: [1] sf_1.0-13 reshape2_1.4.4 ecospat_3.5.1 [4] ggpubr_0.6.0 ggplot2_3.4.4 dismo_1.3-14
[7] raster_3.6-20 sp_1.6-1 dplyr_1.1.2
[10] devtools_2.4.5 usethis_2.2.1 biomod2_4.2-4 [13] terra_1.7-29
loaded via a namespace (and not attached): [1] rstudioapi_0.14 jsonlite_1.8.4
[3] magrittr_2.0.3 rmarkdown_2.21
[5] fs_1.6.2 vctrs_0.6.2
[7] memoise_2.0.1 base64enc_0.1-3
[9] rstatix_0.7.2 htmltools_0.5.5
[11] plotrix_3.8-4 broom_1.0.5
[13] xgboost_1.7.5.1 Formula_1.2-5
[15] pROC_1.18.2 pracma_2.4.2
[17] KernSmooth_2.23-20 htmlwidgets_1.6.2
[19] plyr_1.8.8 poibin_1.5
[21] cachem_1.0.8 mime_0.12
[23] lifecycle_1.0.4 iterators_1.0.14
[25] pkgconfig_2.0.3 Matrix_1.6-4
[27] R6_2.5.1 fastmap_1.1.1
[29] plotmo_3.6.2 shiny_1.8.0
[31] digest_0.6.31 colorspace_2.1-0
[33] reshape_0.8.9 ps_1.7.5
[35] pkgload_1.3.2 Hmisc_5.1-0
[37] vegan_2.6-4 randomForest_4.7-1.1
[39] fansi_1.0.4 gbm_2.1.8.1
[41] abind_1.4-5 mgcv_1.8-42
[43] compiler_4.3.0 proxy_0.4-27
[45] remotes_2.4.2 withr_2.5.2
[47] htmlTable_2.4.1 backports_1.4.1
[49] DBI_1.1.3 carData_3.0-5
[51] pkgbuild_1.4.1 ggsignif_0.6.4
[53] MASS_7.3-58.4 sessioninfo_1.2.2
[55] classInt_0.4-9 gtools_3.9.4
[57] permute_0.9-7 units_0.8-2
[59] tools_4.3.0 foreign_0.8-84
[61] ape_5.7-1 httpuv_1.6.11
[63] TeachingDemos_2.12 nnet_7.3-18
[65] glue_1.6.2 callr_3.7.3
[67] nlme_3.1-162 promises_1.2.0.1
[69] grid_4.3.0 checkmate_2.2.0
[71] cluster_2.1.4 ade4_1.7-22
[73] generics_0.1.3 maxnet_0.1.4
[75] gtable_0.3.4 class_7.3-21
[77] tidyr_1.3.0 nabor_0.5.0
[79] data.table_1.14.8 car_3.1-2
[81] utf8_1.2.3 foreach_1.5.2
[83] pillar_1.9.0 stringr_1.5.1
[85] later_1.3.1 splines_4.3.0
[87] lattice_0.21-8 survival_3.5-5
[89] ks_1.14.0 tidyselect_1.2.0
[91] miniUI_0.1.1.1 knitr_1.42
[93] gridExtra_2.3 xfun_0.39
[95] stringi_1.7.12 evaluate_0.21
[97] codetools_0.2-19 tibble_3.2.1
[99] cli_3.6.1 rpart_4.1.19
[101] xtable_1.8-4 munsell_0.5.0
[103] processx_3.8.1 Rcpp_1.0.10
[105] PresenceAbsence_1.1.11 parallel_4.3.0
[107] ellipsis_0.3.2 mda_0.5-4
[109] prettyunits_1.1.1 mclust_6.0.0
[111] profvis_0.3.8 urlchecker_1.0.1
[113] mvtnorm_1.2-2 scales_1.3.0
[115] e1071_1.7-13 earth_5.3.2
[117] purrr_1.0.1 crayon_1.5.2
[119] rlang_1.1.1
Help please