daijiang / phyr

Functions for phylogenetic analyses
https://daijiang.github.io/phyr/
GNU General Public License v3.0
30 stars 10 forks source link

structuring covariance matrices in communityPGLMM #16

Open arives opened 6 years ago

arives commented 6 years ago

Just some thoughts:

  1. I've been working on a bipartite problem, and the simple format of communityPGLMM with repulsion=T sets both site and sp to the repulsion matrix. To look at repulsion for just one of these, I had to use the extended version of re=list(full V). It would be simpler to allow the formula structure (1 | sp, V.sp), (1 | sp@site, V.sp) and (1 | sp@site, V.sp, V.site); i.e., allowing the specification of the V matrix along with the r.e. term.

  2. In using the full format re=list(full V), the cpp=T option didn't work, so I had to use cpp = F.

  3. This isn't an issue, but it was interesting. For the particular dataset (with only nspp=7), using cpp=F and re=list(full V) was as fast as using the standard formatting (e.g. (1 | sp__)) for the same problem. I thought this was surprising.

  4. method="nelder-mead-nlopt" worked best; it was best-able to bring the random effects variances closer to zero and gave higher logLiks.

daijiang commented 6 years ago

@arives Tony, For 1, would it be okay to split repulsion into two arguments: repulsion.sp and repulsion.site? Instead of the formula you proposed, this may make the formula easier to read. The downside is that the repulsion argument will apply to all random terms, i.e. if repulsion.sp = TRUE then all Vsp will be inverted (but not Vsite).

  1. The cpp should work for this case, if you can send some code to me, I can have a look at it.

  2. For nspp = 7, we probably won't be able to see the differences.

arives commented 6 years ago
  1. I don't think it is worth giving two arguments for repulsion, because this is only going part way. An advantage of specifying a V is that then it could be anything, like a spatial matrix. Presumably you could leave the code as it is, and then have it so that if a V is specified, it is used. It just might be a little fussy to check for things like the formula containing a space before a comma, like (1 | sp__ , V.sp).

  2. I'll do this separately. I did reload phyr first.

  3. Yep.

daijiang commented 6 years ago

@arives Tony,

  1. The specific V can be set to tree_site? We can allow tree_site (and tree) to be either a phylogeny or a matrix. Will this work? I don't really want to mess with the formula given the fussy things you mentioned ...
arives commented 6 years ago

Yeah, I just took a look at prep_dat_pglmm, and it will be a pain to incorporate V into the formula, since you can't use lme4::findbars(), etc.

I like your idea of letting V be a phylogeny or matrix. And then will the "full" version of specifying re, that covers all bases.

arives commented 6 years ago

Daijiang,

Also, I'm finding that "nelder-mead-nlopt" almost always works better than "bobyqa". It might be worth using it as the default.

Cheers, Tony

daijiang commented 6 years ago

Have you tried subplex? It suppose to work faster than nelder-mead-nlopt and get similar results.

daijiang commented 6 years ago

Argument repulsion now can be a vector of length 1 or >1. If length = 1, then all nested terms will have the same "repulsion" setting. If length > 1, it will specify each nested term by order. See the documentation for more details.