daijiang / phyr

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

"undefined column selected" with pglmm_plot_ranef #65

Open jusinowicz opened 3 years ago

jusinowicz commented 3 years ago

Hello,

First, thanks for this awesome R package! It's allowing me to do things that I haven't been able to do with any other GLMM package.

I'm trying to use pglmm_plot_ranef() to extract the random effects predictions on simulated data and I noticed that if I name my "species" phylogeny variable anything other than "sp" that it returns the error:

Error in [.data.frame(data, , sp.var) : undefined columns selected

I ran into this problem with a simulated data set, but it seems to be reproducible running the "### Detailed analysis showing covariance matrices ###" example under the pglmm() documentation. If I run this simulation but change the name of "sp" in the data frame "d" to anything else (and then change the name in the calls to pglmm and pglmm_plot_ranef, of course), then pglmm_plot_ranef will return the error (even though pglmm runs fine). E.g. at these lines change the name and run:


d <- data.frame(species= rep(phy$tip.label, times = nsite),
site = rep(1:nsite, each = nspp))

d$Y <- Y.sp + Y.site + Y.attract + Y.e

#Works
pglmm(Y ~ 1 + (1|species__) + (1|site) + (1|species__@site), data = d, cov_ranef = list(species = phy))

#Does not
re <- pglmm_plot_ranef(Y ~ 1 + (1|species__) + (1|site) + (1|species__@site), data = d,
cov_ranef = list(species= phy), show.image = FALSE, show.sim.image = FALSE)

Am I missing something? Thanks.

daijiang commented 3 years ago

Hi Jacob! Can you try pglmm_plot_ranef(sp.var = "species") and see whether that work?

Btw, it has been several years since our last interaction! Hope to catch up with you sometime soon.

Best, Daijiang

jusinowicz commented 3 years ago

That worked! Was that in the documentation somewhere and I missed it? Sorry if it was.

It has been awhile! It's good to hear from you. Thanks for the fast reply!

Best, Jacob

On Fri, Mar 26, 2021 at 10:37 AM Daijiang Li @.***> wrote:

Hi Jacob! Can you try pglmm_plot_ranef(sp.var = "species") and see whether that work?

Btw, it has been several years since our last interaction! Hope to catch up with you sometime soon.

Best, Daijiang

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/daijiang/phyr/issues/65#issuecomment-808400845, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHOVEWXSNPBILSA46IBRONTTFTA4ZANCNFSM4Z3ZRP5Q .