Learn R Programming

dMod (version 0.3.1)

plotArray: Plot an array of model predictions for a list of parameters

Description

Plot an array of model predictions for a list of parameters

Usage

plotArray(parframe, x, times, data = NULL, ..., fixed = NULL, deriv = FALSE, scales = "free", facet = "wrap")

Arguments

parframe
Object of class parframe, e.g. returned by mstrust or profile
x
The model prediction function x(times, pars, fixed, ...)
times
Numeric vector of time points for the model prediction
data
Named list of data.frames as being used in res, i.e. with columns name, time, value and sigma.
...
Further arguments going to subset.
fixed
Named numeric vector with fixed parameters
deriv
Logical. If x supports the argument deriv, it is used.
scales
The scales argument of facet_wrap or facet_grid, i.e. "free", "fixed", "free_x" or "free_y"
facet
Either "wrap" or "grid"

Value

A plot object of class ggplot.

Details

The data.frame being plotted has columns time, value, sigma, name and condition.

Examples

Run this code
## Generate a prediction function
regfn <- c(y = "sin(a*time)")

g <- Y(regfn, parameters = "a")
x <- Xt(condition = "C1")

## Generate data
data <- datalist(
  C1 = data.frame(
    name = "y",
    time = 1:5,
    value = sin(1:5) + rnorm(5, 0, .1),
    sigma = .1
  )
)

## Initialize parameters and time 
pars <- c(a = 1)
times <- seq(0, 5, .1)

plot((g*x)(times, pars), data)

## Do many fits from random positions and store them into parlist
out <- as.parlist(lapply(1:50, function(i) {
  trust(normL2(data, g*x), pars + rnorm(length(pars), 0, 1), rinit = 1, rmax = 10)
}))

summary(out)

## Reduce parlist to parframe
parframe <- as.parframe(out)
plotValues(parframe)

## Reduce parframe to best fit
bestfit <- as.parvec(parframe)
plot((g*x)(times, bestfit), data)

## Plot array with all solutions
plotArray(parframe, g*x, times, data)

Run the code above in your browser using DataLab