# R -- Introduction & Programming    Examples

1. January 30, 2015 colloquium, Introduction to R Graphics, continued (R Script Files)
2. January 23, 2015 colloquium, Introduction to R Graphics (R Script File): 23Jan15.R.
3. February 7, 2014 colloquium, Introduction to R Graphics
• talk.R (R script)
• mse.R (R script for MSE compariosn)
• Animation examples
• Bivariate Normal (bnorm.pdf). The animation PDF file can be generated by an R code that is used to generate needed image files for the animation. The R code and needed subfolder and a LaTeX file are archived in bnorm.zip. Unzip this archive in a folder, named animate, for example. You will need to have an R image file that is under this folder. For you to run this animation example and to run the R script above, an R image file (.RData) is included here. Run R script first to get image files, then run pdfLaTeX on the LaTeX file to get the animated PDF.
• Central Limit Theorem (CLT.pdf). Unzip the archive file CLT.zip in a folder. Change directory to each of CLT1Images, CLT2Images, and CLT3Images subfolders, double click the R image file and run necessary command to created animated PDF image file and timeline file. In R under CLT1Images, run the command
`source("CLT.R")`.
In R under CLT2Images, run the command
`doCLTbinom("CLT2", n=5:175, p=0.9)`
to animate binomial(n,p=0.9) for n=5 to 175.
In R under CLT3Images, run the command
`doCLTpois("CLT3", lambda=1:101)`
to animate Poisson(lambda) for lambda=1 to 101.
Then run, under the main folder, the LaTeX file CLT.tex using pdfLaTeX to get the animated file.
• Noncentral chi-square and noncentral F (noncentral.pdf). Unzip the archive file noncentral.zip in a folder. Change directory to each of ncchisqImages and ncfImages subfolders, double click the R image file and source the respective R script file in each R session
`source("ncchisq.R")` and
`source("ncf.R")`.
Then run, under the main folder, the LaTeX file noncentral.tex using pdfLaTeX to get the animated file.
• Nonrobustness of sample mean (loc.pdf). Unzip the archive file loc.zip in a folder. Change directory to the subfolder and double click R image file, and source the R script:
`source("loc.R")`.
Then run, under the main folder, the LaTeX file loc.tex using pdfLaTeX to get the animated file.
• Nonrobustness of OLS regression (slr2.pdf). Unzip the archive file reg.zip in a folder. Change directory to the subfolder and double click the R image file and source the R script:
`source("reg.R")`.
Then run, under the main folder, the LaTeX file slr2.tex using pdfLaTeX to get the animated file.
• Calculation of Standard Deviation (SD.pdf). Unzip the archive file SD.zip in a folder. Change directory to the subfolder and double click the R image file and source the R script:
`source("SD.R")`
Then run, under the main folder, the LaTeX file SD.tex using pdfLaTeX to get the animated file.
• If you unzip all zip archive files in the same folder, and you download the R image file mentioned above (in bivariate normal example) into the same folder, the you can open the script file runAnim.R and run through it to get all needed image files for the LaTeX file.
4. R Graphics Intro (Rgraph.R)
5. Sweave examle #1: egSweave1.Rnw (R-sweave file mixed with LaTeX document codes), egSweave1.tex (LaTeX document extracted from egSweave1.Rnw by running R command `Sweave("egSweave1.Rnw")`), egSweave1.R (R code chunks extracted from egSweave1.Rnw by running R command `Stangle("egSweave1.Rnw")`). In addition, 4 graphics files generated by Sweave command that were placed in sub-folder `figures` (this folder was supposed to exist prior to the use of Sweave command): Eg1-fitLine.pdf, Eg1-norm1.pdf, Eg2-norm2.pdf, Eg1-binom1.pdf. The shaded normal curves was created by Pdf curve plot and shading (see Probability Density Curve and Shading) and the normal approximation to binominal probabilities by `binomCLT` function I wrote (source binomCLT.R to get the function).
6. Example #1
7. Example #2, graphics package. pars.R (plotting characters, line types, colors, and text justification).
8. Probability Density Curve and Shading
9. Matrix and Data Frame Example #1 (matrixEg1.txt, an R session output file, plots not included).
10. Matrix and Data Frame Example #2 (matrixEg2.txt, an R session output file, plots not included).
11. Linear Model Simulation #1 (simu1.txt, an R session output file, plots not included).
12. 8oct10.R (R script file showing 3d plot from package rgl, a linear model simulation, linear model example, pima data from package faraway)
13. A user-created function example: Hodges-Lehmann estimate (two versions).

2015-01-30