kollerma / robustlmm

This is an R-package for fitting linear mixed effects models in a robust manner. The method is based on the robustification of the scoring equations and an application of the Design Adaptive Scale approach.
28 stars 9 forks source link

saving rlmer objects for future use #10

Closed garthtarr closed 6 years ago

garthtarr commented 6 years ago

With large data sets it can be quite computationally intensive to fit a rlmer model. I'd like to be able to save a fitted object and load it later. This is possible and partly works, but the summary method fails on the loaded object but it didn't fail in the session where the object was initially created, so it seems something (no idea what) is lost in the saving process.

MWE

This works OK:

library("robustlmm")
test = rlmer(Yield ~ (1|Batch), Dyestuff2, method="DASvar")
summary(test)
saveRDS(test, file = "test.rds")

When I start a new session and load in test.rds the print method works, but the summary method gives the error below.

> x = readRDS("test.rds")
> x
Robust linear mixed model fit by DASvar 
Formula: Yield ~ (1 | Batch) 
   Data: Dyestuff2 
Random effects:
 Groups   Name        Std.Dev.
 Batch    (Intercept) 0.000   
 Residual             4.002   
Number of obs: 30, groups: Batch, 6
Fixed Effects:
(Intercept)  
      5.609  
> summary(x)
Error in .External(list(name = "CppMethod__invoke_notvoid", address = <pointer: 0x0>,  : 
  NULL value passed as symbol address
> 
kollerma commented 6 years ago

Hi there,

I have fixed this bug already, but the fixes are on a brach that is not quite but almost ready for prime-time. This is the new rcpp branch.

You can install it using this:

library(devtools)
install_github("kollerma/fastGHQuad")
install_github("kollerma/robustlmm", ref = "rcpp")

The new version of the package depends on a slightly modified version of fastQHQuad, hence you need to install that version first.

Please let me know whether that works for you.

Best, Manuel

garthtarr commented 6 years ago

Hi, thanks for the quick reply!

I can install

install_github("kollerma/robustlmm")

without any problems, however, when I try to install

install_github("kollerma/robustlmm", ref = "rcpp")

it hangs with the following error

In file included from /Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppEigen/include/unsupported/Eigen/SparseExtra:51:
/Library/Frameworks/R.framework/Versions/3.4/Resources/library/RcppEigen/include/unsupported/Eigen/../../Eigen/src/Core/util/ReenableStupidWarnings.h:10:30: warning: pragma diagnostic pop could not pop, no matching push [-Wunknown-pragmas]
    #pragma clang diagnostic pop
                             ^
PsiFunction.cpp:2:10: fatal error: 'robustbase.h' file not found
#include <robustbase.h>
         ^~~~~~~~~~~~~~
17 warnings and 1 error generated.
make: *** [PsiFunction.o] Error 1
ERROR: compilation failed for package ‘robustlmm’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/robustlmm’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/robustlmm’
Installation failed: Command failed (1)

I have the robustbase package installed, and tried explicitly loading it first, but that didn't help either...

garthtarr commented 6 years ago

As an aside, does this also fix the size of the saved object? I find when saving a rlmer object, the file size is way larger than if I'm saving a lmer object. E.g.

library("lme4")
library("robustlmm")
test1 = rlmer(Yield ~ (1|Batch), Dyestuff2, method="DASvar")
saveRDS(test1, file = "test1.rds")
test2 = lmer(Yield ~ (1|Batch), Dyestuff2)
saveRDS(test2, file = "test2.rds")

On my machine the robust object test1.rds is 144KB whereas the lmer object test2.rds is 30KB. The difference is more pronounced for non-trivial examples.

kollerma commented 6 years ago

It looks like that the version of robustbase that you need hasn't been released yet. Try this:

install.packages("robustbase", repos="http://R-Forge.R-project.org")

You might be able to save some space by using rlmerRcpp instead of rlmer, but I doubt it'll be much. The calculations for the robust fit are much more involved, so they are always going to be slower and will need more memory.

kollerma commented 6 years ago

This was fixed with the release of version 2.2-1.