The second example uses a binary grouping variable with a single column of spending data. The first example assumes that we have two numeric vectors: one with Clevelanders' spending and one with New Yorkers' spending. In the three examples shown here we’ll test the hypothesis that Clevelanders and New Yorkers spend different amounts monthly eating out. To toggle this, we use the flag var.equal=TRUE. By default, R assumes that the variances of y1 and y2 are unequal, thus defaulting to Welch's test. The general form of the test is t.test(y1, y2, paired=FALSE). The independent-samples test can take one of three forms, depending on the structure of your data and the equality of their variances. T.test(preTreat, postTreat, paired = TRUE)Īlternative hypothesis: true difference in means is not equal to 0Īgain, we see that there is a statistically significant difference in means on t = 19.7514, p-value < 2.2e-16 Independent Samples Here, we would conduct a t-test using: set.seed(2820) We can visualize this difference with a kernel density plot as: We find that the mean systolic blood pressure has decreased to 138mmHg with a standard deviation 8mmHg. We find 1000 individuals with a high systolic blood pressure (\(\bar=145\)mmHg, \(SD=9\)mmHg), we give them Procardia for a month, and then measure their blood pressure again. The test is then run using the syntax t.test(y1, y2, paired=TRUE).įor instance, let’s say that we work at a large health clinic and we’re testing a new drug, Procardia, that’s meant to reduce hypertension. To conduct a paired-samples test, we need either two vectors of data, \(y_1\) and \(y_2\), or we need one vector of data with a second that serves as a binary grouping variable. With these simulated data, we see that the current shipment of lumber has a significantly lower volume than we usually see: t = -12.2883, p-value < 2.2e-16 Paired-Samples T-Tests T.test(treeVolume, mu = 39000) # Ho: mu = 39000Īlternative hypothesis: true mean is not equal to 39000 So, for example, if we wanted to test whether the volume of a shipment of lumber was less than usual (\(\mu_0=39000\) cubic feet), we would run: set.seed(0) To conduct a one-sample t-test in R, we use the syntax t.test(y, mu = 0) where x is the name of our variable of interest and mu is set equal to the mean specified by the null hypothesis.
0 Comments
Leave a Reply. |