.fitCurve2 | R Documentation |
stats::optim
L-BFGS-B with fall-back grid/pattern search
if convergence is not achieved.Function to fit curve via stats::optim
.fitCurve2(
par,
x,
y,
fn,
loss,
lower = -Inf,
upper = Inf,
precision = 1e-04,
density = c(2, 10, 5),
step = 0.5/density,
...,
loss_args = list(),
span = 1,
optim_only = FALSE,
control = list(factr = 1e-08, ndeps = rep(1e-04, times = length(par)), trace = 0)
)
par |
|
x |
|
y |
|
fn |
|
loss |
|
lower |
|
upper |
|
precision |
|
density |
|
step |
initial step size for pattern search. |
... |
|
loss_args |
|
span |
|
optim_only |
|
control |
|
TODO
numeric
Vector of optimal parameters for fn
fit against y
on the values of x
.
## Not run:
# Four parameter hill curve equation
hillEqn <- function(x, Emin, Emax, EC50, lambda) {
(Emin + Emax * (x / EC50)^lambda) / (1 + (x / EC50)^lambda)
}
# Make some dummy data
doses <- rev(1000 / (2^(1:20)))
lambda <- 1
Emin <- 1
Emax <- 0.1
EC50 <- median(doses)
response <- hillEqn(doses, Emin=Emin, lambda=lambda, Emax=Emax, EC50=EC50)
nresponse <- response + rnorm(length(response), sd=sd(response)*0.1) # add noise
# 3-parameter optimization
3par <- .fitCurve2(
par=c(Emax, EC50, lambda),
x=doses,
y=nresponse,
fn=hillEqn,
Emin=Emin, # set this as constant in the function being optimized (via ...)
loss=.normal_loss,
loss_args=list(trunc=FALSE, n=1, scale=0.07),
upper=c(1, max(doses), 6),
lower=c(0, min(doses), 0)
)
# 2-parameter optimization
2par <- .fitCurve2(
par=c(Emax, EC50),
x=doses,
y=nresponse,
fn=hillEqn,
Emin=Emin, # set this as constant in the function being optimized (via ...)
lambda=1,
loss=.normal_loss,
loss_args=list(trunc=FALSE, n=1, scale=0.07),
upper=c(1, max(doses)),
lower=c(0, min(doses))
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.