makeQx: Make terms for Edgeworth expansions

View source: R/makeQx.R

makeQxR Documentation

Make terms for Edgeworth expansions

Description

Create functions q(x) used in terms of Edgeworth expansions (EE) for various versions of t-statistic.

Usage

makeQx(stats, type = "short", r = NULL, verbose = TRUE)

Arguments

stats

named vector of distribution parameters or estimates needed for Edgeworth expansion. If no names for the vector are provided and the type is "short", elements are assumed to be scaled cumulants \lambda (3 - 6). If the elements are named, the order of the elements is arbitrary. Required names:

  • for ordinary one-sample t-statistic only (type = "short"): "lam3", "lam4", "lam5", "lam6" (scaled cumulants);

  • for more complicated one-sample versions, such as a moderated t-statistic (type = "one-sample"): "mu2", "mu3", "mu4", "mu5", "mu6" (central moments), "A", and "B";

  • for a two-sample t-statistic (type = "two-sample"): "mu_x2", "mu_x3", "mu_x4", "mu_x5", "mu_x6" (central moments for a treatment group), "mu_y2", "mu_y3", "mu_y4", "mu_y5", "mu_y6" (central moments for a control group), "A", "B_x", "B_y", "b_x", and "b_y". Note that if the same distribution is assumed for the two groups, the values for central moments for these groups should be the same (e.g. pooled variance for a second moment).

  • optionally for a moderated t-statistic: "d0" (prior degrees of freedom). Ignored if df is provided.

type

type of Edgeworth expansions to be used: "short" for ordinary one-sample t-statistic, "one-sample" for a more complicated version such as a moderated t-statistic, and "two-sample" for any kind of two-sample t-statistic.

r

square root of variance adjustment. Provide if wish to use a value that is different from the one that will be calculated from stats for a general version.

verbose

if TRUE, the warning message will be printed when the elements of stats are not named.

Details

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.

Value

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.

See Also

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.

Examples

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)


innager/edgee documentation built on April 24, 2024, 8:14 p.m.