Skip to content

Commit 18204fb

Browse files
authored
Merge branch 'main' into scrutin_test
2 parents b8efa0d + 8cb8087 commit 18204fb

50 files changed

Lines changed: 1428 additions & 236 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODE_OF_CONDUCT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ representative at an online or offline event.
5959
## Enforcement
6060

6161
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62-
reported to the community leaders responsible for enforcement at d.luedecke@uke.de.
62+
reported to the community leaders responsible for enforcement at d.luedecke@uke.de.
6363
All complaints will be reviewed and investigated promptly and fairly.
6464

6565
All community leaders are obligated to respect the privacy and security of the
@@ -121,6 +121,6 @@ Community Impact Guidelines were inspired by
121121
[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion].
122122

123123
For answers to common questions about this code of conduct, see the FAQ at
124-
<https://www.contributor-covenant.org/faq>. Translations are available at <https://www.contributor-covenant.org/translations>.
124+
<https://www.contributor-covenant.org/faq/>. Translations are available at <https://www.contributor-covenant.org/translations/>.
125125

126126
[homepage]: https://www.contributor-covenant.org

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: insight
33
Title: Easy Access to Model Information for Various Model Objects
4-
Version: 1.5.0.1
4+
Version: 1.5.1.4
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",
@@ -90,6 +90,7 @@ Suggests:
9090
BayesFactor,
9191
bayestestR,
9292
bbmle,
93+
BSDA,
9394
bdsmatrix,
9495
betareg,
9596
biglm,
@@ -223,9 +224,9 @@ VignetteBuilder:
223224
knitr
224225
Encoding: UTF-8
225226
Language: en-US
226-
RoxygenNote: 7.3.3
227227
Roxygen: list(markdown = TRUE)
228228
Config/testthat/edition: 3
229229
Config/testthat/parallel: true
230230
Config/Needs/website: easystats/easystatstemplate
231231
Config/Needs/check: stan-dev/cmdstanr
232+
Config/roxygen2/version: 8.0.0

GEMINI.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ This document outlines the common coding conventions observed in the `easystats`
1212

1313
* If pull requests include user-visible changes, the "developer" version number should be increased (e.g. from 0.10.1.5 to 0.10.1.6). This ensures that `easystats::install_latest()` will download the latest versions.
1414

15+
* For the NEWS file, the current development version should not be indicated by a version number, but rather with `(devel)`.
16+
1517
## Code Style & Formatting
1618

1719
* **Assignment:** Use the `<-` operator for assignment, not `=`.
1820
* **Spacing:**
1921
* Use spaces around all infix operators (`<-`, `==`, `+`, etc.).
2022
* Place a space after a comma, but not before.
21-
* **Curly Braces:**
22-
* For function definitions, the opening `{` should be on the same line
23-
as the closing `)` of that function definition. That can be on the
24-
same line as the function definition itself, but might be on a new
25-
line if the argument list is too long for one line.
26-
* For `if`/`else` statements, the opening `{` can be on the same line.
2723
* **Line Length:** Keep lines to a reasonable length (e.g., under 80-100 characters) to improve readability.
2824

2925
## Function Naming
@@ -70,8 +66,9 @@ All exported functions must be documented using `roxygen2`-style comments (`#'`)
7066

7167
* Use base-R wherever possible (to reduce hard dependencies)
7268
* Make sure R-version requirements are not too strict
73-
* **Package Functions:** Always use the `::` operator to call functions from other packages (e.g., `stats::shapiro.test`, `insight::model_info`). Do not use `library()` or `require()` at the top of a file (no full import, only selective import of functions).
69+
* **Package Functions:** Always use the `::` operator to call functions from other packages (e.g., `stats::shapiro.test`, `insight::model_info`). Do not use `library()` or `require()` at the top of a file (no full import, only selective import of functions). However, in test files, package vignettes (.rmd), or in the package documentation, `::` is not required for core R packages like `stats` or `tools`.
7470
* **Conditional Checks:** Use `insight::check_if_installed("pkg_name")` to check if a package is available before using it, especially for optional ("Suggests") dependencies.
71+
* **Argument validation:** Use `insight::validate_argument()` instead of `match.arg()` to validate correct input of arguments, unless you need `several.ok`. In this case, rely on `match.arg()`.
7572

7673
## S3 Object System
7774

@@ -83,7 +80,11 @@ All exported functions must be documented using `roxygen2`-style comments (`#'`)
8380

