Closed sstats2024 closed 1 month ago
Thanks @sstats2024 , can you please include the output you get?
Also please try to install the latest CRAN release and see if the problem persists
Thanks @danielinteractive. I've included the output above. Even after installing the latest version of mmrm, I'm still getting the same output as before.
Hi again @sstats2024 ,
so I ran this on my Macbook, and also get slightly different coefficient estimates each time:
> coef(mmrmfit1)
eye_visitleft_Week0 eye_visitleft_Week4 eye_visitleft_Week8 eye_visitright_Week0
27.2299828 29.2062931 35.7662590 26.6797737
eye_visitright_Week4 eye_visitright_Week8 age
33.3781034 36.9494047 -0.3037041
> coef(mmrmfit2)
age eye_visitleft_Week0 eye_visitleft_Week4 eye_visitleft_Week8
-0.3037215 27.2307519 29.2070622 35.7670281
eye_visitright_Week0 eye_visitright_Week4 eye_visitright_Week8
26.6805428 33.3788725 36.9501738
> c1 <- coef(mmrmfit1)
> c2 <- coef(mmrmfit2)
> setequal(names(c1), names(c2))
[1] TRUE
> c1 - c2[names(c1)]
eye_visitleft_Week0 eye_visitleft_Week4 eye_visitleft_Week8 eye_visitright_Week0
-7.691045e-04 -7.691045e-04 -7.691045e-04 -7.691045e-04
eye_visitright_Week4 eye_visitright_Week8 age
-7.691045e-04 -7.691045e-04 1.736128e-05
> diff_coefs <- c1 - c2[names(c1)]
> diff_coefs
eye_visitleft_Week0 eye_visitleft_Week4 eye_visitleft_Week8 eye_visitright_Week0
-7.691045e-04 -7.691045e-04 -7.691045e-04 -7.691045e-04
eye_visitright_Week4 eye_visitright_Week8 age
-7.691045e-04 -7.691045e-04 1.736128e-05
> rel_diff_coefs <- abs(diff_coefs / c1)
> rel_diff_coefs
eye_visitleft_Week0 eye_visitleft_Week4 eye_visitleft_Week8 eye_visitright_Week0
2.824477e-05 2.633352e-05 2.150363e-05 2.882725e-05
eye_visitright_Week4 eye_visitright_Week8 age
2.304219e-05 2.081507e-05 5.716510e-05
> all(rel_diff_coefs < 1e-3)
[1] TRUE
However, this is completely fine, as both the absolute differences as well as the relative differences are very small. Since we use floating point calculations in the computer, the ordering of the design matrix columns, induced here by the ordering of the covariates in the formula, will slightly influence the results. But these differences don't matter in practice.
You will also see a similar behavior with other modeling packages or methodologies.
If you would like to avoid this, you would have to sort the covariates yourself before putting them in the formula e.g.
Does this solve your question?
Closing because answered and no further replies.
Summary
I tried to fit the following mmrm model, an example I received on Stack Exchange. However, I encountered a bug when I swapped the order of the age and eye_visit variables. It seems a previous post has identified a reproducibility issue, but I am only getting the issue when i swap the order of the variables.
This is my output:
R session info
OS / Environment