Learn R Programming

spsurvey (version 1.6.2)

psurvey.analysis: Create an Object of Class psurvey.analysis

Description

This function creates an object of class psurvey.analysis that contains all of the information necessary to use the analysis functions in the psurvey.analysis library.

Usage

psurvey.analysis(sites=NULL, subpop=NULL, design=NULL, data.cat=NULL,
   data.cont=NULL, siteID=NULL, wgt=NULL, sigma=NULL, var.sigma=NULL,
   xcoord=NULL, ycoord=NULL, stratum=NULL, cluster=NULL, N.cluster=NULL,
   wgt1=NULL, xcoord1=NULL, ycoord1=NULL, popsize=NULL, stage1size=NULL,
   popcorrect=FALSE, support=NULL, sizeweight=FALSE, swgt=NULL, swgt1=NULL,
   unitsize=NULL, vartype="Local", conf=95, pctval=c(5,10,25,50,75,90,95))

Arguments

sites
a data frame consisting of two variables: the first variable is site IDs and the second variable is a logical vector indicating which sites to use in the analysis. If this data frame is not provided, then the data frame will be created
subpop
a data frame describing sets of populations and subpopulations for which estimates will be calculated. The first variable is site IDs and each subsequent variable identifies a Type of population, where the variable name is used to ide
design
a data frame consisting of design variables. If variable names are provided as formulas in the corresponding arguments, then the formulas are interpreted using this data frame. If this data frame is not provided, then the data frame wi
data.cat
a data frame of categorical response variables. The first variable is site IDs. Subsequent variables are response variables. Missing data (NA) is allowed. The default is NULL.
data.cont
a data frame of continuous response variables. The first variable is site IDs. Subsequent variables are response variables. Missing data (NA) is allowed. The default is NULL.
siteID
site IDs. This variable can be input directly or as a formula and must be supplied either as this argument or in the design data frame. The default is NULL.
wgt
the final adjusted weight (inverse of the sample inclusion probability) for each site, which is either the weight for a single-stage sample or the stage two weight for a two-stage sample. The default is NULL.
sigma
measurement error variance. This variable must be a vector containing a value for each response variable and must have the names attribute set to identify the response variable names. Missing data (NA) is allowed. The default is NULL.
var.sigma
variance of the measurement error variance. This variable must be a vector containing a value for each response variable and must have the names attribute set to identify the response variable names. Missing data (NA) is allowed. The def
xcoord
x-coordinate for location for each site, which is either the x-coordinate for a single-stage sample or the stage two x-coordinate for a two-stage sample. The default is NULL.
ycoord
y-coordinate for location for each site, which is either the y-coordinate for a single-stage sample or the stage two y-coordinate for a two-stage sample. The default is NULL.
stratum
the stratum codes. This variable can be input directly or as a formula. The default is NULL.
cluster
the stage one sampling unit (primary sampling unit or cluster) codes. This variable can be input directly or as a formula. The default is NULL.
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 two-stage sample. For a stratified sample this variable must be a vector containing a
wgt1
the final adjusted stage one weights. This variable can be input directly or as a formula. The default is NULL.
xcoord1
the stage one x-coordinates for location. This variable can be input directly or as a formula. The default is NULL.
ycoord1
the stage one y-coordinates for location. This variable can be input directly or as a formula. The default is NULL.
popsize
the known size of the resource - the total number of sampling units of a finite resource or the measure of an extensive resource, which is used to adjust estimators for the known size of a resource. This argument also is required for calcu
stage1size
the known size of the stage one sampling units of a two- stage sample, which is required for calculation of finite and continuous population correction factors for a two-stage sample and must have the names attribute set to identify the
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
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 pop
sizeweight
a logical value that indicates whether size-weights should be used in the analysis, where TRUE = use the size-weights and FALSE = do not use the size-weights. The default is FALSE.
swgt
the size-weight for each site, which is the stage two size-weight for a two-stage sample. This variable can be input directly or as a formula. The default is NULL.
swgt1
the stage one size-weight for each site. This variable can be input directly or as a formula. The default is NULL.
unitsize
the known sum of the size-weights of the resource. The argument must be in the form of a list containing an element for each population Type in the subpop data frame, where NULL is a valid choice for a population Type. The list must
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%.
pctval
the set of values at which percentiles are estimated. The default set is: {5, 10, 25, 50, 75, 90, 95}.