8481
* Use `tryCatch` for operations that might fail. The internal `.safe()` helper is a good example.
8582
* Use the `insight` package's functions for user-facing messages:
86-
* `insight::format_error()`
87-
* `insight::format_warning()`
88-
* `insight::format_alert()`
89-
* `insight::print_color()`
83+
* For errors: `insight::format_error()`
84+
* For warnings: `insight::format_warning()`
85+
* For messages: `insight::format_alert()`
86+
* To highlight messages: `insight::print_color()`
87+
Note that character vectors are not pasted together, unlike in `message()`,
88+
thus you usually want to use something like `paste()` to concatenate the
89+
string. Character vectors will add a new paragraph for each string element,
90+
not paste them together.

NAMESPACE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ S3method(ellipsis_info,default)
4040
S3method(find_algorithm,Arima)
4141
S3method(find_algorithm,BBmm)
4242
S3method(find_algorithm,BBreg)
43+
S3method(find_algorithm,CmdStanFit)
4344
S3method(find_algorithm,Gam)
4445
S3method(find_algorithm,LORgee)
4546
S3method(find_algorithm,MixMod)
@@ -206,6 +207,7 @@ S3method(find_parameters,BBmm)
206207
S3method(find_parameters,BBreg)
207208
S3method(find_parameters,BFBayesFactor)
208209
S3method(find_parameters,BGGM)
210+
S3method(find_parameters,CmdStanFit)
209211
S3method(find_parameters,DirichletRegModel)
210212
S3method(find_parameters,Gam)
211213
S3method(find_parameters,HLfit)
@@ -503,6 +505,7 @@ S3method(get_data,meta_random)
503505
S3method(get_data,metaplus)
504506
S3method(get_data,mhurdle)
505507
S3method(get_data,mipo)
508+
S3method(get_data,mira)
506509
S3method(get_data,mixed)
507510
S3method(get_data,mixor)
508511
S3method(get_data,mjoint)
@@ -704,6 +707,7 @@ S3method(get_parameters,BBmm)
704707
S3method(get_parameters,BBreg)
705708
S3method(get_parameters,BFBayesFactor)
706709
S3method(get_parameters,BGGM)
710+
S3method(get_parameters,CmdStanFit)
707711
S3method(get_parameters,DirichletRegModel)
708712
S3method(get_parameters,Gam)
709713
S3method(get_parameters,HLfit)
@@ -1179,6 +1183,7 @@ S3method(get_varcov,glmx)
11791183
S3method(get_varcov,hglm)
11801184
S3method(get_varcov,hurdle)
11811185
S3method(get_varcov,ivFixed)
1186+
S3method(get_varcov,lavaan)
11821187
S3method(get_varcov,lcmm)
11831188
S3method(get_varcov,list)
11841189
S3method(get_varcov,lmRob)
@@ -1244,6 +1249,10 @@ S3method(get_weights,svycoxph)
12441249
S3method(get_weights,svyglm)
12451250
S3method(get_weights,svyolr)
12461251
S3method(get_weights,svysurvreg)
1252+
S3method(has_intercept,default)
1253+
S3method(has_intercept,felm)
1254+
S3method(has_intercept,fepois)
1255+
S3method(has_intercept,fixest)
12471256
S3method(is_converged,"_glm")
12481257
S3method(is_converged,default)
12491258
S3method(is_converged,glm)
@@ -1881,6 +1890,21 @@ S3method(text_remove_backticks,matrix)
18811890
S3method(trim_ws,data.frame)
18821891
S3method(trim_ws,default)
18831892
S3method(trim_ws,list)
1893+
S3method(vcovFPC,clm)
1894+
S3method(vcovFPC,clm2)
1895+
S3method(vcovFPC,default)
1896+
S3method(vcovFPC,glm)
1897+
S3method(vcovFPC,glmRob)
1898+
S3method(vcovFPC,glmmTMB)
1899+
S3method(vcovFPC,glmrob)
1900+
S3method(vcovFPC,lm)
1901+
S3method(vcovFPC,lmRob)
1902+
S3method(vcovFPC,lm_robust)
1903+
S3method(vcovFPC,merMod)
1904+
S3method(vcovFPC,model_fit)
1905+
S3method(vcovFPC,polr)
1906+
S3method(vcovFPC,speedglm)
1907+
S3method(vcovFPC,speedlm)
18841908
export(all_models_equal)
18851909
export(all_models_same_class)
18861910
export(broom_columns)
@@ -2007,3 +2031,4 @@ export(supported_models)
20072031
export(text_remove_backticks)
20082032
export(trim_ws)
20092033
export(validate_argument)
2034+
export(vcovFPC)

