# Confidence interval from raster data

I have raster data that represents a probability distribution, i.e. each cell has a probability value (in my case the probability that an animal may be found in the cell), and all the cells add up to 100% (I know for certain the animal is within the extents of my raster). I want to be able to generate vector data for confidence values. For example, the 95% line/polygon denotes the boundary wherein I am 95% confident that I will find the animal.

Similarly, if I have a kernel density estimate, How do I generate the XX% line/polygon that borders the densest part of the raster containing XX% of the total population?

I am willing to use ArcGIS, or open-source software. If there isn't a tool to perform this for me, what is an algorithm I can implement?

Confidence is not an applicable concept, although it is superficially similar. The question sounds rather like you want to identify the smallest region having a total probability at least 95%. This region can be obtained (at least conceptually) by sorting all the probabilities and accumulating them from highest to lowest until the partial sum first equals or exceed 95%, then selecting the cells corresponding to the values that have been accumulated. This leads to a straightforward solution, as exemplified by this R (open source) example:

``````library(raster)
set.seed(17)                   # Seed a reproducible random sequence
nr <- 30                       # Number of rows
nc <- 50                       # Number of columns
#
# Create a zone raster for normalizing the probabilities.
#
zone <- raster(ncol=nc, nrow=nr)
zone[] <- 0
#
# Create a probability raster (for illustrating the algorithm later).
#
p <- raster(ncol=nc, nrow=nr)
p[] <- (1:(nc*nr) - 1/2) / (nc*nr) + rnorm(nc*nr, sd=0.5)
p <- abs(focal(p, ngb=5, run=mean))
z <- zonal(p, zone, stat='sum')
p <- p / z[] # This normalizes p to sum to unity as required
#------------------------------------------------------------------------------#
#
# The algorithm begins here.
#
pvec <- sort(getValues(p), decreasing=TRUE) # The probabilities, sorted
d <- cumsum(pvec)                           # Cumulative probabilities
dpos <- d[d <= 0.95]                        # Position to stop
region <- p                                 # Initialize the output
region[p < pvec[length(dpos)]] <- NA        # Exclude the last 5% of the probability
plot(region)                                # Display the result
``````

Here is the resulting image of the 95% probability region with the original probabilities shown in color: they sum to just over 95%, by construction, and eliminating even the smallest value will reduce the sum to less than 95%. The white area at the top includes the remaining 5% of the probability outside this region. The desired contour is the boundary between the white cells and the colored cells. The same method will work on a KDE grid.

There is no straightforward ArcGIS solution for this problem.

• Ha ha, superficial correctly describes my understanding of probability. Thanks so much for a) correctly interpreting my poorly worded question, and b) providing a clear answer. – Regan Sarwas Feb 2 '12 at 17:12

In ArcGIS...

• Spatial Statistics Tools > Reclass > Reclassify Tool
• Create 2 reclassify methods:
• OldValues = 0-94.99 | NewValues = 0
OldValues = 95-100 | NewValues = 1

This will create a new raster with 2 values, 0 = outside confidence interval, 1 = inside 95% confidence interval.

• Conversion Tools > From Raster > Raster to Polygon tool
• Input = Reclassed Raster
Field = Value

This will create a vector polygon with 2 FIDs, one with the shape of your 95% confidence interval and the other your remaining raster area. I would suggest exploring the simplify option to see what results would suit your needs better.

FYI, apply the same method to get the polygons for your Kernal Density estimates.

• Perhaps I wasn't clear (I'm not very good with probability). To restate, the total of the values in all my cells is 1.0, so with a uniform distribution in a 100x100 grid, each cell would have a value of 1/10000. Now imagine the cell values vary from some slightly larger number near the center to values of zero near the edges (still totaling 1.0). If I start removing cells with the smallest values, eventually I will be left with a total of 0.95. How do I do this so I can reclassify as you have suggested. – Regan Sarwas Feb 1 '12 at 23:02
• Strange, fromy understanding of using rasters to display statistical representation of data, your probability value (cell value) would be anywhere from 0 to 100 (or in your case 0 to 1), and the distribution of these values (cell values) would represent a normal distribytion. – Michael Markieta Feb 1 '12 at 23:19
• If true, than we can reclassify the data using the method suggested above, albeit substitutig values of .9499 and .95 for 94.99 and 95 – Michael Markieta Feb 1 '12 at 23:20
• This solution does not reflect the grid described in the question. Think of the input grid as representing a discrete two-dimensional probability distribution rather than being a "statistical representation of data." In practical cases (medium to large grids, moderately well distributed animal range) most of the probabilities will be extremely small, far less than 95%, so the reclassification will merely wipe out all the information: everything turns to zero. – whuber Feb 2 '12 at 2:11