Title: | Estimation of an Ordinary Differential Equation Model by Parameter Cascade Method |
---|---|
Description: | An implementation of the parameter cascade method Ramsay, J. O., Hooker,G., Campbell, D., and Cao, J. (2007) <doi:10.1111/j.1467-9868.2007.00610.x> for estimating ordinary differential equation models with missing or complete observations. It combines smoothing method and profile estimation to estimate any non-linear dynamic system. The package also offers variance estimates for parameters of interest based on either bootstrap or Delta method. |
Authors: | Haixu Wang [aut, cre], Jiguo Cao [aut] |
Maintainer: | Haixu Wang <[email protected]> |
License: | GPL |
Version: | 0.9.4 |
Built: | 2024-11-14 06:01:13 UTC |
Source: | https://github.com/alex-haixuw/pcode |
Obtaining an estimate of variance for structural parameters by bootstrap method.
bootsvar(data, time, ode.model,par.names,state.names, likelihood.fun = NULL, par.initial, basis.list, lambda = NULL,bootsrep,controls = NULL)
bootsvar(data, time, ode.model,par.names,state.names, likelihood.fun = NULL, par.initial, basis.list, lambda = NULL,bootsrep,controls = NULL)
data |
A data frame or a matrix contain observations from each dimension of the ODE model. |
time |
A vector contain observation times or a matrix if time points are different between dimensions. |
ode.model |
An R function that computes the time derivative of the ODE model given observations of states variable and structural parameters. |
par.names |
The names of structural parameters defined in the 'ode.model'. |
state.names |
The names of state variables defined in the 'ode.model'. |
likelihood.fun |
A likelihood function passed to PCODE in case of that the error termsdevtools::document()do not have a Normal distribution. |
par.initial |
Initial value of structural parameters to be optimized. |
basis.list |
A list of basis objects for smoothing each dimension's observations. Can be the same or different across dimensions. |
lambda |
Penalty parameter. |
bootsrep |
Bootstrap sample to be used for estimating variance. |
controls |
A list of control parameters. Same as the controls in |
boots.var The bootstrap variance of each structural parameters.
Obtaining variance of structural parameters by Delta method.
deltavar(data, time, ode.model,par.names,state.names, likelihood.fun, par.initial, basis.list, lambda,stepsize,y_stepsize,controls)
deltavar(data, time, ode.model,par.names,state.names, likelihood.fun, par.initial, basis.list, lambda,stepsize,y_stepsize,controls)
data |
A data frame or a matrix contain observations from each dimension of the ODE model. |
time |
A vector contain observation times or a matrix if time points are different between dimensions. |
ode.model |
An R function that computes the time derivative of the ODE model given observations of states variable and structural parameters. |
par.names |
The names of structural parameters defined in the 'ode.model'. |
state.names |
The names of state variables defined in the 'ode.model'. |
likelihood.fun |
A likelihood function passed to PCODE in case of that the error termsdevtools::document()do not have a Normal distribution. |
par.initial |
Initial value of structural parameters to be optimized. |
basis.list |
A list of basis objects for smoothing each dimension's observations. Can be the same or different across dimensions. |
lambda |
Penalty parameter. |
stepsize |
Stepsize used in estimating partial derivatives with respect to structural parameters for the Delta method. |
y_stepsize |
Stepsize used in estimating partial derivatives with respect to observations for the Delta method. |
controls |
A list of control parameters. Same as the controls in |
par.var The variance of structural parameters obtained by Delta method.
An objective function combines the sum of squared error of basis expansion estimates and the penalty controls how those estimates fail to satisfies the ODE model
innerobj(basis_coef, ode.par, input, derive.model,NLS)
innerobj(basis_coef, ode.par, input, derive.model,NLS)
basis_coef |
Basis coefficients for interpolating observations given a basis object. |
ode.par |
Structural parameters of the ODE model. |
input |
Contains dependencies for the optimization, including observations, penalty parameter lambda, and etc.. |
derive.model |
The function defines the ODE model and is the same as the ode.model in 'pcode' |
NLS |
Default is |
residual.vec |
Vector of residuals and evaluation of penalty function on quadrature points for approximating the integral. |
An objective function combines the likelihood or loglikelihood of errors from each dimension of state variables and the penalty controls how the state estimates fail to satisfy the ODE model.
innerobj_lkh(basis_coef, ode.par, input, derive.model, likelihood.fun)
innerobj_lkh(basis_coef, ode.par, input, derive.model, likelihood.fun)
basis_coef |
Basis coefficients for interpolating observations given a basis boject. |
ode.par |
Structural parameters of the ODD model. |
input |
Contains dependencies for the optimization, including observations, ode penalty, and etc.. |
derive.model |
The function defines the ODE model and is the same as the ode.model in 'pcode'. |
likelihood.fun |
The likelihood or loglikelihood function of the errors. |
obj.eval The evaluation of the inner objective function.
An objective function combines the likelihood or loglikelihood of errors from each dimension of state variables and the penalty controls how the state estimates fail to satisfy the ODE model.
innerobj_lkh_1d(basis_coef, ode.par, input, derive.model, likelihood.fun)
innerobj_lkh_1d(basis_coef, ode.par, input, derive.model, likelihood.fun)
basis_coef |
Basis coefficients for interpolating observations given a basis boject. |
ode.par |
Structural parameters of the ODD model. |
input |
Contains dependencies for the optimization, including observations, ode penalty, and etc.. |
derive.model |
The function defines the ODE model and is the same as the ode.model in 'pcode'. |
likelihood.fun |
The likelihood or loglikelihood function of the errors. |
obj.eval The evaluation of the inner objective function.
An objective function combines the sum of squared error of basis expansion estimates and the penalty controls how those estimates fail to satisfies the ODE model
innerobj_multi(basis_coef, ode.par, input, derive.model,NLS)
innerobj_multi(basis_coef, ode.par, input, derive.model,NLS)
basis_coef |
Basis coefficients for interpolating observations given a basis object. |
ode.par |
Structural parameters of the ODE model. |
input |
Contains dependencies for the optimization, including observations, penalty parameter lambda, and etc.. |
derive.model |
The function defines the ODE model and is the same as the |
NLS |
Default is |
residual.vec |
Vector of residuals and evaluation of penalty function on quadrature points for approximating the integral. |
An objective function combines the sum of squared error of basis expansion estimates and the penalty controls how those estimates fail to satisfies the ODE model
innerobj_multi_missing(basis_coef, ode.par, input, derive.model,NLS)
innerobj_multi_missing(basis_coef, ode.par, input, derive.model,NLS)
basis_coef |
Basis coefficients for interpolating observations given a basis object. |
ode.par |
Structural parameters of the ODE model. |
input |
Contains dependencies for the optimization, including observations, penalty parameter lambda, and etc.. |
derive.model |
The function defines the ODE model and is the same as the ode.model in 'pcode' |
NLS |
Default is |
residual.vec |
Vector of residuals and evaluation of penalty function on quadrature points for approximating the integral. |
Obtain the solution to minimize the sum of squared errors of the defined function fun
by levenberg-marquardt method. Adapted from PRACMA package.
nls_optimize(fun, x0, ..., options,verbal)
nls_optimize(fun, x0, ..., options,verbal)
fun |
The function returns the vector of weighted residuals. |
x0 |
The initial value for optimization. |
... |
Parameters to be passed for |
options |
Additional optimization controls. |
verbal |
Default = 1 for printing iteration and other for suppressing |
par |
The solution to the non-linear least square problem, the same size as |
Obtain the solution to minimize the sum of squared errors of the defined function fun
by levenberg-marquardt method. Adapted from PRACMA package.
nls_optimize.inner(fun, x0, ..., options)
nls_optimize.inner(fun, x0, ..., options)
fun |
The function returns the vector of weighted residuals. |
x0 |
The initial value for optimization. |
... |
Parameters to be passed for |
options |
Additional optimization controls. |
par |
The solution to the non-linear least square problem, the same size as |
An objective function of the structural parameter computes the measure of fit.
outterobj(ode.parameter, basis.initial, derivative.model, inner.input, NLS)
outterobj(ode.parameter, basis.initial, derivative.model, inner.input, NLS)
ode.parameter |
Structural parameters of the ODE model. |
basis.initial |
Initial values of the basis coefficients for nonlinear least square optimization. |
derivative.model |
The function defines the ODE model and is the same as the ode.model in 'pcode' |
inner.input |
Input that will be passed to the inner objective function. Contains dependencies for the optimization, including observations, penalty parameter lambda, and etc.. |
NLS |
Default is |
residual |
Vector of residuals and evaluation of penalty function on quadrature points for approximating the integral. |
An objective function of the structural parameter computes the measure of fit.
outterobj_lkh(ode.parameter, basis.initial, derivative.model, likelihood.fun, inner.input)
outterobj_lkh(ode.parameter, basis.initial, derivative.model, likelihood.fun, inner.input)
ode.parameter |
Structural parameters of the ODE model. |
basis.initial |
Initial values of the basis coefficients for nonlinear least square optimization. |
derivative.model |
The function defines the ODE model and is the same as the ode.model in 'pcode' |
likelihood.fun |
The likelihood or loglikelihood function of the errors. |
inner.input |
Input that will be passed to the inner objective function. Contains dependencies for the optimization, including observations, penalty parameter lambda, and etc.. |
neglik The negative of the likelihood or the loglikelihood function that will be passed further to the 'optim' function.
An objective function of the structural parameter computes the measure of fit.
outterobj_lkh_1d(ode.parameter, basis.initial, derivative.model, likelihood.fun, inner.input)
outterobj_lkh_1d(ode.parameter, basis.initial, derivative.model, likelihood.fun, inner.input)
ode.parameter |
Structural parameters of the ODE model. |
basis.initial |
Initial values of the basis coefficients for nonlinear least square optimization. |
derivative.model |
The function defines the ODE model and is the same as the ode.model in 'pcode' |
likelihood.fun |
The likelihood or loglikelihood function of the errors. |
inner.input |
Input that will be passed to the inner objective function. Contains dependencies for the optimization, including observations, penalty parameter lambda, and etc.. |
neglik The negative of the likelihood or the loglikelihood function that will be passed further to the 'optim' function.
An objective function of the structural parameter computes the measure of fit for the basis expansion.
outterobj_multi_missing(ode.parameter, basis.initial, derivative.model, inner.input, NLS)
outterobj_multi_missing(ode.parameter, basis.initial, derivative.model, inner.input, NLS)
ode.parameter |
Structural parameters of the ODE model. |
basis.initial |
Initial values of the basis coefficients for nonlinear least square optimization. |
derivative.model |
The function defines the ODE model and is the same as the ode.model in 'pcode' |
inner.input |
Input that will be passed to the inner objective function. Contains dependencies for the optimization, including observations, penalty parameter lambda, and etc.. |
NLS |
Default is |
residual |
Vector of residuals and evaluation of penalty function on quadrature points for approximating the integral. |
An objective function of the structural parameter computes the measure of fit for the basis expansion.
outterobj_multi_nls(ode.parameter, basis.initial, derivative.model, inner.input, NLS)
outterobj_multi_nls(ode.parameter, basis.initial, derivative.model, inner.input, NLS)
ode.parameter |
Structural parameters of the ODE model. |
basis.initial |
Initial values of the basis coefficients for nonlinear least square optimization. |
derivative.model |
The function defines the ODE model and is the same as the |
inner.input |
Input that will be passed to the inner objective function. Contains dependencies for the optimization, including observations, penalty parameter lambda, and etc.. |
NLS |
Default is |
residual |
Vector of residuals and evaluation of penalty function on quadrature points for approximating the integral. |
Obtain estimates of both structural and nuisance parameters of an ODE model by parameter cascade method.
pcode(data, time, ode.model, par.names, state.names, likelihood.fun, par.initial, basis.list,lambda,controls)
pcode(data, time, ode.model, par.names, state.names, likelihood.fun, par.initial, basis.list,lambda,controls)
data |
A data frame or a matrix contain observations from each dimension of the ODE model. |
time |
A vector contain observation times or a matrix if time points are different between dimensions. |
ode.model |
An R function that computes the time derivative of the ODE model given observations of states variable and structural parameters. |
par.names |
The names of structural parameters defined in the 'ode.model'. |
state.names |
The names of state variables defined in the 'ode.model'. |
likelihood.fun |
A likelihood function passed to PCODE in case of that the error terms do not have a Normal distribution. |
par.initial |
Initial value of structural parameters to be optimized. |
basis.list |
A list of basis objects for smoothing each dimension's observations. Can be the same or different across dimensions. |
lambda |
Penalty parameter for controling the fidelity of interpolation. |
controls |
A list of control parameters. See Details. |
The controls
argument is a list providing addition inputs for the nonlinear least square optimizer or general optimizer optim
:
nquadpts
Determine the number of quadrature points for approximating an integral. Default is 101.
smooth.lambda
Determine the smoothness penalty for obtaining initial value of nuisance parameters.
tau
Initial value of Marquardt parameter. Small values indicate good initial values for structural parameters.
tolx
Tolerance for parameters of objective functions. Default is set at 1e-6.
tolg
Tolerance for the gradient of parameters of objective functions. Default is set at 1e-6.
maxeval
The maximum number of evaluation of the outter optimizer. Default is set at 20.
structural.par |
The structural parameters of the ODE model. |
nuisance.par |
The nuisance parameters or the basis coefficients for interpolating observations. |
library(fda) library(deSolve) library(MASS) library(pracma) #Simple ode model example #define model parameters model.par <- c(theta = c(0.1)) #define state initial value state <- c(X = 0.1) #Define model for function 'ode' to numerically solve the system ode.model <- function(t, state,parameters){ with(as.list(c(state,parameters)), { dX <- theta*X*(1-X/10) return(list(dX)) }) } #Observation time points times <- seq(0,100,length.out=101) #Solve the ode model desolve.mod <- ode(y=state,times=times,func=ode.model,parms = model.par) #Prepare for doing parameter cascading method #Generate basis object for interpolation and as argument of pcode #21 konts equally spaced within [0,100] knots <- seq(0,100,length.out=21) #order of basis functions norder <- 4 #number of basis funtions nbasis <- length(knots) + norder - 2 #creating Bspline basis basis <- create.bspline.basis(c(0,100),nbasis,norder,breaks = knots) #Add random noise to ode solution for simulating data nobs <- length(times) scale <- 0.1 noise <- scale*rnorm(n = nobs, mean = 0 , sd = 1) observation <- desolve.mod[,2] + noise #parameter estimation pcode(data = observation, time = times, ode.model = ode.model, par.initial = 0.1, par.names = 'theta',state.names = 'X', basis.list = basis, lambda = 1e2)
library(fda) library(deSolve) library(MASS) library(pracma) #Simple ode model example #define model parameters model.par <- c(theta = c(0.1)) #define state initial value state <- c(X = 0.1) #Define model for function 'ode' to numerically solve the system ode.model <- function(t, state,parameters){ with(as.list(c(state,parameters)), { dX <- theta*X*(1-X/10) return(list(dX)) }) } #Observation time points times <- seq(0,100,length.out=101) #Solve the ode model desolve.mod <- ode(y=state,times=times,func=ode.model,parms = model.par) #Prepare for doing parameter cascading method #Generate basis object for interpolation and as argument of pcode #21 konts equally spaced within [0,100] knots <- seq(0,100,length.out=21) #order of basis functions norder <- 4 #number of basis funtions nbasis <- length(knots) + norder - 2 #creating Bspline basis basis <- create.bspline.basis(c(0,100),nbasis,norder,breaks = knots) #Add random noise to ode solution for simulating data nobs <- length(times) scale <- 0.1 noise <- scale*rnorm(n = nobs, mean = 0 , sd = 1) observation <- desolve.mod[,2] + noise #parameter estimation pcode(data = observation, time = times, ode.model = ode.model, par.initial = 0.1, par.names = 'theta',state.names = 'X', basis.list = basis, lambda = 1e2)
Obtain estiamtes of structural parameters of an ODE model by parameter cascade method.
pcode_1d(data, time, ode.model, par.initial,par.names, basis,lambda,controls = list())
pcode_1d(data, time, ode.model, par.initial,par.names, basis,lambda,controls = list())
data |
A data frame or a vector contains observations from the ODE model. |
time |
The vector contain observation times. |
ode.model |
Defined R function that computes the time derivative of the ODE model given observations of states variable. |
par.initial |
Initial value of structural parameters to be optimized. |
par.names |
The names of structural parameters defined in the 'ode.model'. |
basis |
A basis objects for smoothing observations. |
lambda |
Penalty parameter. |
controls |
A list of control parameters. See ‘Details’. |
structural.par |
The structural parameters of the ODE model. |
nuisance.par |
The nuisance parameters or the basis coefficients for interpolating observations. |
Obtain estimates of both structural and nuisance parameters of an ODE model by parameter cascade method.
pcode_lkh(data, likelihood.fun, time, ode.model, par.names, state.names, par.initial, basis.list, lambda, controls)
pcode_lkh(data, likelihood.fun, time, ode.model, par.names, state.names, par.initial, basis.list, lambda, controls)
data |
A data frame or a matrix contain observations from each dimension of the ODE model. |
likelihood.fun |
A function computes the likelihood or the loglikelihood of the errors. |
time |
A vector contains observation ties or a matrix if time points are different between dimesion. |
ode.model |
An R function that computes the time derivative of the ODE model given observations of states variable and structural parameters. |
par.names |
The names of structural parameters defined in the 'ode.model'. |
state.names |
The names of state variables defined in the 'ode.model'. |
par.initial |
Initial value of structural parameters to be optimized. |
basis.list |
A list of basis objects for smoothing each dimension's observations. Can be the same or different across dimensions. |
lambda |
Penalty parameter. |
controls |
A list of control parameters. See ‘Details’. |
The controls
argument is a list providing addition inputs for the nonlinear least square optimizer:
nquadpts
Determine the number of quadrature points for approximating an integral. Default is 101.
smooth.lambda
Determine the smoothness penalty for obtaining initial value of nuisance parameters.
tau
Initial value of Marquardt parameter. Small values indicate good initial values for structural parameters.
tolx
Tolerance for parameters of objective functions. Default is set at 1e-6.
tolg
Tolerance for the gradient of parameters of objective functions. Default is set at 1e-6.
maxeval
The maximum number of evaluation of the optimizer. Default is set at 20.
structural.par |
The structural parameters of the ODE model. |
nuisance.par |
The nuisance parameters or the basis coefficients for interpolating observations. |
Obtain estimates of both structural and nuisance parameters of an ODE model by parameter cascade method.
pcode_lkh_1d(data, likelihood.fun, time, ode.model, par.names, state.names, par.initial, basis.list, lambda, controls)
pcode_lkh_1d(data, likelihood.fun, time, ode.model, par.names, state.names, par.initial, basis.list, lambda, controls)
data |
A data frame or a matrix contain observations from each dimension of the ODE model. |
likelihood.fun |
A function computes the likelihood or the loglikelihood of the errors. |
time |
A vector contains observation ties or a matrix if time points are different between dimesion. |
ode.model |
An R function that computes the time derivative of the ODE model given observations of states variable and structural parameters. |
par.names |
The names of structural parameters defined in the 'ode.model'. |
state.names |
The names of state variables defined in the 'ode.model'. |
par.initial |
Initial value of structural parameters to be optimized. |
basis.list |
A list of basis objects for smoothing each dimension's observations. Can be the same or different across dimensions. |
lambda |
Penalty parameter. |
controls |
A list of control parameters. See ‘Details’. |
The controls
argument is a list providing addition inputs for the nonlinear least square optimizer:
nquadpts
Determine the number of quadrature points for approximating an integral. Default is 101.
smooth.lambda
Determine the smoothness penalty for obtaining initial value of nuisance parameters.
tau
Initial value of Marquardt parameter. Small values indicate good initial values for structural parameters.
tolx
Tolerance for parameters of objective functions. Default is set at 1e-6.
tolg
Tolerance for the gradient of parameters of objective functions. Default is set at 1e-6.
maxeval
The maximum number of evaluation of the optimizer. Default is set at 20.
structural.par |
The structural parameters of the ODE model. |
nuisance.par |
The nuisance parameters or the basis coefficients for interpolating observations. |
Obtain estiamtes of both structural and nuisance parameters of an ODE model by parameter cascade method when the dynamics are partially observed.
pcode_missing(data, time, ode.model, par.names, state.names, likelihood.fun,par.initial, basis.list,lambda,controls)
pcode_missing(data, time, ode.model, par.names, state.names, likelihood.fun,par.initial, basis.list,lambda,controls)
data |
A data frame or a matrix contain observations from each dimension of the ODE model. |
time |
A vector contain observation times or a matrix if time points are different between dimensions. |
ode.model |
An R function that computes the time derivative of the ODE model given observations of states variable and structural parameters. |
par.names |
The names of structural parameters defined in the 'ode.model'. |
state.names |
The names of state variables defined in the 'ode.model'. |
likelihood.fun |
A likelihood function passed to PCODE in case of that the error termsdevtools::document()do not have a Normal distribution. |
par.initial |
Initial value of structural parameters to be optimized. |
basis.list |
A list of basis objects for smoothing each dimension's observations. Can be the same or different across dimensions. |
lambda |
Penalty parameter. |
controls |
A list of control parameters. See Details. |
The controls
argument is a list providing addition inputs for the nonlinear least square optimizer or general optimizer optim
:
nquadpts
Determine the number of quadrature points for approximating an integral. Default is 101.
smooth.lambda
Determine the smoothness penalty for obtaining initial value of nuisance parameters.
tau
Initial value of Marquardt parameter. Small values indicate good initial values for structural parameters.
tolx
Tolerance for parameters of objective functions. Default is set at 1e-6.
tolg
Tolerance for the gradient of parameters of objective functions. Default is set at 1e-6.
maxeval
The maximum number of evaluation of the optimizer. Default is set at 20.
structural.par |
The structural parameters of the ODE model. |
nuisance.par |
The nuisance parameters or the basis coefficients for interpolating observations. |
Calculate all basis functions over observation time points and store them as columns in a single matrix for each dimension. Also include first and second order derivative. Repeat over quadrature points.
prepare_basis(basis, times, nquadpts)
prepare_basis(basis, times, nquadpts)
basis |
A basis object. |
times |
The vector contain observation times for corresponding dimension. |
nquadpts |
Number of quadrature points will be used later for approximating integrals. |
Phi.mat |
Evaluations of all basis functions stored as columns in the matrix. |
Qmat |
Evaluations of all basis functions over quadrature points stored as columns in the matrix. |
Q.D1mat |
Evaluations of first order derivative all basis functions over quadrature points stored as columns in the matrix. |
Q.D2mat |
Evaluations of second order derivative all basis functions over quadrature points stored as columns in the matrix. |
quadts |
Quadrature points. |
quadwts |
Quadrature weights. |
Obtain the optimal sparsity parameter given a search grid based on cross validation score with replications.
tunelambda(data, time, ode.model, par.names, state.names, par.initial, basis.list,lambda_grid,cv_portion,kfolds, rep,controls)
tunelambda(data, time, ode.model, par.names, state.names, par.initial, basis.list,lambda_grid,cv_portion,kfolds, rep,controls)
data |
A data frame or matrix contrain observations from each dimension of the ODE model. |
time |
The vector contain observation times or a matrix if time points are different between dimensions. |
ode.model |
Defined R function that computes the time derivative of the ODE model given observations of states variable. |
par.names |
The names of structural parameters defined in the 'ode.model'. |
state.names |
The names of state variables defined in the 'ode.model'. |
par.initial |
Initial value of structural parameters to be optimized. |
basis.list |
A list of basis objects for smoothing each dimension's observations. Can be the same or different across dimensions. |
lambda_grid |
A search grid for finding the optimial sparsity parameter lambda. |
cv_portion |
A number indicating the proportion of data will be saved for doing cross validation. Default is set at 5 as minimum. |
kfolds |
A number indicating the number of folds the data should be seprated into. |
rep |
A integer controls the number of replication of doing cross-validation for each penalty parameter. |
controls |
A list of control parameters. See ‘Details’. |
lambda_grid |
The original input vector of a search grid for the optimal lambda. |
cv.score |
The matrix contains the cross validation score for each lambda of each replication |