Dear community,

I am trying to generate posterior residuals, R2, Loo R2, etc. based on the Poisson truncated model. In all cases, computation takes a lot of time, however, the most disappointing moment occurs when R informs that “it cannot allocate vector of size 500 or 700 Mb” for residuals, R2 and Loo R2.

Is there any possibility to compute residuals and the rest based on a small sample to speed up computation and decrease the size of the vector? For example, a small sample is used in pp_check (fit1, nsample=100).

My code is as following:

```
transform=data %>% mutate(ba_sqrt = sqrt(ba_m2.p), dbh_log = log(dbh_cm.p))
d=subset(transform, species.p %in% c("Acer platanoides", "Acer pseudoplatanus", "Fagus sylvatica", "Ulmus glabra"))
d1=subset(d, species.m %in% c("Acer platanoides", "Acer pseudoplatanus", "Fagus sylvatica"))
alive=subset(d1, status.p %in% c("alive"))
alive$y=as.factor(alive$year)
bprior1 <- c(prior_string("normal(0,2)", class = "Intercept"),
prior(normal(1,1), class = b, coef = species.pAcerpseudoplatanus),
prior(normal(3,1), class = b, coef = species.pFagussylvatica),
prior(normal(1,1), class = b, coef = species.pUlmusglabra),
prior(normal(3,1), class = b, coef = species.mAcerpseudoplatanus),
prior(normal(2,1), class = b, coef = species.mFagussylvatica),
prior(normal(3,1), class = b, coef = position.madjacent_gap),
prior(normal(3,1), class = b, coef = position.mgap),
prior(normal(2,1), class = b, coef = position.mcanopy),
prior(normal(1,2), class = b, coef = ba_sqrt),
prior(normal(1,2), class = b, coef = dbh_log),
prior_(~exponential(4), class = ~sd))
fit1=brm(count|trunc(lb=1)~ba_sqrt+dbh_log+species.p+species.m+position.m+offset(log(population.d))+offset(log(crown_area_m2.m))+(y|subplot_id), data=alive, family=poisson(link="log"), prior=bprior1, save_pars=save_pars(all = TRUE), cores = 4, iter = 1000 + 5000, warmup = 1000, chains = 4, seed=123, sample_prior="yes", silent=TRUE, open_progress=FALSE, control = list(adapt_delta = 0.99, max_treedepth = 15))
resid = resid(fit1)[, "Estimate"]
sresid = resid/sd(resid)
fit = fitted(fit1)[, "Estimate"]
bayes_R2(fit1)
loo_R2(fit1, cores = 4)
```

Data attached: poisson.csv (749.2 KB)

- Operating System: Windows 10
- brms Version: 2.14.0