# FUNCTION to compute the a-posteriori error.

### Description

For a sampling scheme designed to substantiate freedom from disease the function computes the a-posteriori alpha-error, i.e., the actual alpha-error based on the drawn sample.

### Usage

1 2 | ```
computeAposterioriError(alphaErrorVector, nPopulation,
nDiseased, method = "default")
``` |

### Arguments

`alphaErrorVector` |
Numeric vector. Alpha-error (between 0 and 1) of each herd in the sample. |

`nPopulation` |
Integer. Population size, i.e., total numer of herds in the population. |

`nDiseased` |
Integer. Number of diseased herds in the population according to the design prevalence. |

`method` |
Character string. "exact" for exact error, "approx" for approximation (recommended for nDiseased > 7). |

### Details

The exact evaluation of the alpha-error is computationally complex, due
to combinatirical issues. In order to increase effectivity parts of the code
were implemented in C. Still, for `nDiseased`

> 7 the computation may take
very long and it is generally not recommended to use the exact calculation. Rather
the approximation should be used for `nDiseased`

> 7.

### Value

The return value is the a-posteriori alpha-error based on the sample at hand (numeric scalar).

### Author(s)

Ian Kopacka <ian.kopacka@ages.at>

### Examples

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ```
## Freedom from disease using limited sampling with sampleSizeLtd = 7.
## Data: sheep holdings in state "Steiermark".
######################################################################
data(sheepData)
popVec <- sheepData$nSheep[sheepData$state == 6]
N1 <- length(popVec)
sampleSizeLtd <- 7
intraHerdPrev <- 0.13
designPrev <- 0.002
nDiseased <- round(designPrev*N1)
## Draw the sample:
n1 <- 1560
samplePop <- sample(x = popVec, size = n1, replace = FALSE, prob = NULL)
## Compute alpha-errors for the sample:
alphaList <- computeAlphaLimitedSampling(stockSizeVector = samplePop,
sampleSizeLtd = sampleSizeLtd,
intraHerdPrevalence = intraHerdPrev,
diagSensitivity = 0.9, diagSpecificity = 1)
alphaDataFrame <- merge(x = data.frame(size = samplePop),
y = alphaList$alphaDataFrame, by = "size", all.x = TRUE, all.y = FALSE)
## Compute the a-posteriori alpha-error:
alphaAPostApprox <- computeAposterioriError(alphaErrorVector =
alphaDataFrame$alpha, nPopulation = N1, nDiseased = nDiseased,
method = "approx")
alphaAPostExact <- computeAposterioriError(alphaErrorVector =
alphaDataFrame$alpha, nPopulation = N1, nDiseased = nDiseased,
method = "exact")
``` |