I'm trying to run a SEM analysis with count data.
I'm using piecewiseSEM package (2.30) with paths fit via glmmTMB (1.1.8-9000).
Based on previous tests, the fit of piecewiseSEM models using glmmTMB paths is performing ok.
However, there is a possible directionality conflict in the basis set of one model.
This situation is not really an issue and the solutions are well documented by the package author.
(see: text)
However, the problem emerges when the solutions (which works for other packages) don't seem to work for glmmTMB.
I managed to make a minimal reproducible example using the following code:
require(piecewiseSEM)
require(glmmTMB)
simData = data.frame(sp1 = runif(300),
sp2 = rpois(300, 3),
sp3 = rpois(300, 5),
sp4 = rpois(300, 1))
# Model structure:
# sp2
#sp1 < > sp4
# sp3
SEM <- psem(
glmmTMB(sp2 ~ sp1, family = poisson, data = simData),
glmmTMB(sp3 ~ sp1, family = poisson, data = simData),
glmmTMB(sp4 ~ sp2 + sp3, family = poisson, data = simData),
data = simData)
basisSet(SEM)
summary(SEM) #The conflict is shown here
summary(SEM, direction = c("sp3 <- sp2")) #The error happens here
The summary retuns the following error message:
n str2lang(x) : :2:0: unexpected end of input 1: . ~ sp3 + sp2 + sp1 +
^
I tried the same test while fitting the paths with other packages (glmer and glm) and it works.
The problem seems to be limited to glmmTMB (I didn't tested all supported packages though).
I also tried a few package versions (piecewiseSEM and glmmTMB), and a few R versions. But they were the same.
Since I really need to use glmmTMB for my analysis does anyone know whether is this a bug of am I missing something?
Recording how far I've gotten in my archaeology:
Using
traceback()/options(error = recover), we can see that the error happens withinpiecewiseSEM:::testBasisSetElements. This code extracted and modified reproduces the error:onlyBars(...)returns a blank string, which makes me guess that the problem here is thatpiecewiseSEMassumes that models will include/only works with models that include at least one random effect.