Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Mac arm64 but not Mac emulating x86_64 #727

Closed
wch opened this issue Jun 17, 2023 · 3 comments
Closed

Error on Mac arm64 but not Mac emulating x86_64 #727

wch opened this issue Jun 17, 2023 · 3 comments

Comments

@wch
Copy link

wch commented Jun 17, 2023

Let me preface this by saying that I'm helping somebody track down a problem and I personally don't know much about the stats involved.

I am using lmerTest to run an analysis. (I'm filing the issue here instead of on the lmerTest repository because that package doesn't contain any compiled code so I think the issue is with lme4 or possibly a package that lme4 depends on.)

On an ARM Mac, I get slightly different results when running R in native arm64 mode vs. emulated x86_64 mode. And additionally, I get an error in arm64 mode, but not emulated x86_64.

The versions of R and all packages are the same on both.

I've put data and code for reproducing the problem in this repository, along with HTML files generated by processing the .Rmd file with the code: https://github.com/wch/lme4_error_example

The code is in this Rmd file.

The output HTML files can viewed live with the links below:

Here's a short version of the code:

library(lme4)
library(lmerTest)

df <- read.csv("test.csv", header = TRUE)

model <- lmer(y ~ a + b + c + (1 | d/e), data = df)

confint(model)

On arm64, the confint(model) call results in an error:

## Error in zetafun(np, ns): profiling detected new, lower deviance

On emulated x86_64, it prints out several warnings, and then a table:

##                   2.5 %     97.5 %
## .sig01       0.00000000 10.3137767
## .sig02      11.83166671 12.7200232
## .sigma      11.32296523 12.1691009
## (Intercept) 86.27103207 95.6149757
## a           -5.43474058 -3.5641631
## b            0.09815792  0.1765769
## c            0.22653585  1.4608240

Any ideas why this is happening?

@wch
Copy link
Author

wch commented Jun 17, 2023

Some other differences worth noting. (These are visible if you compare the arm64 result vs x86_64 result pages above.)

When running this:

model <- lmer(y ~ a + b + c + (1 | d/e), data = df)

The x86_64 emits the following warning, but arm64 does not:

Warning: Model failed to converge with 1 negative eigenvalue: -9.2e-01

The model has slightly different values for the e:d random effect. (The values for d and Residual print differently because on x86_64 it prints them in scientific notation, but the values seem to be the same, or close enough.)

#### arm64
## Random effects:
##  Groups   Name        Std.Dev. 
##  e:d      (Intercept)  0.000119
##  d        (Intercept) 12.288666
##  Residual             11.677644

#### x86_64
## Random effects:
##  Groups   Name        Std.Dev. 
##  e:d      (Intercept) 1.397e-04
##  d        (Intercept) 1.229e+01
##  Residual             1.168e+01

The value is 0.000119 (arm) vs 0.0001397, which is obviously a very small difference, but I find it surprising that it is different at all.

@bbolker
Copy link
Member

bbolker commented Jun 18, 2023

I've done a fairly thorough exploration of this here. The very short/tl;dr version is that this appears to be a fit that is numerically fairly unstable (can't say for sure why), that it is not at all surprising that such fits would give different answers across different platforms (CPUs, emulation types, compilers, etc.). The other piece is that you can almost certainly work around this problem by setting a higher value of the optional argument devtol when running confint: the default value is 1e-9, I found that confint(model, devtol = 1e-6) worked fine.

@wch
Copy link
Author

wch commented Jun 19, 2023

Thanks for looking into this. I wasn't aware that there would be differences in numerical results across platforms, but now that I know that, it makes sense that some of these differences could matter for these analyses.

You probably know this, but that .Rmd doesn't build on arm64, because of the expected errors.

@bbolker bbolker closed this as completed Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants