TTests
KEY:
ds = dataset you are currently using.
â€‹
DV = dependent variable of interest
â€‹
IV = independent variable of interest
â€‹
XYXY = dummy name for a variable, matrix, or data frame into which you are moving information.
Performing a TTest with betweensubjects data
Reminder: Always begin by performing a test of homogeneity of variance. The car package includes Lavene's test.
_____________________________
library(car)
leveneTest(DV ~ IV, center = mean, data=ds)
_____________________________
If p<.05 you have a situation where group variances are different (var.equal=FALSE). If p>.05, there is insufficient evidence to draw such a conclusion (var.equal=TRUE).
â€‹
"paired" is set to FALSE to indicate that the data are betweensubjects, and thus an independentsamples test should be run.
â€‹
If your IV has only two levels
_____________________________
XYXY < t.test(DV ~ IV, var.equal=??????, paired = FALSE, data=ds)
_____________________________
â€‹
â€‹
If your IV has more than two levels
r has a command (pairwise.t.test) that can perform multiple tests concurrently. However, this does not provide t values or df information. Adding a subset command to t.test will allow you to test specified levels, while producing critical output. Just remember to adjust for multiple tests.
â€‹
For subset:

%in% will pair your IV name with each of the components in the c() list. Make sure to put the names in "".

L1, L2, L3 are the names you may have given to the different levels of the IV
_____________________________
XYXY1 < t.test(DV ~ IV, var.equal=??????, paired = FALSE, data=ds, subset = IV %in% c("L1", "L2"))
XYXY2 < t.test(DV ~ IV, var.equal=??????, paired = FALSE, data=ds, subset = IV %in% c("L1", "L3"))
XYXY3 < t.test(DV ~ IV, var.equal=??????, paired = FALSE, data=ds, subset = IV %in% c("L2", "L3"))
_____________________________
â€‹
Performing a TTest with withinsubjects data
"paired" is set to TRUE to indicate that the data are withinsubjects, and thus an pairedsamples test should be run.
_____________________________
XYXY < t.test(DV ~ IV, paired = TRUE, data=ds)
_____________________________
â€‹
PostHoc TTests using the results of a oneway ANOVA *not complete*
The lsr package can use the results of an aov file to perform multiple ttests and make correct for multiple comparisons.
â€‹
At present, this function is a demo, but it will provide fastaccess to pvalues.
â€‹
_____________________________
library(lsr)
XYXY <posthocPairwiseT(x=aovFile, p.adjust.method="bonferroni")
_____________________________
â€‹