Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jan 27, 2024
1 parent d63950c commit 7da1b83
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 58 deletions.
4 changes: 3 additions & 1 deletion R/display.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#' @name display.parameters_model
#'
#' @description Prints tables (i.e. data frame) in different output formats.
#' `print_md()` is a alias for `display(format = "markdown")`.
#' `print_md()` is a alias for `display(format = "markdown")`, `print_html()`
#' is a alias for `display(format = "html")`. `print_table()` is for specific
#' use cases only, and currently only works for `compare_parameters()` objects.
#'
#' @param x An object returned by [`model_parameters()`][model_parameters].
#' @param object An object returned by [`model_parameters()`][model_parameters],
Expand Down
26 changes: 12 additions & 14 deletions R/methods_glmmTMB.R
Original file line number Diff line number Diff line change
Expand Up @@ -320,22 +320,20 @@ standard_error.glmmTMB <- function(model,
)

if (effects == "random") {
if (requireNamespace("TMB", quietly = TRUE) && requireNamespace("glmmTMB", quietly = TRUE)) {
s1 <- TMB::sdreport(model$obj, getJointPrecision = TRUE)
s2 <- sqrt(s1$diag.cov.random)
rand.ef <- glmmTMB::ranef(model)[[1]]
rand.se <- lapply(rand.ef, function(.x) {
cnt <- nrow(.x) * ncol(.x)
s3 <- s2[1:cnt]
s2 <- s2[-(1:cnt)]
d <- as.data.frame(matrix(sqrt(s3), ncol = ncol(.x), byrow = TRUE))
colnames(d) <- colnames(.x)
d
})
rand.se
} else {
if (!requireNamespace("TMB", quietly = TRUE) && !requireNamespace("glmmTMB", quietly = TRUE)) {
return(NULL)
}
s1 <- TMB::sdreport(model$obj, getJointPrecision = TRUE)
s2 <- sqrt(s1$diag.cov.random)
rand.ef <- glmmTMB::ranef(model)[[1]]
rand.se <- lapply(rand.ef, function(.x) {
cnt <- nrow(.x) * ncol(.x)
s3 <- s2[1:cnt]
s2 <- s2[-(1:cnt)]
d <- as.data.frame(matrix(sqrt(s3), ncol = ncol(.x), byrow = TRUE))
colnames(d) <- colnames(.x)
d
})
} else {
if (is.null(.check_component(model, component, verbose = verbose))) {
return(NULL)
Expand Down
35 changes: 15 additions & 20 deletions R/methods_lme4.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,29 +82,24 @@
#' use `effects = "fixed"`. There is also a [`plot()`-method](https://easystats.github.io/see/articles/parameters.html)
#' implemented in the [**see**-package](https://easystats.github.io/see/).
#'
#' @examples
#' @examplesIf require("lme4") && require("glmmTMB")
#' library(parameters)
#' if (require("lme4")) {
#' data(mtcars)
#' model <- lmer(mpg ~ wt + (1 | gear), data = mtcars)
#' model_parameters(model)
#' }
#' data(mtcars)
#' model <- lme4::lmer(mpg ~ wt + (1 | gear), data = mtcars)
#' model_parameters(model)
#'
#' \donttest{
#' if (require("glmmTMB")) {
#' data(Salamanders)
#' model <- glmmTMB(
#' count ~ spp + mined + (1 | site),
#' ziformula = ~mined,
#' family = poisson(),
#' data = Salamanders
#' )
#' model_parameters(model, effects = "all")
#' }
#' data(Salamanders, package = "glmmTMB")
#' model <- glmmTMB::glmmTMB(
#' count ~ spp + mined + (1 | site),
#' ziformula = ~mined,
#' family = poisson(),
#' data = Salamanders
#' )
#' model_parameters(model, effects = "all")
#'
#' if (require("lme4")) {
#' model <- lmer(mpg ~ wt + (1 | gear), data = mtcars)
#' model_parameters(model, bootstrap = TRUE, iterations = 50, verbose = FALSE)
#' }
#' model <- lme4::lmer(mpg ~ wt + (1 | gear), data = mtcars)
#' model_parameters(model, bootstrap = TRUE, iterations = 50, verbose = FALSE)
#' }
#' @return A data frame of indices related to the model's parameters.
#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/print_html.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ print_html.compare_parameters <- function(x,
if (!is.null(user_labels)) {
new_labels <- c(
colnames(out[["_data"]])[1],
rep(user_labels, length.out = ncol(out[["_data"]]) - 1)
rep_len(user_labels, ncol(out[["_data"]]) - 1)
)
new_labels <- as.list(new_labels)
}
Expand Down Expand Up @@ -270,7 +270,7 @@ print_html.compare_parameters <- function(x,
# check where last parameter row ends. For "compare_models()", the
# first Parameter value after data rows is "". If this is not found,
# simply use number of rows as last row
last_row <- which(out[["_data"]][[pcol_name]] == "")[1]
last_row <- which(!nzchar(as.character(out[["_data"]][[pcol_name]]), keepNA = TRUE))[1]
if (is.na(last_row)) {
last_row <- nrow(out[["_data"]])
} else {
Expand Down
19 changes: 19 additions & 0 deletions R/print_table.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
#' @examplesIf require("tinytable") && require("lme4") && require("glmmTMB")
#' \donttest{
#' data(iris)
#' data(Salamanders, package = "glmmTMB")
#' m1 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
#' m2 <- lme4::lmer(
#' Sepal.Length ~ Petal.Length + Petal.Width + (1 | Species),
#' data = iris
#' )
#' m3 <- glmmTMB::glmmTMB(
#' count ~ spp + mined + (1 | site),
#' ziformula = ~mined,
#' family = poisson(),
#' data = Salamanders
#' )
#' out <- compare_parameters(m1, m2, m3, effects = "all", components = "all")
#' print_table(out)
#'
#' @rdname display.parameters_model
#' @export
print_table <- function(x, digits = 2, p_digits = 3, ...) {
insight::check_if_installed(c("datawizard", "tinytable"))
Expand Down
9 changes: 7 additions & 2 deletions man/display.parameters_model.Rd

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

35 changes: 16 additions & 19 deletions man/model_parameters.merMod.Rd

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

0 comments on commit 7da1b83

Please sign in to comment.