Learn R Programming

dMod (version 0.3.1)

normL2: L2 norm between data and model prediction

Description

For parameter estimation and optimization, an objective function is needed. normL2 returns an objective function for the L2 norm of data and model prediction. The resulting objective function can be used for optimization with the trust optimizer, see mstrust.

Usage

normL2(data, x, errmodel = NULL, times = NULL, attr.name = "data")

Arguments

data
object of class datalist
x
object of class prdfn
errmodel
object of class obsfn
times
numeric vector, the time points where the prediction function is to be evaluated. If NULL, time points are extacted from the datalist. If the prediction function makes use of events, times should be set by hand.
attr.name
character. The constraint value is additionally returned in an attributed with this name

Value

Object of class obsfn, i.e. a function obj(..., fixed, deriv, conditions, env) that returns an objective list, objlist.

Details

Objective functions can be combined by the "+" operator, see sumobjfn.

Examples

Run this code
## Generate a prediction function

times <- 0:5
grid <- data.frame(name = "A", time = times, row.names = paste0("p", times))
x <- Xd(grid, condition = "C1")

pars <- structure(rep(0, nrow(grid)), names = row.names(grid))

## Simulate data
data.list <- lapply(1:3, function(i) {
  prediction <- x(times, pars + rnorm(length(pars), 0, 1))
  cbind(wide2long(prediction), sigma = 1)
})

data <- as.datalist(do.call(rbind, data.list))

## Generate objective function based on data and model
## Then fit the data and plot the result
obj <- normL2(data, x)
myfit <- trust(obj, pars, rinit = 1, rmax = 10)
plot(x(times, myfit$argument), data)

Run the code above in your browser using DataLab