NEWS.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,53 @@
22

33
## Changes
44

5+
* Major performance improvement for `compact_list` on very large, nested list
6+
objects.
7+
8+
* `get_varcov()` now explicitly works for `lavaan` objects.
9+
10+
## Bug fixes
11+
12+
* `get_modelmatrix()` now correctly handles *brms* models fitted with
13+
`0 + Intercept` formulas.
14+
15+
* `get_priors()` did not return degrees of freedom for Student's t-distribution
16+
for *rstanarm* models.
17+
18+
# insight 1.5.1
19+
20+
## Changes
21+
22+
* New support for `CmdStanFit` models from the *cmdstanr* package -
23+
`find_algorithm()`, `find_parameters()`, and `get_parameters()` now work with
24+
these models.
25+
26+
* `model_info()` now correctly detects t- and z-tests from package *BSDA*.
27+
28+
* `format_bf()` gains a `digits` argument.
29+
530
* More informative error message when the response variable in `get_response()`
631
is not present in the data.
732

33+
* `format_table()` now also formats columns for tail and bulk ESS from Bayesian
34+
models.
35+
36+
* `get_data()` now supports objects of class `mira` from package *mice*.
37+
38+
* `get_varcov()` now supports the option `"fpc"` to apply finite population
39+
correction (Lai et al. 2018).
40+
41+
* Added a new function, `vcovFPC()`, to calculate finite-population-adjusted
42+
variance-covariance matrices.
43+
44+
## Bug fixes
45+
46+
* `has_intercept()` now correctly detects whether models from packages *fixest*
47+
and *lfe* have intercepts or not.
48+
49+
* The `vcov` argument in `get_varcov()` was ignored when `vcov` was of class
50+
`"dpoMatrix"` and did not return `TRUE` to `is.matrix()`.
51+
852
# insight 1.5.0
953

1054
## Changes

R/find_algorithm.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,13 @@ find_algorithm.brmsfit <- function(x, ...) {
347347
warmup = info$warmup
348348
)
349349
}
350+
351+
#' @export
352+
find_algorithm.CmdStanFit <- function(x, ...) {
353+
check_if_installed("cmdstanr")
354+
md <- x$metadata()
355+
out <- md[c("method", "num_chains", "iter_sampling", "iter_warmup")]
356+
names(out) <- c("algorithm", "chains", "iterations", "warmup")
357+
out$chains <- out$chains * length(md$id)
358+
out
359+
}

R/find_parameters_bayesian.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,18 @@ find_parameters.stanfit <- function(
557557
l
558558
}
559559
}
560+
561+
#' @export
562+
find_parameters.CmdStanFit <- function(x, flatten = FALSE, ...) {
563+
check_if_installed("cmdstanr")
564+
md <- x$metadata()
565+
566+
v <- md$variables
567+
# v <- md$stan_variables
568+
569+
v <- setdiff(v, "lp__")
570+
if (isTRUE(flatten)) {
571+
return(v)
572+
}
573+
list(conditional = v)
574+
}

