Calculate pseudo-residuals for discrete-valued observations
Calculate pseudo-residuals for discrete-valued observations
For HMMs, pseudo-residuals are used to assess the goodness-of-fit of the model. These are based on the cumulative distribution function (CDF) [REMOVE_ME]FXt(xt)=F(xt∣x1,…,xt−1,xt+1,…,xT)[REMOVEME2]
and can be used to quantify whether an observation is extreme relative to its model-implied distribution.
This function calculates such residuals for discrete-valued observations, based on the local state probabilities obtained by stateprobs or stateprobs_g and the respective parametric family.
obs: vector of discrete-valued observations (of length n)
dist: character string specifying which parametric CDF to use (e.g., "norm" for normal or "pois" for Poisson)
par: named parameter list for the parametric CDF
Names need to correspond to the parameter names in the specified distribution (e.g. list(mean = c(1,2), sd = c(1,1)) for a normal distribution and 2 states). This argument is as flexible as the parametric distribution allows. For example you can have a matrix of parameters with one row for each observation and one column for each state.
stateprobs: matrix of local state probabilities for each observation (of dimension c(n,N), where N is the number of states)
normal: logical, if TRUE, returns Gaussian pseudo residuals
These will be approximately standard normally distributed if the model is correct.
randomise: logical, if TRUE, return randomised pseudo residuals. Recommended for discrete observations.
seed: integer, seed for random number generation
Returns
vector of pseudo residuals
Description
For HMMs, pseudo-residuals are used to assess the goodness-of-fit of the model. These are based on the cumulative distribution function (CDF)
FXt(xt)=F(xt∣x1,…,xt−1,xt+1,…,xT)
and can be used to quantify whether an observation is extreme relative to its model-implied distribution.
This function calculates such residuals for discrete-valued observations, based on the local state probabilities obtained by stateprobs or stateprobs_g and the respective parametric family.
Details
For discrete observations, calculating pseudo residuals is slightly more involved, as the CDF is a step function. Therefore, one can calculate the lower and upper CDF values for each observation. By default, this function does exactly that and then randomly samples the interval in between to give approximately Gaussian psuedo-residuals. If randomise is set to FALSE, the lower, upper and mean pseudo-residuasl are returned.