Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

epi.cp

Extract unique covariate patterns from a data set


Description

Extract the set of unique patterns from a set of covariates.

Usage

epi.cp(dat)

Arguments

dat

an i row by j column data frame where the i rows represent individual observations and the m columns represent a set of m covariates. The function permits one or more covariates for each observation.

Details

This function extracts the k unique covariate patterns in a data set comprised of i observations, labelling them from 1 to k. The frequency of occurrence of each covariate pattern is listed. A vector of length i is also returned, listing the 1:k covariate pattern identifier for each observation.

Value

A list containing the following:

cov.pattern

a data frame with columns: id the unique covariate pattern identifier (labelled 1 to k), n the number of occasions each of the listed covariate pattern appears in the data, and the unique covariate combinations.

id

a vector of length i listing the 1:k covariate pattern identifier for each observation.

Author(s)

Thanks to Johann Popp and Mathew Jay for providing code and suggestions to enhance the utility of this function.

References

Dohoo I, Martin W, Stryhn H (2003). Veterinary Epidemiologic Research. AVC Inc, Charlottetown, Prince Edward Island, Canada.

Examples

## Generate a set of covariates:
set.seed(seed = 1234)
obs <- round(runif(n = 100, min = 0, max = 1), digits = 0)
v1 <- round(runif(n = 100, min = 0, max = 4), digits = 0)
v2 <- round(runif(n = 100, min = 0, max = 4), digits = 0)
dat <- data.frame(obs, v1, v2)

dat.glm <- glm(obs ~ v1 + v2, family = binomial, data = dat)
dat.mf <- model.frame(dat.glm)

## Covariate pattern:
epi.cp(dat.mf[-1])

## There are 25 covariate patterns in this data set. Subject 100 has
## covariate pattern 21.

epiR

Tools for the Analysis of Epidemiological Data

v2.0.19
GPL (>= 2)
Authors
Mark Stevenson <mark.stevenson1@unimelb.edu.au> and Evan Sergeant <evansergeant@gmail.com> with contributions from Telmo Nunes, Cord Heuer, Jonathon Marshall, Javier Sanchez, Ron Thornton, Jeno Reiczigel, Jim Robison-Cox, Paola Sebastiani, Peter Solymos, Kazuki Yoshida, Geoff Jones, Sarah Pirikahu, Simon Firestone, Ryan Kyle, Johann Popp, Mathew Jay and Charles Reynard.
Initial release
2021-01-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.