t_test | R Documentation |
Perform a one-sample t test, a paired-sample t test or an independent-samples t test on variables of a data set. The output is printed as a LaTeX table that mimics the look of SPSS output.
t_test(data, variables, group = NULL, mu = 0, conf.level = 0.95) ## S3 method for class 't_test_SPSS' to_SPSS( object, statistics = c("test", "statistics"), version = r2spss_options$get("version"), digits = 3, ... ) ## S3 method for class 't_test_SPSS' print( x, statistics = c("statistics", "test"), version = r2spss_options$get("version"), digits = 3, ... ) tTest(data, variables, group = NULL, mu = 0, conf.level = 0.95)
data |
a data frame containing the variables. |
variables |
a character vector specifying numeric variable(s) to be
used for testing the mean(s). If |
group |
a character string specifying a grouping variable for an
independent-samples t-test, or |
mu |
a number indicating the true value of the mean for a one-sample t test. |
conf.level |
a number between 0 and 1 giving the confidence level of the confidence interval. |
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 giving the number of digits after the comma to be printed in the SPSS tables. |
... |
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 "t_test_SPSS"
with the following
components:
statistics
a data frame containing the relevant descriptive statistics.
test
an object of class "htest"
as returned by
t.test
(only one-sample and paired-sample tests).
variables
a character vector containing the name(s) of the relevant numeric variable(s).
n
an integer giving the number of observations (only paired-sample test).
levene
an object as returned by
leveneTest
(only independent-samples test).
pooled
an object of class "htest"
as returned
by t.test
assuming equal variances (only
independent-samples test).
satterthwaite
an object of class "htest"
as returned
by t.test
not assuming equal variance (only
independent-samples test).
group
a character string containing the name of the grouping variable (only independent-samples test).
type
a character string giving the type of t test performed
("one-sample"
, "paired"
, or "independent"
).
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.
LaTeX tables that mimic recent versions of SPSS (version = "modern"
)
may require several LaTeX compilations to be displayed correctly.
Andreas Alfons
## one-sample and paired-sample t test # load data data("Exams") # test whether the average grade on the resit # differs from 5.5 (minimum passing grade) t_test(Exams, "Resit", mu = 5.5) # test whether average grades differ between the # regular exam and the resit t_test(Exams, c("Resit", "Regular")) ## independent-samples t test # load data data("Eredivisie") # log-transform market values Eredivisie$logMarketValue <- log(Eredivisie$MarketValue) # test whether average log market values differ between # Dutch and foreign players t_test(Eredivisie, "logMarketValue", group = "Foreign")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.