31
31
# 'approach for model training and testing.
32
32
# '
33
33
# 'We adapt this approach to account for temporal autocorrelation by enabling users to split records
34
- # 'into sampling units based upon spatial or temporal characteristics before blocking occurs.
34
+ # 'into sampling units based upon spatial and temporal characteristic before blocking occurs.
35
35
# '
36
36
# '# Spatial splitting
37
37
# '
45
45
# 'considered unique sampling unit. For instance, if `temporal.block` = `year`, then records from the
46
46
# 'same year are considered a sampling unit to be grouped into blocks.
47
47
# '
48
+ # 'Note: If spatial splitting is also used, then spatial characteristics may split these further into
49
+ # 'separate sampling units.
48
50
# '
49
51
# 'The `temporal.block` option `quarter` splits occurrence records into sampling units based on which
50
52
# 'quarter of the year the record month belongs to: (1) January-March, (2) April-June, (3)
53
55
# '
54
56
# '# Block generation
55
57
# '
56
- # 'Once split into sampling units based upon temporal or spatial characteristics, these units are
58
+ # 'Once split into sampling units based upon temporal and spatial characteristics, these units are
57
59
# 'then assigned into given number of blocks (`n.blocks`), so that the mean and range of explanatory
58
60
# 'variables (`vars.to.block.by`) and total sample size are similar across each. The number of
59
61
# '`iterations` specifies how many random shuffles are used to optimise block equalisation.
65
67
# ' Biology, 19, 1236-1248.
66
68
# '
67
69
# '@return Returns occurrence data frame with column "BLOCK.CATS", assigning each record to a
68
- # ' spatial or temporal block.
70
+ # ' spatiotemporal block.
69
71
# ' @examples
70
72
# ' \donttest{
71
73
# 'data("sample_explan_data")
79
81
# ' occ.data = sample_explan_data,
80
82
# ' spatial.layer = random_cat_layer,
81
83
# ' spatial.split.degrees = 3,
84
+ # ' temporal.block = c("month"),
82
85
# ' vars.to.block.by = colnames(sample_explan_data)[14:16],
83
86
# ' n.blocks = 3,
84
87
# ' iterations = 30
@@ -90,29 +93,24 @@ spatiotemp_block <- function(occ.data,
90
93
vars.to.block.by ,
91
94
spatial.layer ,
92
95
spatial.split.degrees ,
93
- temporal.block ,
96
+ temporal.block ,
94
97
n.blocks = 10 ,
95
98
iterations = 5000 ) {
96
99
97
100
# Save occ.data to return with added block column at end
98
101
occ.data.save <- occ.data
99
102
100
- temporal.block.2 <- NULL
101
103
if (n.blocks < 2 ) {
102
104
stop(" n.blocks must be over one for blocking" )
103
105
}
104
106
105
- if (! missing(spatial.layer )) {
106
- message(" Blocking by spatial features." )
107
- }
108
-
109
- if (! missing(spatial.layer ) && ! missing(temporal.block )) {
110
- stop(" Error: Spatial and Temporal Blocking must be applied separately. Provide only one of `spatial.layer` or `temporal.block`." )
107
+ if (missing(spatial.layer )) {
108
+ message(" spatial.layer is missing. No blocking by spatial features." )
111
109
}
112
110
113
- if (! missing(temporal.block )) {
114
- message(" Blocking by temporal features." )
115
-
111
+ if (missing(temporal.block )) {
112
+ message(" temporal.block is missing. No blocking by temporal features." )
113
+ temporal.block.2 <- NULL
116
114
}
117
115
118
116
if (! missing(temporal.block )) {
0 commit comments