-2

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!

rawr
  • 20,481
  • 4
  • 44
  • 78
Jenny Shu
  • 47
  • 2
  • 4
  • 12

1 Answers1

3

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
Patric
  • 2,063
  • 17
  • 18
  • 1
    ... if you are on Windows. – Rich Scriven Jan 12 '16 at 04:09
  • @Patric If memory.limit() shows 3000 then it means max is 3000Mb? When you set max = 2000 does that mean 2000 Mb? Just want to clarify on the units. Thanks! – Jenny Shu Jan 12 '16 at 14:53
  • 1
    @JennyShu, yes, 3000 is 3000M and about 3G. – Patric Jan 12 '16 at 15:10
  • @Patric Let me clarify. If I did "memory.size" I get 2000, then "memory.limit()" returns 3000. Then I did "memory.size(max=3000)", and then typed in "memory.size" again, and it is still showing 2000. Did I change things or not? Thanks. – Jenny Shu Jan 12 '16 at 15:31
  • 1
    @JennyShu Yes, you changed the upper bound. `memory.size` tell you how many memory you already used so you type two times and get the same value. Try to allocate more memory after you increased the upper bound. – Patric Jan 13 '16 at 02:40