OSA-residuals {RTMB} | R Documentation |
Recursive quantile residuals
Description
OSA residuals are computed using the function
oneStepPredict
. For this to work, you need to mark the
observation inside the objective function using the OBS
function. Thereafter, residual calculation is as simple as
oneStepPredict(obj)
. However, you probably want specify a
method
to use.
Usage
oneStepPredict(
obj,
observation.name = names(obj$env$obs)[1],
data.term.indicator = "_RTMB_keep_",
...
)
## S3 method for class 'osa'
x[...]
## S3 method for class 'osa'
length(x)
## S3 method for class 'osa'
dim(x)
## S3 method for class 'osa'
is.array(x)
## S3 method for class 'osa'
is.matrix(x)
Arguments
obj |
TMB model object (output from |
observation.name |
Auto detected - use the default |
data.term.indicator |
Auto detected - use the default |
... |
Passed to |
x |
Object of class 'osa' |
Value
data.frame
with standardized residuals; Same as oneStepPredict.
Functions
-
oneStepPredict()
: Calculate the residuals. See documentation ofTMB::
oneStepPredict. -
[
: Subset observations marked for OSA calculation. This function makes sure that when you subset an observation of class"osa"
such asobs <- new("osa", x=advector(matrix(1:10,2)), keep = cbind(rep(TRUE,10),FALSE,FALSE))
the 'keep' attribute will be adjusted accordinglyobs[,1:2]
-
length(osa)
: Equivalent of length -
dim(osa)
: Equivalent of dim -
is.array(osa)
: Equivalent of is.array -
is.matrix(osa)
: Equivalent of is.matrix
Examples
set.seed(1)
rw <- cumsum(.5*rnorm(20))
obs <- rpois(20, lambda=exp(rw))
func <- function(p) {
obs <- OBS(obs) ## Mark 'obs' for OSA calculation on request
ans <- 0
jump <- c(p$rw[1], diff(p$rw))
ans <- ans - sum(dnorm(jump, sd=p$sd, log=TRUE))
ans <- ans - sum(dpois(obs, lambda=exp(p$rw), log=TRUE))
ans
}
obj <- MakeADFun(func,
parameters=list(rw=rep(0,20), sd=1),
random="rw")
nlminb(obj$par, obj$fn, obj$gr)
res <- oneStepPredict(obj,
method="oneStepGeneric",
discrete=TRUE,
range=c(0,Inf))$residual