Unbalanced observations in a group, hierarchical poisson model

Dear community,

Please advise how to better approach a problem of unbalanced observations in a group when modelling hierarchical truncated poisson model. My objective is to estimate mean number of young trees per species. Four species of young trees (species.p) are nested within mature trees (id.m) that, in turn, are also nested within subplot_id. The problem is that some subplots_ids have only 1 species, the rest three species are NOT missing, they simply do not grow there.

I am afraid that partial pooling in the hierarchical model will work badly for such subplots, worsening the model fit. I would not include the sub-plots with only 1 species in the model but I am interested to hear your opinion. The model is as follows:

center =data %>% mutate(ba_m2.c = (sqrt(ba_m2.p) - mean(sqrt(ba_m2.p), na.rm=TRUE)), dbh.c = (log(dbh_cm.p) - mean(log(dbh_cm.p), na.rm=TRUE)))
dat1=subset(center, species.p %in% c("Acer platanoides", "Acer pseudoplatanus", "Fagus sylvatica", "Ulmus glabra"))
alive=subset(dat1, status.p %in% c("alive"))
fit=brm(count|trunc(lb=1)~ba_m2.p+species.p+species.m+dbh_cm.p+offset(log(crown_area_m2.m))+offset(log(population.d))+(1|subplot_id/position.m)+(1|year/id.m), 
         data=alive, family=poisson(link="log"), prior=bprior, save_all_pars=TRUE, cores  = 4, iter = 1000 + 6000, warmup = 1000, chains = 4, seed=123,
         sample_prior="yes", silent=TRUE, open_progress=FALSE, control = list(adapt_delta = 0.99, max_treedepth = 15))

Data are enclosed. Thank you in advance for your time!

  • Operating System: Microsoft, Windows 10
  • brms Version: 2.13.5
    poisson.csv (872.2 KB)

Please provide a complete MWE. The variable bprior is not set above.

Oh, and this here:

offset(log(population.d))+(1|subplot_id/position.m)+(1|year/id.m) gives NAs when running with default priors:

Error in FUN(X[[i]], …) : Stan does not support NA (in offsets) in data
failed to preprocess the data; sampling not done

sure,
bprior <- 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(0,1), class = b, coef = species.pUlmusglabra),
prior(normal(1,2), class = b, coef = ba_m2.c),
prior(normal(1,2), class = b, coef = dbh.c),
prior_(~exponential(1), class = ~sd))

Are you sure you sent the correct one?

Error: The following priors do not correspond to any model parameter: 
b_ba_m2.c ~ normal(1, 2)
b_dbh.c ~ normal(1, 2)
Function 'get_prior' might be helpful to you.

When I remove the b_ba_m2.c and b_dbh.c priors I still get the error I got when running with rstan:

Error in FUN(X[[i]], …) : Stan does not support NA (in offsets) in data
failed to preprocess the data; sampling not done

In short, you can’t have NAs for the offset argument in brms.

Can you try the latest github version of brms?

Sorry, two covariates have the wrong names. Here are priors and fit formula (). I used centered covariates as in the script provided earlier.

bprior <- 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(0,1), class = b, coef = species.pUlmusglabra),
prior(normal(1,2), class = b, coef = ba_m2.c),
prior(normal(1,2), class = b, coef = dbh.c),
prior_(~exponential(1), class = ~sd))

fit=brm(count|trunc(lb=1)~ba_m2.c+species.p+species.m+dbh.c+offset(log(crown_area_m2.m))+offset(log(population.d))+(1|subplot_id/position.m)+(1|year/id.m),
data=alive, family=poisson(link=“log”), prior=bprior, save_all_pars=TRUE, cores = 4, iter = 1000 + 6000, warmup = 1000, chains = 4, seed=123,
sample_prior=“yes”, silent=TRUE, open_progress=FALSE, control = list(adapt_delta = 0.99, max_treedepth = 15))

Besides, I enclosed the dataset without NA in “population.d”. poisson.csv (870.9 KB)

P.S. the latest version of brms ran with some issues, so I re-install the older version.

Can you try again with the latest github version of brms. There had been some trouble with NAs that I fixed