makeFx: Make Edgeworth expansions

View source: R/makeFx.R

makeFxR Documentation

Make Edgeworth expansions

Description

Create an Edgeworth series F(x) of orders 1 - 5 for various versions of t-statistic.

Usage

makeFx(
  stats,
  n,
  r = NULL,
  type = "short",
  base = "normal",
  df = NULL,
  moder = FALSE,
  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.

n

a single value for a sample size summary to be used in Edgeworth expansion. Important: an average (not sum!) of two group sizes for a two-sample test.

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 or n.

type

which Edgeworth expansions are to be evaluated: "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.

base

base distribution of Edgeworth expansions. Classic expansions are based on standard normal distribution (base = "normal"), but Student's t-distribution (base = "t") is recommended for approximating far tails of the sampling distribution.

df

degrees of freedom for Student's t-distribution if base = "t". Provide a single value for the first order approximation (zero term). If not provided, df will be calculated as n - 1 for type = "short" and type = "one-sample" or 2n - 2 for type = "two-sample"; for augmented degrees of freedom (moder = TRUE), the value of prior degrees of freedom stats["d0"] will be added.

moder

logical value for calculating augmented degrees of freedom for a moderated t-statistic; if TRUE, the value for prior degrees of freedom shoud be included in stats. Ignored if df is provided.

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 Edgeworth expansions (EE) for t-statistic 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. Variance adjustment r is incorporated and there is not need to pass it to the resulting function.

Value

A function F(x) that takes a quantile x as an input and outputs a vector of values for five orders of approximation. If x is a vector, each order of approximation will contain length(x) values.

See Also

smpStats that creates stats vector from the sample, and makeQx that creates q(x) functions used in EE terms.

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)
Ft <- makeFx(lambdas, n, base = "t")
quant <- -(3:5)
Fmat <- matrix(Ft(quant), nrow = length(quant))
rownames(Fmat) <- quant
colnames(Fmat) <- paste("order", 1:5)
Fmat

Ftnorm <- makeFx(lambdas, n, r = 1, base = "normal")
p <- 0.025
Ftnorm(qnorm(p))[1]

# from sample
smp <- rgamma(n, shape = shp) - shp
stats <- smpStats(smp)
t <- sqrt(n)*mean(smp)/sd(smp)
Ft <- makeFx(stats, n, base = "t")
Ft(t)

# two-sample test
n2 <- 8
smp2 <- c(smp, rnorm(n2))
a <- rep(0:1, c(n, n2))
stats2 <- smpStats(smp2, a)
Ft2 <- makeFx(stats2, n, type = "two-sample", base = "t", df = n + n2 - 2)
Ft2(qt(p, df = n + n2 - 2))  # note 1st order not equal to p because r != 1


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