Estimate the mean, standard deviation, and standard error of the mean nonparametrically given a sample of data, and optionally construct a confidence interval for the mean.
Usage
enpar(x, ci = FALSE, ci.method = "bootstrap", ci.type = "two-sided",
conf.level = 0.95, pivot.statistic = "z", n.bootstraps = 1000, seed = NULL)Details
Extended methods and derivations are available in
Nonparametric estimation and two-sample tests: enpar.
Open the vignette locally with
vignette("nonparametric-methods", package = "EnvStats").
Arguments
- x
numeric vector of observations. Missing (
NA), undefined (NaN), and infinite (Inf,-Inf) values are allowed but will be removed.- ci
logical scalar indicating whether to compute a confidence interval for the mean. The default value is
ci=FALSE.- ci.method
character string indicating what method to use to construct the confidence interval for the mean. The possible values are
"bootstrap"(based on bootstrapping; the default), and"normal.approx"(normal approximation). See the DETAILS section for more information. This argument is ignored ifci=FALSE.- ci.type
character string indicating what kind of confidence interval to compute. The possible values are
"two-sided"(the default),"lower", and"upper". This argument is ignored ifci=FALSE.- conf.level
a scalar between 0 and 1 indicating the confidence level of the confidence interval. The default value is
conf.level=0.95. This argument is ignored ifci=FALSE.- pivot.statistic
character string indicating which statistic to use for the confidence interval for the mean when
ci.method="normal.approx". Possible values are"z"(confidence interval based on the z-statistic; the default), and"t"(confidence interval based on the t-statistic). This argument is ignored ifci=FALSEorci.method="bootstrap".- n.bootstraps
numeric scalar indicating how many bootstraps to use to construct the confidence interval for the mean. This argument is ignored if
ci=FALSEorci.method="normal.approx".- seed
integer supplied to the function
set.seedand used whenci=TRUEandci.method="bootstrap". The default value isseed=NULL, in which case the current value of.Random.seedis used. This argument is ignored ifci=FALSEorci.method="normal.approx". This argument is necessary to create reproducible results for the bootstrapped confidence intervals (see the EXAMPLES section).
Value
a list of class "estimate" containing the estimated parameters
and other information. See estimate.object for details.
References
Efron, B. (1979). Bootstrap Methods: Another Look at the Jackknife. The Annals of Statistics 7, 1–26.
Efron, B., and R.J. Tibshirani. (1993). An Introduction to the Bootstrap. Chapman and Hall, New York, 436pp.
Author
Steven P. Millard (EnvStats@ProbStatInfo.com)
Note
The function enpar is related to the companion function
enparCensored for censored data. To estimate the median and
compute a confidence interval, use eqnpar.
The result of the call to enpar with ci.method="normal.approx"
and pivot.statistic="t" produces the same result as the call to
enorm with ci.param="mean".
Examples
# The data frame ACE.13.TCE.df contains observations on
# Trichloroethylene (TCE) concentrations (mg/L) at
# 10 groundwater monitoring wells before and after remediation.
#
# Compute the mean concentration for each period along with
# a 95% bootstrap BCa confidence interval for the mean.
#
# NOTE: Use of the argument "seed" is necessary to reproduce this example.
#
# Before remediation: 21.6 [14.2, 30.1]
# After remediation: 3.6 [ 1.6, 5.7]
with(ACE.13.TCE.df,
enpar(TCE.mg.per.L[Period=="Before"], ci = TRUE, seed = 476))
#>
#> Results of Distribution Parameter Estimation
#> --------------------------------------------
#>
#> Assumed Distribution: None
#>
#> Estimated Parameter(s): mean = 21.62400
#> sd = 13.51134
#> se.mean = 4.27266
#>
#> Estimation Method: Sample Mean
#>
#> Data: TCE.mg.per.L[Period == "Before"]
#>
#> Sample Size: 10
#>
#> Confidence Interval for: mean
#>
#> Confidence Interval Method: Bootstrap
#>
#> Confidence Interval Type: two-sided
#>
#> Confidence Level: 95%
#>
#> Confidence Interval: Pct.LCL = 13.95560
#> Pct.UCL = 29.79510
#> BCa.LCL = 14.16080
#> BCa.UCL = 30.06848
#> t.LCL = 12.41945
#> t.UCL = 32.47306
#>
#Results of Distribution Parameter Estimation
#--------------------------------------------
#
#Assumed Distribution: None
#
#Estimated Parameter(s): mean = 21.62400
# sd = 13.51134
# se.mean = 4.27266
#
#Estimation Method: Sample Mean
#
#Data: TCE.mg.per.L[Period == "Before"]
#
#Sample Size: 10
#
#Confidence Interval for: mean
#
#Confidence Interval Method: Bootstrap
#
#Number of Bootstraps: 1000
#
#Confidence Interval Type: two-sided
#
#Confidence Level: 95%
#
#Confidence Interval: Pct.LCL = 13.95560
# Pct.UCL = 29.79510
# BCa.LCL = 14.16080
# BCa.UCL = 30.06848
# t.LCL = 12.41945
# t.UCL = 32.47306
#----------
with(ACE.13.TCE.df,
enpar(TCE.mg.per.L[Period=="After"], ci = TRUE, seed = 543))
#>
#> Results of Distribution Parameter Estimation
#> --------------------------------------------
#>
#> Assumed Distribution: None
#>
#> Estimated Parameter(s): mean = 3.632900
#> sd = 3.554419
#> se.mean = 1.124006
#>
#> Estimation Method: Sample Mean
#>
#> Data: TCE.mg.per.L[Period == "After"]
#>
#> Sample Size: 10
#>
#> Confidence Interval for: mean
#>
#> Confidence Interval Method: Bootstrap
#>
#> Confidence Interval Type: two-sided
#>
#> Confidence Level: 95%
#>
#> Confidence Interval: Pct.LCL = 1.833843
#> Pct.UCL = 5.830230
#> BCa.LCL = 1.631655
#> BCa.UCL = 5.677514
#> t.LCL = 1.683791
#> t.UCL = 8.101829
#>
#Results of Distribution Parameter Estimation
#--------------------------------------------
#
#Assumed Distribution: None
#
#Estimated Parameter(s): mean = 3.632900
# sd = 3.554419
# se.mean = 1.124006
#
#Estimation Method: Sample Mean
#
#Data: TCE.mg.per.L[Period == "After"]
#
#Sample Size: 10
#
#Confidence Interval for: mean
#
#Confidence Interval Method: Bootstrap
#
#Number of Bootstraps: 1000
#
#Confidence Interval Type: two-sided
#
#Confidence Level: 95%
#
#Confidence Interval: Pct.LCL = 1.833843
# Pct.UCL = 5.830230
# BCa.LCL = 1.631655
# BCa.UCL = 5.677514
# t.LCL = 1.683791
# t.UCL = 8.101829