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

Description Usage Arguments Value Author(s) See Also Examples

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

1
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

Author(s)

Jelmer Ypma

See Also

createSparseGrid createProductRuleGrid createIntegrationGrid integrate pmvnorm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 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 )

Example output

$nodes
            [,1]       [,2]
 [1,] 0.75499596 0.97234641
 [2,] 0.96499186 0.54072204
 [3,] 0.04143077 0.59282472
 [4,] 0.42781219 0.06154794
 [5,] 0.65170944 0.41997357
 [6,] 0.83836923 0.69418905
 [7,] 0.77428539 0.15256392
 [8,] 0.53199270 0.40790202
 [9,] 0.76871572 0.84687155
[10,] 0.78517465 0.43436065

$weights
 [1] 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1

SparseGrid documentation built on May 2, 2019, 4:51 p.m.