Skip to content

Commit

Permalink
use examplesIf
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 14, 2023
1 parent 05202d2 commit 9805166
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 174 deletions.
14 changes: 5 additions & 9 deletions R/check_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ NULL
#' There is a `plot()` method, which shows the probabilities of all predicted
#' distributions, however, only if the probability is greater than zero.
#'
#' @examples
#' if (require("lme4") && require("parameters") &&
#' require("see") && require("patchwork") && require("randomForest")) {
#' data(sleepstudy)
#'
#' model <<- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
#' check_distribution(model)
#' plot(check_distribution(model))
#' }
#' @examplesIf require("lme4") && require("parameters") && require("see") && require("patchwork") && require("randomForest")
#' data(sleepstudy, package = "lme4")
#' model <<- lme4::lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
#' check_distribution(model)
#' plot(check_distribution(model))
#' @export
check_distribution <- function(model) {
UseMethod("check_distribution")
Expand Down
11 changes: 5 additions & 6 deletions R/check_itemscale.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@
#' - Trochim WMK (2008) Types of Reliability.
#' ([web](https://conjointly.com/kb/types-of-reliability/))
#'
#' @examples
#' @examplesIf require("parameters") && require("psych")
#' # data generation from '?prcomp', slightly modified
#' C <- chol(S <- toeplitz(0.9^(0:15)))
#' set.seed(17)
#' X <- matrix(rnorm(1600), 100, 16)
#' Z <- X %*% C
#' if (require("parameters") && require("psych")) {
#' pca <- principal_components(as.data.frame(Z), rotation = "varimax", n = 3)
#' pca
#' check_itemscale(pca)
#' }
#'
#' pca <- principal_components(as.data.frame(Z), rotation = "varimax", n = 3)
#' pca
#' check_itemscale(pca)
#' @export
check_itemscale <- function(x) {
if (!inherits(x, "parameters_pca")) {
Expand Down
42 changes: 19 additions & 23 deletions R/check_multimodal.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,29 @@
#' @param x A numeric vector or a data frame.
#' @param ... Arguments passed to or from other methods.
#'
#' @examples
#' @examplesIf require("multimode") && require("mclust")
#' \dontrun{
#' if (require("multimode")) {
#' # Univariate
#' x <- rnorm(1000)
#' check_multimodal(x)
#' }
#' # Univariate
#' x <- rnorm(1000)
#' check_multimodal(x)
#'
#' if (require("multimode") && require("mclust")) {
#' x <- c(rnorm(1000), rnorm(1000, 2))
#' check_multimodal(x)
#' x <- c(rnorm(1000), rnorm(1000, 2))
#' check_multimodal(x)
#'
#' # Multivariate
#' m <- data.frame(
#' x = rnorm(200),
#' y = rbeta(200, 2, 1)
#' )
#' plot(m$x, m$y)
#' check_multimodal(m)
#' # Multivariate
#' m <- data.frame(
#' x = rnorm(200),
#' y = rbeta(200, 2, 1)
#' )
#' plot(m$x, m$y)
#' check_multimodal(m)
#'
#' m <- data.frame(
#' x = c(rnorm(100), rnorm(100, 4)),
#' y = c(rbeta(100, 2, 1), rbeta(100, 1, 4))
#' )
#' plot(m$x, m$y)
#' check_multimodal(m)
#' }
#' m <- data.frame(
#' x = c(rnorm(100), rnorm(100, 4)),
#' y = c(rbeta(100, 2, 1), rbeta(100, 1, 4))
#' )
#' plot(m$x, m$y)
#' check_multimodal(m)
#' }
#' @references
#' - Ameijeiras-Alonso, J., Crujeiras, R. M., and Rodríguez-Casal, A. (2019).
Expand Down
29 changes: 12 additions & 17 deletions R/check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,21 @@
#' - Gelman, A., Hill, J., and Vehtari, A. (2020). Regression and Other Stories.
#' Cambridge University Press.
#'
#' @examples
#' library(performance)
#' @examplesIf require("see")
#' # linear model
#' if (require("see")) {
#' model <- lm(mpg ~ disp, data = mtcars)
#' check_predictions(model)
#' }
#' model <- lm(mpg ~ disp, data = mtcars)
#' check_predictions(model)
#'
#' # discrete/integer outcome
#' if (require("see")) {
#' set.seed(99)
#' d <- iris
#' d$skewed <- rpois(150, 1)
#' model <- glm(
#' skewed ~ Species + Petal.Length + Petal.Width,
#' family = poisson(),
#' data = d
#' )
#' check_predictions(model, type = "discrete_both")
#' }
#' set.seed(99)
#' d <- iris
#' d$skewed <- rpois(150, 1)
#' model <- glm(
#' skewed ~ Species + Petal.Length + Petal.Width,
#' family = poisson(),
#' data = d
#' )
#' check_predictions(model, type = "discrete_both")
#'
#' @export
check_predictions <- function(object, ...) {
Expand Down
15 changes: 7 additions & 8 deletions R/check_sphericity.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
#' @return Invisibly returns the p-values of the test statistics. A p-value <
#' 0.05 indicates a violation of sphericity.
#'
#' @examples
#' if (require("car")) {
#' soils.mod <- lm(
#' cbind(pH, N, Dens, P, Ca, Mg, K, Na, Conduc) ~ Block + Contour * Depth,
#' data = Soils
#' )
#' @examplesIf require("car") && require("carData")
#' data(Soils, package = "carData")
#' soils.mod <- lm(
#' cbind(pH, N, Dens, P, Ca, Mg, K, Na, Conduc) ~ Block + Contour * Depth,
#' data = Soils
#' )
#'
#' check_sphericity(Manova(soils.mod))
#' }
#' check_sphericity(Manova(soils.mod))
#' @export
check_sphericity <- function(x, ...) {
UseMethod("check_sphericity")
Expand Down
36 changes: 16 additions & 20 deletions R/icc.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,25 @@
#' very large, the variance ratio in the output makes no sense, e.g. because
#' it is negative. In such cases, it might help to use `robust = TRUE`.
#'
#' @examples
#' if (require("lme4")) {
#' model <- lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris)
#' icc(model)
#' }
#' @examplesIf require("lme4")
#' model <- lme4::lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris)
#' icc(model)
#'
#' # ICC for specific group-levels
#' if (require("lme4")) {
#' data(sleepstudy)
#' set.seed(12345)
#' sleepstudy$grp <- sample(1:5, size = 180, replace = TRUE)
#' sleepstudy$subgrp <- NA
#' for (i in 1:5) {
#' filter_group <- sleepstudy$grp == i
#' sleepstudy$subgrp[filter_group] <-
#' sample(1:30, size = sum(filter_group), replace = TRUE)
#' }
#' model <- lmer(
#' Reaction ~ Days + (1 | grp / subgrp) + (1 | Subject),
#' data = sleepstudy
#' )
#' icc(model, by_group = TRUE)
#' data(sleepstudy, package = "lme4")
#' set.seed(12345)
#' sleepstudy$grp <- sample(1:5, size = 180, replace = TRUE)
#' sleepstudy$subgrp <- NA
#' for (i in 1:5) {
#' filter_group <- sleepstudy$grp == i
#' sleepstudy$subgrp[filter_group] <-
#' sample(1:30, size = sum(filter_group), replace = TRUE)
#' }
#' model <- lme4::lmer(
#' Reaction ~ Days + (1 | grp / subgrp) + (1 | Subject),
#' data = sleepstudy
#' )
#' icc(model, by_group = TRUE)
#' @export
icc <- function(model,
by_group = FALSE,
Expand Down
10 changes: 4 additions & 6 deletions R/r2_nakagawa.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@
#' generalized linear mixed-effects models revisited and expanded. Journal of
#' The Royal Society Interface, 14(134), 20170213.
#'
#' @examples
#' if (require("lme4")) {
#' model <- lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris)
#' r2_nakagawa(model)
#' r2_nakagawa(model, by_group = TRUE)
#' }
#' @examplesIf require("lme4")
#' model <- lme4::lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris)
#' r2_nakagawa(model)
#' r2_nakagawa(model, by_group = TRUE)
#' @export
r2_nakagawa <- function(model,
by_group = FALSE,
Expand Down
14 changes: 6 additions & 8 deletions man/check_distribution.Rd

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

11 changes: 6 additions & 5 deletions man/check_itemscale.Rd

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

44 changes: 21 additions & 23 deletions man/check_multimodal.Rd

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

30 changes: 13 additions & 17 deletions man/check_predictions.Rd

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

15 changes: 8 additions & 7 deletions man/check_sphericity.Rd

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

Loading

0 comments on commit 9805166

Please sign in to comment.