Value

Value is a list of class psurvey.analysis. Only those sites indicated by the logical variable in the sites data frame are retained in the output. The sites, subpop, and design data frames will always exist in the output. At least one of the data.cat and data.cont data frames will exist. Depending upon values of the input variables, other elements in the output may be NULL. The list is composed of the following components:
  • sites- the sites data frame
  • subpop- the subpop data frame
  • design- the design data frame
  • data.cat- the data.cat data frame
  • data.cont- the data.cont data frame
  • N.cluster- the number of stage one sampling units in the resource
  • popsize- the known size of the resource
  • stage1size- the known size of the stage one sampling units
  • unitsize- the known sum of the size-weights of the resource
  • stratum.ind- a logical value that indicates whether the sample is stratified, where TRUE = a stratified sample and FALSE = not a stratified sample
  • cluster.ind- a logical value that indicates whether the sample is a two-stage sample, where TRUE = a two-stage sample and FALSE = not a two-stage sample
  • pcfactor.ind- a logical value that indicates whether the population correction factor is used during variance estimation, where TRUE = use the population correction factor and FALSE = do not use the factor
  • swgt.ind- a logical value that indicates whether the sample is a size-weighted sample, where TRUE = a size-weighted sample and FALSE = not a size-weighted sample
  • vartype- the choice of variance estimator, where "Local" = local mean estimator and "SRS" = SRS estimator
  • conf- the confidence level
  • pctval- the set of values at which percentiles are estimated, where the default set is: {5, 25, 50, 75, 95}

References

Diaz-Ramos, S., D.L. Stevens, Jr., and A.R. Olsen. (1996). EMAP Statistical Methods Manual. EPA/620/R-96/XXX. Corvallis, OR: U.S. Environmental Protection Agency, Office of Research and Development, National Health Effects and Environmental Research Laboratory, Western Ecology Division.

See Also

cat.analysis, cont.analysis

Examples

Run this code
# Categorical variable example
mysiteID <- paste("Site", 1:100, sep="")
mysites <- data.frame(siteID=mysiteID, Active=rep(TRUE, 100))
mysubpop <- data.frame(siteID=mysiteID, All.Sites=rep("All Sites", 100),
   Resource.Class=rep(c("Good","Poor"), c(55,45)))
mydesign <- data.frame(siteID=mysiteID, wgt=runif(100, 10,
   100), xcoord=runif(100), ycoord=runif(100), stratum= rep(c("Stratum1",
   "Stratum2"), 50))
mydata.cat <- data.frame(siteID=mysiteID, CatVar= rep(c("north", "south",
   "east", "west"), 25))
mypopsize <- list(All.Sites=c(Stratum1=3500, Stratum2=2000),
   Resource.Class=list(Good=c(Stratum1=2500, Stratum2=1500),
   Poor=c(Stratum1=1000, Stratum2=500)))
psurvey.analysis(sites=mysites, subpop=mysubpop, design=mydesign,
   data.cat=mydata.cat, popsize=mypopsize)

# Continuous variable example - including deconvolution estimates
mydesign <- data.frame(ID=mysiteID, wgt=runif(100, 10, 100),
   xcoord=runif(100), ycoord=runif(100), stratum=rep(c("Stratum1",
   "Stratum2"), 50))
ContVar <- rnorm(100, 10, 1)
mydata.cont <- data.frame(siteID=mysiteID, ContVar=ContVar,
   ContVar.1=ContVar + rnorm(100, 0, sqrt(0.25)),
   ContVar.2=ContVar + rnorm(100, 0, sqrt(0.50)))
mysigma <- c(ContVar=NA, ContVar.1=0.25, ContVar.2=0.50)
psurvey.analysis(sites=mysites, subpop=mysubpop, design=mydesign,
   data.cont=mydata.cont, siteID=~ID, sigma=mysigma,
   popsize=mypopsize)

Run the code above in your browser using DataLab