dynr.model: Create a dynrModel object for parameter estimation (cooking...

View source: R/dynrModel.R

dynr.modelR Documentation

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

dynr documentation built on May 29, 2024, 2:49 a.m.