Skip to content

Commit

Permalink
Merge pull request #439 from IndrajeetPatil/issue_436
Browse files Browse the repository at this point in the history
stylistic changes
  • Loading branch information
IndrajeetPatil authored Mar 10, 2021
2 parents 44ddc13 + e7bdb02 commit 6ca0344
Show file tree
Hide file tree
Showing 75 changed files with 483 additions and 196 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Suggests:
WRS2
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.1.1
RoxygenNote: 7.1.1.9001
VignetteBuilder: knitr
Config/testthat/edition: 3
Remotes: easystats/insight
7 changes: 6 additions & 1 deletion R/1_model_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ model_parameters.default <- function(model,

# Processing
if (bootstrap) {
params <- bootstrap_parameters(model, iterations = iterations, ci = ci, ...)
params <- bootstrap_parameters(
model,
iterations = iterations,
ci = ci,
...
)
} else {
params <- .extract_parameters_generic(
model,
Expand Down
2 changes: 1 addition & 1 deletion R/5_simulate_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' model <- lm(Sepal.Length ~ Species * Petal.Width + Petal.Length, data = iris)
#' head(simulate_model(model))
#' \donttest{
#' if (require("glmmTMB")) {
#' if (require("glmmTMB", quietly = TRUE)) {
#' model <- glmmTMB(
#' count ~ spp + mined + (1 | site),
#' ziformula = ~mined,
Expand Down
32 changes: 26 additions & 6 deletions R/bootstrap_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#'
#' @examples
#' \dontrun{
#' if (require("boot")) {
#' if (require("boot", quietly = TRUE)) {
#' model <- lm(mpg ~ wt + factor(cyl), data = mtcars)
#' b <- bootstrap_model(model)
#' print(head(b))
Expand All @@ -38,7 +38,10 @@
#' }
#' }
#' @export
bootstrap_model <- function(model, iterations = 1000, verbose = FALSE, ...) {
bootstrap_model <- function(model,
iterations = 1000,
verbose = FALSE,
...) {
UseMethod("bootstrap_model")
}

Expand All @@ -50,7 +53,10 @@ bootstrap_model <- function(model, iterations = 1000, verbose = FALSE, ...) {
#' @importFrom stats coef update setNames complete.cases
#' @importFrom insight get_data find_parameters get_parameters
#' @export
bootstrap_model.default <- function(model, iterations = 1000, verbose = FALSE, ...) {
bootstrap_model.default <- function(model,
iterations = 1000,
verbose = FALSE,
...) {
if (!requireNamespace("boot", quietly = TRUE)) {
stop("Package 'boot' needed for this function to work. Please install it.")
}
Expand Down Expand Up @@ -82,7 +88,12 @@ bootstrap_model.default <- function(model, iterations = 1000, verbose = FALSE, .
return(params)
}

results <- boot::boot(data = data, statistic = boot_function, R = iterations, model = model)
results <- boot::boot(
data = data,
statistic = boot_function,
R = iterations,
model = model
)

out <- as.data.frame(results$t)
out <- out[stats::complete.cases(out), ]
Expand Down Expand Up @@ -115,9 +126,18 @@ bootstrap_model.merMod <- function(model, iterations = 1000, verbose = FALSE, ..
}

if (verbose) {
results <- suppressMessages(lme4::bootMer(model, boot_function, nsim = iterations, verbose = FALSE))
results <- suppressMessages(lme4::bootMer(
model,
boot_function,
nsim = iterations,
verbose = FALSE
))
} else {
results <- lme4::bootMer(model, boot_function, nsim = iterations)
results <- lme4::bootMer(
model,
boot_function,
nsim = iterations
)
}

out <- as.data.frame(results$t)
Expand Down
2 changes: 1 addition & 1 deletion R/bootstrap_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#'
#' @examples
#' \dontrun{
#' if (require("boot")) {
#' if (require("boot", quietly = TRUE)) {
#' set.seed(2)
#' model <- lm(Sepal.Length ~ Species * Petal.Width, data = iris)
#' b <- bootstrap_parameters(model)
Expand Down
11 changes: 7 additions & 4 deletions R/demean.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,13 @@ degroup <- function(x, select, group, center = "mean", suffix_demean = "_within"
not_found <- setdiff(select, colnames(x))

if (length(not_found) && isTRUE(verbose)) {
insight::print_color(sprintf("%i variables were not found in the dataset: %s\n",
length(not_found),
paste0(not_found, collapse = ", ")),
color = "red")
insight::print_color(sprintf(
"%i variables were not found in the dataset: %s\n",
length(not_found),
paste0(not_found, collapse = ", ")
),
color = "red"
)
}

select <- intersect(colnames(x), select)
Expand Down
7 changes: 6 additions & 1 deletion R/describe_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@ describe_distribution.numeric <- function(x,
if (!requireNamespace("boot", quietly = TRUE)) {
warning("Package 'boot' needed for bootstrapping confidence intervals.", call. = FALSE)
} else {
results <- boot::boot(data = x, statistic = .boot_distribution, R = iterations, centrality = centrality)
results <- boot::boot(
data = x,
statistic = .boot_distribution,
R = iterations,
centrality = centrality
)
out_ci <- bayestestR::ci(results$t, ci = ci, verbose = FALSE)
out <- cbind(out, data.frame(CI_low = out_ci$CI_low[1], CI_high = out_ci$CI_high[1]))
}
Expand Down
4 changes: 2 additions & 2 deletions R/dof.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
#' model <- glm(vs ~ mpg * cyl, data = mtcars, family = "binomial")
#' dof(model)
#' \dontrun{
#' if (require("lme4")) {
#' if (require("lme4", quietly = TRUE)) {
#' model <- lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris)
#' dof(model)
#' }
#'
#' if (require("rstanarm")) {
#' if (require("rstanarm", quietly = TRUE)) {
#' model <- stan_glm(
#' Sepal.Length ~ Petal.Length * Species,
#' data = iris,
Expand Down
2 changes: 1 addition & 1 deletion R/equivalence_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bayestestR::equivalence_test
#' equivalence_test(model, rule = "cet")
#'
#' # plot method
#' if (require("see")) {
#' if (require("see", quietly = TRUE)) {
#' result <- equivalence_test(model)
#' plot(result)
#' }
Expand Down
2 changes: 1 addition & 1 deletion R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ format.parameters_model <- function(x,
zap_small = FALSE,
format = NULL,
...) {
# save attributes
# save attributes
coef_name <- attributes(x)$coefficient_name
s_value <- attributes(x)$s_value
m_class <- attributes(x)$model_class
Expand Down
13 changes: 10 additions & 3 deletions R/methods_DirichletReg.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ model_parameters.DirichletRegModel <- function(model,

#' @rdname ci.merMod
#' @export
ci.DirichletRegModel <- function(x, ci = .95, component = c("all", "conditional", "precision"), ...) {
ci.DirichletRegModel <- function(x,
ci = .95,
component = c("all", "conditional", "precision"),
...) {
component <- match.arg(component)
params <- insight::get_parameters(x, component = component)
out <- ci_wald(model = x, ci = ci, dof = Inf, ...)
Expand All @@ -61,7 +64,9 @@ ci.DirichletRegModel <- function(x, ci = .95, component = c("all", "conditional"

#' @rdname standard_error
#' @export
standard_error.DirichletRegModel <- function(model, component = c("all", "conditional", "precision"), ...) {
standard_error.DirichletRegModel <- function(model,
component = c("all", "conditional", "precision"),
...) {
component <- match.arg(component)
params <- insight::get_parameters(model)

Expand Down Expand Up @@ -102,7 +107,9 @@ standard_error.DirichletRegModel <- function(model, component = c("all", "condit
#' @importFrom stats pnorm
#' @importFrom insight get_parameters
#' @export
p_value.DirichletRegModel <- function(model, component = c("all", "conditional", "precision"), ...) {
p_value.DirichletRegModel <- function(model,
component = c("all", "conditional", "precision"),
...) {
component <- match.arg(component)
params <- insight::get_parameters(model)

Expand Down
2 changes: 1 addition & 1 deletion R/methods_averaging.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#'
#' @examples
#' library(parameters)
#' if (require("brglm2")) {
#' if (require("brglm2", quietly = TRUE)) {
#' data("stemcell")
#' model <- bracl(
#' research ~ as.numeric(religion) + gender,
Expand Down
18 changes: 14 additions & 4 deletions R/methods_betareg.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ model_parameters.betareg <- function(model,

#' @rdname ci.merMod
#' @export
ci.betareg <- function(x, ci = .95, component = c("all", "conditional", "precision"), ...) {
ci.betareg <- function(x,
ci = .95,
component = c("all", "conditional", "precision"),
...) {
component <- match.arg(component)
ci_wald(model = x, ci = ci, dof = Inf, component = component)
}


#' @rdname standard_error
#' @export
standard_error.betareg <- function(model, component = c("all", "conditional", "precision"), ...) {
standard_error.betareg <- function(model,
component = c("all", "conditional", "precision"),
...) {
component <- match.arg(component)

params <- insight::get_parameters(model)
Expand All @@ -70,7 +75,9 @@ standard_error.betareg <- function(model, component = c("all", "conditional", "p

#' @rdname p_value.DirichletRegModel
#' @export
p_value.betareg <- function(model, component = c("all", "conditional", "precision"), ...) {
p_value.betareg <- function(model,
component = c("all", "conditional", "precision"),
...) {
component <- match.arg(component)

params <- insight::get_parameters(model)
Expand All @@ -92,7 +99,10 @@ p_value.betareg <- function(model, component = c("all", "conditional", "precisio


#' @export
simulate_model.betareg <- function(model, iterations = 1000, component = c("all", "conditional", "precision"), ...) {
simulate_model.betareg <- function(model,
iterations = 1000,
component = c("all", "conditional", "precision"),
...) {
component <- match.arg(component)
out <- .simulate_model(model, iterations, component = component)

Expand Down
6 changes: 4 additions & 2 deletions R/methods_cplm.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ standard_error.zcpglm <- function(model, component = c("all", "conditional", "zi
#' @inheritParams standard_error
#' @inheritParams ci.merMod
#'
#' @return A data frame with at least two columns: the parameter names and the p-values. Depending on the model, may also include columns for model components etc.
#' @return A data frame with at least two columns: the parameter names and the
#' p-values. Depending on the model, may also include columns for model
#' components etc.
#'
#' @examples
#' if (require("pscl")) {
#' if (require("pscl", quietly = TRUE)) {
#' data("bioChemists")
#' model <- zeroinfl(art ~ fem + mar + kid5 | kid5 + phd, data = bioChemists)
#' p_value(model)
Expand Down
2 changes: 1 addition & 1 deletion R/methods_epi2x2.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ model_parameters.epi.2by2 <- function(model, verbose = TRUE, ...) {
attr(params, "pretty_names") <- stats::setNames(pretty_names, params$Parameter)
class(params) <- c("parameters_model", "see_parameters_model", class(params))
params
}
}
7 changes: 6 additions & 1 deletion R/methods_gam.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ model_parameters.gam <- function(model,

# Processing
if (bootstrap) {
parameters <- bootstrap_parameters(model, iterations = iterations, ci = ci, ...)
parameters <- bootstrap_parameters(
model,
iterations = iterations,
ci = ci,
...
)
} else {
parameters <-
.extract_parameters_generic(
Expand Down
7 changes: 6 additions & 1 deletion R/methods_glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ model_parameters.glmmTMB <- function(model,
if (effects %in% c("fixed", "all")) {
# Processing
if (bootstrap) {
params <- bootstrap_parameters(model, iterations = iterations, ci = ci, ...)
params <- bootstrap_parameters(
model,
iterations = iterations,
ci = ci,
...
)
} else {
params <- .extract_parameters_generic(
model,
Expand Down
17 changes: 13 additions & 4 deletions R/methods_lavaan.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ p_value.blavaan <- function(model, ...) {
#' library(parameters)
#'
#' # lavaan -------------------------------------
#' if (require("lavaan")) {
#' if (require("lavaan", quietly = TRUE)) {
#'
#' # Confirmatory Factor Analysis (CFA) ---------
#'
Expand Down Expand Up @@ -102,8 +102,12 @@ p_value.blavaan <- function(model, ...) {
#' @return A data frame of indices related to the model's parameters.
#'
#' @references \itemize{
#' \item Rosseel Y (2012). lavaan: An R Package for Structural Equation Modeling. Journal of Statistical Software, 48(2), 1-36.
#' \item Merkle EC , Rosseel Y (2018). blavaan: Bayesian Structural Equation Models via Parameter Expansion. Journal of Statistical Software, 85(4), 1-30. http://www.jstatsoft.org/v85/i04/
#' \item Rosseel Y (2012). lavaan: An R Package for Structural Equation
#' Modeling. Journal of Statistical Software, 48(2), 1-36.
#'
#' \item Merkle EC , Rosseel Y (2018). blavaan: Bayesian Structural Equation
#' Models via Parameter Expansion. Journal of Statistical Software, 85(4),
#' 1-30. http://www.jstatsoft.org/v85/i04/
#' }
#' @export
model_parameters.lavaan <- function(model,
Expand All @@ -112,7 +116,12 @@ model_parameters.lavaan <- function(model,
type = c("regression", "correlation", "loading", "defined"),
verbose = TRUE,
...) {
params <- .extract_parameters_lavaan(model, ci = ci, standardize = standardize, verbose = verbose, ...)
params <- .extract_parameters_lavaan(model,
ci = ci,
standardize = standardize,
verbose = verbose,
...
)

# Filter
if (all(type == "all")) {
Expand Down
Loading

0 comments on commit 6ca0344

Please sign in to comment.