Task 1
Assume samples X1, · · · , Xn are independently identically distribution from P(λ), consider the hypothesis
test
and the test statistic is
and the form of rejection region is
Next we will investigate how the sample size n, the true value of λ and the significance level α influence the power of test.
Note that the power function is
g(λ) = P(T(X1, · · · , Xn) ≤ C|T(X1, · · · , Xn) ~ P(nλ)),
which can be obtained via ppois(C, nλ) in R.
- Here, function PoissonPowerf() gives the value of power function for poisson distribution for sample n, the critical value C, and the true λ.
PoissonPowerf<-function(n=10,C=5,lambdas=1){
lam<-n*lambdas
alpha_lam<-ppois(C,lambda = lam)
return(alpha_lam)
- Obtain power function curve under different samples with the sample critical value C.
lams<-seq(0.01,2,by=0.01)
#true value of candidate for lambda
Ns<-c(10,20,40)
#sample size
power.n<-matrix(0,nr=length(lams),nc=length(Ns))
#length(lams) times length(Ns) matrix
#element[i,j] being the power when true value of lambda is lam[i] and sample size is Ns[j].
for (i in 1:length(lams)) {
for (j in 1:length(Ns)) {
power.n[i,j]<-PoissonPowerf(n=Ns[j],C=7,lambdas = lams[i])
} }
#plot
plot(lams,power.n[,1],type = 'l',lty=1,xlab = expression(lambda),ylab = 'Power',
main = 'Power function under different sample sizes',lwd=2)
lines(lams,power.n[,2],lty=2,col=2,lwd=2)
lines(lams,power.n[,3],lty=3,col=3,lwd=2) 1
abline(v=1,lwd=2)
legend('topright',legend = c('n=10', 'n=20','n=40'), lty=1:3,col=1:3,lwd=2)
From the above figure, it follows:
- For fixed n, the power function is decreasing function as λ ranging from 0 to 2, and the power is greater as
the true value of λ deviation from the null hypothesis H0 : λ ≥ 1.
- Given the rejection region W = {T(X1, · · · , Xn) ≤ 7}, the power function decreases as the sample sizes
increase, and specically the significance levels decreases as n increases.
- Obtain power function curve under different samples with the sample α.
To obtain it, we should calculate the rejection region, i.e., the critical value of C. By the definition of
signicance test with significance level α, it suffices to determine C such that
g(λ) = P(T(X1, · · · , Xn ≤ C)|T ~ P(nλ)) ≤ α, ?λ ∈ H0.
Recall that g(λ) is a decreasing function for λ ≥ 1, thus ?λ ≥ 1, g(λ) ≤ α is equivalent to
g(1) = P(T(X1, · · · , Xn ≤ C)|T ~ P(n)) ≤ α,
from which we can obtain C via qpois(α, n) in R. That is,
power.alpha<-matrix(0,nr=length(lams),
nc=length(Ns))
for (j in 1:length(Ns)) {
Cs<-qpois(0.05,Ns[j])
for (i in 1:length(lams)) {
power.alpha[i,j]<-PoissonPowerf(n=Ns[j],C=Cs,lambdas = lams[i])
#plot
plot(lams,power.alpha[,1],type = 'l',lty=1,xlab = expression(lambda),ylab = 'Power',
main = 'Fixed alpha, power function under different sample sizes',lwd=2)
lines(lams,power.alpha[,2],lty=2,col=2,lwd=2)
lines(lams,power.alpha[,3],lty=3,col=3,lwd=2)
abline(v=1,lwd=2)
legend('topright',legend = c('n=10', 'n=20','n=40'), lty=1:3,col=1:3,lwd=2)
Similarly, from the above figure, it follows:
- For fixed n and α, the power function is decreasing function as λ ranging from 0 to 2, and the power is
greater as the true value of λ deviation from the null hypothesis H0 : λ ≥ 1.
- For fixed α, the power function increases as the sample sizes increase.
- In summary, we can see that
the power of test increases as the true value of λ derviation far from H0; ? for fixed significance level α, the power of test increases as sample size increases;
yet for fixed critical value, i.e. C = 7, the power decreases as the sample size increase, which leads the
decreasing of the siginicance level α. 3