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
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
t.test
to calculate the 95% and 90% confidence
intervals for the population mean of iq
. Which interval is
narrower? Why?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).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.
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.
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?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.
Use a two-sample t test to evaluate the null hypothesis that the population means for the two groups are equal.
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.