[R-sig-hpc] function to combine results from foreach

Maas James Dr (MED) J.Maas at uea.ac.uk
Thu Jan 20 13:17:31 CET 2011


I've got foreach to produce some nice results for me, using doMPI but having great difficulty extracting the results.  Would anyone give me some clues about how to write an appropriate function that would combine results from iterative execution of a MCMC (jags) routine?

In this toy example the foreach iterates through jags 3 times. However jags itself iterates 5,000 times but is thinned to 1,000 results.  Therefore to get the mean of the 1000 posterior means from jags I use 

logOR <-  data.frame(apply(results$logOR, c(1,2), mean))

therefore the results from the 3 iterations of jags are:

> results
[[1]]
         X1         X2         X3
1 0.0000000 -0.2929320 -0.5835677
2 0.2929320  0.0000000 -0.2906358
3 0.5835677  0.2906358  0.0000000

[[2]]
         X1         X2         X3
1 0.0000000 -0.2269787 -0.6619444
2 0.2269787  0.0000000 -0.4349657
3 0.6619444  0.4349657  0.0000000

[[3]]
         X1         X2         X3
1 0.0000000 -0.2465974 -0.5616317
2 0.2465974  0.0000000 -0.3150343
3 0.5616317  0.3150343  0.0000000

If I can, what I want to do is combine these 3 matrices, and getting the mean matrix.  I've tried using .combine="+" bu t get an error message.

Error in fun(result.1, result.2) : 
  non-numeric argument to binary operator

I'd like to get back 
>results
[[1]]
	X1		X2		X3
1	0.00		-0.25		-0.60
2	0.25		0.00		-0.34
3	0.60		0.34		0.00


Any suggestions most welcome.  Thanks

J
===============================
Dr. Jim Maas
University of East Anglia



More information about the R-sig-hpc mailing list