#' Wrapper function for use in estimation of data assimilation parameters
#'
#' Return varies depending on output
#'
#' @param par named or unnamed vector of untransformed parameters.
#' @param X an xts object of data
#' @param param a parameter and model object
#' @param output one of param, hydro or error
#'
#' @keywords FloorForT
#' @export
#' @examples
#' # Not Run
#' # ModelBuild()
## wrapper function for use in estimationof da
fssest <- function(par,X,param,output=c("param","hydro","error")){
############ add parameters to structure ############
if(length(par)!=param$mdl[1,'np']){
return(NULL)
}
## mane parameters and add to vector
nms <- paste("Q",1:param$mdl[1,'np'],sep=".")
param$trans[nms] <- exp(par)
## output if the parameters if required
if(output=="param"){
return(param)
}
## call the model
yhat <- fss(param,X)
## output if hydro
if(output=="hydro"){
return(yhat)
}
## compute errors
t0 <- ftinit(X,param$mdl)
t0 <- which(index(X)==t0)
if(output=="error"){
e <- NULL
for(ii in 1:param$mdl[1,'lag']){
idx <- (t0+1+ii):nrow(X)
idx <- idx[ is.finite(X[idx,'output']) ]
e <- c(e, X[idx,'output'] - yhat[idx-ii,paste("f",ii,sep=".")] )
}
idx <- !is.finite(e)
e[idx] <- 2e34
return(e)
}
if(output=="mcp"){
return(yhat)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.