I will wind this thread up with some happy comments. I have indeed succeeded in constructing an R program to do the same thing as my Fortran program for an EM algorithm. I have not done timings yet but it seems to run acceptably fast for my purposes.

The key code to be replaced was the E and the M steps of the algorithm. I decided to try to replace all the loops with matrix operations such as %*%, t(), crossprod(), tcrossprod(). Other operations that I used were of the form
                   A + v

where dim(A) = c(a, b) and length(v) = a. Here the vector v operates term by term down columns, recycling for each new column. [ *, - and / also work similarly.]

I was relived that matrices were as far as I needed to go, and I had visions of having to use tensor products of higher dimensioned arrays. Fortunately it did not come to that.

I didn't actually translate from F to R. The original is itself a translation of my underlying maths, and it was easier to translate the maths into R directly.

I preserved the form of my Fortran input and output files so that I will be able to run either version on the same files.

As I mentioned earlier the main point of doing all this is so that I may try out some variants of the program. I expect this will be much easier to do in R!

Thanks to all who replied.

Murray

--
Dr Murray Jorgensen      http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: m...@waikato.ac.nz                                Fax 7 838 4155
Phone  +64 7 838 4773 wk    Home +64 7 825 0441   Mobile 021 0200 8350

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to