kruskal_test: Kruskal-Wallis Test

View source: R/kruskal_test.R

kruskal_testR Documentation

Kruskal-Wallis Test

Description

Perform a Kruskal-Wallis test on variables of a data set. The output is printed as a LaTeX table that mimics the look of SPSS output.

Usage

kruskal_test(data, variable, group)

## S3 method for class 'kruskal_test_SPSS'
to_SPSS(
  object,
  statistics = c("test", "ranks"),
  version = r2spss_options$get("version"),
  digits = NULL,
  ...
)

## S3 method for class 'kruskal_test_SPSS'
print(
  x,
  statistics = c("ranks", "test"),
  version = r2spss_options$get("version"),
  digits = 2:3,
  ...
)

kruskalTest(data, variable, group)

Arguments

data

a data frame containing the variables.

variable

a character string specifying the numeric variable of interest.

group

a character string specifying a grouping variable.

object, x

an object of class "kruskal_test_SPSS" as returned by function kruskal_test.

statistics

a character string or vector specifying which SPSS tables to produce. Available options are "ranks" for a summary of the ranks and "test" for test results. For the to_SPSS method, only one option is allowed (the default is the table of test results), but the print method allows several options (the default is to print all tables).

version

a character string specifying whether the table should mimic the content and look of recent SPSS versions ("modern") or older versions (<24; "legacy"). The main differences in terms of content are the label of the test statistic and that small p-values are displayed differently.

digits

for the to_SPSS method, an integer giving the number of digits after the comma to be printed in the SPSS table. For the print method, this should be an integer vector of length 2, with the first element corresponding to the number of digits in table with the summary of the ranks, and the second element corresponding to the number of digits in the table for the test.

...

additional arguments to be passed down to format_SPSS.

Details

The print method first calls the to_SPSS method followed by to_latex. Further customization can be done by calling those two functions separately, and modifying the object returned by to_SPSS.

Value

An object of class "kruskal_test_SPSS" with the following components:

statistics

a data frame containing information on the per-group mean ranks.

test

a list containing the results of the Kruskal-Wallis test.

variable

a character string containing the name of the numeric variable of interest.

group

a character string containing the name of the grouping variable.

The to_SPSS method returns an object of class "SPSS_table" which contains all relevant information in the required format to produce the LaTeX table. See to_latex for possible components and how to further customize the LaTeX table based on the returned object.

The print method produces a LaTeX table that mimics the look of SPSS output.

Note

LaTeX tables that mimic recent versions of SPSS (version = "modern") may require several LaTeX compilations to be displayed correctly.

Author(s)

Andreas Alfons

Examples

# load data
data("Eredivisie")

# test whether market values differ by playing position
kruskal_test(Eredivisie, "MarketValue", group = "Position")


r2spss documentation built on May 25, 2022, 5:05 p.m.