Skip to main content

Section A.11 Chapter 12: Testing Hypotheses

Subsection A.11.1 Exercise 12.1

  1. The null hypothesis of no placebo effect corresponds to the expectation of the change equal to 0 (\(H_0: \Expec(X) = 0\)). The alternative hypothesis may be formulated as the expectation not being equal to 0 (\(H_1: \Expec(X) \not = 0\)). This corresponds to a two sided alternative. Observe that a negative expectation of the change still corresponds to the placebo having an effect.
  2. The observations that can be used in order to test the hypothesis are those associated with patients that were treated with the inactive placebo, i.e. the last 21 observations. We extracts these values from the data frame using the expression β€œmagnets$change[30:50]".
  3. In order to carry out the test we read the data from the file β€œmagnets.csv" into the data frame β€œmagnets". The function β€œt.test" is applied to the observations extracted from the data frame. Note that the default expectation value of tested by the function is β€œmu = 0":
    magnets <- read.csv("_data/magnets.csv")
    t.test(magnets$change[30:50])
    
    ## 
    ##  One Sample t-test
    ## 
    ## data:  magnets$change[30:50]
    ## t = 3.1804, df = 20, p-value = 0.004702
    ## alternative hypothesis: true mean is not equal to 0
    ## 95 percent confidence interval:
    ##  0.3768845 1.8135916
    ## sample estimates:
    ## mean of x 
    ##  1.095238
    
    The computed \(p\)-value is 0.004702, which is below 0.05. Consequently, we reject the null hypothesis and conclude that a placebo effect seems to be present.

Subsection A.11.2 Exercise 12.2

  1. We simulate the sampling distribution of the sample average and standard deviation. The sample is composed of \(n=20\) observations from the given Exponential distribution:
    lam <- 1/4
    n <- 20
    X.bar <- rep(0,10^5)
    S <- rep(0,10^5)
    for(i in 1:10^5) {
    X <- rexp(n,lam)
    X.bar[i] <- mean(X)
    S[i] <- sd(X)
    }
    T <- (X.bar - 4)/(S/sqrt(n))
    mean(abs(T) > qt(0.975,n-1))
    
    ## [1] 0.0793
    
    We compute the test statistic β€œT" from the sample average β€œX.bar" and the sample standard deviation β€œS". In the last expression we compute the probability that the absolute value of the test statistic is larger than β€œqt(0.975,19)", which is the threshold that should be used in order to obtain a significance level of 5% for Normal measurements.
    We obtain that the actual significance level of the test is \(0.08047\text{,}\) which is substantially larger than the nominal significance level.
  2. We repeat essentially the same simulations as before. We only change the distribution of the sample from the Exponential to the Uniform distribution:
    a <- 0
    b <- 8
    n <- 20
    X.bar <- rep(0,10^5)
    S <- rep(0,10^5)
    for(i in 1:10^5) {
    X <- runif(n,a,b)
    X.bar[i] <- mean(X)
    S[i] <- sd(X)
    }
    T <- (X.bar - 4)/(S/sqrt(n))
    mean(abs(T) > qt(0.975,n-1))
    
    ## [1] 0.05129
    
    The actual significance level of the test is \(0.05163\text{,}\) much closer to the nominal significance level of 5%.
    A possible explanation for the difference between the two cases is that the Uniform distribution is symmetric like the Normal distribution, whereas the Exponential is skewed. In any case, for larger sample sizes one may expect the Central Limit Theorem to kick in and produce more satisfactory results, even for the Exponential case.

Subsection A.11.3 Exercise 12.3

  1. We input the data to R and then compute the test statistic and the appropriate percentile of the \(t\)-distribution:
    n <- 55
    x.bar <- 22.7
    s <- 5.4
    t <- (x.bar - 20)/(s/sqrt(n))
    abs(t)
    qt(0.975,n-1)
    
    ## [1] 3.708099
    
    ## [1] 2.004879
    
    Observe that the absolute value of the statistic (3.708099) is larger than the threshold for rejection (2.004879). Consequently, we reject the null hypothesis.
  2. We recompute the percentile of the \(t\)-distribution:
    qt(0.995,n-1)
    
    ## [1] 2.669985
    
    Again, the absolute value of the statistic (3.708099) is larger than the threshold for rejection (2.669985). Consequently, we reject the null hypothesis.
  3. In this question we should recompute the test statistic:
    t <- (x.bar - 24)/(s/sqrt(n))
    abs(t)
    
    ## [1] 1.785381
    
    The absolute value of the new statistic (1.785381) is smaller than the threshold for rejection (2.004879). Consequently, we do not reject the null hypothesis.