Learn R Programming

qualmap (version 0.2.2)

qm_summarize: Summarize Clusters

Description

This function creates a column that contains a single observation for each unique value in the key variable. For each feature, a count corresponding to the number of times that feature is identified in a cluster for the give category is also provided.

Usage

qm_summarize(ref, key, clusters, category, count, geometry = TRUE, use.na = FALSE)

Value

A tibble or a sf object (if geometry = TRUE) that contains a count of the number of clusters a given feature is included in. The tibble option (when geometry = FALSE) will only return valid features. The sf option (default; when geometry = TRUE) will return all features with either zeros (when use.na = FALSE) or NA values (when use.na = TRUE) for features not included in any clusters.

Arguments

ref

An sf object that serves as a master list of features

key

Name of geographic id variable in the ref object to match input values to

clusters

A tibble created by qm_combine with two or more clusters worth of data

category

Value of the CAT variable to be analyzed

count

How should clusters be summarized: by counting each time a feature is included in a cluster ("clusters") or by counting the number of respondents ("respondents") who associated a feature with the given category.

geometry

A logical scalar that returns the full geometry and attributes of ref when TRUE (default). If FALSE, only the key and count of features is returned after validation.

use.na

A logical scalar that returns NA values in the count variable if a feature is not included in any clusters when TRUE. If FALSE (default), a 0 value is returned in the count variable for each feature that is not included in any clusters. This parameter only impacts output if the geometry argument is TRUE.

See Also

qm_combine

Examples

Run this code
# load and format reference data
stl <- stLouis
stl <- dplyr::mutate(stl, TRACTCE = as.numeric(TRACTCE))

# create clusters
cluster1 <- qm_define(118600, 119101, 119300)
cluster2 <- qm_define(119300, 121200, 121100)

# create cluster objects
cluster_obj1 <- qm_create(ref = stl, key = TRACTCE, value = cluster1,
    rid = 1, cid = 1, category = "positive")
cluster_obj2 <- qm_create(ref = stl, key = TRACTCE, value = cluster2,
    rid = 1, cid = 2, category = "positive")

# combine cluster objects
clusters <- qm_combine(cluster_obj1, cluster_obj2)

# summarize cluster objects
positive1 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive",
    count = "clusters")
class(positive1)
mean(positive1$positive)

# summarize cluster objects with NA's instead of 0's
positive2 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive",
    count = "clusters", use.na = TRUE)
class(positive2)
mean(positive2$positive, na.rm = TRUE)

# return tibble of valid features only
positive3 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive",
    count = "clusters", geometry = FALSE)
class(positive3)
mean(positive3$positive)

# count respondents instead of clusters
positive4 <- qm_summarize(ref = stl, key = TRACTCE, clusters = clusters, category = "positive",
    count = "respondents")
mean(positive4$positive)

Run the code above in your browser using DataLab