Skip to content

Commit

Permalink
Use rlang::is_installed() instead of requireNamespace for conditional…
Browse files Browse the repository at this point in the history
… examples and vignette code chunks
  • Loading branch information
nehill197 committed Sep 17, 2024
1 parent bd40a97 commit 227c7a6
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion R/dev.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ dev_pois_zi <- function(x, lambda, prob = 0, res = FALSE) {
#' @family dev_dist
#' @export
#'
#' @examplesIf requireNamespace("sn")
#' @examplesIf rlang::is_installed("sn")
#' dev_skewnorm(c(-2:2))
#' dev_skewnorm(-2:2, 0, 1, 5)
#' dev_skewnorm(-2:2, 0, 1, 5, res = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/log-lik.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ log_lik_pois_zi <- function(x, lambda = 1, prob = 0) {
#' @family log_lik_dist
#' @export
#'
#' @examplesIf requireNamespace("sn")
#' @examplesIf rlang::is_installed("sn")
#' log_lik_skewnorm(c(-2:2))
#' log_lik_skewnorm(c(-2:2), shape = -2)
#' log_lik_skewnorm(c(-2:2), shape = 2)
Expand Down
2 changes: 1 addition & 1 deletion R/numericise.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ numericise.POSIXct <- function(x, ...) {
#' @examples
#'
#' # hms
#' @examplesIf requireNamespace("hms")
#' @examplesIf rlang::is_installed("hms")
#' numericise(hms::as_hms("00:01:03"))
numericise.hms <- function(x, ...) {
rlang::check_installed("hms")
Expand Down
2 changes: 1 addition & 1 deletion R/ran.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ran_pois_zi <- function(n = 1, lambda = 1, prob = 0) {
#' @family ran_dist
#' @export
#'
#' @examplesIf requireNamespace("sn")
#' @examplesIf rlang::is_installed("sn")
#' ran_skewnorm(10, shape = -1)
#' ran_skewnorm(10, shape = 0)
#' ran_skewnorm(10, shape = 1)
Expand Down
2 changes: 1 addition & 1 deletion R/res.R
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ res_student_standardized <- function(x, mean, sd, theta) {
#' @family res_dist
#' @export
#'
#' @examplesIf requireNamespace("sn")
#' @examplesIf rlang::is_installed("sn")
#' res_skewnorm(c(-2:2))
res_skewnorm <- function(x, mean = 0, sd = 1, shape = 0, type = "dev", simulate = FALSE) {
rlang::check_installed("sn")
Expand Down
2 changes: 1 addition & 1 deletion R/sens.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ sens_student <- function(mean, sd, theta, sd_mult = 2) {
#' @family sens_dist
#' @export
#'
#' @examplesIf requireNamespace("sn")
#' @examplesIf rlang::is_installed("sn")
#' sens_skewnorm(10, 3, -1, 2)
#' sens_skewnorm(10, 3, 3, 0.8)
sens_skewnorm <- function(mean, sd, shape, sd_mult = 2) {
Expand Down
2 changes: 1 addition & 1 deletion R/skewnorm.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @rdname skewnorm
#' @export
#'
#' @examplesIf requireNamespace("sn")
#' @examplesIf rlang::is_installed("sn")
#' dskewnorm(x = -2:2, mean = 0, sd = 1, shape = 0.1)
#' dskewnorm(x = -2:2, mean = 0, sd = 1, shape = -1)
#' qskewnorm(p = c(0.1, 0.4), mean = 0, sd = 1, shape = 0.1)
Expand Down
2 changes: 1 addition & 1 deletion man/dev_skewnorm.Rd

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

2 changes: 1 addition & 1 deletion man/log_lik_skewnorm.Rd

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

2 changes: 1 addition & 1 deletion man/numericise.Rd

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

2 changes: 1 addition & 1 deletion man/ran_skewnorm.Rd

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

2 changes: 1 addition & 1 deletion man/res_skewnorm.Rd

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

2 changes: 1 addition & 1 deletion man/sens_skewnorm.Rd

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

2 changes: 1 addition & 1 deletion man/skewnorm.Rd

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

8 changes: 4 additions & 4 deletions vignettes/beta-binomial-deviance-residuals.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ knitr::opts_chunk$set(
library(extras)
```

```{r eval = requireNamespace("tidyr") & requireNamespace("ggplot2") & requireNamespace("viridis") & requireNamespace("scales"), include = FALSE}
```{r eval = rlang::is_installed("tidyr") & rlang::is_installed("ggplot2") & rlang::is_installed("viridis") & rlang::is_installed("scales"), include = FALSE}
library(tidyr)
library(ggplot2)
library(viridis)
Expand Down Expand Up @@ -77,7 +77,7 @@ The problem with the first approach is that likelihood profile of the beta-binom
Consequently, increasing $\theta$ increases the deviance even if the expected value of the fitted model is the same as the saturated binomial model.


```{r eval = requireNamespace("tidyr") & requireNamespace("ggplot2") & requireNamespace("viridis") & requireNamespace("scales"), echo = FALSE, fig.width = 7, fig.height = 4, fig.cap = "Fig. 1: Beta-binomial likelihood profile for $x = 1$ and $n = 5$, for different values of $\\theta$. $\\theta = 0$ corresponds to the binomial case."}
```{r eval = rlang::is_installed("tidyr") & rlang::is_installed("ggplot2") & rlang::is_installed("viridis") & rlang::is_installed("scales"), echo = FALSE, fig.width = 7, fig.height = 4, fig.cap = "Fig. 1: Beta-binomial likelihood profile for $x = 1$ and $n = 5$, for different values of $\\theta$. $\\theta = 0$ corresponds to the binomial case."}
n_samp <- 1000
x <- 1
size <- 5
Expand Down Expand Up @@ -144,7 +144,7 @@ We will refer to the optimized $p$ value for the $i^{th}$ data point as $p_i^*$,
We use $p^*$ to calculate the saturated log-likelihood that produces deviances that are (a) strictly positive, and (b) relative to the value of $\theta$.
The value of $p_i^*$ for the example case with $x = 1$, $n = 5$, and $\theta = 0.5$ is shown in Figure 2.

```{r eval = requireNamespace("tidyr") & requireNamespace("ggplot2") & requireNamespace("viridis") & requireNamespace("scales"), echo = FALSE, fig.width = 7, fig.height = 4, fig.cap = "Fig. 2: Beta-binomial likelihood profile for $x = 1$, $n = 5$, and $\\theta = 0.5$. The dashed vertical line shows the likelihood at the expected value of the beta-binomial distribution ($n \\cdot p$) where $p = \\frac{x}{n} = \\frac{1}{5} = 0.2$. As you can see, this is not the $p$ for which the likelihood is maximized. The solid vertical line shows the likelihood at its maximum point. In this case, $p^* = 0.26$."}
```{r eval = rlang::is_installed("tidyr") & rlang::is_installed("ggplot2") & rlang::is_installed("viridis") & rlang::is_installed("scales"), echo = FALSE, fig.width = 7, fig.height = 4, fig.cap = "Fig. 2: Beta-binomial likelihood profile for $x = 1$, $n = 5$, and $\\theta = 0.5$. The dashed vertical line shows the likelihood at the expected value of the beta-binomial distribution ($n \\cdot p$) where $p = \\frac{x}{n} = \\frac{1}{5} = 0.2$. As you can see, this is not the $p$ for which the likelihood is maximized. The solid vertical line shows the likelihood at its maximum point. In this case, $p^* = 0.26$."}
n_samp <- 1000
x <- 1
size <- 5
Expand Down Expand Up @@ -187,7 +187,7 @@ $$r_i = \text{sign}(x_i - (n p_i^*)) \sqrt{d_i}.$$
The following plot shows histograms of deviance residuals for 10,000 randomly generated data points with $n = 50$ and various values of $p$ and $\theta$.


```{r eval = requireNamespace("tidyr") & requireNamespace("ggplot2") & requireNamespace("viridis") & requireNamespace("scales"), echo = FALSE, fig.height = 8, fig.width = 7, fig.cap = "Fig. 4: Histograms of deviance residuals for 10,000 beta-binomial data points simulated with $n = 50$, $p = \\{0.3, 0.5, 0.9 \\}$, and $\\theta = \\{0.0, 0.1, 0.5, 1.0 \\}$. The percentages within each panel (i.e., each combination of $p$ and $\\theta$) sum to 100%."}
```{r eval = rlang::is_installed("tidyr") & rlang::is_installed("ggplot2") & rlang::is_installed("viridis") & rlang::is_installed("scales"), echo = FALSE, fig.height = 8, fig.width = 7, fig.cap = "Fig. 4: Histograms of deviance residuals for 10,000 beta-binomial data points simulated with $n = 50$, $p = \\{0.3, 0.5, 0.9 \\}$, and $\\theta = \\{0.0, 0.1, 0.5, 1.0 \\}$. The percentages within each panel (i.e., each combination of $p$ and $\\theta$) sum to 100%."}
n_samp <- 10000
size <- 50
prob <- c(0.3, 0.5, 0.9)
Expand Down

0 comments on commit 227c7a6

Please sign in to comment.