coverage: coverage and diagnostic plot functions

View source: R/coverage.R

coverageR Documentation

coverage and diagnostic plot functions

Description

functions for calculating covering proportions for a given strength, and for visualizing those

Usage

coverage(D, t, isInteger=TRUE, verbose=0, start0=TRUE, parallel=1)

coverage_iter(D, t, isInteger=TRUE, start0=TRUE,
       progress=FALSE, abortnot1=FALSE, start.proj=1)

coverplot(coverageD, D=NULL, t=NULL, isInteger=TRUE, start0=TRUE,
    type="projections",
    main=NULL, xlab=NULL, ylab=NULL,
    col=rgb(0,0,1,0.5), las=1, plot=TRUE, ...)

Arguments

D

array

t

small positive integer, interaction strength to be considered

isInteger

logical (default TRUE): are the elements of D all consecutive integers starting with 0 or 1?

verbose

0 (default) returns only four percentages, 1 and 2 return more detail. Anything apart from 1 and 2 behaves like 0.

start0

logical (default TRUE): do the integers start with 0 ? (irrelevant for !isInteger)

parallel

number of threads to be used (default: 1); if increased, package parallel must be available

progress

logical (default FALSE): should a progress bar be printed ?

abortnot1

logical (default FALSE): should the function stop at the first projection for which strength t coverage is not perfect ?

start.proj

integer, the number of the projection to start with in lexicographical order; ignored for abortnot1=FALSE; for abortnot1=TRUE, assumes that all projections up to start.proj - 1 were already successfully checked

coverageD

a class CAcoverage object created by function coverage with at least verbose=1. for verbose less than 2, t must be specified. If coverageD is specified, all arguments referring to the design D, except for t in case of verbosity 1 only, are ignored.

type

"projections" (default) or "tuples"

main

title of plot

xlab, ylab

axis titles

las

orientation of tickmark labels

col

color

plot

logical (default TRUE): generate the plot?

...

further arguments to polygon

Value

Functions coverage and coverage_iter return an object of S3 class CAcoverage, which is a list with elements

total

total proportion of covered t-tuples

ave

average of t-tuple proportions taken over projections

min

the minimum proportion of t-tuples covered among the projections

simple

proportion of projections which are fully covered

tots

coverage with verbose=1: the number of t-tuples for the projections

ncovered

coverage with verbose=1: the number of covered t-tuples for the projections

proportions

coverage with verbose=1: ncovered/tots-tuples for the projection

projections

coverage with verbose=2: the projections in a t-row matrix, a column for each projection

tabs

coverage with verbose=2: a list of tables (for mixed levels CAs) or a matrix (for uniform CAs) that shows the number of coverages for each tuple in each projection; the row order of tabs is the same as is used for the numbering of tuples in notcovered (see next item)

notcovereds

coverage with verbose=2: a list of vectors of position numbers of the not-covered tuples for the projection, where position numbers arise having the left-most factor changing fastest

message

coverage_iter with abortnot1=TRUE: message which projection was the first uncovered one and thus stopped the calculations

The coverplot functions return a list of coordinates x and y, strength t and proportions (from call with verbose=1).

Details

If one only needs a TRUE/FALSE check of whether or not perfect coverage is reached, accompanied by the number of uncovered t-tuples and some examples, function ca_verify of package caverify is much faster than function coverage.

Function coverage_iter calculates the same quantities as function coverage; instead of creating all projections at once, it creates them iteratively, which is slower but doable for large cases for which function coverage fails for memory reasons. This iterative version is, at least at present, not parallelized. It allows a progress bar (which slightly deteriorates run time, e.g., on my Windows 10 machine, about 7 milliseconds per 1000 projections). It also allows to request abortion on encountering the first violation of strength t coverage.
In case of aborting, the function returns NA values for all four metrics, and as a fifth list element, the message at which projection the violation occurred; coverage_iter does not have a verbose argument, but using the verbose argument on printing an object that resulted from an aborted run prints that message.
For abortnot1=TRUE, function runs that did not abort up to a particular iteration can be restarted at the subsequent iteration. The actual restart point will be the first projection starting with the same first element as the requested start.proj e.g., for t=3 and a matrix D with 6 columns, the first ten 3-factor projections start with 1, followed by six projections that start with 2, three projections that start with 3 and a single projection that starts with 4 (10 + 6 + 3 + 1 = 20). start.proj=12 will start with the projection 2:3:4, i.e., the 11th projection, which is the first that starts with 2. For projections that start with 1, the second factor is also relevant for the start position: the first four projections have 2 in the second position, then there are three with 3 in the second position, then two with 4, and finally one with 5. Thus, for start.proj=7, start.proj will be reduced to 5, and the projection is 1:3:4 (the first that starts with 1:3).

Per default, the print method for class CAcoverage prints the first four elements only.

Function coverplot, with type=projections, plots the percentage of projections on the horizontal axis and the coverage on the vertical axis (visualizing the average taken over projections); with type=tuples, the percentage of tuples (i.e., projections as weighted by tuples) is shown on the horizontal axis, visualizing the total percentage covered. Sorting of the combinations on the horizontal axis is from best to worst coverage.

Warning

For function coverage_iter, in case of starting at projection start.now, the user is responsible to ensure that all prior runs have also been checked; the calculated values assume that the prior runs showed perfect coverage.

See Also

caverify::ca_verify()

Examples

## fixed levels
D <- KSK(k=10)
coverage(D, 2)
coverage(D, 3)
## mixed levels, total and ave are different
plan <- cbind(rep(0:2, each=3), c(rep(0:1, 4), 1), c(rep(0:1, each=4),0))
coverage(plan, 2)
## verbose content not printed per default
coverage(plan, 2, verbose=1)
print(coverage(plan, 2, verbose=1), digits=4, verbose=TRUE)
print(coverage(plan, 2, verbose=2), digits=4, verbose=TRUE)
## two of three projections fully covered,
## one covered 5/6 only

cD2 <- coverage(plan, 2, verbose=2)
coverplot(cD2, type="projections") ## 2/3 at 1, 1/3 at 5/6=0.833333
## the not fully covered projection involves the 3-level
## column and thus has 6/(6+6+4)=37.5 pct of the tuples instead of 1/3
coverplot(cD2, type="tuples")

## it is also possible to call coverplot on the design itself
##    however, repeated calls will then require recalculation
##    of coverage, which can be demanding.
##    Where storage space is problematic for verbose=2,
##    working directly with the design may be doable
##    (but time is likely also an issue).
##
coverplot(D=plan, t=2, type="projections")
coverplot(D=plan, t=2, type="tuples")

## the Hadamard based 16 run design for 14 columns
##    that is available from FrF2::pb;
##    the design has levels -1 and 1 and columns are factors
##    therefore, isInteger=FALSE has to be used
if (require(FrF2)){
   CA3.2tothe14 <- FrF2::pb(16, 14)
   print(coverage(CA3.2tothe14, 3, isInteger=FALSE))
   }


CAs documentation built on Nov. 29, 2026, 1:06 a.m.