| chisq_test | R Documentation |
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)
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. |
object, x |
an object of class |
statistics |
a character string or vector specifying which SPSS tables
to produce. Available options are |
version |
a character string specifying whether the table should
mimic the content and look of recent SPSS versions ( |
digits |
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
|
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.
An object of class "chisq_test_SPSS" with the following components:
chisqa list containing the results of the chi-squared test.
lra list containing the results of a likelihood ratio test (only test on independence).
MHa list containing the results of a Mantel-Haenszel test of linear association (only test on independence).
observeda table containing the observed frequencies.
expecteda vector or matrix containing the expected frequencies.
nan integer giving the number of observations.
kan integer giving the number of groups (only goodness-of-fit test).
ran integer giving the number of groups in the first variable corresponding to the rows (only test on independence).
can integer giving the number of groups in the second variable corresponding to the columns (only test on independence).
variablesa character vector containing the name(s) of the categorical variable(s) of interest.
typea character string giving the type of
chi-squared test performed ("goodness-of-fit"
or "independence").
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.
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.
Andreas Alfons
# 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.