my_t.test: T-test function

Description Usage Arguments Value Examples

View source: R/my_t.test.R

Description

This function performs a one sample t-test in R.

Usage

1
my_t.test(x, alternative, mu)

Arguments

x

Numeric vector of data.

alternative

Character string specifying the alternative hypothesis. This should only accept "two.sided", "less", or "greater". Otherwise, your function should throw an informative error.

mu

Number indicating the null hypothesis value of the mean.

Value

List with elements: the numeric test statistic test_stat, the degrees of freedom df, the value of the parameter alternative, the numeric p-value p_val.

Examples

1
2
3
4
5
6
7
8
set.seed(302)
x <- rnorm(10, mean = 1, sd = 1)
# two-sided t-test
my_t.test(x, alternative = "two.sided", mu = 0.5)
# one-sided t-test -- upper tail
my_t.test(x, alternative = "greater", mu = 0.5)
# one-sided t-test -- lower tail
my_t.test(x, alternative = "less", mu = 0.5)

JudyTi/STAT302package documentation built on Dec. 18, 2021, 2:32 a.m.