t test
What is t test
t test is used to compare either the means of two sets of data or to compare an observed mean m to a theoretical value mu. There are different types of t test :
- The one-sample t test used to compare an observed mean with a theoretical mean.
- The independent t test (or two sample t test) used to compare the means of two unrelated groups of samples.
- The paired t test used to compare two sets of paired samples.
The different t test formula are described in detail by following this link: t test formula.
The objective of this chapter is to show you how to calculate t test in R.
t.test : R function to calculate t test
The R function to use for t test statistics is t.test(). It can be used to calculate the different types of Student t test mentioned above.
A simplified format of the function is:
# One sample t test :
# Comparison of an observed mean with a
# a theoretical mean
t.test(x, mu=0)
# Independent t test
# Comparison of the means of two independent samples (x & y)
t.test(x, y)
# Paired t test
t.test(x, y, paired=TRUE)
x and y are two numeric vectors.
The argument “alternative =” can be used to specify the alternative hypothesis. It must be one of “two.side” (2 tailed t test, default), “greater” or “less” (one sided t test) (see the R code below ).
t.test(x, y, alternative=c("two.sided", "less", "greater"))
Results of t test R function
The result of t.test() function is a list of class “htest” including the following components :
- statistic : the value of the t test statistics
- parameter : the degrees of freedom for the t test statistics
- p.value : the p-value for the test
- conf.int : a confidence interval for the mean appropriate to the specified alternative hypothesis.
- estimate : the means of the two groups being compared (in the case of independent t test) or difference in means (in the case of paired t test).
The format of the R code to use to get these values is as follow:
test<-t.test(x,y)
res$p.value # get the p-value
res$parameter # get the degrees of freedom
res$statistic # get the t test statistics
Many articles are included in this chapter. Scroll down to the bottom of this page to see some examples on how to perform t test in R.
Infos
This analysis has been done with R (ver. 3.1.0).
Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!!
Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous!
Recommended for You!
Recommended for you
This section contains best data science and self-development resources to help you on your path.
Coursera - Online Courses and Specialization
Data science
- Course: Machine Learning: Master the Fundamentals by Standford
- Specialization: Data Science by Johns Hopkins University
- Specialization: Python for Everybody by University of Michigan
- Courses: Build Skills for a Top Job in any Industry by Coursera
- Specialization: Master Machine Learning Fundamentals by University of Washington
- Specialization: Statistics with R by Duke University
- Specialization: Software Development in R by Johns Hopkins University
- Specialization: Genomic Data Science by Johns Hopkins University
Popular Courses Launched in 2020
- Google IT Automation with Python by Google
- AI for Medicine by deeplearning.ai
- Epidemiology in Public Health Practice by Johns Hopkins University
- AWS Fundamentals by Amazon Web Services
Trending Courses
- The Science of Well-Being by Yale University
- Google IT Support Professional by Google
- Python for Everybody by University of Michigan
- IBM Data Science Professional Certificate by IBM
- Business Foundations by University of Pennsylvania
- Introduction to Psychology by Yale University
- Excel Skills for Business by Macquarie University
- Psychological First Aid by Johns Hopkins University
- Graphic Design by Cal Arts
Books - Data Science
Our Books
- Practical Guide to Cluster Analysis in R by A. Kassambara (Datanovia)
- Practical Guide To Principal Component Methods in R by A. Kassambara (Datanovia)
- Machine Learning Essentials: Practical Guide in R by A. Kassambara (Datanovia)
- R Graphics Essentials for Great Data Visualization by A. Kassambara (Datanovia)
- GGPlot2 Essentials for Great Data Visualization in R by A. Kassambara (Datanovia)
- Network Analysis and Visualization in R by A. Kassambara (Datanovia)
- Practical Statistics in R for Comparing Groups: Numerical Variables by A. Kassambara (Datanovia)
- Inter-Rater Reliability Essentials: Practical Guide in R by A. Kassambara (Datanovia)
Others
- R for Data Science: Import, Tidy, Transform, Visualize, and Model Data by Hadley Wickham & Garrett Grolemund
- Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems by Aurelien Géron
- Practical Statistics for Data Scientists: 50 Essential Concepts by Peter Bruce & Andrew Bruce
- Hands-On Programming with R: Write Your Own Functions And Simulations by Garrett Grolemund & Hadley Wickham
- An Introduction to Statistical Learning: with Applications in R by Gareth James et al.
- Deep Learning with R by François Chollet & J.J. Allaire
- Deep Learning with Python by François Chollet
Click to follow us on Facebook and Google+ :
Comment this article by clicking on "Discussion" button (top-right position of this page)
Articles contained by this category :
Matrix of student t-test
T test analysis : is it always correct to compare means ?
t test calculator : The 3 best one you should know
Welch t-test