```
# Create sample data
<- tibble::tribble(
read ~score, ~count,
40, 2, 47, 2, 52, 2, 26, 1, 19, 2,
25, 2, 35, 4, 39, 1, 26, 1, 48, 1,
14, 2, 22, 1, 42, 1, 34, 2 , 33, 2,
18, 1, 15, 1, 29, 1, 41, 2, 44, 1,
51, 1, 43, 1, 27, 2, 46, 2, 28, 1,
49, 1, 31, 1, 28, 1, 54, 1, 45, 1
)
```

# One Sample t-test

**One Sample t-test in R**

The One Sample t-test is used to compare a single sample against an expected hypothesis value. In the One Sample t-test, the mean of the sample is compared against the hypothesis value. In R, a One Sample t-test can be performed using the Base R `t.test()`

from the **stats** package or the `proc_ttest()`

function from the **procs** package.

### Data Used

The following data was used in this example.

## Normal Data

By default, the R one sample t-test functions assume normality in the data and use a classic Student’s t-test.

### Base R

#### Code

The following code was used to test the comparison in Base R. Note that the baseline null hypothesis goes in the “mu” parameter.

```
# Perform t-test
t.test(read$score, mu = 30)
```

```
One Sample t-test
data: read$score
t = 2.3643, df = 29, p-value = 0.02497
alternative hypothesis: true mean is not equal to 30
95 percent confidence interval:
30.67928 39.38739
sample estimates:
mean of x
35.03333
```

### Procs Package

#### Code

The following code from the **procs** package was used to perform a one sample t-test. Note that the null hypothesis value goes in the “options” parameter.

```
library(procs)
# Perform t-test
proc_ttest(read, var = score,
options = c("h0" = 30))
```

```
$Statistics
VAR N MEAN STD STDERR MIN MAX
1 score 30 35.03333 11.66038 2.128884 14 54
$ConfLimits
VAR MEAN LCLM UCLM STD LCLMSTD UCLMSTD
1 score 35.03333 30.67928 39.38739 11.66038 9.286404 15.67522
$TTests
VAR DF T PROBT
1 score 29 2.364306 0.0249741
```

Viewer Output:

## Lognormal Data

The Base R `t.test()`

function does not have an option for lognormal data. Likewise, the **procs** `proc_ttest()`

function also does not have an option for lognormal data.

One possibility may be the `tTestLnormAltPower()`

function from the **EnvStats** package. This package has not been evaluated yet.