mainEff | R Documentation |
Calculates the main effect of a variable, which is independent of process performance, on a function.
mainEff( BMBobj, fn, rangex, xj, N = 50, res = 100, hdi.params = c(1, 0.95), ... )
BMBobj |
A |
fn |
A character string naming a function with arguments of |
rangex |
A numeric matrix. Each column of |
xj |
Integer indexing which element in x is used for conditioning for E_x\lbrack f(x,y)|x_j\rbrack. If a vector is supplied the marginal main effect of each element is calculated sequentially. The integers supplied in |
N |
Integer specifying the length of the sequence used for |
res |
Integer indicating the number of points to be used for each Monte-Carlo integration step. Larger |
hdi.params |
Numeric vector of length two, used to calculate Highest Posterior Density Interval (HPDI) of the main effect |
... |
Extra arguments passed to the named |
The mainEff
function returns a distribution of E_x\lbrack f(x,y)|x_j\rbrack, marginalized over the samples of BMBobj$ybal
, giving the distribution of E_x\lbrack f(x,y)|x_j\rbrack which incorporates uncertainty of a chemical or particulate process.
In the current implementation of mainEff
in the BayesMassBal
package, only uniformly distributed values of x are supported.
The f(x,y) is equivalent to the supplied function named in mainEff(fn)
. For the arguments of fn
, ybal
is structured in a similar manner as BMBobj$ybal
. The only difference being individual columns of each matrix are used at a time, and are vectorized. Note the way ybal
is subset in the example function fn_example
. The supplied X
is a matrix, with columns corresponding to each element in x. The output to fn
must be a vector of length nrow(x)
. The first argument of fn
must be X
, the second argument must be BMBobj$ybal
. Order of other arguments passed to fn
through ...
does not matter. Look at the example closely for details!
A list of length(xj)
list(s). Each list specifies output for the main effect of a xj
|
The grid used for a particular |
|
A matrix giving results on E_x\lbrack f(x,y)|x_j\rbrack. If |
|
Character string giving the name of the function used. Same value as argument |
|
Integer indicating the index of x corresponding to a grouped |
## Importing Data, generating BMB object y <- importObservations(file = system.file("extdata", "twonode_example.csv", package = "BayesMassBal"), header = TRUE, csv.params = list(sep = ";")) C <- matrix(c(1,-1,0,-1,0,0,1,-1,0,-1), byrow = TRUE, ncol = 5, nrow = 2) X <- constrainProcess(C = C) BMB_example <- BMB(X = X, y = y, cov.structure = "indep", BTE = c(10,200,1), lml = FALSE, verb=0) fn_example <- function(X,ybal){ cu.frac <- 63.546/183.5 feed.mass <- ybal$CuFeS2[1] + ybal$gangue[1] ## Concentrate mass per ton feed con.mass <- (ybal$CuFeS2[3] + ybal$gangue[3])/feed.mass ## Copper mass per ton feed cu.mass <- (ybal$CuFeS2[3]*cu.frac)/feed.mass gam <- c(-1,-1/feed.mass,cu.mass,-con.mass,-cu.mass,-con.mass) f <- X %*% gam return(f) } rangex <- matrix(c(4.00 ,6.25,1125,1875,3880,9080,20,60,96,208,20.0,62.5), ncol = 6, nrow = 2) mE_example <- mainEff(BMB_example, fn = "fn_example",rangex = rangex,xj = 3, N = 15, res = 4)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.