My assumptions are violated!!

M. Drew LaMar
November 13, 2019

Class Announcements

  • Homework #8 (Chap. 13) due Monday, November 18, 11:59 pm
  • Lab #8 (Data Visualization with ggplot2) due November 25, 11:59 pm

Finish up replication and sampling

Examples, examples, examples

Birdsongs and attractiveness

Question: How do we measure relationship between male birdsongs and attractiveness to females?

Experimental Design: Record the complex song of one male and the simple song of another male, and then play these same two songs to each of 40 different females. Compute a confidence interval for the mean attractiveness of the two male songs.

Discuss: What is wrong with this design so far?

Answer: Each measure of female choice is a pseudoreplicate (\( n=40 \)).

Examples, examples, examples

Discuss: What is wrong with this design so far?

Answer: Each measure of female choice is a pseudoreplicate (\( n=40 \)).

Discuss: What can we do to correct for this pseudoreplication?

Answer: Record songs of 40 males with complex songs, and 40 separate males with simple songs. Each female should listen to a unique pair of songs, one simple and one complex. Design can get even more complicated than this.

Discuss: What are examples of confounding variables in the pseudoreplicated case?

Examples, examples, examples

Blood sugar levels

Experimental Design: Phlebotomist takes 15 samples from each of 10 patients, yielding a total of 150 measurements.

Discuss: What is the replicate and sample size in this situation? Why?

Examples, examples, examples

Antibiotics and bacterial growth rates

Experimental Design: Two agar plates: one with antibiotic, one without. Spread bacteria on both plates, let them grow for 24 hours, then measure diameter of 100 colonies on each plate?

Discuss: What is the replicate and sample size in this situation? Why?

What sample size should I use?

Three things:

  • Plan for precision (estimation)
  • Plan for power (hypothesis testing)
  • Plan for data loss

We'll use a two-sample \( t \)-test as the example in this section.

Plan for precision

We would like to compute a 95% confidence interval for \( \mu_{1}-\mu_{2} \).

\[ \bar{Y}_{1}-\bar{Y}_{2} \pm \mathrm{margin \ of \ error}, \]

where “margin of error” is the half-width of the 95% confidence interval.

In this case, the following formula is an approximation to the number of samples needed to achieve the desired margin of error (assuming balanced design, i.e. \( n_{1}=n_{2}=n \)):

\[ n \approx 8\left(\frac{\mathrm{margin \ of \ error}}{\sigma}\right)^{-2} \]

Plan for precision

Plan for power

Two-sample \( t \)-test:

\[ H_{0}: \mu_{1} - \mu_{2} = 0. \] \[ H_{A}: \mu_{1} - \mu_{2} \neq 0. \]

A conventional power to aim for is 0.80, i.e. we aim to prove \( H_{0} \) is false in 80% of experiments.

Assuming a significance level of 0.05, a quick approximation to the planned sample size \( n \) in each of two groups is

\[ n \approx 16\left(\frac{D}{\sigma}\right)^{-2}, \]

where \( D = |\mu_{1}-\mu_{2}| \) is the effect size.

Pwr package in R

library(pwr)
function power calculations for
pwr.2p.test two proportions (equal n)
pwr.2p2n.test two proportions (unequal n)
pwr.anova.test balanced one way ANOVA
pwr.chisq.test chi-square test
pwr.f2.test general linear model
pwr.p.test proportion (one sample)
pwr.r.test correlation
pwr.t.test t-tests (one sample, 2 sample, paired)
pwr.t2n.test t-test (two samples with unequal n)

Two-sample t-test example

Two-sample \( t \)-test with significance level 0.05, 80% power, and relative effect size \( d = \frac{|\mu_{1}-\mu_{2}|}{\sigma} = 0.3 \).

pwr.t.test(d=0.3, power=0.8, type="two.sample")

     Two-sample t test power calculation 

              n = 175.3847
              d = 0.3
      sig.level = 0.05
          power = 0.8
    alternative = two.sided

NOTE: n is number in *each* group

Two-sample t-test example

plot of chunk unnamed-chunk-4

Additional Reading

  • Whitlock & Schluter, Interleaf 2: Pseudoreplication (pp. 115-116)
  • Whitlock & Schluter, Chapter 14: Designing experiments

Handling violations of assumptions

Handling violations of assumptions

Four options for handling violations of assumptions:

  • Ignore the violations of assumptions
  • Transform the data
  • Use a nonparametric method
  • Use a permutation test (computer-intensive methods)

Need to detect deviations first

To check for normality, first (as always) look at your data. Histograms work best here.

Detecting deviations from normality

The following data come from a normal distribution:

They don't look normal, but they:

  • …don't have outliers
  • …aren't skewed

Detecting deviations from normality

Examples of data from non-normal distributions:

Normal quantile plot

Definition: The normal quantile plot compares each observation in the sample with its quantile expected from the standard normal distribution. Points should fall roughly along a straight line if the data come from a normal distribution.

Normal quantile plot - R Example

  1. Sort measurements (\( x \))
  2. Compute percentiles of \( x \) (cumulative probabilities, \( p \))
  3. Compute standard normal quantiles from percentiles (\( q \))
  4. Plot measurements against computed quantiles (\( q \) vs \( x \))
x <- sort(rnorm(20))  # (1)
p <- (1:20)/21  # (2)
q <- qnorm(p, lower.tail = TRUE)  # (3)
plot(q ~ x, xlab="Measurements", ylab="Normal quantiles")  # (4)

Normal quantile plot - R Example

x <- sort(rnorm(20))  # (1)
p <- (1:20)/21  # (2)
q <- qnorm(p, lower.tail = TRUE)  # (3)
plot(q ~ x, xlab="Measurements", ylab="Normal quantiles")  # (4)

plot of chunk unnamed-chunk-6

Normal quantile plot - R Example

Fast way (note: axes are flipped by default!)

qqnorm(x, datax = TRUE)

plot of chunk unnamed-chunk-7

Marine reserve example

Question: Are marine reserves effective in preserving marine wildlife?

Experimental design

Halpern (2003) matched 32 marine reserves to a control location, which was either the site of the reserve before it became protected or a similar unprotected site nearby. They then evaluated the “biomass ratio,” which is the ratio of total masses of all marine plants and animals per unit area of reserve in the protected and matched unprotected areas.

Marine reserve example

Experimental design

Halpern (2003) matched 32 marine reserves to a control location, which was either the site of the reserve before it became protected or a similar unprotected site nearby. They then evaluated the “biomass ratio,” which is the ratio of total masses of all marine plants and animals per unit area of reserve in the protected and matched unprotected areas.

Discuss: Observational or experimental? Paired or unpaired? Interpret response measure in terms of effect of protection.

Answer: Observational. Paired (matching). Biomass ratio = 1 (no effect); > 1 (beneficial effect); < 1 (detrimental effect).

How to interpret normal quantile plots

How to interpret normal quantile plots

How to interpret normal quantile plots

Practice Problem #4: Interpret the following normal quantile plots.