From 995484a9774331f23ddac53b62c70997768a0c28 Mon Sep 17 00:00:00 2001 From: fradenti Date: Fri, 6 Oct 2023 13:50:05 +0200 Subject: [PATCH] added donttest and @return --- R/estimate_clusters.R | 3 ++- R/mcmc_CAM.R | 3 ++- R/mcmc_fSAN.R | 3 ++- R/mcmc_fSAN_sparsemix.R | 2 +- R/mcmc_fiSAN.R | 2 ++ R/mcmc_fiSAN_sparsemix.R | 2 +- R/plot.R | 7 ++++++- R/print.R | 2 ++ R/print_clusters.R | 2 ++ R/traceplot.R | 4 ++++ man/estimate_clusters.Rd | 3 ++- man/plot.SANmcmc.Rd | 5 +++++ man/print.SANclusters.Rd | 3 +++ man/print.SANmcmc.Rd | 3 +++ man/sample_CAM.Rd | 3 ++- man/sample_fSAN.Rd | 3 ++- man/sample_fSAN_sparsemix.Rd | 2 +- man/sample_fiSAN.Rd | 2 ++ man/sample_fiSAN_sparsemix.Rd | 2 +- man/traceplot.Rd | 5 +++++ 20 files changed, 50 insertions(+), 11 deletions(-) diff --git a/R/estimate_clusters.R b/R/estimate_clusters.R index 5c24ac0..fee6b27 100644 --- a/R/estimate_clusters.R +++ b/R/estimate_clusters.R @@ -16,13 +16,14 @@ #' @seealso \code{\link[salso:salso]{salso::salso()}}, \code{\link{print.SANmcmc}}, \code{\link{plot.SANmcmc}}, \code{\link{print.SANclusters}} #' #' @examples +#' \donttest{ #' set.seed(123) #' y <- c(rnorm(170),rnorm(70,5)) #' g <- c(rep(1,100), rep(2, 140)) #' out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) #' estcl <- estimate_clusters(out) #' estcl -#' +#' } #' #' @export #' @importFrom salso salso diff --git a/R/mcmc_CAM.R b/R/mcmc_CAM.R index 7354391..b5c6495 100644 --- a/R/mcmc_CAM.R +++ b/R/mcmc_CAM.R @@ -122,6 +122,7 @@ #' #' #' @examples +#' \donttest{ #' set.seed(123) #' y <- c(rnorm(170),rnorm(70,5)) #' g <- c(rep(1,100), rep(2, 140)) @@ -130,7 +131,7 @@ #' out <- sample_CAM(nrep = 3000, y = y, group = g, #' maxL = 50, maxK = 50) #' out -#' +#' } #' #' @references Denti, F., Camerlenghi, F., Guindani, M., and Mira, A. (2023). A Common Atoms Model for the Bayesian Nonparametric Analysis of Nested Data. #' \emph{Journal of the American Statistical Association}, 118(541), 405-416. DOI: 10.1080/01621459.2021.1933499 diff --git a/R/mcmc_fSAN.R b/R/mcmc_fSAN.R index 706ef81..e4ec9ec 100644 --- a/R/mcmc_fSAN.R +++ b/R/mcmc_fSAN.R @@ -125,6 +125,7 @@ #' #' #' @examples +#' \donttest{ #' set.seed(123) #' y <- c(rnorm(170),rnorm(70,5)) #' g <- c(rep(1,100), rep(2, 140)) @@ -133,7 +134,7 @@ #' out <- sample_fSAN(nrep = 3000, y = y, group = g, #' alpha = 1, beta = 1) #' out -#' +#' } #' #' @references D’Angelo, L., Canale, A., Yu, Z., and Guindani, M. (2023). #' Bayesian nonparametric analysis for the detection of spikes in noisy calcium imaging data. \emph{Biometrics}, 79(2), 1370–1382. DOI: 10.1111/biom.13626 diff --git a/R/mcmc_fSAN_sparsemix.R b/R/mcmc_fSAN_sparsemix.R index 8b84af1..f2ed59c 100644 --- a/R/mcmc_fSAN_sparsemix.R +++ b/R/mcmc_fSAN_sparsemix.R @@ -120,7 +120,7 @@ #' } #' #' @examples -#' \dontrun{ +#' \donttest{ #' set.seed(123) #' y <- c(rnorm(170),rnorm(70,5)) #' g <- c(rep(1,100), rep(2, 140)) diff --git a/R/mcmc_fiSAN.R b/R/mcmc_fiSAN.R index e8c6a2a..2fbf8be 100644 --- a/R/mcmc_fiSAN.R +++ b/R/mcmc_fiSAN.R @@ -125,6 +125,7 @@ #' } #' #' @examples +#' \donttest{ #' set.seed(123) #' y <- c(rnorm(170),rnorm(70,5)) #' g <- c(rep(1,100), rep(2, 140)) @@ -132,6 +133,7 @@ #' lines(density(y[g==2]), col = 2) #' out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) #' out +#' } #' #' @references #' Frühwirth-Schnatter, S., Malsiner-Walli, G. and Grün, B. (2021). diff --git a/R/mcmc_fiSAN_sparsemix.R b/R/mcmc_fiSAN_sparsemix.R index d0c7902..37abbb5 100644 --- a/R/mcmc_fiSAN_sparsemix.R +++ b/R/mcmc_fiSAN_sparsemix.R @@ -124,7 +124,7 @@ #' } #' #' @examples -#' \dontrun{ +#' \donttest{ #' set.seed(123) #' y <- c(rnorm(170),rnorm(70,5)) #' g <- c(rep(1,100), rep(2, 140)) diff --git a/R/plot.R b/R/plot.R index 82cd71e..c19db53 100644 --- a/R/plot.R +++ b/R/plot.R @@ -13,13 +13,18 @@ #' @param ncores if the partition is computed, the number of CPU cores to use to estimate the clusters, i.e., the number of simultaneous runs at any given time. A value of zero indicates to use all cores on the system. #' @param ... additional graphical parameters to be passed when \code{type = "scatter"} is used. #' +#' @return The function plots a summary of the fitted model. +#' #' @seealso \code{\link{print.SANmcmc}}, \code{\link{estimate_clusters}} #' -#' @examples set.seed(123) +#' @examples +#' \donttest{ +#' set.seed(123) #' y <- c(rnorm(170),rnorm(70,5)) #' g <- c(rep(1,100), rep(2, 140)) #' out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) #' plot(out, type = "ecdf", palette_brewed = TRUE) +#' } #' #' @importFrom graphics abline lines points boxplot par #' @importFrom grDevices colorRampPalette diff --git a/R/print.R b/R/print.R index 33295b4..2166ea3 100644 --- a/R/print.R +++ b/R/print.R @@ -6,6 +6,8 @@ #' \code{\link{sample_fSAN}}, \code{\link{sample_fSAN_sparsemix}}, or \code{\link{sample_CAM}}). #' @param ... ignored. #' +#' @return The function prints a summary of the fitted model. +#' #' @seealso \code{\link{estimate_clusters}}, \code{\link{plot.SANmcmc}} #' #' @export diff --git a/R/print_clusters.R b/R/print_clusters.R index b41afea..57be7e7 100644 --- a/R/print_clusters.R +++ b/R/print_clusters.R @@ -4,6 +4,8 @@ #' @param x object of class \code{SANclusters} (the result of a call to \code{\link{estimate_clusters}}) #' @param ... ignored. #' +#' @return The function prints a summary of the estimated clusters. +#' #' @export print.SANclusters <- function(x, ...) { diff --git a/R/traceplot.R b/R/traceplot.R index 1eb615a..b50fc3e 100644 --- a/R/traceplot.R +++ b/R/traceplot.R @@ -21,12 +21,16 @@ #' #' @note The function is not available for the observational weights \eqn{\omega}. #' +#' @return The function displays the traceplots of the MCMC algorithm. +#' #' @examples +#' \donttest{ #' set.seed(123) #' y <- c(rnorm(170),rnorm(70,5)) #' g <- c(rep(1,100), rep(2, 140)) #' out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) #' traceplot(out, params = c("mu", "sigma2"), trunc_plot = 2) +#' } #' #' @importFrom graphics par #' @importFrom grDevices devAskNewPage diff --git a/man/estimate_clusters.Rd b/man/estimate_clusters.Rd index 6efc6f3..55c7f60 100644 --- a/man/estimate_clusters.Rd +++ b/man/estimate_clusters.Rd @@ -29,13 +29,14 @@ Object of class \code{SANclusters}. The object contains: Given the MCMC output, estimate the observational and distributional partitions using \code{\link[salso:salso]{salso::salso()}}. } \examples{ +\donttest{ set.seed(123) y <- c(rnorm(170),rnorm(70,5)) g <- c(rep(1,100), rep(2, 140)) out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) estcl <- estimate_clusters(out) estcl - +} } \seealso{ diff --git a/man/plot.SANmcmc.Rd b/man/plot.SANmcmc.Rd index 40ddcf0..44f29b3 100644 --- a/man/plot.SANmcmc.Rd +++ b/man/plot.SANmcmc.Rd @@ -31,16 +31,21 @@ If \code{estimated_clusters = NULL}, the displayed partition is computed using \ \item{...}{additional graphical parameters to be passed when \code{type = "scatter"} is used.} } +\value{ +The function plots a summary of the fitted model. +} \description{ Plot method for objects of class \code{SANmcmc}. The function displays two graphs, meant to analyze the estimated distributional and observational clusters. } \examples{ +\donttest{ set.seed(123) y <- c(rnorm(170),rnorm(70,5)) g <- c(rep(1,100), rep(2, 140)) out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) plot(out, type = "ecdf", palette_brewed = TRUE) +} } \seealso{ diff --git a/man/print.SANclusters.Rd b/man/print.SANclusters.Rd index c2f0925..27a6204 100644 --- a/man/print.SANclusters.Rd +++ b/man/print.SANclusters.Rd @@ -11,6 +11,9 @@ \item{...}{ignored.} } +\value{ +The function prints a summary of the estimated clusters. +} \description{ Print the cluster-specific sample means and variances of the estimated observational and distributional partition. } diff --git a/man/print.SANmcmc.Rd b/man/print.SANmcmc.Rd index 5e29fa1..58b85c0 100644 --- a/man/print.SANmcmc.Rd +++ b/man/print.SANmcmc.Rd @@ -12,6 +12,9 @@ \item{...}{ignored.} } +\value{ +The function prints a summary of the fitted model. +} \description{ Print method for objects of class \code{SANmcmc}. } diff --git a/man/sample_CAM.Rd b/man/sample_CAM.Rd index 0918daa..e5ff133 100644 --- a/man/sample_CAM.Rd +++ b/man/sample_CAM.Rd @@ -138,6 +138,7 @@ The clustering of observations (observational clustering) is provided by the all The distribution of the probabilities is \eqn{ \{\omega_{l,k}\}_{l=1}^{\infty} \sim GEM(\beta)} for all \eqn{k = 1,2,\dots} } \examples{ +\donttest{ set.seed(123) y <- c(rnorm(170),rnorm(70,5)) g <- c(rep(1,100), rep(2, 140)) @@ -146,7 +147,7 @@ lines(density(y[g==2]), col = 2) out <- sample_CAM(nrep = 3000, y = y, group = g, maxL = 50, maxK = 50) out - +} } \references{ diff --git a/man/sample_fSAN.Rd b/man/sample_fSAN.Rd index f1bb39f..6149fa7 100644 --- a/man/sample_fSAN.Rd +++ b/man/sample_fSAN.Rd @@ -139,6 +139,7 @@ The distribution of the probabilities is \eqn{(\omega_{1,k},\dots,\omega_{L,k})\ Moreover, the dimension \eqn{L} is random (see Frühwirth-Schnatter et al., 2021). } \examples{ +\donttest{ set.seed(123) y <- c(rnorm(170),rnorm(70,5)) g <- c(rep(1,100), rep(2, 140)) @@ -147,7 +148,7 @@ lines(density(y[g==2]), col = 2) out <- sample_fSAN(nrep = 3000, y = y, group = g, alpha = 1, beta = 1) out - +} } \references{ diff --git a/man/sample_fSAN_sparsemix.Rd b/man/sample_fSAN_sparsemix.Rd index 26b46f3..456d112 100644 --- a/man/sample_fSAN_sparsemix.Rd +++ b/man/sample_fSAN_sparsemix.Rd @@ -134,7 +134,7 @@ The clustering of observations (observational clustering) is provided by the all The distribution of the probabilities is \eqn{(\omega_{1,k},\dots,\omega_{L,k})\sim Dirichlet_L(\beta,\dots,\beta)} for all \eqn{k = 1,\dots,K}. } \examples{ -\dontrun{ +\donttest{ set.seed(123) y <- c(rnorm(170),rnorm(70,5)) g <- c(rep(1,100), rep(2, 140)) diff --git a/man/sample_fiSAN.Rd b/man/sample_fiSAN.Rd index af4aaeb..e3aa185 100644 --- a/man/sample_fiSAN.Rd +++ b/man/sample_fiSAN.Rd @@ -141,6 +141,7 @@ The distribution of the probabilities is \eqn{(\omega_{1,k},\dots,\omega_{L,k})\ Moreover, the dimension \eqn{L} is random (see Frühwirth-Schnatter et al., 2021). } \examples{ +\donttest{ set.seed(123) y <- c(rnorm(170),rnorm(70,5)) g <- c(rep(1,100), rep(2, 140)) @@ -148,6 +149,7 @@ plot(density(y[g==1]), xlim = c(-5,10)) lines(density(y[g==2]), col = 2) out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) out +} } \references{ diff --git a/man/sample_fiSAN_sparsemix.Rd b/man/sample_fiSAN_sparsemix.Rd index 57c00b6..3616535 100644 --- a/man/sample_fiSAN_sparsemix.Rd +++ b/man/sample_fiSAN_sparsemix.Rd @@ -139,7 +139,7 @@ The clustering of observations (observational clustering) is provided by the all The distribution of the probabilities is \eqn{(\omega_{1,k},\dots,\omega_{L,k})\sim Dirichlet_L(\beta,\dots,\beta)} for all \eqn{k = 1,2,\dots}. } \examples{ -\dontrun{ +\donttest{ set.seed(123) y <- c(rnorm(170),rnorm(70,5)) g <- c(rep(1,100), rep(2, 140)) diff --git a/man/traceplot.Rd b/man/traceplot.Rd index 911b353..f2989c0 100644 --- a/man/traceplot.Rd +++ b/man/traceplot.Rd @@ -27,6 +27,9 @@ traceplot(object, params, \item{trunc_plot}{integer (default = 10). For multidimensional parameters, the maximum number of components to be plotted.} } +\value{ +The function displays the traceplots of the MCMC algorithm. +} \description{ Check the convergence of the MCMC through visual inspection of the chains. } @@ -34,10 +37,12 @@ Check the convergence of the MCMC through visual inspection of the chains. The function is not available for the observational weights \eqn{\omega}. } \examples{ +\donttest{ set.seed(123) y <- c(rnorm(170),rnorm(70,5)) g <- c(rep(1,100), rep(2, 140)) out <- sample_fiSAN(nrep = 3000, y = y, group = g, beta = 1) traceplot(out, params = c("mu", "sigma2"), trunc_plot = 2) +} }