Skip to content

Error if weight variable and character variable both present #131

@pbreheny

Description

@pbreheny

Here's an example:

library(visreg)
my_data <- data.frame(
  x = runif(100),
  y = rnorm(100),
  g = letters[1:10] |> rep(10),
  w = runif(100)
)
fit <- glm(y ~ x + g, data=my_data, weights= w)
visreg(fit, "x")
#> Error in eval(extras, data, env): object 'w' not found

Currently, visreg converts characters to factors and updates the model, but it can't update the model if it doesn't have the weights.

This issue does not arise if the character variable is turned into a factor before being passed to the model (no update triggered):

library(visreg)
my_data <- data.frame(
  x = runif(100),
  y = rnorm(100),
  g = letters[1:10] |> rep(10),
  w = runif(100)
)
my_data$g <- factor(my_data$g)
fit <- glm(y ~ x + g, data=my_data, weights= w)
visreg(fit, "x")
# No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions