Reputation: 451
I am attempting to build a mixed effects linear regression model using the lmer function in R. I am building a fixed effects and mixed effects model using the following code to justify the use of a mixed effects model by comparing the AICs. I have tried reloading the lme4 package multiple times and restarting between uploads (as recommended in other questions); however, this has not resolved the error. Thank you in advance for any guidance.
`# generate models
m0.glm <- glm(SPL ~ 1, family = Gamma, data = CP)
m0.lmer = lmer(SPL ~ 1 + (1|Lunar), REML = T, data = CP)
`# compare models
AIC(logLik(m0.glm))
AIC(logLik(m0.lmer))
> m0.glm <- glm(SPL ~ 1, family = Gamma, data = CP)
> m0.lmer = lmer(SPL ~ 1 + (1|Lunar), REML = T, data = CP)
Error in initializePtr() :
function 'cholmod_factor_ldetA' not provided by package 'Matrix'`
Upvotes: 45
Views: 67354
Reputation: 11306
Matrix < 1.6-2 and Matrix >= 1.6-2 are binary incompatible. When you change between them, you must re-install from sources packages that link Matrix and therefore depend on the Matrix ABI:
> tools::package_dependencies("Matrix", which = "LinkingTo", reverse = TRUE)[[1L]]
[1] "ahMLE" "bayesWatch" "cplm"
[4] "GeneralizedWendland" "hibayes" "irlba"
[7] "lme4" "mcmcsae" "OpenMx"
[10] "PRIMME" "robustlmm" "spGARCH"
[13] "TMB" "bcSeq"
If you have the required tools [1], then you can re-install lme4 from sources:
utils::install.packages("lme4", type = "source")
If not, then you need to install compatible binaries of Matrix and lme4 from a repository. Not all repositories provide compatible binaries, but CRAN does [2], so the following should work in most cases:
oo <- options(repos = "https://cran.r-project.org/")
utils::install.packages("Matrix")
utils::install.packages("lme4")
options(oo)
Note that binaries in all repositories will be rebuilt automatically once lme4 > 1.1-35.1 is released. At that point, a simple utils::install.packages("lme4")
call will get things working again, even without explicit setting of repos
.
See also my announcement on the R-package-devel mailing list from November 11: https://stat.ethz.ch/pipermail/r-package-devel/2023q4/010054.html
Edit on 2024-05-02 qualifies calls to install.packages
with utils::
. Inexplicably, RStudio masks the function in package utils with its own function that behaves wrongly in this case.
Windows users should install RTools, as described here; macOS users should install the Command Line Tools for Xcode and GNU Fortran, as described here; Linux users should already have the required tools.
For Windows x86_64, macOS x86_64, and macOS arm64; R versions 4.2, 4.3, 4.4.
Upvotes: 46
Reputation: 131
I recieved the same error, but using the binary version (1.5-4) of Matrix fixed it.
Edit: My solution to this error was as described below.
Bolker and Jagan have more insightful contributions
remove.packages("Matrix")
install.packages("Matrix")
Simply click "no" in the pop up about installing from source and compilation.
library(matrix)
Or alternatively this should work
remove.packages("Matrix")
remove.packages("lme4")
install.packages("lme4", type = "source")
library(lme4)
Installing lme4 will also include the Matrix package (a binary version).
However you want to go about it, just make sure you're using a binary version of the Matrix packag (1.5-4 being the latest).
Upvotes: 12
Reputation: 11
I had the same error code. Trying to update/reinstall packages using the code above starting with oo<- led to multiple errors and loops asking about restarting R. However closing R and restarting seems to have solved the problem.
Upvotes: 0