1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
\name{epi.cp}
\alias{epi.cp}
\title{
Extract unique covariate patterns from a data set
}
\description{
Extract the set of unique patterns from a set of covariates (explanatory variables).
}
\usage{
epi.cp(dat)
}
\arguments{
\item{dat}{an \emph{i} row by \emph{j} column data frame where the \emph{i} rows represent individual observations and the \emph{m} columns represent a set of \emph{m} covariates. The function allows for one or more covariates for each observation.}
}
\details{
This function extracts the \emph{k} unique covariate patterns in a data set comprised of \emph{i} observations, labelling them from 1 to \emph{k}. The frequency of occurrence of each covariate pattern is listed. A vector of length \emph{i} is also returned, listing the 1:\emph{k} covariate pattern identifier for each observation.
}
\value{
A list containing the following:
\item{cov.pattern}{a data frame with columns: \code{id} the unique covariate pattern identifier (labelled 1 to \emph{k}), \code{n} the number of occasions each of the listed covariate pattern appears in the data, and the unique covariate combinations.}
\item{id}{a vector of length \emph{i} listing the 1:\emph{k} covariate pattern identifier for each observation.}
}
\author{
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{
## EXAMPLE 1:
## 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.df01 <- data.frame(obs, v1, v2)
dat.glm01 <- glm(obs ~ v1 + v2, family = binomial, data = dat.df01)
dat.mf01 <- model.frame(dat.glm01)
## Covariate pattern. Drop the first column of dat.mf01 (since column 1 is the
## outcome variable:
epi.cp(dat.mf01[,2:3])
## There are 25 covariate patterns in this data set. Subject 100 has
## covariate pattern 21.
}
\keyword{univar}
|