% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/partition_3D.R
\name{partition_3D}
\alias{partition_3D}
\title{Create 3D partitions}
\usage{
partition_3D(
  maxent_df,
  coord_df,
  which_partition = "k.fold",
  kfolds = NULL,
  orientation = "lon_lat",
  return_format = "vector",
  ensure_all_folds = TRUE,
  max_attempts = 100,
  na_strategy = "NA"
)
}
\arguments{
\item{maxent_df}{Data frame with column 'p' (1=presence, 0=absence).}

\item{coord_df}{Data frame with 'longitude','latitude','depth' aligned with maxent_df.}

\item{which_partition}{"k.fold" (default) or "block".}

\item{kfolds}{Integer >= 2 for k.fold.}

\item{orientation}{For "block": "lon_lat" (default) or "lat_lon".}

\item{return_format}{"vector" (default) or "list".}

\item{ensure_all_folds}{(k.fold) Ensure all folds appear among presences with known depth (default TRUE).}

\item{max_attempts}{(k.fold) Retry cap when ensure_all_folds=TRUE (default 100).}

\item{na_strategy}{(k.fold) How to handle NA depth rows: "NA" (default) leaves them NA; "random" assigns a random fold.}
}
\value{
If return_format="vector": integer vector (1..k or 1..4), length == nrow(maxent_df).
Unassignable rows get NA. If "list": list(occ_partitions, bg_partitions).
}
\description{
Creates partition schemes in 3D for model training and testing.
Can create block or kfold partitions, with output as a \code{vector} or \code{list}
}
\details{
maxent_df and coord_df should be the same dataframes to be provided
to \code{maxent_3D()} for model production.
The spatial block partition, similarly to a traditional 2D partition,
will separate the occurrences into 4 groups of equal (or about equal) size,
with two groups making up two blocks on the upper half of the depth distribution
and two groups on the lower half. Background points are assigned to spatial groups
according to how they fall into the spatial partitions delimited by the occurrences.
Note that this means the number of background points in each partition may not be as
close to equal as the occurrences.
}
\examples{
\donttest{
# create test dataframe
occ <- rep(1, times = 10)
bg <- rep(0, times = 1000)
env1 <- sample(c(1:100), size = 1010, replace = TRUE)
env2 <- sample(c(1:1000), size = 1010, replace = TRUE)
p <- c(occ, bg)
testdf <- data.frame(p, env1, env2)

# create test coord data
r <- terra::rast(ncol = 100, nrow = 100)
set.seed(0)
longitude <- sample(terra::ext(r)[1]:terra::ext(r)[2], size = 1010, replace = TRUE)
set.seed(0)
latitude <- sample(terra::ext(r)[3]:terra::ext(r)[4], size = 1010, replace = TRUE)
depth <- sample(c(0, 5, 10, 15, 20, 25, 30, 35, 40, 45), size = 1010, replace = TRUE)
test_coords <- data.frame(longitude, latitude, depth)

# Here's the function
result_kfold <- partition_3D(maxent_df = testdf, coord_df = test_coords,
which_partition = 'k.fold', kfolds = 3)

result_block <- partition_3D(maxent_df = testdf, coord_df = test_coords,
which_partition = 'block', orientation = 'lat_lon')
}

}
\keyword{partition}
\keyword{validation}
