Introduction to prevR"

Sys.setenv(LANG = "en")

This package performs a methodological approach for spatial estimation of regional trends of a prevalence using data from surveys using a stratified two-stage sample design (as Demographic and Health Surveys). In these kind of surveys, positive and control cases are spatially positioned at the centre of their corresponding surveyed cluster.

This package provides functions to estimate a prevalence surface using a kernel estimator with adaptative bandwiths of equal number of persons surveyed (a variant of the nearest neighbour technique) or with fixed bandwiths. The prevalence surface could also be calculated using a spatial interpolation (kriging or inverse distance weighting) after a moving average smoothing based on circles of equal number of observed persons or circles of equal radius.

With the kernel estimator approach, it's also possible to estimate a surface of relative risks.

The methodological approach has been described in:

Application to generate HIV prevalence surfaces can be found at:

Other papers using prevR could be found on Google Scholar.

Importing data

To create a prevR object, you need three elements:

library(prevR, quietly = TRUE)
col <- c(id = "cluster", x = "x", y = "y", n = "n", pos = "pos", c.type = "residence", wn = "weighted.n", wpos = "weighted.pos")
dhs <- as.prevR(fdhs.clusters, col, fdhs.boundary)

An interactive helper function import.dhs() could be used to compute statistics per cluster and to generate the prevR object for those who downloaded individual files (SPSS format) and location of clusters (dbf format) from DHS website (

imported_data <- import.dhs("data.sav", "gps.dbf")

Boudaries of a specific country could be obtained with create.boundary().

Plotting a prevR object

plot(dhs, main = "Clusters position")
plot(dhs, type = "c.type", main = "Clusters by residence")
plot(dhs, type = "count", main = "Observations by cluster")
plot(dhs, type = "flower", main = "Positive cases by cluster")

Changing coordinates projection

plot(dhs, axes = TRUE)
dhs <- changeproj(dhs, "+proj=utm +zone=30 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
plot(dhs, axes = TRUE)

Quick analysis

Function quick.prevR() allows to perform a quick analysis:

qa <- quick.prevR(fdhs, return.results = TRUE, return.plot = TRUE, plot.results = FALSE, progression = FALSE)

Several values of N could be specified, and several options allows you to return detailed results.

res <- quick.prevR(fdhs, N = c(100, 200, 300), return.results = TRUE, return.plot = TRUE, plot.results = FALSE, progression = FALSE, nb.cells = 50)

Step by step analysis

# Calculating rings of the same number of observations for different values of N
dhs <- rings(fdhs, N = c(100, 200, 300, 400, 500), progression = FALSE)

# Prevalence surface for N=300
prev.N300 <- kde(dhs, N = 300, nb.cells = 200, progression = FALSE)
spplot(prev.N300, "k.wprev.N300.RInf", cuts = 100, col.regions =, main = "Regional trends of prevalence (N=300)")

# Surface of rings' radius
radius.N300 <- krige("r.radius", dhs, N = 300, nb.cells = 200)
spplot(radius.N300, cuts = 100, col.regions =, main = "Radius of circle (N=300)")

# ggplot2 graph
res <-
res <- res[!$k.wprev.N300.RInf), ]
ggplot(data = res) +
  aes(x = x, y = y, fill = k.wprev.N300.RInf) +
  geom_raster() +
  scale_fill_gradientn( +
  coord_fixed() +
  theme_prevR_light() +
  labs(fill = "Prevalence (%)")

Functions and methods provided by prevR

The content of prevR can be broken up as follows:


Creating objects

prevR functions takes as input ojects of class prevR.

Data visualisation

Data manipulation

Data analysis

Results visualisation and export

Try the prevR package in your browser

Any scripts or data that you put into this service are public.

prevR documentation built on Aug. 28, 2020, 5:08 p.m.