-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
effect_plot() does not work for a model with prior weights #156
Comments
Hi @deloverov, I'm unable to replicate this issue. I'm not sure of the data being referred to in your example code so I get the error message you're sharing here related to the data object not being found. Trying to replicate with data built into R, I don't get any errors. library(jtools)
states <- as.data.frame(state.x77)
fit <- glm(Income ~ Murder, data = states, weights = runif(nrow(states), 0.5, 2))
effect_plot(fit, Murder) # no error |
Thanks @jacob-long. Please find the data attached. It seems to be working with nrow() in weights and not so much when I pass it as a number: library(readr)
library(jtools)
lake <- read_csv("data/Lake180.csv")
#> Rows: 180 Columns: 2
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): habitat
#> dbl (1): predation
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
model <- glm(predation ~ habitat,
weights = rep(10, 180),
family = binomial(link = "logit"),
data = lake)
effect_plot(model, pred = habitat)
#> Error in colnames(data)[which(colnames(data) == "(weights)")] <- wname: replacement has length zero
model <- glm(predation ~ habitat,
weights = rep(10, nrow(lake)),
family = binomial(link = "logit"),
data = lake)
#data = subset(subset(lake, species == "D"), density == "H"))
effect_plot(model, pred = habitat)
#> Nice plot here Even though: identical(rep(10, nrow(lake)), rep(10, 180))
#> [1] TRUE And same with your example: library(jtools)
states <- as.data.frame(state.x77)
nrow(states)
#> [1] 50
fit <- glm(Income ~ Murder, data = states, weights = runif(50, 0.5, 2))
effect_plot(fit, Murder)
#> Error in colnames(data)[which(colnames(data) == "(weights)")] <- wname: replacement has length zero Works fine also if I pass the number as a variable: nlake <- 180
model <- glm(predation ~ habitat,
weights = rep(10, nlake),
family = binomial(link = "logit"),
data = lake)
effect_plot(model, pred = habitat)
#> Nice plot here |
Thanks for following up! This helped me figure out where things were going wrong. Fix is inbound... |
Error trying to plot effects of a GLM with prior weights. Works well for models without weights.
The text was updated successfully, but these errors were encountered: