HD 5514 Research Methods (Fall 2019)

In-Class Acitivity: One-Sample T-Test

Load Data

We are going to use mtcars data included in R by default. We will load and print the mtcars data.

Compute one-sample t-test (one.sided)

Using the alternative argument to change the alternative hypothesis. alternative argument allows one of the following options: “two.sided” (default), “greater” or “less”.

Compute one-sample t-test with a different mean

Using the mu argument to change the theoretical mean. Default is 18 but you can change it (mu = 20).

Use the help function

If you want to learn more about the t.test function.

In-Class Acitivity: Two-Sample T-Test

Check two data frame columns (mpg, am)

If two samples come from unrelated populations, they are independent.

First, find the data column, named mpg (gas mileage) of the mtcars data set.

Next, find another data column, named am (transmission type; 0 = automatic, 1 = manual) in the mtcars data set.

Conduct the unpaired t-test between two populations means

If two samples come from unrelated populations, they are independent. Compute the difference in means of the two sample data using the t.test fuction

Assignment 8 (Week 12)

Read Data

We will use build-in data set sleep. We will load and print the survey data.

Use the help function to learn about variables

If you want to learn more about the t.test function.

Check two data frame columns (group, extra)

First, find the data column, named extra, of the survey data set.

Next, find another data column, named group in the survey data set.

Conduct the unpaired t-test between two populations means (Welch t-test by default)

Compute the difference in means of the two sample data using the t.test fuction. By default, t.test does not assume equal variances; instead of Student’s t-test, it uses the Welch t-test by default.

Conduct the unpaired t-test between two populations means (Student’s t-test)

Now, assume equal variance and use Student’s t-test by setting var.equal=TRUE.

FYI: Test equal variance using Bartlett’s test

You can test whether two or more samples are drawn from populations with “equal variance” using Bartlett’s test. The null hypothesis of this test is that the variances are equal. The alterntive hypothesis is that they are not equal. If you fail to reject the null hypothesis, that means there is not enough evidence to suggest that the variance is different for groups. Thus, you can assume equal variance.

FYI: Visualize your data using a box plot by group

You can visualize both groups (1 and 2) using the boxplot function.

FYI: Conduct the paired t-test

When each subject is measured twice such as repeated-measures designs, it will result in pairs of observations that are not independent. In this case, we analyze the differences before and after using a paird sample t-test. We will test whether the mean values for the extra variable differs by the group variable to look at the difference between the two groups (group 1 and group 2).


    Paired t-test

data:  extra by group
t = -4.0621, df = 9, p-value = 0.002833
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -2.4598858 -0.7001142
sample estimates:
mean of the differences 
                  -1.58 

Koeun Choi

November 13, 2019