Analysis of Deviance

Classic One-Way ANOVA

As an introduction, three random variables following a normal distribution with a common standard deviation are created. For this test, the null hypothesis is

\[ H_{0}: \mu_0 = \mu_1 = \mu_2 \]

library(LRTesteR)

set.seed(123)
x <- c(
  rnorm(n = 50, mean = 1, sd = 1),
  rnorm(n = 50, mean = 3, sd = 1),
  rnorm(n = 50, mean = 5, sd = 1)
)
fctr <- c(rep(1, 50), rep(2, 50), rep(3, 50))
fctr <- factor(fctr, levels = c("1", "2", "3"))
gaussian_mu_one_way_test(x = x, fctr = fctr, conf.level = 0.95)
#> Log Likelihood Statistic: 194.76
#> p value: 0
#> Confidence Level Of Set: 95%
#> Individual Confidence Level: 98.3%
#> Confidence Interval For Group 1: (0.715, 1.354)
#> Confidence Interval For Group 2: (2.834, 3.459)
#> Confidence Interval For Group 3: (4.405, 5.087)

Statistically, there are a number of things worth noting:

For a normal distribution, none of this is optimal. The F statistic is exact while the log likelihood statistic is only an asymptotic approximation, and the Bonferroni correction leads to the widest confidence intervals of any correction technique.

The principal advantage of the likelihood approach is its generality. The same machinery applies nonparametrically and to other distributions. The rest of this vignette works through both.

Nonparametric One-Way ANOVA

The same comparison of means, without assuming the data are normally distributed. The null hypothesis is unchanged.

\[ H_{0}: \mu_0 = \mu_1 = \mu_2 \]

empirical_mu_one_way_test(x = x, fctr = fctr, conf.level = 0.95)
#> Log Likelihood Statistic: 600
#> p value: 0
#> Confidence Level Of Set: 95%
#> Individual Confidence Level: 98.3%
#> Confidence Interval For Group 1: (0.724, 1.355)
#> Confidence Interval For Group 2: (2.829, 3.457)
#> Confidence Interval For Group 3: (4.426, 5.099)

Nonparametric Equality of Variance

Reusing the same data, the equality of variances is tested nonparametrically. The null hypothesis is

\[ H_{0}: \sigma^2_0 = \sigma^2_1 = \sigma^2_2 \]

empirical_variance_one_way_test(x = x, fctr = fctr, conf.level = 0.95)
#> Log Likelihood Statistic: 0.46
#> p value: 0.796
#> Confidence Level Of Set: 95%
#> Individual Confidence Level: 98.3%
#> Confidence Interval For Group 1: (0.547, 1.276)
#> Confidence Interval For Group 2: (0.492, 1.334)
#> Confidence Interval For Group 3: (0.61, 1.462)

Cauchy Random Variables

Here two random variables following a Cauchy distribution with a common location and different scales are created. For this test, the null hypothesis is

\[ H_{0}: \gamma_0 = \gamma_1 \]

set.seed(1)
x <- c(rcauchy(n = 50, location = 2, scale = 1), rcauchy(n = 50, location = 2, scale = 3))
fctr <- c(rep(1, 50), rep(2, 50))
fctr <- factor(fctr, levels = c("1", "2"))
cauchy_scale_one_way_test(x = x, fctr = fctr, conf.level = 0.95)
#> Log Likelihood Statistic: 19.15
#> p value: 0
#> Confidence Level Of Set: 95%
#> Individual Confidence Level: 97.5%
#> Confidence Interval For Group 1: (0.715, 1.71)
#> Confidence Interval For Group 2: (2.388, 5.612)

Poisson Random Variables

Finally, three poisson random variables with different lambdas are created. The null hypothesis is

\[ H_{0}: \lambda_0 = \lambda_1 = \lambda_2 \]

set.seed(1)
x <- c(rpois(n = 50, lambda = 1), rpois(n = 50, lambda = 2), rpois(n = 50, lambda = 3))
fctr <- c(rep(1, 50), rep(2, 50), rep(3, 50))
fctr <- factor(fctr, levels = c("1", "2", "3"))
poisson_lambda_one_way_test(x = x, fctr = fctr, conf.level = 0.95)
#> Log Likelihood Statistic: 51.11
#> p value: 0
#> Confidence Level Of Set: 95%
#> Individual Confidence Level: 98.3%
#> Confidence Interval For Group 1: (0.765, 1.471)
#> Confidence Interval For Group 2: (1.541, 2.495)
#> Confidence Interval For Group 3: (2.541, 3.735)