Skip to content

Commit

Permalink
Merge pull request #1 from Sciurus365/feature-boot-se
Browse files Browse the repository at this point in the history
Feature calculating se with boot
  • Loading branch information
Sciurus365 authored Jul 17, 2024
2 parents 2e4fb63 + 6b93c98 commit b64627c
Show file tree
Hide file tree
Showing 18 changed files with 522 additions and 339 deletions.
6 changes: 5 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ BugReports: https://github.com/Sciurus365/Isinglandr/issues
Depends:
R (>= 2.10)
Imports:
boot,
boot.pval,
broom,
cli,
dplyr,
gganimate,
ggplot2,
Expand All @@ -46,4 +50,4 @@ Suggests:
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.2
19 changes: 11 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Generated by roxygen2: do not edit by hand

S3method(autolayer,resilience_2d_Isingland)
S3method(autolayer,stability_2d_Isingland)
S3method(calculate_barrier,"2d_Isingland")
S3method(calculate_barrier,"2d_Isingland_matrix")
S3method(calculate_resilience,"2d_Isingland")
S3method(calculate_resilience,"2d_Isingland_matrix")
S3method(calculate_stability,"2d_Isingland")
S3method(calculate_stability,"2d_Isingland_matrix")
S3method(plot,"2d_Isingland")
S3method(plot,"2d_Isingland_matrix")
S3method(plot,"3d_Isingland")
Expand All @@ -14,22 +14,25 @@ S3method(plot,sim_2d_Isingland_matrix)
S3method(print,barrier_2d_Isingland)
S3method(print,barrier_2d_Isingland_matrix)
S3method(print,landscape)
S3method(print,resilience_2d_Isingland)
S3method(print,resilience_2d_Isingland_matrix)
S3method(print,sim_Isingland)
S3method(print,stability_2d_Isingland)
S3method(print,stability_2d_Isingland_matrix)
S3method(print,stability_se)
S3method(simulate_Isingland,"2d_Isingland")
S3method(simulate_Isingland,"2d_Isingland_matrix")
S3method(summary,barrier_2d_Isingland)
S3method(summary,barrier_2d_Isingland_matrix)
S3method(summary,resilience_2d_Isingland)
S3method(summary,resilience_2d_Isingland_matrix)
S3method(summary,stability_2d_Isingland)
S3method(summary,stability_2d_Isingland_matrix)
export("%>%")
export(all_thresholds)
export(autolayer)
export(beta_list)
export(calculate_barrier)
export(calculate_resilience)
export(calculate_stability)
export(calculate_stability_se)
export(chain_simulate_Isingland)
export(compare_stability)
export(make_2d_Isingland)
export(make_2d_Isingland_matrix)
export(make_3d_Isingland)
Expand Down
2 changes: 1 addition & 1 deletion R/barrier.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ calculate_barrier.2d_Isingland <- function(l, ...) {
}
}

