Compute the Relative Risk Estimate
Description
This function calculates the relative risk estimate for a 2x2 table of cell counts defined by a categorical response variable and a categorical explanatory (stressor) variable for an unequal probability design. Relative risk is the ratio of two probabilities: the numerator is the probability that the first level of the response variable is observed given occurrence of the first level of the stressor variable, and the denominator is the probability that the first level of the response variable is observed given occurrence of the second level of the stressor variable. The standard error of the base e log of the relative risk estimate and confidence limits for the estimate also are calculated.
Usage
1 2 3 4 5 6  relrisk.est(response, stressor, response.levels=c("Poor", "Good"),
stressor.levels=c("Poor", "Good"), wgt, xcoord=NULL, ycoord=NULL,
stratum=NULL, cluster=NULL, wgt1=NULL, xcoord1=NULL, ycoord1=NULL,
popcorrect=FALSE, pcfsize=NULL, N.cluster=NULL, stage1size=NULL,
support=NULL, sizeweight=FALSE, swgt=NULL, swgt1=NULL, vartype="Local",
conf=95, check.ind=TRUE, warn.ind=NULL, warn.df=NULL, warn.vec=NULL)

Arguments
response 
the categorical response variable values. 
stressor 
the categorical explanatory (stressor) variable values. 
response.levels 
category values (levels) for the categorical response variable, where the first level is used for calculating the numerator and the denominator of the relative risk estimate. If response.levels is not supplied, then values "Poor" and "Good" are used for the first level and second level of the response variable, respectively. The default is c("Poor", "Good"). 
stressor.levels 
category values (levels) for the categorical stressor variable, where the first level is used for calculating the numerator of the relative risk estimate and the second level is used for calculating the denominator of the estimate. If stressor.levels is not supplied, then values "Poor" and "Good" are used for the first level and second level of the stressor variable, respectively. The default is c("Poor", "Good"). 
wgt 
the final adjusted weight (inverse of the sample inclusion probability) for each site, which is either the weight for a singlestage sample or the stage two weight for a twostage sample. 
xcoord 
xcoordinate for location for each site, which is either the xcoordinate for a singlestage sample or the stage two xcoordinate for a twostage sample. The default is NULL. 
ycoord 
ycoordinate for location for each site, which is either the ycoordinate for a singlestage sample or the stage two ycoordinate for a twostage sample. The default is NULL. 
stratum 
the stratum for each site. The default is NULL. 
cluster 
the stage one sampling unit (primary sampling unit or cluster) code for each site. The default is NULL. 
wgt1 
the final adjusted stage one weight for each site. The default is NULL. 
xcoord1 
the stage one xcoordinate for location for each site. The default is NULL. 
ycoord1 
the stage one ycoordinate for location for each site. The default is NULL. 
popcorrect 
a logical value that indicates whether finite or continuous population correction factors should be employed during variance estimation, where TRUE = use the correction factors and FALSE = do not use the correction factors. The default is FALSE. To employ the correction factor for a singlestage sample, values must be supplied for arguments pcfsize and support. To employ the correction factor for a twostage sample, values must be supplied for arguments N.cluster, stage1size, and support. 
pcfsize 
size of the resource, which is required for calculation of finite and continuous population correction factors for a singlestage sample. For a stratified sample this argument must be a vector containing a value for each stratum and must have the names attribute set to identify the stratum codes. The default is NULLL. 
N.cluster 
the number of stage one sampling units in the resource, which is required for calculation of finite and continuous population correction factors for a twostage sample. For a stratified sample this variable must be a vector containing a value for each stratum and must have the names attribute set to identify the stratum codes. The default is NULL. 
stage1size 
size of the stage one sampling units of a twostage sample, which is required for calculation of finite and continuous population correction factors for a twostage sample and must have the names attribute set to identify the stage one sampling unit codes. For a stratified sample, the names attribute must be set to identify both stratum codes and stage one sampling unit codes using a convention where the two codes are separated by the & symbol, e.g., "Stratum 1&Cluster 1". The default is NULL. 
support 
the support value for each site  the value one (1) for a site from a finite resource or the measure of the sampling unit associated with a site from an extensive resource, which is required for calculation of finite and continuous population correction factors. The default is NULL. 
sizeweight 
a logical value that indicates whether sizeweights should be used in the analysis, where TRUE = use the sizeweights and FALSE = do not use the sizeweights. The default is FALSE. 
swgt 
the sizeweight for each site, which is the stage two sizeweight for a twostage sample. The default is NULL. 
swgt1 
the stage one sizeweight for each site. The default is NULL. 
vartype 
the choice of variance estimator, where "Local" = local mean estimator and "SRS" = SRS estimator. The default is "Local". 
conf 
the confidence level. The default is 95%. 
check.ind 
a logical value that indicates whether compatability checking of the input values is conducted, where TRUE = conduct compatibility checking and FALSE = do not conduct compatibility checking. The default is TRUE. 
warn.ind 
a logical value that indicates whether warning messages were generated, where TRUE = warning messages were generated and FALSE = warning messages were not generated. The default is NULL. 
warn.df 
a data frame for storing warning messages. The default is NULL. 
warn.vec 
a vector that contains names of the population type, the subpopulation, and an indicator. The default is NULL. 
Details
The relative risk estimate is computed using the ratio of a numerator probability to a denominator probability, which are estimated using cell and marginal totals from a 2x2 table of cell counts defined by a categorical response variable and a categorical stressor variable (Van Sickle and Paulsen, 2008). An estimate of the numerator probability is provided by the ratio of the cell total defined by the first level of the response variable and the first level of the stressor variable to the marginal total for the first level of the stressor variable. An estimate of the denominator probability is provided by the ratio of the cell total defined by the first level of response variable and the second level of the stressor variable to the marginal total for the second level of the stressor variable. Cell and marginal totals are estimated using the HorvitzThompson estimator. The standard error of the base e log of the relative risk estimate is calculated using a firstorder Taylor series linearization (Sarndal et al., 1992).
Value
If the function was called by the relrisk.analysis function, then value is a list containing the following components:

