Search code examples
rperformanceplotdistributiondata-fitting

Count number of points outside confidence interval (CI) in qqp (Quantile-Comparison Plot) plot


I've like to find any function for calculated number of points outside confidence interval (CI 95%) in qqp (Quantile-Comparison Plot) plot.

In my example:

Packages

require(MASS)
require(car)

Simulated 60 Poisson values

Resp<-rpois(60,1)

Fitting Binomial negative dstribution

nbinom <- fitdistr(Resp, "Negative Binomial")

Plot using qqp

qqp(Resp, "nbinom", size = nbinom$estimate[[1]], mu = nbinom$estimate[[2]])

qqp plot

Now I would like to use any function for create a vector with the numbers of points outside confidence interval (CI) in qqp (Quantile-Comparison Plot) plot. This is possible? Thanks


Solution

  • qqp() doesn't count the number of points outside the confidence envelope but it computes the information that's needed to get this count. You can simply modify the code (car:::qqPlot.default) if you change:

    outerpoints <- sum(ord.x > upper |  ord.x < lower)
    print(outerpoints)
    if (length(outerpoints) > -1) 
        outerpoints
    else invisible(NULL)
    

    the output show the number of points outside the confidence envelope.