# One sample Student’s t-test

**Statistic on aiR**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Comparison of the sample mean with a known value, when the variance of the population is not known.

Consider the exercise we have just seen before.

It was made an intelligence test in 10 subjects, and here are the results obtained. The average result of the population whici received the same test, is equal to 75. You want to check if the sample mean is significantly similar (when the significance level is 95%) to the average population, assuming that the variance of the population is not known.

Contrary to the one sample Z-test, the **Student’s t-test** for a **single sample** have a pre-set function in R we can apply immediately.

It is the `t.test (a, mu)`

, we can see below applied.

a = c(65, 78, 88, 55, 48, 95, 66, 57, 79, 81)

t.test (a, mu=75)

One Sample t-test

data: a

t = -0.783, df = 9, p-value = 0.4537

alternative hypothesis: true mean is not equal to 75

95 percent confidence interval:

60.22187 82.17813

sample estimates:

mean of x

71.2

The function `t.test`

on one sample provides in output the value of t calculated; also gives us degrees of freedom, the confidence interval and the average (mean of x).

In order to take your statistic decision, you can proceed in two ways. We can compare the value of t with the value of the tabulated student t with 9 degrees of freedom. If we do not have tables, we can calculate the value t-tabulated in the following way:

qt(0.975, 9)

[1] 2.262157

The function `qt (p, df)`

returns the value of t computed considering the significance level (we chose a significance level equal to 95%, which means that each tail is the 2.5% which corresponds to the value of *p = 1 – 0.025*), and the degrees of freedom. By comparing the value of t-tabulated with t-computed, t-computed appears smaller, which means that we accept the null hypothesis of equality of the averages: our sample mean is significantly similar to the mean of the population.

Alternatively we could consider the p-value. With a significance level of 95%, remember this rule: If **p-value is greater than 0.05** then **we accept the null hypothesis H0**; if **p-value is less than 0.05** then **we reject the null hypothesis H0** in favor of the alternative hypothesis H1.

**leave a comment**for the author, please follow the link and comment on their blog:

**Statistic on aiR**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.