I have some data that has missing values. I am trying to fit a curve on this data, using Richard’s Model which is
where K is fixed and I am trying to estimate a, \tau, and r. So for any time t, I want to be able to compute I(t) and it should be close to my data. I do have missing points in my time series.
I know how to do this in R
, with the following code (here \tau is replaced with b.
######
richards.model <- function(prm, K, x) {
a = prm[['a']]
b = prm[['b']]
r = prm[['r']]
denom <- (1+exp(-r*a*(x-b)))^(1/a)
res <- K / denom
return(res)
}
errfct <- function(prm,K,dat) {
xx <- dat$t
yy <- richards.model(prm , K=K, x=xx)
return( sum( (yy-dat$cum.cases)^2, na.rm = T))
}
## compute on all data points
K <- 5500
pfit <- optim(par = list(a=2,b=80,r=0.1),
fn = errfct, dat = dat, K=K)
So the optim
function calls the errfct
with an estimate of parameters. The errfct
function simply calculates I(t) with the given parameters, and calculates the sum of square errors. I am assuming the optim
function is trying to minimize the least squares error.
Is there an equivalent package in Julia?