8.4: Testing...
The significance of difference between means for paired parametric data (t-test for paired data):
Code \(\PageIndex{1}\) (R):
... t-test for independent data:
Code \(\PageIndex{2}\) (R):
(Last example is for learning purpose only because our data is paired since every row corresponds with one animal. Also, "paired=FALSE" is the default for the t.test() , therefore one can skip it.)
Here is how to compare values of one character between two groups using formula interface:
Code \(\PageIndex{3}\) (R):
Formula was used because our weight/sex data is in the long form :
Code \(\PageIndex{4}\) (R):
Convert weight/sex data into the short form and test:
Code \(\PageIndex{5}\) (R):
(Note that test results are exactly the same. Only format was different.)
If the p-value is equal or less than 0.05, then the difference is statistically supported. R does not require you to check if the dispersion is the same.
Nonparametric Wilcoxon test for the differences:
Code \(\PageIndex{6}\) (R):
One-way test for the differences between three and more groups (the simple variant of ANOVA, analysis of variation):
Code \(\PageIndex{7}\) (R):
Which pair(s) are significantly different?
Code \(\PageIndex{8}\) (R):
(We used Bonferroni correction for multiple comparisons.)
Nonparametric Kruskal-Wallis test for differences between three and more groups:
Code \(\PageIndex{9}\) (R):
Which pairs are significantly different in this nonparametric test?
Code \(\PageIndex{10}\) (R):
The significance of the correspondence between categorical data (nonparametric Pearson chi-squared, or \(\chi^2\) test):
Code \(\PageIndex{11}\) (R):
The significance of proportions (nonparametric):
Code \(\PageIndex{12}\) (R):
(Here we checked if this is true that the proportion of male is different from 50%.)
The significance of linear correlation between variables, parametric way (Pearson correlation test):
Code \(\PageIndex{13}\) (R):
... and nonparametric way (Spearman’s correlation test):
Code \(\PageIndex{14}\) (R):
The significance (and many more) of the linear model describing relation of one variable on another:
Code \(\PageIndex{15}\) (R):
... and analysis of variation (ANOVA) based on the linear model:
Code \(\PageIndex{16}\) (R):