Preface
This text provides R tutorials on statistics including hypothesis testing, ANOVA and linear regressions.It fulfills popular demands by users of r-tutor.comfor exercise solutions and offline access.
Part III of the text is about Bayesian statistics. It begins with closed analytic solutions and basic BUGS models for simple examples. Then it covers OpenBUGS for Bayesian ANOVA and regression analysis.Finally, it shows how to build more complex Bayesian models and demonstrates CODA for Markov Chain Monte Carlo (MCMC) convergence.
The last part of this text discusses advanced GPU computing in Rusing the RPUDPLUS package.Topics include hierarchical clustering, Kendall's tau,support vector machines and Bayesian classification.It illustrates the importance of High Performance Computing (HPC)in the future of statistics. The text concludes with an extra section on hierarchical multinomial logit model for marketing research.
This eBook is published in Amazon Kindle format. It is a great tool for self-study. The R source code is available for download in r-tutor.com.
I am grateful to users who sent me donations in the past. It provides meencouragement and support in ways unimaginable. I would also like to thank users who alert me of errors.I really appreciate it if you can email me further feedback to user.feedback@r-tutor.com.
Chi Yau
Palo Alto, California
April, 2014
TABLE OF CONTENTS
PART I
CHAPTER 1
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
PART II
CHAPTER 6
CHAPTER 7
CHAPTER 8
CHAPTER 9
CHAPTER 10
CHAPTER 11
CHAPTER 12
CHAPTER 13
CHAPTER 14
CHAPTER 15
CHAPTER 16
CHAPTER 17
CHAPTER 18
CHAPTER 19
PART III
CHAPTER 20
CHAPTER 21
CHAPTER 22
CHAPTER 23
CHAPTER 24
CHAPTER 25
CHAPTER 26
CHAPTER 27
CHAPTER 28
CHAPTER 29
PART IV
CHAPTER 30
Appendix
Full Table of Contents
PART I
CHAPTER 1
1.1
1.2
1.3
1.4
1.5
1.6
CHAPTER 2
2.1
2.2
2.3
2.4
2.5
2.6
CHAPTER 3
3.1
3.2
3.3
CHAPTER 4
4.1
4.2
CHAPTER 5
5.1
5.2
5.3
5.4
PART II
CHAPTER 6
6.1
6.2
6.3
6.4
6.5
CHAPTER 7
7.1
7.2
7.3
7.4
7.5
7.6
7.7
7.8
7.9
CHAPTER 8
8.1
8.2
8.3
8.4
8.5
8.6
8.7
8.8
8.9
8.10
8.11
8.12
8.13
8.14
CHAPTER 9
9.1
9.2
9.3
9.4
9.5
9.6
9.7
9.8
9.9
9.10
CHAPTER 10
10.1
10.2
10.3
10.4
10.5
10.6
10.7
CHAPTER 11
11.1
11.2
11.3
11.4
11.5
11.6
11.7
11.8
11.9
CHAPTER 12
12.1
12.2
12.3
12.4
12.5
12.6
CHAPTER 13
13.1
13.2
13.3
CHAPTER 14
14.1
14.2
CHAPTER 15
15.1
15.2
15.3
CHAPTER 16
16.1
16.2
16.3
16.4
CHAPTER 17
17.1
17.2
17.3
17.4
17.5
17.6
17.7
17.8
CHAPTER 18
18.1
18.2
18.3
18.4
18.5
18.6
CHAPTER 19
19.1
19.2
PART III
CHAPTER 20
20.1
20.2
20.3
CHAPTER 21
21.1
21.2
21.3
CHAPTER 22
22.1
22.2
22.3
CHAPTER 23
23.1
23.2
23.3
23.4
CHAPTER 24
24.1
24.2
24.3
CHAPTER 25
25.1
25.2
25.3
25.4
CHAPTER 26
26.1
26.2
26.3
CHAPTER 27
27.1
27.2
CHAPTER 28
28.1
28.2
28.3
CHAPTER 29
29.1
29.2
29.3
PART IV
CHAPTER 30
30.1
30.2
30.3
30.4
30.5
30.6
30.7
30.8
30.9
30.10
Appendix
A1.
A2.
A3.
Part I
R Introduction
We begin with a series of introductory R tutorials. It serves as background material for our discussions on .
The only hardware requirement for most of the R tutorials is a PC with the latest free open source R software installed. R has extensive documentation and active online community support. It is the perfect environment to get started in statistical computing.
Installation
We can visit the R homepage for its latest update,and find a list of CRAN mirrorsthat provide installation files in nearby locations.
Using External Data
R offers plenty of options for loading external data, including Excel, Minitab and SPSS files. We have included a tutorial on for the purpose.
R Session
After R is started, there is a console awaiting for input. At the prompt (>
), we can enter numbers and perform calculations right away.
> 1 + 2 [1] 3
Variable Assignment
We assign values to variables with the assignment operator "="
.Just typing the variable by itself at the prompt will print out the value.We should note that another form of assignment operator "<-"
is also in use.
> x = 1> x[1] 1
Functions
R functions are invoked by its name, then followed by the parenthesis, and zero or more arguments.The following apply the function c
to combine three numeric values into a vector.
> c(1, 2, 3)[1] 1 2 3
Comments
All text after the pound sign #
within the same line is considered a comment.
> 1 + 1 # this is a comment[1] 2
Extension Package
Sometimes we need additional functionality beyond those offered by the core R library.In order to install an extension package, we should invoke the install.packages
function at the prompt and follow the instruction.
> install.packages()
Getting Help
R provides extensive documentation. For example, entering ?c
or help(c)
at the prompt gives documentation of the function c
in R. Please give it a try.
> help(c)
If we are not sure about the name of the function we are looking for, we can perform a fuzzy search with the