Learn R Programming

lgcp (version 1.8)

MonteCarloAverage: MonteCarloAverage function

Description

This function creates an object of class MonteCarloAverage. The purpose of the function is to compute Monte Carlo expectations online in the function lgcpPredict, it is set in the argument gridmeans of the argument output.control.

Usage

MonteCarloAverage(funlist, lastonly = TRUE)

Arguments

funlist

a character vector of names of functions, each accepting single argument Y

lastonly

compute average using only time T? (see ?lgcpPredict for definition of T)

Value

object of class MonteCarloAverage

Details

A Monte Carlo Average is computed as: $$E_{\pi(Y_{t_1:t_2}|X_{t_1:t_2})}[g(Y_{t_1:t_2})] \approx \frac1n\sum_{i=1}^n g(Y_{t_1:t_2}^{(i)})$$ where \(g\) is a function of interest, \(Y_{t_1:t_2}^{(i)}\) is the \(i\)th retained sample from the target and \(n\) is the total number of retained iterations. For example, to compute the mean of \(Y_{t_1:t_2}\) set, $$g(Y_{t_1:t_2}) = Y_{t_1:t_2},$$ the output from such a Monte Carlo average would be a set of \(t_2-t_1\) grids, each cell of which being equal to the mean over all retained iterations of the algorithm (NOTE: this is just an example computation, in practice, there is no need to compute the mean on line explicitly, as this is already done by defaul in lgcpPredict). For further examples, see below. The option last=TRUE computes, $$E_{\pi(Y_{t_1:t_2}|X_{t_1:t_2})}[g(Y_{t_2})],$$ so in this case the expectation over the last time point only is computed. This can save computation time.

See Also

setoutput, lgcpPredict, GAinitialise, GAupdate, GAfinalise, GAreturnvalue, exceedProbs

Examples

Run this code
# NOT RUN {
fun1 <- function(x){return(x)}   # gives the mean
fun2 <- function(x){return(x^2)} # computes E(X^2). Can be used with the 
                                 # mean to compute variances, since 
                                 # Var(X) = E(X^2) - E(X)^2
fun3 <- exceedProbs(c(1.5,2,3))  # exceedance probabilities, 
                                 #see ?exceedProbs
mca <- MonteCarloAverage(c("fun1","fun2","fun3"))
mca2 <- MonteCarloAverage(c("fun1","fun2","fun3"),lastonly=TRUE)
# }

Run the code above in your browser using DataLab