dynr.model | R Documentation |
dynr.cook
Create a dynrModel object for parameter estimation (cooking dynr) using dynr.cook
dynr.model(dynamics, measurement, noise, initial, data, ...,
outfile = tempfile())
dynamics |
a dynrDynamics object prepared with |
measurement |
a dynrMeasurement object prepared with |
noise |
a dynrNoise object prepared with |
initial |
a dynrInitial object prepared with |
data |
a dynrData object made with |
... |
additional arguments specifying other dynrRecipe objects. Argument regimes is for
a dynrRegimes object prepared with |
outfile |
a character string of the name of the output C script of model functions to be compiled for parameter estimation. The default is the name for a potential temporary file returned by tempfile(). |
A dynrModel
is a collection of recipes. The recipes are constructed with the functions prep.measurement
, prep.noise
, prep.formulaDynamics
, prep.matrixDynamics
, prep.initial
, and in the case of regime-switching models prep.regimes
. Additionally, data must be prepared with dynr.data
and added to the model.
Several named arguments can be passed into the ...
section of the function. These include
Argument regimes
is for a dynrRegimes object prepared with prep.regimes
Argument transform
is for a dynrTrans object prepared with prep.tfun
.
Argument options
a list of options. Check the NLopt website https://nlopt.readthedocs.io/en/latest/NLopt_Reference/#stopping-criteria
for details. Available options for use with a dynrModel object
include xtol_rel, stopval, ftol_rel, ftol_abs, maxeval, and maxtime,
all of which control the termination conditions for parameter optimization. The examples below show a case where options were set.
There are several available methods for dynrModel
objects.
The dollar sign ($) can be used to both get objects out of a model and to set pieces of the model.
names
returns the names of the free parameters in a model.
printex
prints LaTeX expressions for the equations that compose a model. The output can then be readily typeset for inclusion in presentations and papers.
nobs
gives the total number of observations (e.g. all times across all people)
coef
gives the free parameter starting values. Free parameters can also be assigned with coef(model) <- aNamedVectorOfCoefficients
Object of class 'dynrModel'
# Create a minimal model called 'model'
# without 'cooking' (i.e., estimating parameters)
require(dynr)
meas <- prep.measurement(
values.load=matrix(c(1, 0), 1, 2),
params.load=matrix(c('fixed', 'fixed'), 1, 2),
state.names=c("Position","Velocity"),
obs.names=c("y1"))
ecov <- prep.noise(
values.latent=diag(c(0, 1), 2),
params.latent=diag(c('fixed', 'dnoise'), 2),
values.observed=diag(1.5, 1),
params.observed=diag('mnoise', 1))
initial <- prep.initial(
values.inistate=c(0, 1),
params.inistate=c('inipos', 'fixed'),
values.inicov=diag(1, 2),
params.inicov=diag('fixed', 2))
dynamics <- prep.matrixDynamics(
values.dyn=matrix(c(0, -0.1, 1, -0.2), 2, 2),
params.dyn=matrix(c('fixed', 'spring', 'fixed', 'friction'), 2, 2),
isContinuousTime=TRUE)
data(Oscillator)
data <- dynr.data(Oscillator, id="id", time="times", observed="y1")
# Now here's the model!
model <- dynr.model(dynamics=dynamics, measurement=meas,
noise=ecov, initial=initial, data=data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.