ropensci / GLMMcosinor

An R package for flexible cosinor modelling using the glmmTMB framework
https://docs.ropensci.org/GLMMcosinor/
GNU General Public License v3.0
1 stars 0 forks source link

Dropped effects when doing interactions #27

Closed MilaSMayor closed 3 weeks ago

MilaSMayor commented 1 month ago

Dear GLMMcosinor developer,

First at all, I apoligise because I created this issue before, but I did not know that it was sent, my mistake. I just saw it when I got an email that you closed the issue and what you wrote.

Here is the issue with my specific problem.

I am trying to run a cosinor mixed effect model with your package.

The model I am trying to run is related with the interaction of two predictors. Both predictors are binary variables. The number of components is 2, otherwise I get the error:

Error in amp_acro_iteration(time_col = time_col, n_components = n_components,  : 
  Grouping variable in amp_acro() must be of length 1 or the same as n_components

Then, please, see below the example. In the example you will see that when trying to do the interaction I get always the problem that some effects are dropped. I need to say that I have been trying interactions since last week in different examples, and always I get the same.

So, I hope that this report is more explicit than the previous one. My question is related to the dropped effects. I do not think it is correct, but please, maybe I am wrong.

Best,

Mila

> cglmm(
+     original_data ~ P2* P1 +
+         amp_acro(time_col = hour,
+                  n_components = 2,
+                  group = c("P2", "P1"),
+                  period = 24) +
+         (1 | new_ID ),
+     REML=TRUE,
+     data = send)
dropping columns from rank-deficient conditional model: P11:main_rrr2, P11:main_sss2

 Conditional Model 

 Raw formula: 
original_data ~ P2 + P1 + P2*p1 + P2:main_rrr1 + P2:main_sss1 +   P1:main_rrr2 + P1:main_sss2 + (1 | new_ID) 

 Raw Coefficients: 
               Estimate
(Intercept)    78.11819
P2           -1.41628
P11            10.89425
P21:P11        3.72769
P20:main_rrr1 -0.79041
P21:main_rrr1 -0.06033
P20:main_sss1 -2.59294
P21:main_sss1 -1.73536
P10:main_rrr2  -2.76320
P11:main_rrr2        NA
P10:main_sss2   6.13491
P11:main_sss2        NA

 Transformed Coefficients: 
               Estimate
(Intercept)    78.11819
[P2=1]        -1.41628
[P1=1]         10.89425
[P2=1]:[P1=1]  3.72769
[P2=0]:amp1    2.71074
[P2=1]:amp1    1.73641
[P1=0]:amp2     6.72848
[P1=1]:amp2          NA
[P2=0]:acr1   -1.86668
[P2=1]:acr1   -1.60555
[P1=0]:acr2     1.99399
[P1=1]:acr2          NA
MilaSMayor commented 1 month ago

Also, I think that with interaction for two predictors, I must have as well, two other effects, in this case, they would be P1P2rrr and P1P2sss.

RWParsons commented 4 weeks ago

Ahh yeah I see what's going on here. It unnecessarily makes the rrr2 and sss2. There are two components with the same period (one for each group) but it should be fitting the model with an interaction term between P1 and rrr1/sss1 rather than these new variables (rrr2 and sss2). Since rrr1 = rrr2 and sss1= sss2, the model becomes rank deficient and it drops those variables. I'll need to make some changes to the package to avoid this behaviour. I'll keep you updated.

In the meantime, you can use this attached model (I adjusted the formula before the model gets fit so that it has the interactions for both groups with rrr1/sss1). Could you please try this model and see if it is as you'd expect? milas-model.zip

I've made a separate issue (https://github.com/ropensci/GLMMcosinor/issues/29) which is a bit more explicit around the cause of the problem.

RWParsons commented 3 weeks ago

I'm closing this issue as it'll be addressed in #29 (eventually).