Skip to content
Prev 9246 / 398502 Next

Avoiding another loop

Sorry, I can now see why I needed to provide more information.

I am trying to use simulation to estimate a likelihood function 
that cannot be evaluated explicitly:  a multinomial probit model
with a spatail autocorrelation parameter for each latent dependent
variable.  "myfunction" generates a single latent observation (for
all latent 
dependent variables less one) for a parameter guess.  Clearly, I
need
to do this many times to get an accurate estimate of the likelihood.

Is a loop the best way to do this?

Thanks much,



Michael J. Roberts
Resource Economics Division, PMT
USDA-ERS
202-694-5557
On Mon, 29 Jan 2001, Michael Roberts wrote:

            
You will need to tell us a lot more. At present it appears that you
are
doing the same calculation nsize times, which is of course easy to
avoid.

Avoiding loops in R is by no mean always useful or effective.  There
are
myths about that go back to long-forgotten versions of S, in which
for
loops were  very much to be avoided.   Up to a point *vectorization*
is
worthwhile, the point being where handling large vectors becones
expensive.