seananderson / glmm-course

Workshop exercises on regression, GLMs, mixed-effects models, and GLMMs in R
172 stars 66 forks source link

zero-inflated code - tibble error #16

Closed achekroud closed 7 years ago

achekroud commented 7 years ago

hey

i tried to follow the code in the zero-inflated markdown and got a tibble error. not sure why since you never call a function from tibble..

inverse_logit <- function(x) plogis(x)
set.seed(123)
d <- data.frame(f = factor(rep(letters[1:10], each = 10)), x = runif(100))
u <- rnorm(10, sd = 2)
d$eta <- with(d, u[f] + 1 + 4 * x)
pz <- 0.2 # probability of excess zeros
zi <- rbinom(100, size = 1, prob = pz)
d$y <- ifelse(zi, 0, rpois(100, lambda = exp(d$eta)))
d$zi <- zi

ggplot(d, aes(x, y, colour = f, shape = as.factor(zi))) + geom_point() +
    scale_shape_manual(values = c(20, 21))

all works

but

ggplot(d, aes(x, y, colour = f)) + geom_point() + facet_wrap(~zi)

fails, returning Error: 'as_tibble' is not an exported object from 'namespace:tibble'

achekroud commented 7 years ago

fairly vanilla sessionInfo() :

> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.12.3 (Sierra)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_0.5.0     purrr_0.2.2     readr_1.0.0     tidyr_0.6.0     tibble_1.0     
[6] ggplot2_2.2.1   tidyverse_1.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.5      digest_0.6.9     assertthat_0.1   R6_2.1.2        
 [5] grid_3.3.1       plyr_1.8.4       DBI_0.4-1        gtable_0.2.0    
 [9] magrittr_1.5     scales_0.4.1     lazyeval_0.2.0   labeling_0.3    
[13] tools_3.3.1      munsell_0.4.3    colorspace_1.2-6
seananderson commented 7 years ago

Might be because you have an older version of the tibble package? It looks like ggplot is now calling as_tibble: https://github.com/tidyverse/ggplot2/search?utf8=%E2%9C%93&q=as_tibble

achekroud commented 7 years ago

bingo! rookie error, thanks a lot for spotting. have a great weekend.