On Thu, Nov 6, 2014 at 2:05 PM, Matteo Richiardi
wrote:
Final question: in your code you have mean(M[t-1L,]): what is the 'L'
for? I removed it at apparently the code produces the same output...
The constant "1L" is stored as an integer; the constant "1" is stored as
double precisio
Loops are not slow, but your code did a lot of unneeded operations in each
loop.
E.g, you computed
D$id==i & D$t==t
for each row of D. That involves 2*nrow(D) equality tests for each of the
nrow(D)
rows, i.e., it is quadratic in N*T.
Then you did a data.frame replacement operation
D[k,]$y
I find that representing the simulated data as a T row by N column matrix
allows for a clearer and faster simulation function. E.g., compare the
output of the following two functions, the first of which uses your code
and the second a matrix representation (which I convert to a data.frame at
the e
Matteo,
Ah — OK, N=20, I did not catch that. You have nested for loops, which R is
known to be exceedingly slow at handling — if you can reorganize the code
to eliminate the loops, your performance will increase significantly.
Tom
On Thu, Nov 6, 2014 at 7:47 AM, Matteo Richiardi wrote:
> I wis
Matteo,
I tried your example code using R 3.1.1 on an iMac (24-inch, Early 2009), 3.06
GHz Intel Core 2 Duo, 8 GB 1333 MHz DDR3, NVIDIA GeForce GT 130 512 MB
running Mac OS X 10.10 (Yosemite).
After entering your code, the elapsed time from the time I hit return to
when the graphics appeared was
5 matches
Mail list logo