Generic fundtion that extracts model residuals from a 'mobility.model' object.

residuals(object, type, ...)

Arguments

object

a mobility.model object produced by the mobility function

type

the type of residuals to be returned. Available residual types include: 'deviance' (default), 'pearson', and 'raw'.

...

further arguments passed to or from other methods

Value

a matrix containing model residuals

Details

Residual types are calculated as:

raw

\(y_i - \mu_i\)

pearson

\((y_i - \mu_i)/\sqrt{\mu_i}\)

deviance

\(sign(y_i - \mu_i) * \sqrt(2(log(y_i/\mu_i) - (y_i - \mu_i)))\)

Where, \(y_i\) is the observed data and \(\mu_i\) is the value predicted by the model using the mean of parameter posterior distributions

See also

Other model: check(), compare(), fit_jags(), fit_prob_travel(), mobility(), predict(), summary()

Author

John Giles

Examples

mod <- mobility(data=mobility_matrices, model='gravity', type='transport', DIC=TRUE)
#> ::Fitting transport gravity model for 10 origins and 10 destinations::
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 70 #> Unobserved stochastic nodes: 32 #> Total graph size: 417 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>
residuals(mod, type='pearson')
#> destination #> origin A B C D E F #> A -9.727654 -3.4389996 -8.270340 0.9049681 -9.830448 -3.727131 #> B NA 58.9442623 -13.186808 -18.6951555 -22.040889 NA #> C -13.884195 NA NA -14.3178706 -16.564951 -11.004330 #> D 69.102942 7.5860865 NA -37.7923031 6.437228 6.033682 #> E NA 0.2465985 1.051018 -16.6350061 -1.875854 NA #> F -16.552813 -6.6610458 -6.952761 NA -10.230354 NA #> G -15.096695 -16.8969626 NA NA -21.944888 -15.868190 #> H -19.399215 -20.1684657 NA NA -24.432107 -18.268479 #> I -15.394388 -15.3484793 -11.702817 -14.8247602 -17.810360 -13.227514 #> J 23.209310 NA 3.617761 11.9484837 23.894183 NA #> destination #> origin G H I J #> A 32.317097 24.72611 26.546926 -3.496748 #> B -19.219388 -20.94084 -14.212372 -16.068028 #> C -14.498404 NA -10.955009 -11.916011 #> D 32.473192 NA NA 26.222635 #> E -7.459356 NA -3.805125 NA #> F NA NA NA -12.910245 #> G 21.542908 13.47227 NA NA #> H 3.593597 -41.97874 239.701994 -17.670855 #> I -7.115980 NA NA NA #> J 26.101604 16.37034 NA NA #> attr(,"model") #> [1] "gravity" #> attr(,"type") #> [1] "transport" #> attr(,"residuals") #> [1] "pearson"