R/MCIntegration.R

Defines functions MCIntegration

Documented in MCIntegration

## Function to perform simple multidimensional Monte Carlo integration
#
#	func				-	Integrand function
#	lower				-	Lower limit of integration
#	upper				-	Upper limit of integration
#	initial.step			-	Number of runs to do in the first step
#	step.size			-	Number of runs to do in one time step
#	max.rel.var			-	Maximum relative variance before stopping MC integration
#	max.runs			-	Maximum number of runs before stopping MC integration
#	...				-	Extra parameters to pass to the integrand function
#
MCIntegration <- function(func, lower, upper, initial.step = 10000, step.size = 10000, max.rel.var = .Machine$double.eps^0.25, max.runs = +Inf, ...)
{
	out <- .External("MCIntegration",
		func = as.function(func),
		lower = as.double(lower),
		upper = as.double(upper),
		initial.step = as.integer(initial.step)[1],
		step.size = as.integer(step.size)[1],
		max.rel.var = as.double(max.rel.var)[1],
		max.runs = as.double(max.runs)[1],
		PACKAGE = "ecomodtools",
		...)
	list(
		val = as.double(out[1]),
		abs.var = as.double(out[2]),
		runs = as.integer(out[3]))
}

Try the ecomodtools package in your browser

Any scripts or data that you put into this service are public.

ecomodtools documentation built on May 31, 2017, 2:44 a.m.