arives / rr2

R2 for correlated data; see https://academic.oup.com/sysbio/advance-article/doi/10.1093/sysbio/syy060/5098616
GNU General Public License v3.0
18 stars 7 forks source link

potential bug in r2_lik.R? #13

Closed atanzap closed 1 year ago

atanzap commented 5 years ago

Thanks Tony for the great package!

I noticed some funny behaviour with rr2_1.0.2 and a phyloglm that I wanted to run past you.

The R2.lik.phyloglm function in r2_lik.R takes the model log-likelihood. But depending on the model fit, this can actually lead to negative values of R2_lik, which seems to contradict your 2019 Syst Biol paper.

According to the paper, shouldn't you be taking the penalized ML? So LL.r <- mod.r$logLik should be replaced with LL.r <- mod.r$penlogLik in the R2.lik.phyloglm function?

Cheers Andrew

arives commented 5 years ago

Andrew,

Thanks for the question. I think what might be going on is that the phylogenetic parameter in phyloglm is estimated as showing no signal (e.g., alpha=50). In this case, all the results you get for parameters (other than alpha) and the logLik are suspect, because phyloglm is bad at finding ML estimates at parameter boundaries. When the phylogenetic signal is estimated by phyloglm as zero, I automatically use lm or glm.

Try this, and I bet the problem goes away. Even though phyloglm can use the penalized LL for solutions, the unpenalized ML should be generally be used for LRTs and r2_lik.

Let me know what happens! And thanks for contacting me about this.

Cheers, Tony

From: atanzap notifications@github.com Reply-To: arives/rr2 reply@reply.github.com Date: Wednesday, June 5, 2019 at 5:56 AM To: arives/rr2 rr2@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [arives/rr2] potential bug in r2_lik.R? (#13)

Thanks Tony for the great package!

I noticed some funny behaviour with rr2_1.0.2 and a phyloglm that I wanted to run past you.

The R2.lik.phyloglm function in r2_lik.Rhttps://github.com/arives/rr2/blob/master/R/r2_lik.R#L303 takes the model log-likelihood. But depending on the model fit, this can actually lead to negative values of R2_lik, which seems to contradict your 2019 Syst Biol paperhttps://academic.oup.com/sysbio/article/68/2/234/5098616.

According to the paper, shouldn't you be taking the penalized ML? So LL.r <- mod.r$logLik should be replaced with LL.r <- mod.r$penlogLik in the R2.lik.phyloglm function?

Cheers Andrew

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/arives/rr2/issues/13?email_source=notifications&email_token=ACYX6LD5H3QKKCTNCOURXZ3PY6LWZA5CNFSM4HTVHFBKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GXXVCCA, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACYX6LEXKWBEXBA3MJZX2P3PY6LWZANCNFSM4HTVHFBA.

arives commented 5 years ago

You’re right. But I’m still suspicious about the fitting.

Would you mind sending a file with the data and R script with the analyses so I can take a look? I’m in Iceland doing fieldwork right now, so I can’t guarantee I will look at it immediately. But I’ll try to get back to you quickly.

From: atanzap notifications@github.com Reply-To: arives/rr2 reply@reply.github.com Date: Thursday, June 6, 2019 at 5:49 AM To: arives/rr2 rr2@noreply.github.com Cc: "Anthony R. Ives" arives@wisc.edu, Comment comment@noreply.github.com Subject: Re: [arives/rr2] potential bug in r2_lik.R? (#13)

phyloglm estimates alpha=0.1089099, so that means this isn't the problem?...

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/arives/rr2/issues/13?email_source=notifications&email_token=ACYX6LDXQEP6APAEWQCVQGDPZDTSLA5CNFSM4HTVHFBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXCPBCI#issuecomment-499445897, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACYX6LDKXKD2TCZASAMKMPDPZDTSLANCNFSM4HTVHFBA.

atanzap commented 5 years ago

Sorry for deleting the message. Thought I made a mistake, but didn't. Problem also happens with slightly larger alpha = 0.5.

Yes - will email you now. Thanks for looking at this!

rvosa commented 2 years ago

Hi! We are noticing what might be similar behavior but we are not quite sure. Using a phylolm we attempted to assess phylogenetic signal using Pagel's lambda (if that's even appropriate at all) and had a value of ±0.8, i.e. pretty high signal. Nevertheless, we get negative values for R2.lik.

Here we have a tiny gist that reproduces the behavior: https://gist.github.com/yuxin0406/cb9a80b21d86052ce4af21265c9c79e9

What are we looking at? We're not quite sure?