library(knitr) # creating slides
library(ggplot2) # making plots
library(reshape2) # handling data frames
02/01/2021
library(knitr) # creating slides
library(ggplot2) # making plots
library(reshape2) # handling data frames
:: \(H_0\) is \(\mu_0\) = 30
:: \(H_a\) is \(\mu_a\) > 30
Where (X’-30)/(\(s\)/\(\sqrt(n)\)) measures the number of standard
errors the sample mean is from the mean hypothesized by \(H_0\)
and the denominator, (\(s\)/\(\sqrt(n)\)) is the standard error of
the sample mean.
:: flip the following reasoning
:: look at the right tail
Power is the probability of rejecting the NULL HYPOTHESIS
\(H_0\), when it is false.
:: Used to determine if your sample size was big enough
to yield a meaningful, rather than random result
:: Detect if your ALTERNATIVE HYPOTHESIS, \(H_a\) is true,
to lower the risk of a Type II errors.
As beta, \(\beta\), is the probability of a Type II error,
for accepting a false null hypothesis, then the complement
of this the power is (1-\(\beta\)).
\[ P = (1-\beta) \]
:: As \(\mu_a\) gets bigger, the test gets more powerful
:: As \(n\) gets bigger, the test gets more powerful
:: Power decreases with increases in variation
:: As \(\alpha\) increases, power increases
:: In a one sided test the power is greater as \(\alpha\)
is bigger than \(\alpha\)/2
Power is the probability that the true mean \(\mu\) is greater
than the (1-\(\alpha\)) quantile, in our sleep example:
:: if \(\alpha\) = .05 and as \(H_a\) \(\mu_a\) > 30
:: for normal distributions of which we know the variances
:: we make p = qnorm(.95) our reference
If a test statistic fell in the shaded portion, 5% of the area under the curve, we would reject \(H_0\) in favor \(H_a\).
The two hypotheses, \(H_0\) and \(H_a\), represent two distributions
:: since they’re talking about means or
:: centers of distributions.
For a random variable X which is distributed as Normal
with a mean mu, \(\mu\) and variance sigma squared, \(\sigma^2\):
:: under \(H_0\), X’ is N(\(\mu_0\) , \(\sigma^2\)/n)
:: under \(H_a\), X’ is N(\(\mu_a\) , \(\sigma^2\)/n)
The distribution represented by \(H_a\) will moved to the right,
most of the blue curve is to the right of the vertical line,
indicating that with \(\mu_a\) = 34, the test is more powerful,
so it is
:: correct to reject the \(H_0\) as it appears to be false.
The distribution represented by \(H_a\), in the above graph
moved under the blue curve, indicating that with
:: \(\mu_a\) = 30 = \(\mu_0\) , the test,
:: \(H_a\) is almost as powerful as \(H_0\), so it is
:: incorrect to reject the null hypothesis since it does
not appear to be false.
The distribution represented by \(H_a\) will move to the left of
\(\mu_0\) = 30, the area under the blue curve is less than the
5% our \(\alpha\), so the test is not only less powerful, it even
contradicts \(H_a\)
:: it is therefore not worth looking into.
Power is a function that depends on a specific value of an
alternative mean, \(\mu_a\), which is any value greater than
\(\mu_0\), the mean hypothesized by \(H_0\)
:: Recall that H_a specified mu > 30, in the sleep case.
If \(\mu_a\) is much bigger than \(\mu_0\) = 30 then the power
a probability, is bigger than if \(\mu_a\) is close to 30.
:: As \(\mu_a\) approaches 30, the mean under \(H_0\), the power
approaches \(\alpha\).
# mean=30 z <- qnorm(.95) pnorm(30+z,mean=30,lower.tail=FALSE)
## [1] 0.05
With the mean set to \(\mu_0\) the two distributions,
null and alternative, are the same and power = \(\alpha\) = 5%.
#mean=32 z <- qnorm(.95) pnorm(30+z, mean=32,lower.tail=FALSE)
## [1] 0.63876
With \(\mu_a\) > \(\mu_0\)mu_a the power is greater than \(\alpha\), at 64%.
:: When the sample mean is many standard errors greater than
the mean hypothesized by the null hypothesis,
:: the probability of rejecting \(H_0\) is false is much higher.
# sd=1 z <- qnorm(.95) pnorm(30+z, mean=32, sd= 1, lower.tail=FALSE)
## [1] 0.63876
# sd=2 z <- qnorm(.95) pnorm(30+z, mean=32, sd= 2, lower.tail=FALSE)
## [1] 0.5704709
:: Power decreases with increases in variation
:: As \(\alpha\) increases, power increases
:: In a one sided test the power is greater as \(\alpha\) is bigger than \(\alpha\)/2
:: flip the above reasoning
:: look at the right tail
Assumed that X’~ N(\(\mu_a\), \(\sigma^2/n\))
Supposed that \(H_a\) says that \(\mu\) > \(\mu_0\)
:: As power = 1 - beta
= Prob ( X’ > \(\mu_0\) + z_(1-\(\alpha\)) * \(\sigma\)/\(\sqrt(n)\))
:: the population mean equals \(\mu_0\)
:: the level size of the test is \(\alpha\)
:: But are given \(\mu_a\) > \(\mu_0\), \(\mu_0\) and \(\alpha\)
:: and X’ depends on the data.
:: As power = 1 - beta
= Prob ( X’ > \(\mu_0\) + z_(1-\(\alpha\)) * \(\sigma\)/\(\sqrt(n)\))
:: only \(\sqrt(n)\) * \(\frac{\mu_a - \mu_0}{\sigma}\) is needed
:: this is the effect size
:: t quantile instead of the z
Power is still a probability, namely
:: \(\frac{P(X' - \mu_0)}{(S /\sqrt(n)}\) > t_(1-\(\alpha\), \(n\)-1)
for \(H_a\) that \(\mu\) > \(mu_a\)
:: the proposed distribution is not centered at \(mu_0\),
:: so we have to use the non-central t distribution.
:: omit one of the arguments and power.t.test()
solves for it
power.t.test(n = 16,delta = 2 / 4, sd=1, type = "one.sample",
alt = "one.sided")$power
## [1] 0.6040329
power.t.test(n = 16, delta = 2 , sd=4, type = "one.sample",
alt ="one.sided")$power
## [1] 0.6040329
power.t.test(n = 16, delta = 100 , sd=200, type = "one.sample",
alt ="one.sided")$power
## [1] 0.6040329
:: keeping the effect size (the ratio delta/sd) constant preserved the power
:: get a constant effect size with
with the same values for n (16) & alpha (.05), but
different delta and standard deviation values
:: specify a power we want and solve for the sample size \(n\).
power.t.test(power = .8, delta = 2 / 4, sd=1, type = "one.sample",
alt = "one.sided")$n
## [1] 26.13751
power.t.test(power = .8, delta = 2, sd=4, type = "one.sample",
alt = "one.sided")$n
## [1] 26.13751
power.t.test(power = .8, delta = 100, sd=200, type = "one.sample",
alt = "one.sided")$n
## [1] 26.13751
# use power.t.test to find delta for a power=.8 and n=26 and sd=1
power.t.test(power = .8, n=26, sd=1, type = "one.sample",
alt = "one.sided")$delta
## [1] 0.5013986
#use power.t.test to find delta for a power=.8 and n=27 and sd=1
power.t.test(power = .8, n=27, sd=1, type = "one.sample",
alt = "one.sided")$delta
## [1] 0.4914855
#use power.t.test to find delta for a power=.8 and n=26 and sd=2
power.t.test(power = .8, n=26, sd=2, type = "one.sample",
alt = "one.sided")$delta
## [1] 1.002797
:: As \(\mu_a\) gets bigger, the test gets more powerful
:: As \(n\) gets bigger, the test gets more powerful
:: Power decreases with increases in variation
:: As \(\alpha\) increases, power increases, so
:: A one sided test has greater power