sample2pop | R Documentation |
Converts sample count to population count in the square contingency table, assuming a stratified random sampling
sample2pop(ctmatrix, population)
ctmatrix |
matrix representing a sampling-derived square contingency table between a comparison variable (rows) and a reference variable (columns) |
population |
an n x 2 matrix provided to correct the sample count to population count in the square contingency table. See Details below |
The first column of population
must contain integer identifiers of each category, corresponding to the categories in the comparison and reference variables. The second column corresponds to the population totals for each category.
matrix representing a population-adjusted square contingency table for the crosstabulation between a comparison variable (rows) and a reference variable (columns). Output values are given in the same units as ctmatrix
crosstabm
comp <- rast(system.file("external/comparison.rst", package = "diffeR"))
ref <- rast(system.file("external/reference.rst", package = "diffeR"))
# Sample square contingency table
(ctmatCompRef <- crosstabm(comp, ref))
# Population-adjusted square contingency table
(population <- matrix(c(1, 2, 3, 2000, 4000, 6000), ncol = 2))
sample2pop(ctmatCompRef, population = population)
# The square contingency table can also be adjusted directly using the
# crosstabm function
crosstabm(comp, ref, population = population)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.