Introduction to R Introduction http://www.iq.harvard.edu Goals Why should I use R

Introduction to R Introduction http://www.iq.harvard.edu Goals Why should I use R www.phwiki.com

Introduction to R Introduction http://www.iq.harvard.edu Goals Why should I use R

Black, Shannon, Morning Show Host has reference to this Academic Journal, PHwiki organized this Journal Introduction to R ComputeFest 2012 Alex Storer Institute as long as Quantitative Social Science at Harvard astorer@iq.harvard.edu http://www.people.fas.harvard.edu/~astorer/computefest2012/ Introduction Research Technology Consulting at IQSS Dataverse Research Computing Environment OpenScholar Packages as long as computational text analysis, multiple imputation, in addition to statistics modeling in R Trainings on R, Stata, SAS 1/20/12 Introduction to R (Alex Storer, IQSS) http://www.iq.harvard.edu Goals Why should anyone use R Basic Familiarity with R Getting Help in addition to Installing Packages Data Input in addition to Output Making Plots Per as long as ming Statistical Analysis Functions, loops in addition to building blocks of programming Introduction to R (Alex Storer, IQSS) 1/20/12

Francis Marion University US www.phwiki.com

This Particular University is Related to this Particular Journal

Why should I use R Matlab is expensive. R is open-source in addition to community developed. R is plat as long as m independent ( in addition to can even be run online) Beautiful graphics with clear syntax The most actively developed cutting-edge statistics applications can be installed from inside R! Introduction to R (Alex Storer, IQSS) 1/20/12 Why should I use R R is designed to do data-processing in addition to statistical analysis, in addition to it makes it easy. More support in R (e.g., the Use R! series) More active development in R as long as data analysis Who are you sharing your code with Introduction to R (Alex Storer, IQSS) 1/20/12 Starting R Introduction to R (Alex Storer, IQSS) 1/20/12

Syntax Notes Introduction to R (Alex Storer, IQSS) 1/20/12 Vectors in R Introduction to R (Alex Storer, IQSS) 1/20/12 Logical Indexing, Growing Vectors Introduction to R (Alex Storer, IQSS) 1/20/12

Exercise 1 Introduction to R (Alex Storer, IQSS) 1/20/12 Use logical indexing to find the area of Georgia. Use the included vectors state.name in addition to state.area What happens when you combine 2 in addition to “2” using the c() comm in addition to Make a vector containing 100 numbers, in addition to use plot to visualize a mathematical function of your choice! One more function Introduction to R (Alex Storer, IQSS) 1/20/12 Exercise 2 Which is bigger, or What does the function rep do Make a vector containing 50 ones in addition to call it fib Use a as long as loop to compute the first 50 Fibonacci numbers (store them in fib) Recall: F-n = F-{n-1} + F-{n-2}, F-1 = 1, F-2 = 1 What does the function table do How many of the first 50 Fibonacci numbers are divisible by 3 (Recall: a %% b) What is the mean of the first 15 Fibonacci numbers Introduction to R (Alex Storer, IQSS) 1/20/12

Data Frames Data frames are the most common way to store data in R Like a matrix, but columns in addition to rows can have names > head(mtcars) mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 You can access columns by name using the $ operator e.g., count(mtcars$gear) Introduction to R (Alex Storer, IQSS) 1/20/12 Data Frames: viewing in addition to manipulating Introduction to R (Alex Storer, IQSS) 1/20/12 Data Frames: viewing in addition to manipulating Introduction to R (Alex Storer, IQSS) 1/20/12

Exercise 2 What is the median mpg as long as cars with horsepower (“hp”) less than 100 Use the order comm in addition to to print the state.name sorted by state.area Use the order comm in addition to in addition to write.csv to save the mtcars dataset sorted by horsepower What is the name of the car with the most horsepower out of all cars with 4 cylinders (“cyl”) Introduction to R (Alex Storer, IQSS) 1/20/12 The best thing about R Curated Lists of Packages: Chemometrics in addition to Computational Physics Medical Image Analysis Phylogenetics Ecological in addition to Environmental Data Introduction to R (Alex Storer, IQSS) 1/20/12 Example: Rainfall Anomalies http://jisao.washington.edu/data/doe-prec/ Goals: Make a ‘movie’ of rainfall anomalies on a map of the Earth in addition to compare data in Boston in addition to Tokyo This is a long example! We’ll look a lot of R tricks along the way Most important: how to solve general “how do I do” problems! Introduction to R (Alex Storer, IQSS) 1/20/12

