Hi all,

I am trying to implement a Monte-Carlo simulation for each cell in a 
spatial matrix (using mcd2 package) .
I have figured out how to conduct the simulation using data from a single 
location (where I manually input distribution parameters into the R code), 
but am having trouble (a) adjusting the code to pull input variables from 
my various data sets and then (b) applying the entire process across each 
of the cells of the matrices.

I have been doing a lot of reading about loops (a big no-no?), apply, and 
ddply, but can not quite figure it out. 

Here is the situation:

Data: 
I have (for simplicity) 3 spatial raster data sets (each 4848 x 4053 
cells) as ASCII files:
-Poultry density (mean value in each cell) 
-Poultry density (standard deviation in each cell)
-Wild bird density (single estimate in each cell)
I read them into R using read.table. The data look correct:
Pmn <- read.table("D:/Data/PoultryMeans.txt")
Psd <- read.table("D:/Data/PoultryStDev.txt")
Wde <- read.table("D:/Data/WildBirdDensity.txt")

The Model:
In the Monte-Carlo simulation, Poultry and Wild birds have different 
distributions (normal and triangle, respectively).
Below are the 2 lines of code that use the mcstoc function to draw the 
samples.
The values in bold are ones that I would like to draw from the data tables 
I read in above. 
For example, 3.5 would be cell (i,j) in the Poultry MEAN density table; 
0.108 would be cell (i,j) in the Poultry STDEV table; and 47 the single 
estimate for cell (i,j) of the Wild bird density table.

Poultry <- mcstoc(rnorm, type="U", 3.5, 0.108, rtrunc=TRUE, linf=0)
Wild <- mcstoc(rtriang, type="U", min=0, mode=47, max=75)
Risk <- Poultry * Wild        #this is the risk function the MC is applied 
to

Questions:
1) How can I edit the Poultry and Wild variables above to read the data 
values directly from the 3 input tables (i.e., replacing 3.5, 0.108, and 
47 with some variable name for the data table and using a loop?? Or 
somehow use apply or ddply?)
2) Have the entire process be run for every cell in the 4848 x 4053 
matrix?

Thank you for any help you can provide to get me moving forward!
Diann


	[[alternative HTML version deleted]]

