Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dynr.model

Create a dynrModel object for parameter estimation (cooking dynr) using dynr.cook


Description

Create a dynrModel object for parameter estimation (cooking dynr) using dynr.cook

Usage

dynr.model(dynamics, measurement, noise, initial, data, ...,
  outfile = tempfile())

Arguments

dynamics

a dynrDynamics object prepared with prep.formulaDynamics or prep.matrixDynamics

measurement

a dynrMeasurement object prepared with prep.loadings or prep.measurement

noise

a dynrNoise object prepared with prep.noise

initial

a dynrInitial object prepared with prep.initial

data

a dynrData object made with dynr.data

...

additional arguments specifying other dynrRecipe objects. Argument regimes is for a dynrRegimes object prepared with prep.regimes and argument transform is for a dynrTrans object prepared with prep.tfun.

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().

Details

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

Value

Object of class 'dynrModel'

Examples

# Create a minimal cooked model called 'model'
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)

dynr

Dynamic Models with Regime-Switching

v0.1.16-2
GPL-3
Authors
Lu Ou [aut], Michael D. Hunter [aut, cre] (<https://orcid.org/0000-0002-3651-6709>), Sy-Miin Chow [aut] (<https://orcid.org/0000-0003-1938-027X>), Linying Ji [aut], Meng Chen [aut], Hui-Ju Hung [aut], Jungmin Lee [aut], Yanling Li [aut], Jonathan Park [aut], Massachusetts Institute of Technology [cph], S. G. Johnson [cph], Benoit Scherrer [cph], Dieter Kraft [cph]
Initial release
2021-03-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.