This function creates an object of class prevR
from a data frame.
as.prevR(data, col, boundary = NULL, proj = "+proj=longlat +datum=WGS84")
data frame, each line corresponding to an observed cluster.
vector identifying the columns of data
to use.clusters
columns names are fixed:
"id" (optional) cluster's identifier.
"x" cluster's longitude.
"y" cluster's latitude.
"n" number of valid observations in the cluster.
"pos" number of positive cases in the cluster.
"wn" (optional) sum of observations weight.
"wpos" (optional) sum of positive cases weight.
"c.type" (optional) type of cluster (used only by plot()
).
See examples.
object of class sf::sf defining the studied area.
projection of clusters coordinates used in data
(longitude and latitude in decimal degrees by default). One of
(i) character: a string accepted by GDAL, (ii) integer, a valid EPSG value
(numeric), or (iii) an object of class crs
, see sf::st_crs()
.
Object of class prevR
Only "x", "y" "n" and "pos" are required in col
.
If "id" is not specified, a numerical identifier will be automatically
created.
If boundary
is not defined (NULL
), a rectangle corresponding to minimal
and maximal coordinates of data
will be used.
boundary
could be the result of the function create.boundary()
.
It's not possible to change projection of data
with as.prevR()
.
Use changeproj()
instead.
prevR
class, create.boundary()
,
changeproj()
, import.dhs()
.
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)
str(dhs)
#> Formal class 'prevR' [package "prevR"] with 4 slots
#> ..@ clusters:'data.frame': 401 obs. of 10 variables:
#> .. ..$ id : int [1:401] 1 10 100 101 102 103 104 105 106 107 ...
#> .. ..$ x : num [1:401] -1.21 -1.79 -2.29 -2.71 -1.96 ...
#> .. ..$ y : num [1:401] 7.29 6.13 5.96 6.04 5.12 ...
#> .. ..$ n : num [1:401] 23 22 22 28 21 21 11 24 23 15 ...
#> .. ..$ pos : num [1:401] 0 0 0 0 3 4 0 1 0 0 ...
#> .. ..$ c.type: Factor w/ 2 levels "Rural","Urban": 1 1 1 1 1 1 1 1 1 1 ...
#> .. ..$ wn : num [1:401] 19.8 19.8 20.2 20.2 20.2 ...
#> .. ..$ wpos : num [1:401] 0 0 0 0 2.88 ...
#> .. ..$ prev : num [1:401] 0 0 0 0 14.3 ...
#> .. ..$ wprev : num [1:401] 0 0 0 0 14.3 ...
#> ..@ boundary:Classes ‘sf’ and 'data.frame': 1 obs. of 1 variable:
#> .. ..$ geometry:sfc_POLYGON of length 1; first list element: List of 1
#> .. .. ..$ : num [1:4056, 1:2] 1.28 1.25 1.23 1.22 1.22 ...
#> .. .. ..- attr(*, "class")= chr [1:3] "XY" "POLYGON" "sfg"
#> .. ..- attr(*, "sf_column")= chr "geometry"
#> .. ..- attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..:
#> .. .. ..- attr(*, "names")= chr(0)
#> .. ..- attr(*, "valid")= logi TRUE
#> ..@ proj :List of 2
#> .. ..$ input: chr "+proj=longlat +datum=WGS84"
#> .. ..$ wkt : chr "GEOGCRS[\"unknown\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.25722"| __truncated__
#> .. ..- attr(*, "class")= chr "crs"
#> ..@ rings : list()
print(dhs)
#> Object of class 'prevR'
#> Number of clusters: 401
#> Number of observations: 8000
#> Number of positive cases: 810
#> The dataset is weighted.
#>
#> National prevalence: 10.12%
#> National weighted prevalence: 10.16%
#>
#> Projection used: +proj=longlat +datum=WGS84
#>
#> Coordinate range
#> min max
#> x -5.37750 3.6850
#> y 4.80326 14.1225
#>
#> Boundary coordinate range
#> xmin ymin xmax ymax
#> -5.518916 4.736723 3.851701 15.082593