在我的例子中:
library(dplyr)
library(readr)
library(ggplot2)
library(ggeffects)
# Read in the data
ds <- structure(list(Especie = c("C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1", "C_externa_1",
"C_externa_1", "C_externa_1", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2", "C_cubana_2",
"C_cubana_2", "C_cubana_2", "C_cubana_2"),
Tentou_predar = c(3L, 25L, 20L, 36L, 12L, 0L, 1L, 10L,
0L, 14L, 2L, 0L, 0L, 0L, 0L, 32L, 0L, 0L, 25L, 0L, 2L, 2L, 35L,
0L, 0L, 0L, 22L, 0L, 2L, 9L, 54L, 57L, 26L, 17L, 18L, 34L, 2L,
0L, 20L, 25L, 6L, 65L, 36L, 6L, 62L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L,
1L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 1L)), class = "data.frame", row.names = c(NA,
-105L))
str(ds)
# Create a glm model
m_Pred <- glm(Tentou_predar ~ Especie, data = ds,
family = "poisson")
# Organized data and plot
ds.1.1.1 <- ds %>% mutate(x_1= 1+(readr::parse_number(Especie)-2)*0.05,
group = Especie)
df_gg <-ggeffects::ggpredict(m_Pred, terms = "Especie [all]")%>%
mutate(x_1= 1+(readr::parse_number(as.character(group))-2)*0.05)
str(df_gg)
df_gg %>% plot(add.data = TRUE)
# Raw data not available.
# Error in if (attr(x, "logistic", exact = TRUE) == "1" && attr(x, "is.trial", :
# missing value where TRUE/FALSE needed
我不知道为什么不管用。拜托,有什么办法吗?
1条答案
按热度按时间j5fpnvbx1#
问题是
mutate
从ggeffects
对象中剥离了所有的attributes
,包括rawdata
属性,这就是为什么会出现错误。这可以通过在
mutate
之前和之后调用str
看出:在
mutate
步骤之前,ggeffects
对象包括一组属性:但在
mutate
步骤之后没有:要解决您的问题,您可以使用例如base R添加
x1
列,如下所示: