View source: R/residual_functions.R
pseudo_res | R Documentation |
For HMMs, pseudo-residuals are used to assess the goodness-of-fit of the model. These are based on the cumulative distribution function (CDF)
F_{X_t}(x_t) = F(x_t \mid x_1, \dots, x_{t-1}, x_{t+1}, \dots, x_T)
and can be used to quantify whether an observation is extreme relative to its model-implied distribution.
This function calculates such residuals via probability integral transform, based on the local state probabilities obtained by stateprobs
or stateprobs_g
and the respective parametric family.
pseudo_res(
obs,
dist,
par,
stateprobs = NULL,
mod = NULL,
normal = TRUE,
discrete = NULL,
randomise = TRUE,
seed = NULL
)
obs |
vector of continuous-valued observations (of length n) |
dist |
character string specifying which parametric CDF to use (e.g., |
par |
named parameter list for the parametric CDF Names need to correspond to the parameter names in the specified distribution (e.g. |
stateprobs |
matrix of local state probabilities for each observation (of dimension c(n,N), where N is the number of states) as computed by |
mod |
optional model object containing initial distribution If you are using automatic differentiation either with |
normal |
logical, if These will be approximately standard normally distributed if the model is correct. |
discrete |
logical, if By default, will be determined using |
randomise |
for discrete pseudo residuals only. Logical, if |
seed |
for discrete pseudo residuals only. Integer, seed for random number generation |
When used for discrete pseudo-residuals, this function is just a wrapper for pseudo_res_discrete
.
vector of pseudo residuals
## continuous-valued observations
obs = rnorm(100)
stateprobs = matrix(0.5, nrow = 100, ncol = 2)
par = list(mean = c(1,2), sd = c(1,1))
pres = pseudo_res(obs, "norm", par, stateprobs)
## discrete-valued observations
obs = rpois(100, lambda = 1)
stateprobs = matrix(0.5, nrow = 100, ncol = 2)
par = list(lambda = c(1,2))
pres = pseudo_res(obs, "pois", par, stateprobs)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.