### Hypothesis Testing Examples ### Locating the critical value of the test. ####################################################### ####################################################### # Example 1: Normal assume theta0 < theta1 # How to make a normal table in R/S-Plus ####################################################### # Suppose alpha = 0.05 theta0 = 25; sigma0 = 3; n = 30; xx = seq(theta0-5*sigma0/sqrt(n),theta0+5*sigma0/sqrt(n),.01) yy = dnorm(xx, mean = theta0, sd = sigma0/sqrt(n)) plot(xx,yy,type="l") # plot the null distribution ####################################################### low = 1.6 # change these values to locate alpha = 0.05 up = 1.7 k = seq(low,up,0.001) cv = 1 - pnorm(k) # critical value is for alpha = 0.05 cv = round(cv,4) cv = matrix(c(k,cv),ncol=2) cv cv = cv[cv[,2]==alpha] rr = theta0 + cv[1]*sigma0/sqrt(n) rr ####################################################### ####################################################### # Example 2: Exponential assume lambda0 > lambda1 ####################################################### # Suppose alpha = 0.05 lambda0 = 1.3; n = 3; m = n/lambda0; v = n/lambda0^n; xx = seq(0,m+5*v,.01) xx = seq(0,5,0.1) yy = dgamma(xx, shape = n, rate = lambda0) plot(xx,yy,type="l") ####################################################### low = 0 # change these values to locate alpha = 0.05 up = 5 k = seq(low, up, 0.001) cv = 1 - pgamma(k,shape = n, rate = lambda0) # critical value is for alpha = 0.05 cv = round(cv,4) cv = matrix(c(k,cv),ncol=2) cv cv = cv[cv[,2]==alpha] rr = cv[1] rr ####################################################### ####################################################### # Example 3: Poisson assume lambda0 > lambda1 ####################################################### # Suppose alpha = 0.05 lambda0 = 1; n = 10; xx = seq(0,3*n*lambda0,1) yy = dpois(xx, lambda = n*lambda0) plot(xx,yy,type="h") # plot the null distribution ####################################################### low = 0 # change these values to locate alpha = 0.05 up = 30 k = seq(low, up, 1) cv = ppois(k,n*lambda0) # critical value is for alpha = 0.05 cv = round(cv,4) cv = matrix(c(k,cv),ncol=2) cv cv = matrix(cv[cv[,2]<=alpha],ncol=2) row.max = dim(cv)[1] # Find the last row cv = cv[row.max,] rr = cv[1] rr # Note: This is a concervative test and that the alpha here is less than alpha = 0.05 ####################################################### ####################################################### # Example 4: Bernoulli assume p0 < p1 ####################################################### # Suppose alpha = 0.05 p0 = .5; n = 20; xx = seq(0,n,1) yy = dbinom(xx, n, p0) plot(xx,yy,type="h") # plot the null distribution ####################################################### low = 0 # change these values to locate alpha = 0.05 up = n k = seq(low, up, 1) cv = 1 - pbinom(k,n,p0) # critical value is for alpha = 0.05 cv = round(cv,4) cv = matrix(c(k,cv),ncol=2) cv cv = matrix(cv[cv[,2]<=alpha],ncol=2) cv = cv[1,] rr = cv[1] rr # Note: This is a concervative test and that the alpha here is less than alpha = 0.05