Skip to content

Commit

Permalink
Preparing for CRAN submission
Browse files Browse the repository at this point in the history
  • Loading branch information
PPaccioretti committed Jul 14, 2024
1 parent cf16688 commit 02b88e1
Show file tree
Hide file tree
Showing 21 changed files with 179 additions and 138 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ extra/*
^_pkgdown\.yml$
^docs$
^pkgdown$
^CRAN-SUBMISSION$
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.0.0
Date: 2024-07-14 16:18:21 UTC
SHA: cf16688021606b21a9f4ec274e2dd4ebd51210dc
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2020
YEAR: 2024
COPYRIGHT HOLDER: Pablo Paccioretti
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2020 Pablo Paccioretti
Copyright (c) 2024 Pablo Paccioretti

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
31 changes: 9 additions & 22 deletions R/compare_zones.R → R/compare_zone.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,15 @@
#' @param grid_dim \code{numeric} grid dimentins to estimate spatial variance
#'
#' @return \code{list} with differences and descriptive_stat
#' @references
#' Paccioretti, P., Córdoba, M., & Balzarini, M. (2020).
#' FastMapping: Software to create field maps and identify management zones
#' in precision agriculture. Computers and Electronics in Agriculture, 175,
#' 105556 https://doi.org/10.1016/j.compag.2020.105556.
#' @export
#'
#' @examples
#' @example inst/examples/compare_zone.R
#'
#' library(sf)
#' data(wheat, package = "paar")
#'
#' ##Convert to an sf object
#' wheat <- sf::st_as_sf(wheat,
#' coords = c("x", "y"),
#' crs = 32720)
#' clusters <- paar::kmspc(
#' wheat,
#' variables = c('CE30', 'CE90', 'Elev', 'Pe', 'Tg'),
#' number_cluster = 3:4
#' )
#' data_clusters <- cbind(wheat, clusters$cluster)
#' compare_zone(data_clusters,
#' "Elev",
#' "Cluster_3")

compare_zone <- function(data,
variable,
Expand Down Expand Up @@ -317,7 +306,6 @@ CalcLetras <- function(myMeans, pvalue, alpha = 0.05) {
if (chequeo > n)
break
for (i in j:n) {
# browser()
stest <- Qm[q[i], q[j]] > alpha
if (stest) {
if (lastC(M[i]) != letras[k]) {
Expand All @@ -330,7 +318,7 @@ CalcLetras <- function(myMeans, pvalue, alpha = 0.05) {
cambio1 <- 0
ja <- j
for (jj in cambio:n)
M[jj] <- paste(M[jj], "", sep = "") # El espacio
M[jj] <- paste(M[jj], "", sep = "")
M[cambio] <- paste(M[cambio], letras[k], sep = "")
for (v in ja:cambio) {
if (Qm[q[v], q[cambio]] <= alpha) {
Expand All @@ -346,15 +334,14 @@ CalcLetras <- function(myMeans, pvalue, alpha = 0.05) {
if (cambio1 == 0)
j <- j + 1
}
#-----------
# browser()

w <- data.frame(w, stat = M)
if (k > 81
)
cat(
"\n",
k,
"groups are estimated.The number of groups exceeded the maximum of 81 labels. change to group=FALSE.\n"
"groups are estimated.The number of groups exceeded the maximum of 81 labels. Change to group=FALSE.\n"
)
invisible(w)
}
Expand Down
46 changes: 38 additions & 8 deletions R/depurate.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,33 @@
#' outliers and spatial outliers or local defective observations. Default
#' values are optimized for precision agricultural data.
#'
#' @inheritParams remove_border
#' @inheritParams remove_outlier
#' @inheritParams remove_inlier
#' @param x an \code{sf} points object
#' @param y \code{character} with the name of the variable to use for
#' depuration/filtering process
#' @param toremove \code{character} vector specifying the procedure to
#' implement for errors removal. Default 'edges', 'outlier', 'inlier'.
#' See Details.
#' @param crs coordinate reference system: integer with the EPSG code,
#' or character with proj4string to convert coordinates if \code{x} has
#' longitude/latitude data
#' @param buffer \code{numeric} distance in meters to be removed. Negative
#' values are recommended
#' @param ylimitmax \code{numeric} of length 1 indicating the maximum limit
#' for the \code{y} variable. If \code{NA} \code{Inf} is assumed
#' @param ylimitmin \code{numeric} of length 1 indicating the minimum limit
#' for the \code{y} variable. If \code{NA} \code{-Inf} is assumed
#' @param sdout \code{numeric} values outside the interval
#' \eqn{mean ± sdout × sdout} values will be removed
#' @param ldist \code{numeric} lower distance bound to identify neighbors
#' @param udist \code{numeric} upper distance bound to identify neighbors
#' @param criteria \code{character} with "LM" and/or "MP" for methods to
#' identify spatial outliers
#' @param zero.policy default NULL, use global option value;
#' if FALSE stop with error for any empty neighbors sets,
#' if TRUE permit the weights list to be formed with zero-length
#' weights vectors
#' @param poly_border \code{sf} object with one polygon or NULL. Can be
#' the result of \code{concaveman::concaveman}
#'
#' @details
#' Possible values for \code{toremove} are one or more elements of:
Expand All @@ -26,7 +47,13 @@
#' automating error removal from yield maps. Precision Agric 20, 1030–1044
#' (2019). https://doi.org/10.1007/s11119-018-09632-8
#'
#' @return an object of class \code{paar}
#' @return an object of class \code{paar} with two elements:
#' \describe{
#' \item{depurated_data}{\code{sf} object with the data after the removal
#' process}
#' \item{condition}{\code{character} vector with the condition of each
#' observation}
#' }
#' @export
#' @example inst/examples/depurate.R

Expand Down Expand Up @@ -141,7 +168,8 @@ depurate <- function(x,
#' values are recommended
#' @param poly_border \code{sf} object with one polygon or NULL. Can be
#' the result of \code{concaveman::concaveman}
#'
#' @noRd
#' @keywords internal
remove_border <- function(x,
crs = NULL,
buffer,
Expand Down Expand Up @@ -282,8 +310,8 @@ remove_border <- function(x,
#' for the \code{y} variable. If \code{NA} \code{-Inf} is assumed
#' @param sdout \code{numeric} values outside the interval
#' \eqn{mean ± sdout × sdout} values will be removed
#'
#'
#' @noRd
#' @keywords internal
remove_outlier <- function(x,
y,
ylimitmax = NA,
Expand Down Expand Up @@ -351,7 +379,8 @@ remove_outlier <- function(x,
#' if FALSE stop with error for any empty neighbors sets,
#' if TRUE permit the weights list to be formed with zero-length
#' weights vectors
#'
#' @noRd
#' @keywords internal
remove_inlier <- function(x,
y,
ldist = 0,
Expand Down Expand Up @@ -442,6 +471,7 @@ remove_inlier <- function(x,
#' @param is_error internal object
#' @param remove_result internal results from remove_* functions
#' @noRd
#' @keywords internal
is_error_update <- function(is_error, remove_result) {
# Keeps NA, others are conditions
is_error_no_na <- is_error[is.na(is_error$because),]
Expand Down
1 change: 1 addition & 0 deletions R/fuzzy_k_means.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#' @return a list with classification results and indices to select best number of
#' clusters.
#' @export
#' @example inst/examples/fuzzy_k_means.R
#'
fuzzy_k_means <- function(data,
variables,
Expand Down
2 changes: 1 addition & 1 deletion R/kmspc.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' MULTISPATI-PCA clustering
#'
#'
#' @inheritParams remove_inlier
#' @inheritParams depurate
#' @param data sf object
#' @param variables variables to use for clustering, if missing, all numeric
#' variables will be used
Expand Down
5 changes: 3 additions & 2 deletions R/spatial_t_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
#' columns \code{matrix} or \code{data.frame} specifying coordinates.
#'
#' @param variables \code{character} vector with column names to perform ttest
#'
#' @return a data.frame with the correlation and p-value for each pair
#' of variables
#' @export


spatial_t_test <- function(data, variables) {

if (!requireNamespace("SpatialPack", quietly = TRUE)) {
stop(paste0("SpatialPack package is needed to perform spatial_t_test", "\n",
"Install it with 'install.packages(SpatialPack)'"),
"Install it with 'install.packages(\'SpatialPack\')'"),
.call = FALSE)
}

Expand Down
8 changes: 4 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ precision agriculture spatial data depuration.

## Installation

<!-- You can install the released version of paar from [CRAN](https://CRAN.R-project.org) with: -->
You can install the released version of paar from [CRAN](https://CRAN.R-project.org) with (not-yet):

<!-- ``` r -->
<!-- install.packages("paar") -->
<!-- ``` -->
``` r
# install.packages("paar")
```
You can install the development version from [GitHub](https://github.com/PPaccioretti/paar) with:

``` r
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ agriculture spatial data depuration.

## Installation

<!-- You can install the released version of paar from [CRAN](https://CRAN.R-project.org) with: -->
<!-- ``` r -->
<!-- install.packages("paar") -->
<!-- ``` -->
You can install the released version of paar from
[CRAN](https://CRAN.R-project.org) with (not-yet):

``` r
# install.packages("paar")
```

You can install the development version from
[GitHub](https://github.com/PPaccioretti/paar) with:
Expand Down
16 changes: 16 additions & 0 deletions inst/examples/compare_zone.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
library(sf)
data(wheat, package = "paar")

##Convert to an sf object
wheat <- sf::st_as_sf(wheat,
coords = c("x", "y"),
crs = 32720)
clusters <- paar::kmspc(
wheat,
variables = c('CE30', 'CE90', 'Elev', 'Pe', 'Tg'),
number_cluster = 3:4
)
data_clusters <- cbind(wheat, clusters$cluster)
compare_zone(data_clusters,
"Elev",
"Cluster_3")
27 changes: 27 additions & 0 deletions inst/examples/fuzzy_k_means.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
library(sf)
data(wheat, package = 'paar')

# Transform the data.frame into a sf object
wheat_sf <- st_as_sf(wheat,
coords = c('x', 'y'),
crs = 32720)

# Run the fuzzy_k_means function
fuzzy_k_means_results <- fuzzy_k_means(wheat_sf,
variables = 'Tg',
number_cluster = 2:4)

# Print the summaryResults
fuzzy_k_means_results$summaryResults

# Print the indices
fuzzy_k_means_results$indices

# Print the cluster
head(fuzzy_k_means_results$cluster, 5)

# Combine the results in a single object
wheat_clustered <- cbind(wheat_sf, fuzzy_k_means_results$cluster)

# Plot the results
plot(wheat_clustered[, "Cluster_2"])
20 changes: 20 additions & 0 deletions inst/examples/spatial_t_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if (requireNamespace("SpatialPack", quietly = TRUE)) {
library(sf)
data(wheat, package = 'paar')

# Transform the data.frame into a sf object
wheat_sf <- st_as_sf(wheat,
coords = c('x', 'y'),
crs = 32720)

# Run spatial t test
t_test_results <-
spatial_t_test(
wheat_sf,
variables = c('CE30', 'CE90'))

# Print the t_test_results
t_test_results


}
9 changes: 7 additions & 2 deletions man/compare_zone.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/depurate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/fuzzy_k_means.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 02b88e1

Please sign in to comment.