Learn R Programming

SparseGrid (version 0.8.2)

createMonteCarloGrid: Create a multidimensional grid of nodes and weights for Monte Carlo integration

Description

Simulate nodes using a random number generator supplied by the user, and combine these with a vector of equal weights into a list. Sparse grids can be created with the function createSparseGrid.

Usage

createMonteCarloGrid( rng, dimension, num.sim, ... )

Arguments

rng
function that generates random numbers. The first argument of this function should be called n. Examples are the R built-in functions rnorm and runif for random numbers from a standard normal or uniform distribution.
dimension
dimension of the integration problem.
num.sim
number of simulated integration nodes.
...
arguments that will be passed to the random number generator rng.

Value

The return value contains a list with nodes and weights
nodes
matrix with a node in each row
weights
vector with corresponding weights

See Also

createSparseGrid createProductRuleGrid createIntegrationGrid integrate pmvnorm

Examples

Run this code
# load library
library('SparseGrid')

# set random seed
set.seed( 3141 )

# Create Monte Carlo integration grids
# 1. with draws from a uniform distribution
mc.grid <- createMonteCarloGrid( runif, dimension=2, num.sim=10 )
mc.grid

# 2. with draws from a standard normal distribution
mc.grid <- createMonteCarloGrid( rnorm, dimension=3, num.sim=1000 )

# 3. with draws from a normal distribution with mean=2 and sd=5
mc.grid <- createMonteCarloGrid( rnorm, dimension=3, num.sim=1000, mean=2, sd=5 )

Run the code above in your browser using DataLab