Learn R Programming

lsr (version 1.0.0)

oneSampleTTest: One sample t-test

Description

Runs a one-sample t-test and prints the results in a readable format.

Usage

oneSampleTTest(x, mu, one.sided = FALSE, conf.level = 0.95)

Value

Prints a summary showing the variable name, descriptive statistics, null and alternative hypotheses, test results (t-statistic, degrees of freedom, p-value), a confidence interval, and Cohen's d as a measure of effect size. The underlying results are also returned as a list, so the output can be assigned to a variable and inspected if needed.

Arguments

x

A numeric vector containing the data to be tested.

mu

The hypothesised population mean to test against.

one.sided

Set to FALSE (default) for a two-sided test. Set to "greater" if you expect the population mean to be above mu, or "less" if you expect it to be below.

conf.level

The confidence level for the confidence interval. The default is 0.95 for a 95% interval.

Details

Runs a one-sample t-test comparing the mean of x to the hypothesised value mu, and prints the results in a beginner-friendly format. The calculations are done by t.test and cohensD. Missing values in x are removed with a warning.

See Also

t.test, pairedSamplesTTest, independentSamplesTTest, cohensD

Examples

Run this code
likert <- c(3, 1, 4, 1, 4, 6, 7, 2, 6, 6, 7)

# two-sided test (the default)
oneSampleTTest(x = likert, mu = 4)

# one-sided test: is the mean greater than 4?
oneSampleTTest(x = likert, mu = 4, one.sided = "greater")

# wider confidence interval
oneSampleTTest(x = likert, mu = 4, conf.level = 0.99)

# missing values are removed with a warning
likert <- c(3, NA, 4, NA, 4, 6, 7, NA, 6, 6, 7)
oneSampleTTest(x = likert, mu = 4)

Run the code above in your browser using DataLab