| makeQx | R Documentation |
Create functions q(x) used in terms of Edgeworth expansions (EE) for
various versions of t-statistic.
makeQx(stats, type = "short", r = NULL, verbose = TRUE)
stats |
named vector of distribution parameters or estimates needed for
Edgeworth expansion. If no names for the vector are provided and the type
is
|
type |
type of Edgeworth expansions to be used: |
r |
square root of variance adjustment. Provide if wish to use a value
that is different from the one that will be calculated from |
verbose |
if |
Given sample statistics or distribution parameters, produce the defining
portion of EE terms as a function of x (quantile). Includes short (for
ordinary one-sample t-statistic) and general versions, which can be used for
ordinary and moderated one- and two-sample t-statistics and Welch t-test.
When used in Edgeworth expansions, the argument to a q() function
should incorporate variance adjustment (see examples); this adjustment is
equal to 1 if naive biased variance estimates are used in a one-sample
t-statistic or a Welch test.
A list of functions named "q1", "q2", "q3", and
"q4" to be used in respective terms of an Edgeworth expansion
(orders 2 - 5). These functions take a vector of quantiles x as an
input and output a vector of the same length as x. For a general
version (type = "one-sample" and type = "two-sample"), the
list also includes a calculated value for variance adjustment r.
smpStats that creates stats vector from the
sample and makeFx that creates a function returning the
values of Edgeworth series of orders 1 - 5 as a function of x.
n <- 10 # sample size
# Gamma distribution with shape parameter \code{shp}
shp <- 3
ord <- 3:6 # orders of scaled cumulants
lambdas <- factorial(ord - 1)/shp^((ord - 2)/2)
qt <- makeQx(lambdas)
quant <- -(3:5)
qt[[1]](quant)
# from sample
smp <- rgamma(n, shape = shp) - shp
stats <- smpStats(smp)
t <- sqrt(n)*mean(smp)/sd(smp)
r <- sqrt((n - 1)/n)
qt <- makeQx(stats)
sapply(qt, function(f) f(t/r))
# 2nd order (1-term) Edgeworth expansion, standard normal base
pnorm(t/r) + n^(-1/2)*qt[[1]](t/r)*dnorm(t/r)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.