t_test: t Tests

View source: R/t_test.R

t_testR Documentation

t Tests

Description

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.

Usage

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)

Arguments

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 is NULL, a one-sample t test is performed if only one variable is specified, and a paired-sample t test is performed if two variables are specified. If a grouping variable is specified in group, an independent-samples t-test is performed and this should be a character string specifying the numeric variable of interest.

group

a character string specifying a grouping variable for an independent-samples t-test, or NULL.

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 "t_test_SPSS" as returned by function t_test.

statistics

a character string or vector specifying which SPSS tables to produce. Available options are "statistics" for descriptive statistics and "test" for test results. For the to_SPSS method, only one option is allowed (the default is the table of test results), but the print method allows several options (the default is to print all tables).

version

a character string specifying whether the table should mimic the content and look of recent SPSS versions ("modern") or older versions (<24; "legacy"). The main differences in terms of content are that recent SPSS versions show a one-sided p-value in addition to the two-sided p-value, and that small p-values are displayed differently. For the paired-sample test, recent versions of SPSS also display a label Pair 1 for the selected pair of variables.

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 format_SPSS.

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 "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.

Note

LaTeX tables that mimic recent versions of SPSS (version = "modern") may require several LaTeX compilations to be displayed correctly.

Author(s)

Andreas Alfons

Examples

## 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")


r2spss documentation built on May 25, 2022, 5:05 p.m.