I've been trying to apply a poisson model to some count data. I was careful to use only character values, remove duplicated lines, and convert NA values to string so categories wouldn't have only one level. Even then, whenever I try to run the code, I get the following error:
pm <- X |> glm(formula = Cases ~ ., family = poisson(link = "log"))
library(MASS)
library(ecostats)
pm <- stepAIC(pm, direction = "both")
plotenvelope(pm, which = 2, n.sim = 1000)
Error: inner loop 1; cannot correct step size In addition: Warning message: Truncated step size due to divergence Error in object$na.action : $ operator is invalid for atomic vectors
Data
Since I'm working with sensible data, I'll provide another of similar structure:
X = structure(list(Type = c(1, 1, 2, 2, 3, 3),
Variable = c("A", "B", "C", "D", "E", "F"),
Class = c("Yes", "No", "Ocasionally", "Never", "Two days ago", "Seven days ago"),
Cases = c(14, 2, 8, 3, 1, 5)), class = "data.frame", row.names = c(NA, -6L))