@@ -188,7 +188,7 @@ setGeneric("BIOMOD.formated.data", def = function(sp, env, ...) { standardGeneri
188
188
available.types.resp <- c(' integer' , ' numeric' , ' data.frame' , ' matrix' ,
189
189
' SpatialPointsDataFrame' , ' SpatialPoints' , ' SpatVector' )
190
190
.fun_testIfInherits(TRUE , " sp" , sp , available.types.resp )
191
-
191
+
192
192
# # SpatialPoints, SpatialPointsDataFrame, SpatVector
193
193
if (inherits(sp , c(' SpatialPoints' ,' SpatVector' ))) {
194
194
.tmp <- .check_formating_spatial(resp.var = sp ,
@@ -934,7 +934,7 @@ setMethod('plot', signature(x = 'BIOMOD.formated.data', y = "missing"),
934
934
allPA <- allrun <- NA
935
935
if (! is.null(calib.lines )) {
936
936
.fun_testIfInherits(TRUE , " calib.lines" , calib.lines , c(" matrix" ))
937
-
937
+
938
938
expected_CVnames <- c(paste0(" _allData_RUN" , seq_len(ncol(calib.lines ))), " _allData_allRun" )
939
939
if (inherits(x , " BIOMOD.formated.data.PA" )) {
940
940
expected_CVnames <- c(expected_CVnames
@@ -1170,20 +1170,20 @@ setMethod('summary', signature(object = 'BIOMOD.formated.data'),
1170
1170
output <- data.frame (" dataset" = " initial" ,
1171
1171
" run" = NA ,
1172
1172
" PA" = NA ,
1173
- " Presences" = sum( object @ data.species , na.rm = TRUE ),
1174
- " True_Absences" = sum( object @ data.species == 0 , na.rm = TRUE ),
1173
+ " Presences" = length(which( object @ data.species == 1 ) ),
1174
+ " True_Absences" = length(which( object @ data.species == 0 ) ),
1175
1175
" Pseudo_Absences" = 0 ,
1176
- " Undefined" = sum( is.na(object @ data.species ), na.rm = TRUE ))
1176
+ " Undefined" = length(which( is.na(object @ data.species )) ))
1177
1177
1178
1178
if (object @ has.data.eval ) {
1179
1179
output <- rbind(output ,
1180
1180
data.frame (" dataset" = " evaluation" ,
1181
1181
" run" = NA ,
1182
1182
" PA" = NA ,
1183
- " Presences" = sum( object @ eval.data.species , na.rm = TRUE ),
1184
- " True_Absences" = sum( object @ eval.data.species == 0 , na.rm = TRUE ),
1183
+ " Presences" = length(which( object @ eval.data.species == 1 ) ),
1184
+ " True_Absences" = length(which( object @ eval.data.species == 0 ) ),
1185
1185
" Pseudo_Absences" = 0 ,
1186
- " Undefined" = sum( is.na(object @ eval.data.species ), na.rm = TRUE )))
1186
+ " Undefined" = length(which( is.na(object @ eval.data.species )) )))
1187
1187
}
1188
1188
1189
1189
PA <- run <- NA
@@ -1199,47 +1199,48 @@ setMethod('summary', signature(object = 'BIOMOD.formated.data'),
1199
1199
output <-
1200
1200
rbind(
1201
1201
output ,
1202
- foreach(this_PA = PA , this_run = run , .combine = ' rbind' ) %do % {
1203
- if (is.na(this_PA ) || this_PA == ' allData' ) { # run only
1204
- this_name <- paste0(" _" , this_PA , " _" , this_run )
1205
- this_calib <- calib.lines [ , this_name ]
1206
- this_valid <- ! calib.lines [ , this_name ]
1207
- } else if (is.na(this_run )) { # PA only
1208
- this_calib <- object @ PA.table [ , this_PA ]
1209
- } else { # PA+run
1210
- this_name <- paste0(" _" , this_PA , " _" , this_run )
1211
- this_calib <- calib.lines [ , this_name ] & object @ PA.table [ , this_PA ]
1212
- this_valid <- ! calib.lines [ , this_name ] & object @ PA.table [ , this_PA ]
1213
- }
1214
- calib.resp <- object @ data.species [which(this_calib )]
1215
- tmp <- data.frame (" dataset" = " calibration" ,
1216
- " run" = this_run ,
1217
- " PA" = this_PA ,
1218
- " Presences" = length(which(calib.resp == 1 )),
1219
- " True_Absences" = length(which(calib.resp == 0 )),
1220
- " Pseudo_Absences" =
1221
- length(which(this_calib )) -
1222
- length(which(calib.resp == 1 )) -
1223
- length(which(calib.resp == 0 )),
1224
- " Undefined" = NA )
1225
-
1226
- if (! is.na(this_run )) {
1227
- valid.resp <- object @ data.species [this_valid ]
1228
- tmp <- rbind(tmp ,
1229
- data.frame (" dataset" = " validation" ,
1230
- " run" = this_run ,
1231
- " PA" = this_PA ,
1232
- " Presences" = length(which(valid.resp == 1 )),
1233
- " True_Absences" = length(which(valid.resp == 0 )),
1234
- " Pseudo_Absences" =
1235
- length(valid.resp ) -
1236
- length(which(valid.resp == 1 )) -
1237
- length(which(valid.resp == 0 )),
1238
- " Undefined" = NA ))
1202
+ foreach(this_run = run , .combine = ' rbind' ) %: %
1203
+ foreach(this_PA = PA , .combine = ' rbind' ) %do % {
1204
+ if (is.na(this_PA ) || this_PA == ' allData' ) { # run only
1205
+ this_name <- paste0(" _" , this_PA , " _" , this_run )
1206
+ this_calib <- calib.lines [ , this_name ]
1207
+ this_valid <- ! calib.lines [ , this_name ]
1208
+ } else if (is.na(this_run )) { # PA only
1209
+ this_calib <- object @ PA.table [ , this_PA ]
1210
+ } else { # PA+run
1211
+ this_name <- paste0(" _" , this_PA , " _" , this_run )
1212
+ this_calib <- calib.lines [ , this_name ] & object @ PA.table [ , this_PA ]
1213
+ this_valid <- ! calib.lines [ , this_name ] & object @ PA.table [ , this_PA ]
1214
+ }
1215
+ calib.resp <- object @ data.species [which(this_calib )]
1216
+ tmp <- data.frame (" dataset" = " calibration" ,
1217
+ " run" = this_run ,
1218
+ " PA" = this_PA ,
1219
+ " Presences" = length(which(calib.resp == 1 )),
1220
+ " True_Absences" = length(which(calib.resp == 0 )),
1221
+ " Pseudo_Absences" =
1222
+ length(which(this_calib )) -
1223
+ length(which(calib.resp == 1 )) -
1224
+ length(which(calib.resp == 0 )),
1225
+ " Undefined" = NA )
1239
1226
1240
- }
1241
- return (tmp ) # end foreach
1242
- })
1227
+ if (! is.na(this_run )) {
1228
+ valid.resp <- object @ data.species [this_valid ]
1229
+ tmp <- rbind(tmp ,
1230
+ data.frame (" dataset" = " validation" ,
1231
+ " run" = this_run ,
1232
+ " PA" = this_PA ,
1233
+ " Presences" = length(which(valid.resp == 1 )),
1234
+ " True_Absences" = length(which(valid.resp == 0 )),
1235
+ " Pseudo_Absences" =
1236
+ length(valid.resp ) -
1237
+ length(which(valid.resp == 1 )) -
1238
+ length(which(valid.resp == 0 )),
1239
+ " Undefined" = NA ))
1240
+
1241
+ }
1242
+ return (tmp ) # end foreach
1243
+ })
1243
1244
}
1244
1245
output
1245
1246
}
@@ -1488,9 +1489,11 @@ setMethod('BIOMOD.formated.data.PA', signature(sp = 'numeric', env = 'SpatRaster
1488
1489
if (inherits(env , ' SpatRaster' )) {
1489
1490
categorical_var <- names(env )[is.factor(env )]
1490
1491
1491
- output <- check_duplicated_cells(env , xy , sp , filter.raster )
1492
+ output <- check_duplicated_cells(env , xy , sp , filter.raster ,
1493
+ PA.user.table = PA.user.table )
1492
1494
xy <- output $ xy
1493
1495
sp <- output $ sp
1496
+ PA.user.table <- output $ PA.user.table
1494
1497
rm(output )
1495
1498
}
1496
1499
0 commit comments