mainEff {BayesMassBal} | R Documentation |
Main Effects
Description
Calculates the main effect of a variable, which is independent of process performance, on a function.
Usage
mainEff(
BMBobj,
fn,
rangex,
xj,
N = 50,
res = 100,
hdi.params = c(1, 0.95),
...
)
Arguments
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 |
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 |
Details
The mainEff
function returns a distribution of , marginalized over the samples of
BMBobj$ybal
, giving the distribution of which incorporates uncertainty of a chemical or particulate process.
In the current implementation of mainEff
in the BayesMassBal
package, only uniformly distributed values of are supported.
The 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 . 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!
Value
A list of length(xj)
list(s). Each list specifies output for the main effect of a xj
g |
The grid used for a particular |
fn.out |
A matrix giving results on |
fn |
Character string giving the name of the function used. Same value as argument |
xj |
Integer indicating the index of |
Examples
## 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)