Type: | Package |
Title: | Two-Way Tests in Independent Groups Designs |
Version: | 1.5 |
Date: | 2024-11-11 |
Depends: | R (≥ 3.5.0) |
Imports: | onewaytests, stats, ggplot2, nortest, car, wesanderson, MASS |
Suggests: | WRS2 |
Author: | Osman Dag [aut, cre], Sam Weerahandi [aut], Malwane Ananda [aut], Muhammed Ali Yilmaz [aut], Merve Kasikci [aut] |
Maintainer: | Osman Dag <osman.dag@outlook.com> |
Description: | Performs two-way tests in independent groups designs. These are two-way ANOVA, two-way ANOVA under heteroscedasticity: parametric bootstrap based generalized test and generalized pivotal quantity based generalized test, two-way ANOVA for medians, trimmed means, M-estimators. The package performs descriptive statistics and graphical approaches. Moreover, it assesses variance homogeneity and normality of data in each group via tests and plots. All 'twowaytests' functions are designed for two-way layout (Dag et al., 2024, <doi:10.1016/j.softx.2024.101862>). |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
NeedsCompilation: | no |
Packaged: | 2024-11-11 13:59:16 UTC; osmandag |
Repository: | CRAN |
Date/Publication: | 2024-11-11 14:20:02 UTC |
Two-Way ANOVA for M-estimators
Description
MestTwoWay
computes a two-way ANOVA for M-estimators.
Usage
MestTwoWay(formula, data, estimator = c("mom_est", "onestep_est", "median",
"bisquare", "hampel"), nboot = 500, distance = c("mahalanobis", "projected"),
seed = 123, alpha = 0.05, na.rm = TRUE, verbose = TRUE)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
estimator |
a character string to select one of the estimators. "mom_est": the modified one-step estimator of location based on Huber's Psi, "onestep_est": one-step estimator of location using Huber's Psi, "median": median, "bisquare": Tukey's biweight (bisquare) estimator, "hampel": Hampel's estimator. |
nboot |
the number of bootstrap samples. |
distance |
the specified distance. Default is set to "mahalanobis". |
seed |
a seed number for the reproducibility of results. Default is set to 123. |
alpha |
the level of significance to assess the statistical difference. Default is set to alpha = 0.05. |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds. |
verbose |
a logical for printing output to R console. |
Value
A list containing the following components:
output |
a data frame of output. |
alpha |
the level of significance to assess the statistical difference. |
method |
the method name. |
data |
a data frame containing the variables in which NA values (if exist) are removed. |
formula |
a formula of the form |
Author(s)
Muhammed Ali Yilmaz, Osman Dag
References
Dag, O., Kasikci, M., Yilmaz, M.A., Weerahandi, S., Ananda, M.M.A. (2024). twowaytests: An R Package for Two-Way Tests in Independent Groups Designs. SoftwareX, 27, 1-8.
Wilcox, R.R. (2011). Introduction to robust estimation and hypothesis testing. Academic press.
See Also
Examples
library(twowaytests)
data(alveolar)
MestTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
out <- MestTwoWay(cell ~ ovalbumin*treatment, data = alveolar, verbose = FALSE)
paircompTwoWay(out)
out <- MestTwoWay(cell ~ treatment*ovalbumin, data = alveolar, verbose = FALSE)
paircompTwoWay(out)
Alveolar Cell Count Data
Description
Alveolar cell count data were collected by Lacroix et al. (2002).
Usage
data(alveolar)
Format
A data frame with 36 observations on the following 3 variables.
ovalbumin
a factor with levels: no (ovalbumin-nonsensitized); yes (ovalbumin-sensitized)
treatment
a factor with levels: acetaldehyde; air; benzaldehyde
cell
Alveolar count x 10^6
References
Lacroix, G., Tissot, S., Rogerieux, F., Beaulieu, R., Cornu, L., Gillet, C., ..., Bois, F. Y. (2002). Decrease in ovalbumin-induced pulmonary allergic response by benzaldehyde but not acetaldehyde exposure in a guinea pig model. Journal of Toxicology and Environmental Health, Part A, 65:14, 995-1012.
Examples
library(twowaytests)
data(alveolar)
Two-Way ANOVA
Description
aovTwoWay
computes a two-way ANOVA for main effects and interaction effect.
Usage
aovTwoWay(formula, data, alpha = 0.05, na.rm = TRUE, verbose = TRUE)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
alpha |
the level of significance to assess the statistical difference. Default is set to alpha = 0.05. |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds. |
verbose |
a logical for printing output to R console. |
Value
A list containing the following components:
output |
a data frame of output. |
alpha |
the level of significance to assess the statistical difference. |
method |
the method name. |
data |
a data frame containing the variables in which NA values (if exist) are removed. |
formula |
a formula of the form |
Author(s)
Muhammed Ali Yilmaz, Osman Dag
References
Dag, O., Kasikci, M., Yilmaz, M.A., Weerahandi, S., Ananda, M.M.A. (2024). twowaytests: An R Package for Two-Way Tests in Independent Groups Designs. SoftwareX, 27, 1-8.
Toutenburg, H., Shalabh, S., Shalabh, H. (2002). Statistical analysis of designed experiments. Springer.
Examples
library(twowaytests)
data(alveolar)
aovTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
out <- aovTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
paircompTwoWay(out)
out <- aovTwoWay(cell ~ ovalbumin*treatment, data = alveolar, alpha = 0.10)
paircompTwoWay(out)
out <- aovTwoWay(cell ~ treatment*ovalbumin, data = alveolar, alpha = 0.10)
paircompTwoWay(out)
Descriptive Statistics for Two-Way Layout
Description
descTwoWay
produces basic descriptive statistics including sample size, mean, standard deviation, median, minimum value, maximum value, 25th quantile, 75th quantile, skewness, kurtosis, the number of missing value for two-way layout.
Usage
descTwoWay(formula, data)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
Value
Returns a data.frame of output.
Author(s)
Osman Dag, Sam Weerahandi, Malwane Ananda
Examples
library(twowaytests)
data(alveolar)
descTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
Two-Way ANOVA under Heteroscedasticity
Description
gpTwoWay
computes a two-way ANOVA for main effects and interaction effect under heteroscedasticity.
Usage
gpTwoWay(formula, data, method = c("gPB","gPQ"), seed = 123, alpha = 0.05,
na.rm = TRUE, verbose = TRUE)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
method |
a character string to select the method. "gPB": Parametric Bootstrap based Generalized Test, "gPQ": Generalized Pivotal Quantity based Generalized Test. |
seed |
a seed number for the reproducibility of results. Default is set to 123. |
alpha |
the level of significance to assess the statistical difference. Default is set to alpha = 0.05. |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds. |
verbose |
a logical for printing output to R console. |
Value
A list containing the following components:
output |
a data frame of output. |
alpha |
the level of significance to assess the statistical difference. |
method |
the selected method used in generalized test. |
data |
a data frame containing the variables in which NA values (if exist) are removed. |
formula |
a formula of the form |
Note
These tests available from this R library are based on two Generalized P-value approaches, for Two-Way ANOVA under unequal variances and cell frequencies. The first test, the gPQ, is an extension Li et al. (2011), and the second test, gPB, is a generalized test that is numerically equivalent to the Parametric Bootstrap test derived by Xu et al. (2013). The gPQ test tends to assure the intended size of the test, but somewhat conservative, especially when the sample sizes are small.
The gPB test tends to exceed the intended size of the test. Hence, the gPB is recommended for situations of small sample sizes, and gPQ otherwise.
Author(s)
Sam Weerahandi, Osman Dag, Malwane Ananda
References
Dag, O., Kasikci, M., Yilmaz, M.A., Weerahandi, S., Ananda, M.M.A. (2024). twowaytests: An R Package for Two-Way Tests in Independent Groups Designs. SoftwareX, 27, 1-8.
Ananda, M.M., Dag, O., Weerahandi, S. (2023). Heteroscedastic two-way ANOVA under constraints. Communications in Statistics-Theory and Methods, 52:22, 8207-8222.
Li, X., Wang J., Liang H. (2011). Comparison of several means: a fiducial based approach. Computational Statistics and Data Analysis, 55:5, 1993-2002.
Xu L., Yang F., Abula A., Qin, S. (2013). A parametric bootstrap approach for two-way ANOVA in presence of possible interactions with unequal variances. Journal of Multivariate Analysis, 115, 172-180.
Examples
library(twowaytests)
data(alveolar)
# to use Parametric Bootstrap based Generalized Test
gpTwoWay(cell ~ ovalbumin*treatment, data = alveolar, method = "gPB")
# to use Generalized Pivotal Quantity based Generalized Test
gpTwoWay(cell ~ ovalbumin*treatment, data = alveolar, method = "gPQ")
out <- gpTwoWay(cell ~ ovalbumin*treatment, data = alveolar, method = "gPB")
paircompTwoWay(out)
out <- gpTwoWay(cell ~ treatment*ovalbumin, data = alveolar, method = "gPB")
paircompTwoWay(out)
Box-and-Whisker, Violin Plots and Error Bars for Two-Way Layout
Description
gplotTwoWay
produces box-and-whisker, violin plots, and error bars for two-way layout.
Usage
gplotTwoWay(formula, data, type = c("errorbar", "violin", "boxplot",
"interaction"), color_manual = NULL, back_color = FALSE, xlab = NULL,
ylab = NULL, title = NULL, legend.title = NULL, width = NULL,
option = c("sd", "se"), metric = c("mean", "median"), na.rm = TRUE)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
type |
a character string to select one of the plots. "errorbar": error bar, "violin": violin plot, "boxplot": box-and-whisker plot, and "interaction": interaction plot. |
color_manual |
a vector of colors. A palette can also be defined with |
back_color |
a logical to make background grey or white. |
xlab |
a label for the x axis, defaults to a description of x. |
ylab |
a label for the y axis, defaults to a description of y. |
title |
a main title for the plot. |
legend.title |
a legend title for the plot. |
width |
a numeric giving the width of the little lines at the tops and bottoms of the error bars (defaults to 0.35) and the width of the boxes for box-and-whisker plots (defaults to 0.75). |
option |
a character string to select one of the options to draw error bars with standard error or standard deviation. "se": standard error, "sd": standard deviation. Defaults to "se". |
metric |
a character string to draw interaction plot with a desired metric. Defaults to "mean". |
na.rm |
a logical indicating whether NA values should be stripped before the computation proceeds. |
Details
The upper whisker of box-and-whisker plots extends from the hinge to the highest value that is within 1.5 * IQR of the hinge, where IQR is the inter-quartile range. The lower whisker extends from the hinge to the lowest value within 1.5 * IQR of the hinge. Data out of the ends of the whiskers are outliers and plotted as points.
Author(s)
Osman Dag, Muhammed Ali Yilmaz, Merve Kasikci
Examples
library(twowaytests)
data(alveolar)
# to obtain error bar (mean +- standard deviation)
gplotTwoWay(cell ~ ovalbumin*treatment, data = alveolar, type = "errorbar", option = "sd")
# to change factor places in graph
gplotTwoWay(cell ~ treatment*ovalbumin, data = alveolar, type = "errorbar", option = "sd")
# to obtain error bar (mean +- standard error)
gplotTwoWay(cell ~ ovalbumin*treatment, data = alveolar, type = "errorbar", option = "se")
# to draw interaction plot with mean
gplotTwoWay(cell ~ ovalbumin*treatment, data = alveolar, type = "interaction", metric = "mean")
# to draw interaction plot with median
gplotTwoWay(cell ~ ovalbumin*treatment, data = alveolar, type = "interaction", metric = "median")
# to obtain box-and-whisker plot
gplotTwoWay(cell ~ ovalbumin*treatment, data = alveolar, type = "boxplot")
# to obtain violin plot
gplotTwoWay(cell ~ ovalbumin*treatment, data = alveolar, type = "violin")
# to define specific colors
gplotTwoWay(cell ~ ovalbumin*treatment, data = alveolar, type = "errorbar", option = "sd",
color_manual = c("#999999", "#E69F00", "#56B4E9"))
# to change color palette
library(wesanderson)
gplotTwoWay(cell ~ ovalbumin*treatment, data = alveolar, type = "errorbar", option = "sd",
color_manual = wes_palette(name = "GrandBudapest1", n = 3))
Variance Homogeneity Tests for Two-Way Layout
Description
homogtestTwoWay
performs variance homogeneity tests including Levene, Bartlett, Fligner-Killeen tests for two-way layout.
Usage
homogtestTwoWay(formula, data, method = c("Levene", "Bartlett", "Fligner"),
alpha = 0.05, na.rm = TRUE, verbose = TRUE)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
method |
a character string to select one of the variance homogeneity tests. "Levene": Levene's test, "Bartlett": Bartlett's test, "Fligner": Fligner-Killeen test. |
alpha |
the level of significance to assess variance homogenity. Default is set to alpha = 0.05. |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds. |
verbose |
a logical for printing output to R console. |
Value
A list containing the following components:
statistic |
the corresponding test statistic. |
parameter |
the parameter(s) of the approximate corresponding distribution of the test statistic. The corresponding distribution is F distribution for Levene's test, Chi-square disribution for Bartlett's test and Fligner-Killeen test. |
p.value |
the p-value of the test. |
Author(s)
Osman Dag, Malwane Ananda, Sam Weerahandi
See Also
leveneTest
bartlett.test
fligner.test
Examples
library(twowaytests)
data(alveolar)
homogtestTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
homogtestTwoWay(cell ~ ovalbumin*treatment, data = alveolar, method = "Bartlett")
Two-Way ANOVA for Medians
Description
medTwoWay
computes a two-way ANOVA for medians.
Usage
medTwoWay(formula, data, alpha = 0.05, na.rm = TRUE, verbose = TRUE)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
alpha |
the level of significance to assess the statistical difference. Default is set to alpha = 0.05. |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds. |
verbose |
a logical for printing output to R console. |
Value
A list containing the following components:
output |
a data frame of output. |
alpha |
the level of significance to assess the statistical difference. |
method |
the method name. |
data |
a data frame containing the variables in which NA values (if exist) are removed. |
formula |
a formula of the form |
Author(s)
Muhammed Ali Yilmaz, Osman Dag
References
Dag, O., Kasikci, M., Yilmaz, M.A., Weerahandi, S., Ananda, M.M.A. (2024). twowaytests: An R Package for Two-Way Tests in Independent Groups Designs. SoftwareX, 27, 1-8.
Wilcox, R.R. (2011). Introduction to robust estimation and hypothesis testing. Academic press.
See Also
Examples
library(twowaytests)
data(alveolar)
medTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
out <- medTwoWay(cell ~ ovalbumin*treatment, data = alveolar, verbose = FALSE)
paircompTwoWay(out)
out <- medTwoWay(cell ~ treatment*ovalbumin, data = alveolar, verbose = FALSE)
paircompTwoWay(out)
Normality Tests for Two-Way Layout
Description
nortestTwoWay
performs normality tests including Shapiro-Wilk, Shapiro-Francia, Kolmogorov-Smirnov, Anderson-Darling, Cramer-von Mises, Pearson Chi-square tests, and also assess the normality of each group through plots for two-way layout.
Usage
nortestTwoWay(formula, data, method = c("SW", "SF", "LT", "AD", "CVM", "PT"),
alpha = 0.05, plot = c("qqplot", "histogram"), na.rm = TRUE, verbose = TRUE)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
method |
a character string to select one of the normality tests. "SW": Shapiro-Wilk test, "SF": Shapiro-Francia test, "LT": Lilliefors (Kolmogorov-Smirnov) test, "AD": Anderson-Darling test, "CVM": Cramer-von Mises test, "PT": Pearson Chi-square test. |
alpha |
the level of significance to assess normality. Default is set to alpha = 0.05. |
plot |
a character string to select one of the plots including qqplot and histogram. The red line is the density line of normal distribution. If plot is set to NULL, the plot is not returned. |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds. |
verbose |
a logical for printing output to R console. |
Value
A data frame gives the test results for the normality of each subset via corresponding normality.
Author(s)
Osman Dag, Sam Weerahandi, Malwane Ananda
See Also
Examples
library(twowaytests)
data(alveolar)
nortestTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
Pairwise Comparisons for Two Way Layout
Description
paircompTwoWay
is a generic function for pairwise comparisons by adjusting p-values.
Usage
## S3 method for class 'twt'
paircompTwoWay(x, adjust.method = c("bonferroni", "holm", "hochberg", "hommel", "BH",
"BY", "fdr", "none"), verbose = TRUE, ...)
Arguments
x |
a |
adjust.method |
Method for adjusting p values (see |
verbose |
a logical for printing output to R console. |
... |
Additional arguments affecting multiple comparisons of groups in two-way independent designs. |
Details
The paircompTwoWay function makes pairwise comparisons depending on significance of interaction term. It calculates p-values with corresponding same test if the interaction term is not statistically significant. Otherwise, it calculates p-values with st.test
after two-way ANOVA, wt.test
after two-way ANOVA under heteroscedasticity and mw.test
after other tests. Then, it adjusts p-values with p.adjust
.
Value
Returns a data.frame of output.
Author(s)
Muhammed Ali Yilmaz, Osman Dag
Examples
library(twowaytests)
data(alveolar)
out <- aovTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
paircompTwoWay(out)
out <- aovTwoWay(cell ~ treatment*ovalbumin, data = alveolar)
paircompTwoWay(out)
out <- aovTwoWay(cell ~ ovalbumin*treatment, data = alveolar, alpha = 0.10)
paircompTwoWay(out)
out <- aovTwoWay(cell ~ treatment*ovalbumin, data = alveolar, alpha = 0.10)
paircompTwoWay(out)
paircompTwoWay(out, adjust.method = "hochberg")
Two-Way ANOVA for Trimmed Means
Description
tmeanTwoWay
computes a two-way ANOVA for trimmed means.
Usage
tmeanTwoWay(formula, data, tr = 0.1, alpha = 0.05, na.rm = TRUE, verbose = TRUE)
Arguments
formula |
a formula of the form |
data |
a data frame containing the variables in |
tr |
the rate of observations trimmed from each tail of the distribution. Default is set to 0.1. |
alpha |
the level of significance to assess the statistical difference. Default is set to 0.05. |
na.rm |
a logical value indicating whether NA values should be stripped before the computation proceeds. |
verbose |
a logical for printing output to R console. |
Value
A list containing the following components:
output |
a data frame of output. |
alpha |
the level of significance to assess the statistical difference. |
method |
the method name. |
data |
a data frame containing the variables in which NA values (if exist) are removed. |
formula |
a formula of the form |
Author(s)
Muhammed Ali Yilmaz, Osman Dag
References
Dag, O., Kasikci, M., Yilmaz, M.A., Weerahandi, S., Ananda, M.M.A. (2024). twowaytests: An R Package for Two-Way Tests in Independent Groups Designs. SoftwareX, 27, 1-8.
Wilcox, R.R. (2011). Introduction to robust estimation and hypothesis testing. Academic press.
See Also
Examples
library(twowaytests)
data(alveolar)
tmeanTwoWay(cell ~ ovalbumin*treatment, data = alveolar)
out <- tmeanTwoWay(cell ~ ovalbumin*treatment, data = alveolar, verbose = FALSE)
paircompTwoWay(out)
out <- tmeanTwoWay(cell ~ treatment*ovalbumin, data = alveolar, verbose = FALSE)
paircompTwoWay(out)