Skip to content

Commit

Permalink
update priors to support named vectors, addresses #24
Browse files Browse the repository at this point in the history
  • Loading branch information
jhelvy committed Nov 2, 2024
1 parent 4f2397f commit 62f5f5b
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 186 deletions.
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# cbcTools 0.6.0

- Major revisions made to `cbc_design()` function.
- New `"efficient"` method added for obtaining D-efficient designs.
- Old methods removed: `"full"`, `"orthogonal"`, `"dopt"`, `"CEA"`, and `"Modfed"`. Now there are only `"random"` and `"efficient"` designs
- Bayesian D-efficient designs are now created by setting `method = "efficient"` and a set of priors with a diagonal or full covariance matrix.
- New `"efficient"` method added for obtaining D-efficient designs.
- Old methods removed: `"full"`, `"orthogonal"`, `"dopt"`, `"CEA"`, and `"Modfed"`. Now there are only `"random"` and `"efficient"` designs
- Bayesian D-efficient designs are now created by setting `method = "efficient"` and a set of priors with a diagonal or full covariance matrix.
- New `cbc_d_error()` function added to obtain the D-error of a given design.
- New `cbc_priors()` function for defining a variety of prior model coefficients.
- Coefficients for levels of an attribute in cbc_priors can be named vectors, addressing #24.
- New `cbc_levels()` function for viewing a summary of the levels in a design.

# cbcTools 0.5.2
Expand Down
61 changes: 61 additions & 0 deletions R/methods.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# Print method for cbc_priors objects
#' @export
print.cbc_priors <- function(x, ...) {
cat("CBC Prior Specification:\n\n")

# Print means with full level information
cat("Means:\n")
for (attr in names(x$means)) {
cat(" ", attr, ":\n", sep = "")

if (x$attr_info[[attr]]$type == "continuous") {
# Get all unique values in sequential order
levels <- sort(unique(x$attr_info[[attr]]$levels))
cat(" Continuous attribute with levels:\n",
" ", paste(levels, collapse = ", "), "\n",
" Coefficient: ", round(x$means[[attr]], 3), "\n",
sep = "")
} else {
# Find reference level (the one not in names of means)
all_levels <- x$attr_info[[attr]]$levels
coef_levels <- names(x$means[[attr]])
ref_level <- setdiff(all_levels, coef_levels)

cat(" Categorical attribute (reference level: ", ref_level, ")\n", sep = "")
for (level in names(x$means[[attr]])) {
cat(" ", level, ": ", round(x$means[[attr]][[level]], 3), "\n", sep = "")
}
}
cat("\n")
}

# Print SDs if present
if (!is.null(x$sd)) {
cat("Standard Deviations:\n")
for (attr in names(x$sd)) {
cat(" ", attr, ": ", sep = "")
if (length(x$sd[[attr]]) == 1) {
cat(round(x$sd[[attr]], 3), "\n")
} else {
cat(paste(round(x$sd[[attr]], 3), collapse = ", "), "\n")
}
}
cat("\n")
}

# Print correlation if present
if (!is.null(x$correlation)) {
cat("Correlation Matrix:\n")
print(round(x$correlation, 3))
cat("\n")
}

# Print distributions if present
if (!is.null(x$distribution)) {
cat("Distributions:\n")
print(x$distribution)
}

invisible(x)
}

#' Methods for cbc_models objects
#'
#' Miscellaneous methods for `cbc_models` class objects.
Expand Down
Loading

0 comments on commit 62f5f5b

Please sign in to comment.