A function to create the normal conditional (randomized) quantile residuals. The majority of the code and descriptions are taken from Dunsmuir and Scott (2015).
compnormRandPIT(object)
an object class "cmp", obtained from a call to glm.cmp
.
A list consisting of two elements:
the normal conditional randomized quantile residuals
the midpoints of the predictive probability intervals
The function compPredProb
produces the non-randomized probability integral
transform(PIT). It returns estimates of the cumulative predictive probabilities as
upper and lower bounds of a collection of intervals. If the model is correct, a
histogram drawn using these estimated probabilities should resemble a histogram
obtained from a sample from the uniform distribution.
This function aims to produce observations which instead resemble a sample from a normal distribution. Such a sample can then be examined by the usual tools for checking normality, such as histograms and normal Q-Q plots.
For each of the intervals produced by compnormRandPIT
, a random uniform observation
is generated, which is then converted to a normal observation by applying the inverse
standard normal distribution function (using qnorm
). The vector of these values
is returned by the function in the list element rt
. In addition non-random
observations which should appear similar to a sample from a normal distribution
are obtained by applying qnorm
to the mid-points of the predictive distribution
intervals. The vector of these values is returned by the function in the list element
rtMid
.
Berkowitz, J. (2001). Testing density forecasts, with applications to risk management. Journal of Business \& Economic Statistics, 19, 465--474.
Dunn, P. K. and Smyth, G. K. (1996). Randomized quantile residuals. Journal of Computational and Graphical Statistics, 5, 236--244.
Dunsmuir, W.T.M. and Scott, D.J. (2015). The glarma
Package for Observation-Driven
Time Series Regression of Counts. Journal of Statistical Software,
67, 1--36.
data(takeoverbids)
M.bids <- glm.cmp(numbids ~ leglrest + rearest + finrest + whtknght
+ bidprem + insthold + size + sizesq + regulatn, data = takeoverbids)
compnormRandPIT(M.bids)
#> $rt
#> [1] -0.232081869 -2.682847155 -0.703139634 0.141562512 0.217653960
#> [6] 1.090484742 0.140694640 0.233545689 0.223844127 -1.310757771
#> [11] 0.087812476 -0.007566345 0.224157350 0.104574797 0.390417947
#> [16] -0.127400895 0.972469931 0.396715574 0.839440976 -0.199187526
#> [21] 1.885703456 -0.534403970 -0.152151253 0.454238772 -0.818439563
#> [26] -1.077140508 -0.969063033 -0.144275368 1.457422236 -0.176746224
#> [31] 0.013863470 -0.240697664 1.976648638 -0.929899541 -0.789128295
#> [36] 2.886044203 -0.101053615 -0.234921859 -0.050555856 -0.645533602
#> [41] 0.501865740 -0.020855275 -1.583742919 -0.053897914 0.849629700
#> [46] -0.524479594 -1.444596701 -0.647615445 -0.412845950 1.065904585
#> [51] -0.604996238 1.098432214 0.259329691 1.046413162 0.880911785
#> [56] -0.337214621 0.033536319 -0.184295615 0.485276753 0.361690741
#> [61] -1.146364267 0.841851587 -1.778939757 -0.709429644 2.999669622
#> [66] -0.170055480 0.156838565 -0.301187581 0.161909393 -0.156667340
#> [71] -1.511131718 1.407878116 1.104096171 2.617979320 -1.144941706
#> [76] -0.223530689 -0.315859674 0.003286685 0.683085239 0.350097915
#> [81] 0.469652620 -0.807007410 -0.540698048 -0.513277723 0.343630485
#> [86] 0.902303785 2.390445741 0.561459582 -1.158211603 0.128355095
#> [91] -0.546625695 -0.335400327 -0.292532984 -1.102271826 -1.587870160
#> [96] -1.397189172 -2.063878281 -0.752352324 -0.657599753 -0.577137891
#> [101] -0.077102382 -1.734278965 -0.042623065 -0.170043070 -0.367597412
#> [106] 0.875037997 -1.459337672 -0.769328910 -0.104671700 -0.933629148
#> [111] -2.788816268 -0.016688960 -0.347641385 -0.259739213 -0.444712184
#> [116] -0.269057753 0.710076130 2.859472485 0.085566742 1.190991933
#> [121] 0.811860980 2.178867260 0.782185571 0.379208943 -1.211660027
#> [126] -2.586713624
#>
#> $rtMid
#> [1] -0.4898606057 -1.2821938867 -0.9046825634 -0.1188628663 -0.1341943954
#> [6] 0.7653209649 0.2351273795 0.0171245478 0.3047524696 -1.1693426929
#> [11] 0.0792278584 0.1389754521 -0.1034624756 -0.3370842295 0.3110988250
#> [16] 0.1809578920 0.6063865734 0.1827372114 0.4748603624 0.1493556284
#> [21] 2.0323888736 -0.4065244788 -0.0484976126 0.5966832630 -0.7121949356
#> [26] -0.4681955938 -0.4067855844 0.0763118539 1.5778089671 -0.0213205176
#> [31] 0.4153366138 -0.6181257786 1.5710150671 -0.4889168754 -0.6975868864
#> [36] 2.8736704081 0.0293201148 -0.2299245556 -0.5074023916 -0.3107316172
#> [41] 0.0040065545 0.3722261174 -1.0535891327 0.0433498529 0.2062825009
#> [46] -0.6344033284 -1.0333900475 -1.0037282461 0.1400302406 0.6852283194
#> [51] -0.3569787944 0.9064627309 0.3550496840 0.4009327342 1.1722251736
#> [56] -0.5882093509 0.0362166244 0.1670724301 0.3196225942 0.7366028169
#> [61] -1.0515786490 1.0488723314 -1.3465565764 -0.9436796458 3.0214268722
#> [66] 0.1992771107 0.1892685795 -0.3062366882 0.3521605190 0.2239147662
#> [71] -0.9333315837 1.2075756668 1.2234166311 2.2949753838 -1.3122964298
#> [76] 0.1964248365 0.1269481756 0.0006044535 1.0115869876 0.1407696911
#> [81] -0.0423125857 -1.0175105921 -0.7704861895 -0.0680272238 0.0658472524
#> [86] 0.9119777104 1.8459551277 0.7570070434 -0.6610489092 0.1146635070
#> [91] -0.4192417435 -0.6305074008 -0.2280802143 -0.7868264227 -1.8992452803
#> [96] -0.7696441407 -1.2730186285 -0.4626315566 -0.8699211671 -0.1090825303
#> [101] -0.0729589353 -1.2752291754 -0.0714993130 -0.5068596336 0.0602518486
#> [106] 0.9397780470 -1.3557052949 -0.3086795427 -0.0736675540 -0.9880935056
#> [111] -2.2394275128 -0.1111248838 0.0010495723 -0.1014678557 -0.2458562636
#> [116] -0.6169651649 0.6335435906 2.7480914094 0.4121673590 1.3053444188
#> [121] 1.0357631161 1.8208308609 0.5919705281 0.6312364259 -0.9654756216
#> [126] -2.1524864294
#>