Conversation
Summary of ChangesHello @DominiqueMakowski, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request introduces the get_simulated() generic and several S3 methods to simulate responses from fitted models (lm, betareg, glmmTMB, merMod). The implementation is well-structured and follows the package's architecture. However, there are several adherence issues with the repository's style guide, specifically regarding the placement of curly braces in function definitions, the mandatory use of the :: operator for functions from external packages (especially stats), and the preference for insight::format_error() over stop(). Additionally, optional dependencies should be checked using insight::check_if_installed() before use.
There was a problem hiding this comment.
Pull request overview
This pull request introduces a new get_simulated() function to the insight package that provides a unified interface for simulating response values from fitted statistical models. The implementation mirrors the design pattern of existing get_* functions in the package (like get_predicted()) and adds support for multiple model types including lm/glm, betareg, glmmTMB, and merMod models.
Changes:
- Added new generic function
get_simulated()with methods for lm, betareg, glmmTMB, merMod, data.frame, and a default method for unsupported models - Implemented comprehensive test suite covering the main supported model types
- Added documentation with usage examples for the new functionality
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| R/get_simulated.R | Core implementation of the get_simulated generic and all its methods, including RNG state management and model-specific simulation logic |
| tests/testthat/test-get_simulated.R | Test suite covering lm, betareg, glmmTMB, merMod models, and error cases |
| man/get_simulated.Rd | Auto-generated documentation describing the function interface and parameters |
| NAMESPACE | Export declarations for the new function and all its S3 methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
My feeling is that get_simulated should be useable from within get_predicted (which would enable seemless integration at higher levels, modelbased etc). The question is how to do it in a conceptually consistent and logical manner. @bwiernik: "specifying bootstrap should be in ci_method not predict" Current behaviour:
(Note: for LMs, predict type doesn't matter here) New proposal:
|
|
I wouldn't add |
|
The logic is that we have draws / samples, and then have different ways to extract the 95% quantiles via the method (https://easystats.github.io/bayestestR/reference/ci.html). |
|
I suppose what you say also makes sense. Formally, the hiatus is between these two positions:
|
Are there situations where you really want these? They're probably no good "dispersion" or "uncertainty" estimates and - in extreme cases - may not even include the point estimate (predicted value)? |
|
Why do we have all these #' @export
get_simulated.polr <- get_simulated.default? |
Placeholders to remember to add specific methods I think (I asked to add placeholders to all the classes supported by get_predicted)
Yeah, probably not really in practice. But does it make sense logically? don't know either 🤷 |
|
Maybe this?
Or we could just change the following: when |
|
We should check whether we have binary, ordinal or categorical outcomes. In this case, library(insight)
model <- glm(vs ~ am + wt, data = mtcars, family = "binomial")
# fails, because we call `simulate()` on the entire model,
# but we do not filter data
out <- get_simulated(
model,
iterations = 2,
seed = 123,
data = insight::get_datagrid(model, "am")
)
#> Error in `dim(val) <- c(n, iterations)`:
#> ! dims [product 4] do not match the length of object [64]
# works, but anyway - simulated values are only 0 or 1, we can't calculate
# a probability or useful intervals
out <- get_simulated(
model,
iterations = 2,
seed = 123
)
out
#> iter_1 iter_2
#> Mazda RX4 0 0
#> Mazda RX4 Wag 0 0
#> Datsun 710 1 1
#> Hornet 4 Drive 0 1
#> Hornet Sportabout 1 1
#> Valiant 0 0
#> Duster 360 0 0
#> Merc 240D 0 1
#> Merc 230 1 1
#> Merc 280 0 0
#> Merc 280C 1 0
#> Merc 450SE 0 0
#> Merc 450SL 0 0
#> Merc 450SLC 0 0
#> Cadillac Fleetwood 0 0
#> Lincoln Continental 0 0
#> Chrysler Imperial 0 0
#> Fiat 128 1 0
#> Honda Civic 1 1
#> Toyota Corolla 1 1
#> Toyota Corona 1 1
#> Dodge Challenger 1 0
#> AMC Javelin 0 0
#> Camaro Z28 1 0
#> Pontiac Firebird 0 0
#> Fiat X1-9 1 1
#> Porsche 914-2 1 0
#> Lotus Europa 1 1
#> Ford Pantera L 0 0
#> Ferrari Dino 0 0
#> Maserati Bora 0 0
#> Volvo 142E 1 0Created on 2026-02-21 with reprex v2.1.1 |
|
Ok, should work for binomial now. But we have to add internal simulate-function for other glm-families, too (to make it work with data grids) |
No description provided.