adSim: Bootstrap-based Anderson-Darling Test for Univariate
Source:R/8_dpq_distributions_adSim.R
adSim.RdPerforms the Anderson-Darling test for univariate distributions with an option for bootstrap-based p-value determination. It also allows p-value determination using tabled critical values.
Arguments
- x
A numeric vector.
- distribution
A character string specifying the distribution to test. Recognized distributions include
`cauchy`,`exponential`,`gumbel`,`gamma`,`log-normal`,`lognormal`,`logistic`,`normal`, and`weibull`.- b
A numeric value indicating the number of bootstraps to perform. Allowed values range from 1000 to 1,000,000. If
bis set toNA, the Anderson-Darling test will be applied without simulation. Note that higher values ofbcan significantly increase computation time, potentially taking hours depending on the distribution, sample size, and computer system.
Value
A list containing the following components:
distributionThe distribution for which the Anderson-Darling test was applied.
parameter_estimationThe estimated parameters for the distribution.
Anderson_DarlingThe value of the Anderson-Darling test statistic.
p_valueThe corresponding p-value, either simulated or from tabled values.
critical_valuesThe critical values corresponding to the 0.75, 0.90, 0.95, 0.975, and 0.99 quantiles, either simulated or from tables.
simADThe bootstrap-based Anderson-Darling distribution.
Details
The function first estimates the parameters for the tested distribution, typically using Maximum-Likelihood Estimation (MLE) via the FitDistr function. For normal and log-normal distributions, parameters are estimated by the mean and standard deviation. Cauchy distribution parameters are fitted by the sums of the weighted order statistic when using tabled critical values. The Anderson-Darling statistic is then calculated based on these estimated parameters.
Parametric bootstrapping generates the distribution of the Anderson-Darling test statistic, which is used to determine the p-value. This simulation-based Anderson-Darling distribution and its corresponding critical values for selected quantiles can be printed. If simulation is not performed, a p-value is obtained from tabled critical values, although no exact expressions exist except for the log-normal, normal, and exponential distributions.
Examples
x <- rnorm(25, 32, 2)
adSim(x)
#>
#> ... simulating the Anderson-Darling distribution by10000bootstraps fornormaldistribution...
#>
#> $distribution
#> [1] "normal"
#>
#> $parameter_estimation
#> mean sd
#> 32.020482 1.944843
#>
#> $Anderson_Darling
#> [1] 0.1704118
#>
#> $p_value
#> [1] 0.9437
#>
adSim(x, "logistic", 2000)
#>
#> ... simulating the Anderson-Darling distribution by2000bootstraps forlogisticdistribution...
#>
#> $distribution
#> [1] "logistic"
#>
#> $parameter_estimation
#> $parameter_estimation$estimate
#> location scale
#> 32.03572 1.06294
#>
#> $parameter_estimation$sd
#> location scale
#> 0.3675452 0.1787948
#>
#>
#> $Anderson_Darling
#> [1] 0.1121003
#>
#> $p_value
#> [1] 0.995
#>
adSim(x, "cauchy", NA)
#> $distribution
#> [1] "cauchy"
#>
#> $parameter_estimation
#> location scale
#> 33.351391 1.160257
#>
#> $Anderson_Darling
#> [1] 5.551802
#>
#> $p_value
#> [1] "<= 0.05"
#>
adSim(x, "exponential", 2000)
#>
#> ... simulating the Anderson-Darling distribution by2000bootstraps forexponentialdistribution...
#>
#> $distribution
#> [1] "exponential"
#>
#> $parameter_estimation
#> $parameter_estimation$estimate
#> rate
#> 0.03123001
#>
#> $parameter_estimation$sd
#> rate
#> 0.006246002
#>
#>
#> $Anderson_Darling
#> [1] 10.19722
#>
#> $p_value
#> [1] 0
#>
adSim(x, "gumbel", 2000)
#>
#> ... simulating the Anderson-Darling distribution by2000bootstraps forgumbeldistribution...
#>
#> $distribution
#> [1] "gumbel"
#>
#> $parameter_estimation
#> location scale
#> 31.052483 1.974123
#>
#> $Anderson_Darling
#> [1] 0.6307183
#>
#> $p_value
#> [1] 0.104
#>