Weird Error with as.array(stanfit)

Very brief post, I have had the same error occurring several times for no apparent reason when I try to transform the stanfit object in an array on R, in order to use mcmc functions, such as mcmc_intervals

post_Experiment <- as.array(Experiment_1)

and the error is this:

Error: cannot allocate vector of size 1.2 Gb

This error happened several times with different simulations, one thing that I noticed is that it always happen with particularly large stanfit. This one is 4.1 GB.

What can I do? Is there a wat to go around it?

1 Like

A sort of solution I found was doing this:

post_Experiment <- as.array(Experiment_1, pars=param)

where I just put the parameter I want to plot, but still I find that it is a very weird error.

1 Like

Hi, I think the error says that you don’t have enough RAM to hold another copy of the fit in memory. So reducing the number of parameters you store is a very natural solution and I don’t think you have many better options… The only other option is IMHO to reduce the number of parameters you keep from sampling, reducing the size of the stanfit object (either by moving transformed parameters to model block or removing unneeded genereated quantities, or by specifying pars when calling sampling) You can also definitely buy more RAM, but I guess that’s not a very appealing solution :-).

Best of luck with your model!

1 Like

Hi Martin, I took a long break from the Stan forum so I saw your reply only now. Thanks a lot for the help though :)