evalFunc: Evaluates a function passed as a list with function name and...

Description Usage Arguments Details Value Examples

Description

Evaluates a function passed as a list with function name and named parameters.

Usage

1
evalFunc(x, fun, p = 1)

Arguments

x

Numeric vector where fun will be evaluated. If fun is not a list, x is not used. This parameter was placed first because is a requirement of the statsuniroot function.

fun

A list with the function name and named parameters. See examples.

p

Positive integer with the position in fun of the name of the function. Default to 1.

Details

Evaluates a function in a list with the function name and named parameters. x go to the first input parameter of the function f.

Value

If fun is a list, the evaluation of fun at points x. If f is not a list, the result is the input f.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Example 1: no evaluation because f is already given.
evalFunc(x = 0:2, fun = 1)
evalFunc(x = 0:2, fun = 1:3)

# Example 2: function evaluation
fe <- list(fun = 'dnorm', mean = 3, sd = 2)
evalFunc(x = 0:2, fun = fe) # # dnorm(0:2, mean = 3, sd =2)

# Example 3: Function name not being the first element of the list fe.
fe <- list(mean = 1.5, sd = 2, f = 'dnorm')
evalFunc(x = 0:2, fun = fe, p = 3) # dnorm(0:2, mean = 1.5, sd =2)

# Example 4:
library(empiricalDistribution)
library(bernstein)
ex <- cbind(1:5, c(2, 4, 3, 6, 7)); print(ex)
set.seed(1); ex <- ex[sample(1:5), ]
eDiffEC <- forwardDifference(empiricalCDF2Dcounts(ex))
eu <- 0.3; ev <- 0.1
bernstein2DderivativeX(v = ev, u = eu, diffEC = eDiffEC)
efun <- list(fun = 'bernstein2DderivativeX', u = eu, diffEC = eDiffEC)
evalFunc(x = ev, fun = efun)

mathphysmx/inverseFunction documentation built on May 7, 2019, 10:55 p.m.