rlang::abort("The shape of the landscape is not supported for calculating barrier.")
cli::cli_abort("The shape of the landscape is not supported for calculating barrier.")
}
#' @export
#' @rdname calculate_barrier.Isingland
Expand Down
4 changes: 2 additions & 2 deletions R/chain-simulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ chain_simulate_Isingland <- function(Ising_chain, transform = FALSE,
make_Ising_chain <- function(...) {
Igrids <- list(...)
if (any(lapply(Igrids, methods::is, class2 = "Ising_grid") == FALSE)) {
rlang::abort("All arguments should be `Ising_grid`s.")
cli::cli_abort("All arguments should be `Ising_grid`s.")
}
if (any(lapply(Igrids, \(x) length(attr(x, "par_name"))) > 1)) {
rlang::abort("Each `Ising_grid` should only contain one varying condition.")
cli::cli_abort("Each `Ising_grid` should only contain one varying condition.")
}

Igrids <- Igrids %>% lapply(
Expand Down
20 changes: 12 additions & 8 deletions R/landscape.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#' plot(result1)
#' @export
make_2d_Isingland <- function(thresholds, weiadj, beta = 1, transform = FALSE) {
if (!transform) {
cli::cli_inform("The Ising network uses -1 and 1 for two states. If it uses 0 and 1, {.strong (which is often the case for psychological datasets)}, set `transform = TRUE`.", .frequency = "regularly", .frequency_id = "Isingland_transform")
}

Nvar <- length(thresholds)

# transformation
Expand Down Expand Up @@ -112,9 +116,9 @@ make_2d_Isingland <- function(thresholds, weiadj, beta = 1, transform = FALSE) {
#' w <- matrix(0.1, Nvar, Nvar)
#' diag(w) <- 0
#' result4 <- make_Ising_grid(
#' all_thresholds(seq(-0.1, 0.1, 0.1), .f = `+`),
#' whole_weiadj(seq(0.5, 1.5, 0.5)),
#' m, w
#' all_thresholds(seq(-0.1, 0.1, 0.1), .f = `+`),
#' whole_weiadj(seq(0.5, 1.5, 0.5)),
#' m, w
#' ) %>% make_2d_Isingland_matrix()
#' plot(result4)
#' @export
Expand Down Expand Up @@ -149,7 +153,7 @@ make_2d_Isingland_matrix <- function(Ising_grid, transform = FALSE) {

#' @export
print.landscape <- function(x, ...) {
cat("A landscape object of the class", class(x)[1], "was estimated. Use `plot()` to draw the landscape plot.")
cat("A landscape object of the class", class(x)[1], "was estimated. Use `plot()` to draw the landscape plot.")
}

#' @export
Expand All @@ -159,7 +163,7 @@ plot.2d_Isingland <- function(x, ...) {
ggplot2::geom_line() +
ggplot2::theme_bw() +
ggplot2::xlab("Number of active nodes") +
ggplot2::scale_x_continuous(breaks = seq(from = 0, to = x$Nvar, by = 3), minor_breaks = 1:x$Nvar)
ggplot2::scale_x_continuous(breaks = seq(from = 0, to = x$Nvar, by = 3), minor_breaks = 1:x$Nvar)
}

#' @export
Expand All @@ -169,7 +173,7 @@ plot.2d_Isingland_matrix <- function(x, ...) {
ggplot2::geom_line() +
ggplot2::theme_bw() +
ggplot2::xlab("Number of active nodes") +
ggplot2::scale_x_continuous(breaks = seq(from = 0, to = x$Nvar, by = 3), minor_breaks = 1:x$Nvar)
ggplot2::scale_x_continuous(breaks = seq(from = 0, to = x$Nvar, by = 3), minor_breaks = 1:x$Nvar)

if (length(attr(x, "par_name")) == 1) {
p <- p + ggplot2::facet_wrap(attr(x, "par_name"))
Expand Down Expand Up @@ -209,11 +213,11 @@ make_3d_Isingland <- function(thresholds, weiadj, x, y, beta = 1, transform = FA
d <- l_2d$dist_raw

if (is.character(x)) {
if (!all(x %in% row.names(thresholds))) stop("The names in x are not found in the row names of the thresholds matrix.")
if (!all(x %in% row.names(thresholds))) stop("The names in x are not found in the row names of the thresholds matrix.")
x <- which(row.names(thresholds) %in% x)
}
if (is.character(y)) {
if (!all(y %in% row.names(thresholds))) stop("The names in y are not found in the row names of the thresholds matrix.")
if (!all(y %in% row.names(thresholds))) stop("The names in y are not found in the row names of the thresholds matrix.")
y <- which(row.names(thresholds) %in% y)
}

Expand Down
233 changes: 0 additions & 233 deletions R/resilience.R

This file was deleted.

Loading

0 comments on commit b64627c

Please sign in to comment.