1 Initialize R

Initialize R with the following commands:

# Initialize R -------------------------------------

# I set the working directory to be the folder that includes this document
graphics.off() # clear all graphs
options(digits=6,width=80) # R console display parameters
options(contrasts=c("contr.sum","contr.poly") ) # set up coding scheme for factors:
op <- par(no.readonly = TRUE) # save copy of current parameters
# usually a good idea to CLEAR WORKSPACE MEMORY
# use command in RStudio "Session" menu
# load libraries into R:
library(effectsize)
library(pwr)
library(TOSTER) # optional

2 One-sample t test

Load the iq data file.

load(file=url("http://pnb.mcmaster.ca/bennett/psy710/datasets/iq.rda"))

The numeric variable iq contains IQ scores from 20 individuals. Graphically inspect the data: check for outliers, extreme skew, etc.

# Check distributions:
par(mfrow=c(1,2)); # create 2 graphs on 1 page
boxplot(iq); # box plot
qqnorm(iq);qqline(iq) # qq plot

The data were analyzed with the following command.

# The data were analyzed with the following command.
t.test(iq,mu=100) # do t test
  1. What are the null and alternative hypotheses that are being evaluated by this t test?
  1. Assuming alpha is 0.05, can we conclude that our sample came from a population with a mean that differed from 100?
  1. Use t.test to calculate the 95% and 90% confidence intervals for the population mean of iq. Which interval is narrower? Why?
  1. Calculate the mean and standard deviation of iq. How many standard deviations is the mean away from 100? Next, read the help page for cohens_d and then use that command to compute Cohens d, a common measure of effect size, for iq (assuming that the true value of the population mean is 100).
  1. Statistical power refers to the probability of correctly rejecting a false null hypothesis. Assuming that our sample of 20 was drawn from a population with a true mean of 95 and a standard deviation of 10, use the command power.t.test to calculate the power of our t test to reject the false null hypothesis \(\mu=100\). (You may want to read the help page for power.t.test.)

5b. Now use power.t.test to calculate the sample size that we would need to attain a power of 0.8.

  1. Use a t test to determine if the sample was drawn from a population with a mean that is less than 100.

3 One-sample equivalence test

An equivalence test is used to determine if an effect falls between pre-defined lower and upper bounds. IQ tests are designed to have a population mean of 100 and a standard deviation of 15. Let’s assume that the smallest difference of interest is 7 (i.e., approximately 1/2 of a standard deviation). In other words, we will assume that any population mean 93 and 107 is essentially equivalent to a mean of 100.

  1. Use two one-sided tests (TOST) to evaluate the null hypothesis that the population mean is less than 93 OR greater than 107. Set alpha to 0.05 for these tests. Based on those tests, do you reject the null hypothesis that our sample was selected from a population with a mean that is equivalent to 100?
  1. Use a two-tailed t test to evaluate the null hypothesis that the population mean IQ equals 100. However, for this this test I want you to set the parameter conf.level to 0.90 (rather than the default value of 0.95). This parameter sets the width of the confidence interval returned by t.test. What is the value of the confidence interval, and how does it compare to the equivalence test performed in the previous question?

4 Two-sample t test & equivalence test

Load the vitcap data file.

load(file=url("http://pnb.mcmaster.ca/bennett/psy710/datasets/vitcap.rda"))

The data frame vitcap contains two numeric variables, control and exposed, each containing 75 values. The data are from an experiment that measured so-called vital capacity (a measure of lung volume) in liters in a group of workers exposed to cadmium and an age-matched control group. Use box plots to graphically inspect each variable for outliers, extreme skew, etc.

  1. Use a two-sample t test to evaluate the null hypothesis that the population means for the two groups are equal.

  2. Use an equivalence test to evaluate the null hypothesis that the true difference between populations means is less than -0.5 OR greater than +0.5. Using an alpha of 0.05, what is your decision about this null hypothesis.