Search code examples
rmemoryout-of-memorylogistic-regressionmultinomial

can I set memory size in R?


I'm running this model:

library('nnet')
test <- multinom(events ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10 + X11, data = data)

And I got this error:

Error: cannot allocate vector of size 313.3 Mb

Is there a way to fix this? For example is there somewhere in R that I can set memory, like the "setmem" in Stata? Thanks!


Solution

  • Set the memory limit and extend max number of your R by following commands:

    memory.limit()
    # set max memory usage is 2G
    memory.size(max=2000)
    

    Case like this as Jenny's comments

    memory.size()
    #[1] 104.15
    memory.limit()
    #[1] 7888
    a <- matrix(0, ncol=5000, nrow=5000)
    memory.size()
    #[1] 296.07
    memory.size(max=8000)
    #[1] 8000
    memory.limit()
    #[1] 8000
    memory.size()
    #[1] 297.23
    b <- matrix(0, ncol=10000, nrow=10000)
    memory.size()
    #[1] 1059.07