R/format_bf.R

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#' @param inferiority_star String, indicating the symbol that is used to
1010
#' indicate inferiority, i.e. when the Bayes Factor is smaller than one third
1111
#' (the thresholds are smaller than one third, 1/10 and 1/30).
12+
#' @param digits Number of significant digits. Can also be `"scientific"` (which
13+
#' is identical to `exact = TRUE`).
1214
#' @inheritParams format_p
1315
#'
1416
#' @return A formatted string.
@@ -30,10 +32,12 @@ format_bf <- function(
3032
name = "BF",
3133
protect_ratio = FALSE,
3234
na_reference = NA,
33-
exact = FALSE
35+
exact = FALSE,
36+
digits = NULL
3437
) {
38+
bad_bf <- is.na(bf)
3539
if (is.na(na_reference)) {
36-
bf[bad_bf <- is.na(bf)] <- 1
40+
bf[bad_bf] <- 1
3741
} else {
3842
bf[is.na(bf)] <- na_reference
3943
}
@@ -47,16 +51,30 @@ format_bf <- function(
4751
is_small <- logical(length(bf))
4852
}
4953

50-
digits <- ifelse(is.na(bf), 0, ifelse(bf < 1, 3, 2)) # nolint
54+
# digis = scientific is the same as exact = TRUE
55+
if (identical(digits, "scientific")) {
56+
exact <- TRUE
57+
digits <- NULL
58+
}
59+
60+
if (is.null(digits) || is.character(digits)) {
61+
digits <- ifelse(is.na(bf), 0, ifelse(bf < 1, 3, 2))
62+
}
5163

5264
bf_text <- paste0(
5365
"= ",
5466
ifelse(is_small, "1/", ""),
5567
format_value(bf, digits = digits)
5668
)
5769

70+
# what is extreme small?
71+
extreme_small <- (10^max(digits))
72+
if (extreme_small < 1000) {
73+
extreme_small <- 1000
74+
}
75+
5876
## Very big/small values
59-
is_extreme <- bf_orig > 1000 | bf_orig < 1 / 1000
77+
is_extreme <- bf_orig > 1000 | bf_orig < 1 / extreme_small
6078
if (any(is_extreme)) {
6179
if (exact) {
6280
bf_text[is_extreme] <- ifelse(
@@ -65,9 +83,9 @@ format_bf <- function(
6583
bf_text[is_extreme]
6684
)
6785
bf_text[is_extreme] <- ifelse(
68-
bf_orig[is_extreme] < 1 / 1000,
86+
bf_orig[is_extreme] < 1 / extreme_small,
6987
ifelse(
70-
is_small[is_extreme], # nolint
88+
is_small[is_extreme],
7189
sprintf("= 1/%.2e", bf[is_extreme]),
7290
sprintf("= %.2e", bf_orig[is_extreme])
7391
),
@@ -80,8 +98,15 @@ format_bf <- function(
8098
bf_text[is_extreme]
8199
)
82100
bf_text[is_extreme] <- ifelse(
83-
bf_orig[is_extreme] < 1 / 1000,
84-
ifelse(is_small[is_extreme], "< 1/1000", "< 0.001"), # nolint
101+
bf_orig[is_extreme] < 1 / extreme_small,
102+
ifelse(
103+
is_small[is_extreme],
104+
paste0("< 1/", extreme_small),
105+
paste0(
106+
"< ",
107+
format_value(1 / extreme_small, digits = round(log10(extreme_small)))
108+
)
109+
),
85110
bf_text[is_extreme]
86111
)
87112
}
@@ -93,20 +118,20 @@ format_bf <- function(
93118
paste0(bf_text, "***"),
94119
ifelse(
95120
bf_orig > 10,
96-
paste0(bf_text, "**"), # nolint
97-
ifelse(bf_orig > 3, paste0(bf_text, "*"), bf_text) # nolint
121+
paste0(bf_text, "**"),
122+
ifelse(bf_orig > 3, paste0(bf_text, "*"), bf_text)
98123
)
99124
)
100125

101126
## Add inferiority stars
102127
if (!is.null(inferiority_star)) {
103128
bf_text <- ifelse(
104129
bf_orig < (1 / 30),
105-
paste0(bf_text, paste(rep_len(inferiority_star, 3), collapse = "")), # nolint
130+
paste0(bf_text, paste(rep_len(inferiority_star, 3), collapse = "")),
106131
ifelse(
107132
bf_orig < 0.1,
108-
paste0(bf_text, paste(rep_len(inferiority_star, 2), collapse = "")), # nolint
109-
ifelse(bf_orig < (1 / 3), paste0(bf_text, inferiority_star), bf_text) # nolint
133+
paste0(bf_text, paste(rep_len(inferiority_star, 2), collapse = "")),
134+
ifelse(bf_orig < (1 / 3), paste0(bf_text, inferiority_star), bf_text)
110135
)
111136
)
112137
}

R/format_table.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,13 @@ format_table <- function(
802802
if ("ESS" %in% names(x)) {
803803
x$ESS <- round(x$ESS)
804804
}
805+
if ("ESS_tail" %in% names(x)) {
806+
x$ESS_tail <- round(x$ESS_tail)
807+
}
808+
if ("ESS_bulk" %in% names(x)) {
809+
x$ESS_bulk <- round(x$ESS_bulk)
810+
}
811+
colnames(x) <- gsub("^ESS_(.*)$", "ESS (\\1)", colnames(x))
805812

806813
if ("ROPE_Equivalence" %in% names(x)) {
807814
names(x)[names(x) == "ROPE_Equivalence"] <- "Equivalence (ROPE)"

0 commit comments

Comments
 (0)