[R-sig-Geo] Monte Carlo with mc2d

Vijay Lulla vijaylulla at gmail.com
Tue Jan 30 20:36:16 CET 2018


Return the min,mean,max values as a list of numbers and calc will create a
RasterStack.  ?`calc` states that 'calc' returns a RasterBrick if 'fun'
returns more than one number.  Below are a few minor changes I had to make
to your function.

fun <- function(x) {
  # Convert each raster to mcnode object
  dA <- mcdata(x[1], type="0")
  dB <- mcdata(x[2], type="0")
  dC <- mcdata(x[3], type="0")
  dD <- mcdata(x[4], type="0")

  # Define uniform distirbutions for each raster
  stA <- mcstoc(runif, type="U", min=dA-uA, max=dA+uA, rtrunc=TRUE, linf=0)
# modified: fixed typo!
  stB <- mcstoc(runif, type="U", min=dA-uB, max=dA+uB, rtrunc=TRUE, linf=0)
  stC <- mcstoc(runif, type="U", min=dA-uC, max=dA+uC, rtrunc=TRUE, linf=0)
  stD <- mcstoc(runif, type="U", min=dA-uD, max=dA+uD, rtrunc=TRUE, linf=0)

  # Apply Monte Carlo to this equation
  CL <- stA + stB + stC + stD
  # Extract the min, mean, and max CL from the 1000 iterations
  c(min(CL), mean(CL), max(CL))  # modified: return vector of numbers
}

HTH,
Vijay.


On Tue, Jan 30, 2018 at 11:23 AM, Todd McDonnell <
todd.mcdonnell at esenvironmental.com> wrote:

> Hi all,
>
>
>
> I posted a question to Stack Overflow a couple weeks ago regarding Monte
> Carlo simulation with mc2d with no replies:
>
> https://stackoverflow.com/questions/48306933/grid-based-
> monte-carlo-simulati
> on-using-mc2d
>
>
>
> Might anyone here have a suggestion for how to address the error?
>
>
>
> My approach is largely based on this advice:
>
> http://r-sig-geo.2731867.n2.nabble.com/apply-monte-carlo-
> simulation-for-each
> -cell-in-a-matrix-originally-raster-td7367094.html#a7367555
>
>
>
> Thanks in advance for any suggestions,
>
> Todd
>
>
>
> --
>
> Todd McDonnell
>
> Research Scientist, Ph.D.
>
> E&S Environmental Chemistry
>
> 2161 NW Fillmore Ave., Corvallis, OR
>
>
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
Vijay Lulla, Ph.D.

Assistant Professor,
Dept. of Geography, IUPUI
425 University Blvd, CA-207C.
Indianapolis, IN-46202
vlulla at iupui.edu

<http://vijaylulla.com>
http://vijaylulla.com

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list