10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Confidence intervals 203data is more than the median. The distribution of this statistic, under the assumption, canbe computed and used to give confidence intervals. It is available in R under the familyname signrank. In particular, qsignrank() will return the quantiles.This procedure is implemented in the wilcox.test() function. Unlike with prop.test()and t.test(), to return a confidence interval when using wilcox.test () we need to specifythat a confidence interval is desired with the argument conf . int=TRUE.■ Example 7.12: CEO confidence interval The data on CEOs is too skewed to applythis test, but after taking a log trans<strong>for</strong>m we will see a symmetric data set (Figure 7.7).>boxplot(scale(x),scale(log(x)),names=c("CEO","log.CEO"))> title("Boxplot of CEO data and its logarithm”)<strong>Using</strong> scale() makes a data set have mean a and variance 1, so the shape is all that is seenand comparisons of shapes are possible.Figure 7.7 Comparison of CEO dataand its logarithm on the same scaleThus we can apply the Wilocoxon method to the log-trans<strong>for</strong>med data, and thentrans<strong>for</strong>m back.> wilcox.test(log(x), conf.int=TRUE, conf.level=0.9)Wilcoxon signed rank testdata: log(x)V = 55, p-value = 0.001953alternative hypothesis: true mu is not equal to a90 percent confidence interval:2.963 5.540sample estimates:(pseudo)median4.345> exp(c(2.863,5.540)) # inverse of log.[1] 17.51 254.68

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!