Skip to content

Commit db2ae4e

Browse files
Copilotosorensen
andcommitted
Add CRAN-compliant example to set_hyperparameters documentation
Co-authored-by: osorensen <21175639+osorensen@users.noreply.github.com>
1 parent ccb3f14 commit db2ae4e

File tree

2 files changed

+81
-11
lines changed

2 files changed

+81
-11
lines changed

R/set_hyperparameters.R

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,50 @@
11
#' Set hyperparameters
22
#'
3+
#' Set the hyperparameters for the Bayesian Mallows model. This function
4+
#' creates a list of hyperparameter values that can be passed to
5+
#' [compute_sequentially()].
6+
#'
37
#' @param n_items Integer defining the number of items.
4-
#' @param alpha_shape Shape of gamma prior for alpha.
5-
#' @param alpha_rate Rate of gamma prior for alpha.
6-
#' @param cluster_concentration Concentration parameter of Dirichlet distribution for cluster probabilities.
7-
#' @param n_clusters Integer defining the number of clusters.
8+
#' @param alpha_shape Shape parameter of the gamma prior distribution for the
9+
#' scale parameter alpha. Defaults to 1.
10+
#' @param alpha_rate Rate parameter of the gamma prior distribution for the
11+
#' scale parameter alpha. Defaults to 0.5.
12+
#' @param cluster_concentration Concentration parameter of the Dirichlet
13+
#' distribution for cluster probabilities. Only used when `n_clusters > 1`.
14+
#' Defaults to 10.
15+
#' @param n_clusters Integer defining the number of clusters. Defaults to 1.
816
#'
9-
#' @return A list
17+
#' @return A list with components `n_items`, `alpha_shape`, `alpha_rate`,
18+
#' `cluster_concentration`, and `n_clusters`.
1019
#' @export
1120
#'
21+
#' @examples
22+
#' # Example: Set hyperparameters and use them with partial rankings
23+
#' # Set hyperparameters with default values
24+
#' hyperparams1 <- set_hyperparameters(n_items = 5)
25+
#'
26+
#' # Set hyperparameters with custom prior for alpha
27+
#' # A larger alpha_shape and smaller alpha_rate increases the prior mean
28+
#' hyperparams2 <- set_hyperparameters(
29+
#' n_items = 5,
30+
#' alpha_shape = 2,
31+
#' alpha_rate = 1
32+
#' )
33+
#'
34+
#' # Use the hyperparameters with compute_sequentially
35+
#' # This example uses partial rankings with a small number of particles
36+
#' # for fast execution suitable for CRAN checks
37+
#' set.seed(123)
38+
#' mod <- compute_sequentially(
39+
#' partial_rankings,
40+
#' hyperparameters = hyperparams2,
41+
#' smc_options = set_smc_options(
42+
#' n_particles = 20,
43+
#' n_particle_filters = 4,
44+
#' max_rejuvenation_steps = 3
45+
#' )
46+
#' )
47+
#'
1248
set_hyperparameters <- function(
1349
n_items, alpha_shape = 1, alpha_rate = .5, cluster_concentration = 10,
1450
n_clusters = 1) {

man/set_hyperparameters.Rd

Lines changed: 40 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)