For Lab Assignment 3, you are going to conduct a t-test. We will also be building off of previous R experience to help us graphically display the results.

In the first line of code, I am going to create a fake dataset. To follow along with my example, you should copy and paste this entire chunk of code into your script.

For our (fake) dataset, we will pretend we ran a simple experiment. We randomly sampled forty students from Maryville College to take part in our study. Participants were randomly assigned to an experimental or control condition. In the experimental condition, participants were given a $100 gift card for every A they received. In the control group, they were sent a note that was signed by the Dean of the college. The students GPA at the end of the semester was measured.

# you should copy this entire chunk into your R script

set.seed(120) # sets a random number generator seed

gender <- sample(c("male","female"), 40, replace=TRUE)
condition <- c(rep("experimental", 20), rep("control", 20))
gpa <- round(c(rnorm(n=20, mean=3.68, sd=.41), rnorm(n=20, mean=3.11, sd=.56)),2)

data <- data.frame(gender, condition, gpa)

The first step in data analysis is to get to know the data. I will use the summary function to see the variables in my dataset.

summary(data)
##     gender          condition       gpa       
##  female:19   control     :20   Min.   :2.360  
##  male  :21   experimental:20   1st Qu.:3.147  
##                                Median :3.330  
##                                Mean   :3.453  
##                                3rd Qu.:3.750  
##                                Max.   :4.780

Next I will look at the mean and standard deviation for the GPA.

mean(data$gpa)
## [1] 3.4525
sd(data$gpa)
## [1] 0.5464231

To conduct a t-test, I will use the t.test function. This has some new syntax. In R, we can write out a statistical formula using the syntax: DV ~ IV, where the DV is our response variable and the IV is our explanatory variable. We will see this syntax again when we do regression.

I am going to run a t-test to analyze the GPAs between males and females and graph the results. Notice that the results will contain confidence intervals.

# t-test
t.test(gpa ~ gender, data=data)
## 
##  Welch Two Sample t-test
## 
## data:  gpa by gender
## t = 0.4991, df = 37.001, p-value = 0.6207
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2676248  0.4425621
## sample estimates:
## mean in group female   mean in group male 
##             3.498421             3.410952

The results of the t-test are not significant, as our p-value is higher than .05 (p = .23). This indicates that males and females do not differ in their GPA. I can also see this by looking at the 95% confidence intervals, which indicate that zero is a plausible value for the difference between the means.

To graph the mean GPA, I will have to first aggregate the data. You can see the process below. I will include lots of options in the bar graph, though most of them are not strictly necessary.

# aggregating the data
means <-aggregate(data$gpa, by=list(gender), FUN=mean)

# graphing the results (note that this can appear on one line or multiple lines)
barplot(means$x, names=means$Group.1, 
        ylab="GPA", 
        col=c("darkred","goldenrod"),
        main="Mean GPA")

Your job is to use this same data to answer the following questions. Please submit a document that contains the answers to the questions and your R code.

Lab Questions:

  1. Conduct a t-test to compare GPA in our experimental and control conditions. What is the t-value?

  2. What is the p-value for the t-test?

  3. What are the 95% confidence intervals for the difference between the means?

  4. What is our decision regarding the null hypothesis?

  5. What population can we generalize our results to?

  6. Can we make a claim about causation?

  7. What did we find? Put the results in plain English.

Include a bar graph showing the difference between the means and copy your R code used to complete the assignment.