Example: Rainfall Anomalies Sub-goal: Just load the data into R Data is in NetCDF as long as mat there’s a package as long as that! We only need to install the package once. We have to load it each time we wish to use it. Introduction to R (Alex Storer, IQSS) 1/20/12 Example: Rainfall Anomalies Sub-goal: Just load the data into R Let’s just get the data! Notice the use of ‘/’ (this can trip you up in Windows!) [1] “file /tmp/recip.nc has 3 dimensions:” [1] “lat Size: 44” [1] “lon Size: 72” [1] “time Size: 556” [1] “—” [1] “file /tmp/recip.nc has 1 variables:” [1] “short data[lon,lat,time] Longname:djf,mam,jja,son mm. Missval:32767” Introduction to R (Alex Storer, IQSS) 1/20/12 Example: Rainfall Anomalies Sub-goal: Just load the data into R The data is in R, but we have to load the variables. Introduction to R (Alex Storer, IQSS) 1/20/12

Aside: a few more R basics We can examine the variables in our workspace: guesses on how to remove a variable Introduction to R (Alex Storer, IQSS) 1/20/12 Aside: a few more R basics Some basic R comm in addition to s are overloaded: e.g., plot can plot classes “array” in addition to “data.frame” Most analyses can be stored as an object that can be summarized, plotted in addition to contain relevant in as long as mation R is object oriented in addition to each object’s class can be queried. Introduction to R (Alex Storer, IQSS) 1/20/12 Exercises 3 Use the diff comm in addition to to investigate the spacing of the data points in time Make a new variable called rain.lat.inc that contains the latitude values in increasing order. (Hint: can you reverse the array Use the seq function to index the array from the end to the beginning.) Use the ls comm in addition to to verify that this variable now exists in addition to check its object type using class. Make an array containing all points at time 300. Bonus! Figure out how to write a function that reverses an array. (Try function) Introduction to R (Alex Storer, IQSS) 1/20/12

Black, Shannon KIIM-FM Morning Show Host www.phwiki.com

Example: Rainfall Anomalies Sub-goal: Just plot one time point Axes are strange South North Introduction to R (Alex Storer, IQSS) 1/20/12 Example: Rainfall Anomalies Sub-goal: Fix our plot Introduction to R (Alex Storer, IQSS) 1/20/12 Example: Rainfall Anomalies Sub-goal: Fix our plot Introduction to R (Alex Storer, IQSS) 1/20/12

Package: maps Introduction to R (Alex Storer, IQSS) 1/20/12 Example: Rainfall Anomalies Sub-goal: Add map to our plot Introduction to R (Alex Storer, IQSS) 1/20/12 Example: Rainfall Anomalies Goal: Make a “movie” Display all time points one after another Make sure we pause after a plot is displayed! Add a title that tells us what time we’re looking at Introduction to R (Alex Storer, IQSS) 1/20/12

More Time Series Data IQSS, Harvard University Exercise! Install the as long as ecast package Use auto.arima to fit a model to the data Use as long as ecast to plot the model prediction Can you find a model that gives a better prediction 1/20/12 Introduction to R (Alex Storer, IQSS) Thank You! 1/20/12 Introduction to R (Alex Storer, IQSS)

Black, Shannon Morning Show Host

Black, Shannon is from United States and they belong to KIIM-FM and they are from  Tucson, United States got related to this Particular Journal. and Black, Shannon deal with the subjects like Country Music; Entertainment

Journal Ratings by Francis Marion University

This Particular Journal got reviewed and rated by Francis Marion University and short form of this particular Institution is US and gave this Journal an Excellent Rating.