Skip to content

Instantly share code, notes, and snippets.

Threestates = function(t,state,parameters) {
with(as.list(c(state,parameters)),{
dU = - pBeta*U*V
dI = pBeta*U*V - pDelta*I
dV = pP*I - pC*V
list(c(dU,dI,dV))
})
}
times <- seq(0, 12, by = 0.01)
@kklot
kklot / MetropolisHasting.R
Last active September 28, 2016 11:47
Metropolis Hasting sampling
#' MetropolisAP function
#'
#' Using fixed range covariance adjusting strategy.
#' @export
#' MetropolisAP()
MetropolisAP <- function(
Y, # the data
tData, # corresponding time points
Inits = smidR:::state,# Vector of initial values
model = smidR::UIV, # Model for deSolve
@kklot
kklot / Robust.R
Created September 28, 2016 11:45
Robust correction
#' robustODE function
#'
#' @export
robustODE <- function(LS, init = initPars, crit.Tukey = 0.01, crit.huber = 0.05, optim.ctrl, resODE, maxit = 10) {
environment(LS) <- environment()
if (missing(resODE)) stop("Provide function to calculate residual")
## =========================================================================
## IRLS and robust
## =========================================================================
# 1. Obtain starting values.