chisq_test {r2spss} | R Documentation |
\chi^{2}
Tests
Description
Perform a \chi^{2}
goodness-of-fit test or a
\chi^{2}
test on independence on variables of
a data set. The output is printed as a LaTeX table that mimics
the look of SPSS output.
Usage
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)
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. |
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
|
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 "chisq_test_SPSS"
with the following components:
chisq
a list containing the results of the
\chi^{2}
test.lr
a list containing the results of a likelihood ratio test (only test on independence).
MH
a list containing the results of a Mantel-Haenszel test of linear association (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^{2}
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.
Note
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.
Author(s)
Andreas Alfons
Examples
# 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"))