Results
 a list containing estimates, confidence bounds, and associated values 
warn.ind
 a logical value indicating whether warning messages were generated 
warn.df
 a data frame containing warning messages
If the function was called directly, then value is the Results list, which contains the following components:

RelRisk
 the relative risk estimate 
RRnum
 numerator ("elevated" risk) of the relative risk estimate 
RRdenom
 denominator ("baseline" risk) of the relative risk estimate 
RRlog.se
 standard error for the log of the relative risk estimate 
ConfLimits
 confidence limits for the relative risk estimate 
WeightTotal
 sum of the final adjusted weights 
CellCounts
 cell and margin counts for the 2x2 table 
CellProportions
 estimated cell proportions for the 2x2 table
Author(s)
Tom Kincaid Kincaid.Tom@epa.gov
Tony Olsen Olsen.Tony@epa.gov
John Vansickle Vansickle.John@epa.gov
References
Van Sickle, J. and S. G. Paulsen. (2008). Assessing the attributable risks,
relative risks, and regional extent of aquatic stressors. Journal of the
North American Benthological Society 27, 920931.
Sarndal, C.E., B. Swensson, and J. Wretman. (1992). Model Assisted
Survey Sampling. SpringerVerlag, New York.
Examples
1 2 3 4 5 6 7 8  response < sample(c("Poor", "Good"), 100, replace=TRUE)
stressor < sample(c("Poor", "Good"), 100, replace=TRUE)
wgt < runif(100, 10, 100)
relrisk.est(response, stressor, wgt=wgt, vartype="SRS")
xcoord < runif(100)
ycoord < runif(100)
relrisk.est(response, stressor, wgt=wgt, xcoord=xcoord, ycoord=ycoord)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker. Vote for new features on Trello.