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.
chisq_test(data, variables, p = NULL) ## S3 method for class 'chisq_test_SPSS' to_SPSS( object, statistics = c("test", "frequencies"), version = r2spss_options$get("version"), digits = c(1, 3), ... ) ## S3 method for class 'chisq_test_SPSS' print( x, statistics = c("frequencies", "test"), version = r2spss_options$get("version"), digits = c(1, 3), ... ) chisqTest(data, variables, p = NULL)
a data frame containing the 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).
a vector of probabilities for the categories in the goodness-of-fit test.
an object of class
a character string or vector specifying which SPSS tables
to produce. Available options are
a character string specifying whether the table should
mimic the content and look of recent SPSS versions (
an integer vector giving the number of digits after the comma to be printed in the SPSS tables. The first element corresponds to the number of digits for the expected frequencies, and the second element corresponds to the number of digits in the table for the test.
additional arguments to be passed down to
to_SPSS method followed
to_latex. Further customization can be done by calling
those two functions separately, and modifying the object returned by
An object of class
"chisq_test_SPSS" with the following components:
a list containing the results of the chi-squared test.
a list containing the results of a likelihood ratio test (only test on independence).
a list containing the results of a Mantel-Haenszel test of linear association (only test on independence).
a table containing the observed frequencies.
a vector or matrix containing the expected frequencies.
an integer giving the number of observations.
an integer giving the number of groups (only goodness-of-fit test).
an integer giving the number of groups in the first variable corresponding to the rows (only test on independence).
an integer giving the number of groups in the second variable corresponding to the columns (only test on independence).
a character vector containing the name(s) of the categorical variable(s) of interest.
a character string giving the type of
chi-squared test performed (
to_SPSS method returns an object of class
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 test on independence also reports the results of a likelihood ratio test.
LaTeX tables that mimic recent versions of SPSS (
version = "modern")
may require several LaTeX compilations to be displayed correctly.
# load data data("Eredivisie") # test whether the traditional Dutch 4-3-3 (total football) # is still reflected in player composition chisq_test(Eredivisie, "Position", p = c(1, 4, 3, 3)/11) # test whether playing position and dummy variable for # foreign players are independent chisq_test(Eredivisie, c("Position", "Foreign"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.