Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Hypothesis Testing page 65 • Unlike prop.test and t.test, we needed to specify that we wanted a confidence interval computed. • For this data, the confidence interval is enormous as the size of the sample is small and the range is huge. • We couldn’t have used a t-test as the data isn’t even close to normal. Problems 9.1 Create 15 random numbers that are normally distributed with mean 10 and s.d. 5. Find a 1-sample z-test at the 95% level. Did it get it right? 9.2 Do the above 100 times. Compute what percentage is in a 95% confidence interval. Hint: The following might prove useful > f=function () mean(rnorm(15,mean=10,sd=5)) > SE = 5/sqrt(15) > xbar = simple.sim(100,f) > alpha = 0.1;zstar = qnorm(1-alpha/2);sum(abs(xbar-10) < zstar*SE) [1] 87 > alpha = 0.05;zstar = qnorm(1-alpha/2);sum(abs(xbar-10) < zstar*SE) [1] 92 > alpha = 0.01;zstar = qnorm(1-alpha/2);sum(abs(xbar-10) < zstar*SE) [1] 98 9.3 The t-test is just as easy to do. Do a t-test on the same data. Is it correct now? Comment on the relationship between the confidence intervals. 9.4 Find an 80% and 95% confidence interval for the median for the exec.pay dataset. 9.5 For the Simple data set rat do a t-test for mean if the data suggests it is appropriate. If not, say why not. (This records survival times for rats.) 9.6 Repeat the previous for the Simple data set puerto (weekly incomes of Puerto Ricans in Miami.). 9.7 The median may be the appropriate measure of center. If so, you might want to have a confidence interval for it too. Find a 90% confidence interval for the median for the Simple data set malpract (on the size of malpractice awards). Comment why this distribution doesn’t lend itself to the z-test or t-test. 9.8 The t-statistic has the t-distribution if the Xi ’s are normally distributed. What if they are not? Investigate the distribution of the t-statistic if the Xi ’s have different distributions. Try short-tailed ones (uniform), long-tailed ones (t-distributed to begin with), Uniform (exponential or log-normal). (For example, If the Xi are nearly normal, but there is a chance of some errors introducing outliers. This can be modeled with Xi = ζ(µ + σZ) + (1 − ζ)Y where ζ is 1 with high probability and 0 otherwise and Y is of a different distribution. For concreteness, suppose µ = 0, σ = 1 and Y is normal with mean 0, but standard deviation 10 and P (ζ = 1) = .9. Here is some R code to simulate and investigate. (Please note, the simulations for the suggested distributions should be much simpler.) > + + + > > > > f = function(n=10,p=0.95) { y = rnorm(n,mean=0,sd=1+9*rbinom(n,1,1-p)) t = (mean(y) - 0) / (sqrt(var(y))/sqrt(n)) } sample = simple.sim(100,f) qqplot(sample,rt(100,df=9),main="sample vs. t");qqline(sample) qqnorm(sample,main="sample vs. normal");qqline(sample) hist(sample) The resulting graphs are shown. First, the graph shows the sample against the t-quantiles. A bad, fit. The normal plot is better but we still see a skew in the histogram due to a single large outlier.) Hypothesis Testing page 66 −2 0 2 −2 sample 0 2 Theoretical Quantiles 0 5 10 15 20 25 30 Histogram of sample Frequency Sample Quantiles −4 −4 −3 −2 −1 0 1 2 3 sample vs. normal −3 −2 −1 0 1 2 3 rt(100, df = 9) sample vs. t −4 0 2 sample Figure 47: t-statistic for contaminated normal data Section 10: Hypothesis Testing Hypothesis testing is mathematically related to the problem of finding confidence intervals. However, the approach is different. For one, you use the data to tell you where the unknown parameters should lie, for hypothesis testing, you make a hypothesis about the value of the unknown parameter and then calculate how likely it is that you observed the data or worse. However, with R you will not notice much difference as the same functions are used for both. The way you use them is slightly different though. Testing a population parameter Consider a simple survey. You ask 100 people (randomly chosen) and 42 say “yes” to your question. Does this support the hypothesis that the true proportion is 50%? To answer this, we set up a test of hypothesis. The null hypothesis, denoted H 0 is that p = .5, the alternative hypothesis, denoted HA , in this example would be p 6= 0.5. This is a so called “two-sided” alternative. To test the assumptions, we use the function prop.test as with the confidence interval calculation. Here are the commands > prop.test(42,100,p=.5) 1-sample proportions test with continuity correction data: 42 out of 100, null probability 0.5 X-squared = 2.25, df = 1, p-value = 0.1336 alternative hypothesis: true p is not equal to 0.5 95 percent confidence interval: 0.3233236 0.5228954 sample estimates: p 0.42 Note the p-value of 0.1336. The p-value reports how likely we are to see this data or worse assuming the null hypothesis. The notion of worse, is implied by the alternative hypothesis. In this example, the alternative is twosided as too small a value or too large a value or the test statistic is consistent with H A . In particular, the p-value is the probability of 42 or fewer or 58 or more answer “yes” when the chance a person will answer “yes” is fifty-fifty. Now, the p-value is not so small as to make an observation of 42 seem unreasonable in 100 samples assuming the null hypothesis. Thus, one would “accept” the null hypothesis. Next, we repeat, only suppose we ask 1000 people and 420 say yes. Does this still support the null hypothesis that p = 0.5? > prop.test(420,1000,p=.5) 1-sample proportions test with continuity correction