Skip to content

Bootstrap for intercept-only models #1128

@mcfanda

Description

@mcfanda

Hello,
parameters::bootstrap_model() fails when the model has only the intercept.

library(reprex)

y<-1:10
mod<-lm(y~1)
parameters::bootstrap_model(mod)
#> Error in model.frame.default(formula = y ~ 1, data = d, drop.unused.levels = TRUE): 'data' must be a data.frame, environment, or list

Created on 2025-07-07 with reprex v2.1.1

By inspecting the code, it seems that the issue arises in the bootstrap function in bootstrap_model.default()

    boot_function <- function(model, data, indices) {
        d <- data[indices, ]
      .....

If modified like this

    boot_function <- function(model, data, indices) {
        d <- data[indices, , drop=FALSE]
      .....

the whole bootstrapping works also for intercept-only models

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions