chisqTest: Chi-squared Tests

Description Usage Arguments Value Note Author(s) Examples

View source: R/chisqTest.R

Description

Perform a chi-squared goodness-of-fit test or a chi-squared test on independence on variables of a data set. The output is printed as a LaTeX table that mimics the look of SPSS output (version <24).

Usage

1
2
3
4
chisqTest(data, variables, p = NULL)

## S3 method for class 'chisqTestSPSS'
print(x, digits = c(1, 3), statistics = c("frequencies", "test"), ...)

Arguments

data

a data frame containing the variables.

variables

a character vector specifying the categorical variable(s) of interest. If only one variable is specified, a goodness-of-fit test is performed. If two variables are specified, a test on independence is performed (with the first variable used for the rows and the second variable for the columns of the crosstabulation).

p

a vector of probabilities for the categories in the goodness-of-fit test.

x

an object of class "chisqTestSPSS" as returned by function chisqTest.

digits

an integer vector giving the number of digits after the comma to be printed in the LaTeX tables. The first element corresponds to the number of digits in the table of frequencies, and the second element corresponds to the number of digits in the table for the test.

statistics

a character vector specifying which LaTeX tables should be printed. Available options are "frequencies" for a table of the observed and expected frequencies, and "test" for test results. The default is to print both tables.

...

currently ignored.

Value

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

chisq

a list containing the results of the chi-squared test.

lr

a list containing the results of a likelihood ratio test (only test on independence).

observed

a table containing the observed frequencies.

expected

a vector or matrix containing the expected frequencies.

n

an integer giving the number of observations.

k

an integer giving the number of groups (only goodness-of-fit test).

r

an integer giving the number of groups in the first variable corresponding to the rows (only test on independence).

c

an integer giving the number of groups in the second variable corresponding to the columns (only test on independence).

variables

a character vector containing the name(s) of the categorical variable(s) of interest.

type

a character string giving the type of chi-squared test performed ("goodness-of-fit" or "independence").

The print method produces a LaTeX table that mimics the look of SPSS output (version <24).

Note

The test on independence also reports the results of a likelihood ratio test.

Author(s)

Andreas Alfons

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# load data
data("Eredivisie")

# test whether playing position and dummy variable for
# foreign players are independent
chisqTest(Eredivisie, c("Position", "Foreign"))

# test whether the traditional Dutch 4-3-3 (total football)
# is still reflected in player composition
chisqTest(Eredivisie, "Position", p = c(1, 4, 3, 3)/11)

r2spss documentation built on Nov. 25, 2021, 1:06 a.m.