SlideShare a Scribd company logo
1 of 60
An Interactive Introduction to R November 2009 Michael E. Driscoll, Ph.D. med@dataspora.com http://www.dataspora.com Daniel Murphy FCAS, MAAA dmurphy@trinostics.com
January 6, 2009
R is a tool for… Data Manipulation connecting to data sources slicing & dicing data Modeling & Computation statistical modeling numerical simulation Data Visualization visualizing fit of models composing statistical graphics
R is an environment
Its interface is plain
Let’s take a tour of some claim datain R
Let’s take a tour of some claim datain R ## load in some Insurance Claim data library(MASS) data(Insurance) Insurance <- edit(Insurance) head(Insurance) dim(Insurance) ## plot it nicely using the ggplot2 package library(ggplot2) qplot(Group, Claims/Holders,       data=Insurance, geom="bar",       stat='identity',       position="dodge",       facets=District ~ .,       fill=Age, ylab="Claim Propensity", xlab="Car Group") ## hypothesize a relationship between Age ~ Claim Propensity ## visualize this hypothesis with a boxplot x11() library(ggplot2) qplot(Age, Claims/Holders,       data=Insurance, geom="boxplot",       fill=Age) ## quantify the hypothesis with linear model m <- lm(Claims/Holders ~ Age + 0, data=Insurance) summary(m)
R is “an overgrown calculator” sum(rgamma(rpois(1,lambda=2),shape=49,scale=.2)))
R is “an overgrown calculator” ,[object Object],> 2+2 4 ,[object Object],> x <- 2+2    ## ‘<-’ is R syntax for ‘=’ or assignment > x^2  16 ,[object Object],> weight <- c(110, 180, 240)      ## three weights > height <- c(5.5, 6.1, 6.2)      ## three heights > bmi <- (weight*4.88)/height^2   ## divides element-wise 17.7  23.6  30.4
R is “an overgrown calculator” ,[object Object],mean(weight) 	   sd(weight)		sqrt(var(weight)) 176.6             65.0			65.0  # same as sd ,[object Object],union		   intersect		 setdiff ,[object Object],   > pbinom(40, 100, 0.5)  ##  P that a coin tossed 100 times    0.028##  that comes up 40 heads is ‘fair’    > pshare <- pbirthday(23, 365, coincident=2)    0.530  ## probability that among 23 people, two share a birthday
Try It! #1 Overgrown Calculator ,[object Object],> 2 + 2       [Hit ENTER] > log(100)    [Hit ENTER] ,[object Object],> 100 * exp(0.05*10) [Hit ENTER] ,[object Object],> year <- (1,2,5,10,25)  [Hit ENTER]   this returns an error.  why? > year <- c(1,2,5,10,25) [Hit ENTER] > 100 * exp(0.05*year)   [Hit ENTER]
R is a numerical simulator  ,[object Object]
let’s simulate 10,000 trials of 100 coin flips.  what’s the distribution of heads?> heads <- rbinom(10^5,100,0.50) > hist(heads)
Functions for Probability Distributions > pnorm(0) 	0.05  > qnorm(0.9) 	1.28 > rnorm(100) 	vector of length 100
Functions for Probability Distributions How to find the functions for lognormal distribution?   1) Use the double question mark ‘??’ to search > ??lognormal 2) Then identify the package  > ?Lognormal 3) Discover the dist functions  dlnorm, plnorm, qlnorm, rlnorm
Try It! #2 Numerical Simulation ,[object Object],> numclaims <- rpois(n, lambda) (hint: use ?rpoisto understand the parameters) ,[object Object],> mean(numclaims) > var(numclaims) ,[object Object],> hist(numclaims)
Getting Data In 	- from Files > Insurance <- read.csv(“Insurance.csv”,header=TRUE) 	  from Databases > con <- dbConnect(driver,user,password,host,dbname) > Insurance <- dbSendQuery(con, “SELECT * FROM claims”) 	  from the Web > con <- url('http://labs.dataspora.com/test.txt') > Insurance <- read.csv(con, header=TRUE) 	   from R objects > load(‘Insurance.RData’)
Getting Data Out to Files write.csv(Insurance,file=“Insurance.csv”) to Databases con <- dbConnect(dbdriver,user,password,host,dbname) dbWriteTable(con, “Insurance”, Insurance)      to R Objects save(Insurance, file=“Insurance.RData”)
Navigating within the R environment listing all variables > ls() examining a variable ‘x’ > str(x) > head(x) > tail(x) > class(x) removing variables > rm(x) > rm(list=ls())    # remove everything
Try It! #3 Data Processing  ,[object Object],library(MASS) head(Insurance)  ## the first 7 rows dim(Insurance)   ## number of rows & columns ,[object Object],write.csv(Insurance,file=“Insurance.csv”, row.names=FALSE) getwd()  ## where am I? ,[object Object],	 remove the first district ,[object Object],Insurance <- read.csv(file=“Insurance.csv”) plot(Claims/Holders ~ Age, data=Insurance)
A Swiss-Army Knife for Data
A Swiss-Army Knife for Data Indexing Three ways to index into a data frame array of integer indices array of character names array of logical Booleans Examples: df[1:3,] df[c(“New York”, “Chicago”),] df[c(TRUE,FALSE,TRUE,TRUE),] df[city == “New York”,]
A Swiss-Army Knife for Data ,[object Object],subset(Insurance, District==1) subset(Insurance, Claims < 20) ,[object Object],transform(Insurance, Propensity=Claims/Holders) cut – cut a continuous value into groups    cut(Insurance$Claims, breaks=c(-1,100,Inf), labels=c('lo','hi'))   Put it all together: create a new, transformed data frame transform(subset(Insurance, District==1),   ClaimLevel=cut(Claims, breaks=c(-1,100,Inf),       labels=c(‘lo’,’hi’)))
A Statistical Modeler R’s has a powerful modeling syntax Models are specified with formulae, like  			y ~ x 	growth ~ sun + water model relationships between continuous and categorical variables. Models are also guide the visualization of relationships in a graphical form
A Statistical Modeler ,[object Object],m <- lm(Claims/Holders ~ Age, data=Insurance) ,[object Object],	summary(m) ,[object Object],	plot(m)
A Statistical Modeler Logistic model 	m <- glm(Age ~ Claims/Holders, data=Insurance,          family=binomial(“logit”)) ) Examine it 	summary(m) Plot it 	plot(m)
Try It! #4 Statistical Modeling ,[object Object],m <- lm(Claims/Holders ~ Age + 0, data=Insurance)  ,[object Object],summary(m) ,[object Object],plot(m)
Visualization:  Multivariate Barplot library(ggplot2) qplot(Group, Claims/Holders,       data=Insurance,       geom="bar",       stat='identity',       position="dodge",       facets=District ~ .,        fill=Age)
Visualization:  Boxplots library(ggplot2) qplot(Age, Claims/Holders,    data=Insurance,   geom="boxplot“) library(lattice) bwplot(Claims/Holders ~ Age,    data=Insurance)
Visualization: Histograms library(ggplot2) qplot(Claims/Holders,   data=Insurance,   facets=Age ~ ., geom="density") library(lattice) densityplot(~ Claims/Holders | Age, data=Insurance, layout=c(4,1)
Try It! #5 Data Visualization ,[object Object],> x <- 1:10 > y <- x^2 > plot(y ~ x) ,[object Object],> library(lattice) > boxplot(Claims/Holders ~ Age, data=Insurance) ,[object Object],> abline()
Getting Help with R Help within R itself for a function > help(func) > ?func For a topic > help.search(topic) > ??topic search.r-project.org Google Code Search  www.google.com/codesearch Stack Overflow  http://stackoverflow.com/tags/R R-help list http://www.r-project.org/posting-guide.html
Six Indispensable Books on R Learning R Data Manipulation Visualization Statistical Modeling
Extending R with Packages Over one thousand user-contributed packages are available on CRAN – the Comprehensive R Archive Network http://cran.r-project.org Install a package from the command-line > install.packages(‘actuar’) Install a package from the GUI menu “Packages”--> “Install packages(s)”
Final Try It!Simulate a Tweedie ,[object Object]
For as many claims as were randomly simulated, simulate a severity from a gamma distribution with shape α=49 and scale θ=0.2 (NB: mean gamma = αθ, variance gamma = αθ2)
Is the total simulated claim amount close to expected?
Calculate usual parameterization (μ,p,φ)of this Tweedie distribution
Extra credit:
Repeat the above 10000 times.
Does your histogram look like Glenn Meyers’?http://www.casact.org/newsletter/index.cfm?fa=viewart&id=5756,[object Object]
P&C Actuarial Models Design • Construction Collaboration • Education Valuable • Transparent Daniel Murphy, FCAS, MAAAdmurphy@trinostics.com 925.381.9869 From Data to Decision Big Data • Analytics • Visualization www.dataspora.com Michael E. Driscoll, Ph.D. med@dataspora.com 415.860.4347 37 Contact Us
Appendices R as a Programming Language Advanced Visualization Embedding R in a Server Environment
R as a Programming Language fibonacci <- function(n) {   fib <- numeric(n)   fib [1:2] <- 1   for (i in 3:n) {        fib[i] <- fib[i-1] + fib[i-2]   }   return(fib[n]) } Image from cover of Abelson & Sussman’stextThe Structure and Interpretation of Computer Languages
Assignment x <- c(1,2,6) x		 a variable x <-	 R’s assignment operator, equivalent to ‘=‘  c(	 a function c which combines its arguments into a vector y <- c(‘apples’,’oranges’) z <- c(TRUE,FALSE) 	c(TRUE,FALSE) -> z These are also valid assignment statements.
Function Calls ,[object Object],output <- function(arg1, arg2, …) ,[object Object], +  -  *  /  ^ ,[object Object],		x <- x/3 	works whether x is a one or many-valued vector
Data Structures in R numeric x <- c(0,2:4) vectors Character y <- c(“alpha”, “b”, “c3”, “4”) logical z <- c(1, 0, TRUE, FALSE) > class(x) [1] "numeric" > x2 <- as.logical(x) > class(x2) [1] “logical”
Data Structures in R lists lst <- list(x,y,z) objects matrices M <- matrix(rep(x,3),ncol=3) data frames* df <- data.frame(x,y,z) > class(df) [1] “data.frame"
Summary of Data Structures ? matrices vectors data frames* lists
Advanced Visualization lattice, ggplot2, and colorspace
ggplot2 =grammar of graphics
ggplot2 =grammar ofgraphics
qplot(log(carat), log(price), data = diamonds, alpha=I(1/20)) + facet_grid(. ~ color) Achieving small multiples with “facets”
lattice = trellis (source: http://lmdvr.r-forge.r-project.org )
list of latticefunctions densityplot(~ speed | type, data=pitch)
visualizing six dimensions of MLB pitches with lattice
xyplot(x ~ y | type, data=pitch, fill.color = pitch$color, panel = function(x,y, fill.color, …, subscripts) {   fill <- fill.color[subscripts] panel.xyplot(x, y, fill= fill, …) })
Beautiful Colors with Colorspace library(“Colorspace”) red <- LAB(50,64,64) blue <- LAB(50,-48,-48) mixcolor(10, red, blue)
efficient plotting with hexbinplot hexbinplot(log(price)~log(carat),data=diamonds,xbins=40)

More Related Content

What's hot

Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Guy Lebanon
 
Predicates and Quantifiers
Predicates and QuantifiersPredicates and Quantifiers
Predicates and Quantifiersblaircomp2003
 
R language tutorial
R language tutorialR language tutorial
R language tutorialDavid Chiu
 
5 R Tutorial Data Visualization
5 R Tutorial Data Visualization5 R Tutorial Data Visualization
5 R Tutorial Data VisualizationSakthi Dasans
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programmingKrish_ver2
 
Introduction to Rstudio
Introduction to RstudioIntroduction to Rstudio
Introduction to RstudioOlga Scrivner
 
Data Exploration and Visualization with R
Data Exploration and Visualization with RData Exploration and Visualization with R
Data Exploration and Visualization with RYanchang Zhao
 
EULER AND FERMAT THEOREM
EULER AND FERMAT THEOREMEULER AND FERMAT THEOREM
EULER AND FERMAT THEOREMankita pandey
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingVictor Ordu
 
Exploratory Data Analysis using Python
Exploratory Data Analysis using PythonExploratory Data Analysis using Python
Exploratory Data Analysis using PythonShirin Mojarad, Ph.D.
 
R Programming Language
R Programming LanguageR Programming Language
R Programming LanguageNareshKarela1
 
Exploratory data analysis in R - Data Science Club
Exploratory data analysis in R - Data Science ClubExploratory data analysis in R - Data Science Club
Exploratory data analysis in R - Data Science ClubMartin Bago
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressionsvishaljot_kaur
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IMohamed Loey
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R PackagesRsquared Academy
 
How to get started with R programming
How to get started with R programmingHow to get started with R programming
How to get started with R programmingRamon Salazar
 

What's hot (20)

Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
Predicates and Quantifiers
Predicates and QuantifiersPredicates and Quantifiers
Predicates and Quantifiers
 
R language tutorial
R language tutorialR language tutorial
R language tutorial
 
5 R Tutorial Data Visualization
5 R Tutorial Data Visualization5 R Tutorial Data Visualization
5 R Tutorial Data Visualization
 
5.3 dynamic programming
5.3 dynamic programming5.3 dynamic programming
5.3 dynamic programming
 
Introduction to Rstudio
Introduction to RstudioIntroduction to Rstudio
Introduction to Rstudio
 
Data Exploration and Visualization with R
Data Exploration and Visualization with RData Exploration and Visualization with R
Data Exploration and Visualization with R
 
EULER AND FERMAT THEOREM
EULER AND FERMAT THEOREMEULER AND FERMAT THEOREM
EULER AND FERMAT THEOREM
 
Big o notation
Big o notationBig o notation
Big o notation
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
Exploratory Data Analysis using Python
Exploratory Data Analysis using PythonExploratory Data Analysis using Python
Exploratory Data Analysis using Python
 
Unit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptxUnit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptx
 
R Programming Language
R Programming LanguageR Programming Language
R Programming Language
 
Eulers totient
Eulers totientEulers totient
Eulers totient
 
Exploratory data analysis in R - Data Science Club
Exploratory data analysis in R - Data Science ClubExploratory data analysis in R - Data Science Club
Exploratory data analysis in R - Data Science Club
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R Packages
 
How to get started with R programming
How to get started with R programmingHow to get started with R programming
How to get started with R programming
 

Viewers also liked

How to Plug a Leaky Sales Funnel With Facebook Retargeting
How to Plug a Leaky Sales Funnel With Facebook RetargetingHow to Plug a Leaky Sales Funnel With Facebook Retargeting
How to Plug a Leaky Sales Funnel With Facebook RetargetingDigital Marketer
 
10 Mobile Marketing Campaigns That Went Viral and Made Millions
10 Mobile Marketing Campaigns That Went Viral and Made Millions10 Mobile Marketing Campaigns That Went Viral and Made Millions
10 Mobile Marketing Campaigns That Went Viral and Made MillionsMark Fidelman
 
The Beginners Guide to Startup PR #startuppr
The Beginners Guide to Startup PR #startupprThe Beginners Guide to Startup PR #startuppr
The Beginners Guide to Startup PR #startupprOnboardly
 
Lean Community Building: Getting the Most Bang for Your Time & Money
Lean Community Building: Getting the Most Bang for  Your Time & MoneyLean Community Building: Getting the Most Bang for  Your Time & Money
Lean Community Building: Getting the Most Bang for Your Time & MoneyJennifer Lopez
 
Some Advanced Remarketing Ideas
Some Advanced Remarketing IdeasSome Advanced Remarketing Ideas
Some Advanced Remarketing IdeasChris Thomas
 
The Science behind Viral marketing
The Science behind Viral marketingThe Science behind Viral marketing
The Science behind Viral marketingDavid Skok
 
Google Analytics Fundamentals: Set Up and Basics for Measurement
Google Analytics Fundamentals: Set Up and Basics for MeasurementGoogle Analytics Fundamentals: Set Up and Basics for Measurement
Google Analytics Fundamentals: Set Up and Basics for MeasurementOrbit Media Studios
 
How Top Brands Use Referral Programs to Drive Customer Acquisition
How Top Brands Use Referral Programs to Drive Customer AcquisitionHow Top Brands Use Referral Programs to Drive Customer Acquisition
How Top Brands Use Referral Programs to Drive Customer AcquisitionKissmetrics on SlideShare
 
LinkedIn Ads Platform Master Class
LinkedIn Ads Platform Master ClassLinkedIn Ads Platform Master Class
LinkedIn Ads Platform Master ClassLinkedIn
 
The Science of Marketing Automation
The Science of Marketing AutomationThe Science of Marketing Automation
The Science of Marketing AutomationHubSpot
 
Mastering Google Adwords In 30 Minutes
Mastering Google Adwords In 30 MinutesMastering Google Adwords In 30 Minutes
Mastering Google Adwords In 30 MinutesNik Cree
 
A Guide to User Research (for People Who Don't Like Talking to Other People)
A Guide to User Research (for People Who Don't Like Talking to Other People)A Guide to User Research (for People Who Don't Like Talking to Other People)
A Guide to User Research (for People Who Don't Like Talking to Other People)Stephanie Wills
 
Brenda Spoonemore - A biz dev playbook for startups: Why, when and how to do ...
Brenda Spoonemore - A biz dev playbook for startups: Why, when and how to do ...Brenda Spoonemore - A biz dev playbook for startups: Why, when and how to do ...
Brenda Spoonemore - A biz dev playbook for startups: Why, when and how to do ...GeekWire
 
The Essentials of Community Building by Mack Fogelson
The Essentials of Community Building by Mack FogelsonThe Essentials of Community Building by Mack Fogelson
The Essentials of Community Building by Mack FogelsonMackenzie Fogelson
 
User experience doesn't happen on a screen: It happens in the mind.
User experience doesn't happen on a screen: It happens in the mind.User experience doesn't happen on a screen: It happens in the mind.
User experience doesn't happen on a screen: It happens in the mind.John Whalen
 
No excuses user research
No excuses user researchNo excuses user research
No excuses user researchLily Dart
 
10 Ways You're Using AdWords Wrong and How to Correct Those Practices
10 Ways You're Using AdWords Wrong and How to Correct Those Practices 10 Ways You're Using AdWords Wrong and How to Correct Those Practices
10 Ways You're Using AdWords Wrong and How to Correct Those Practices Kissmetrics on SlideShare
 
Stop Leaving Money on the Table! Optimizing your Site for Users and Revenue
Stop Leaving Money on the Table! Optimizing your Site for Users and RevenueStop Leaving Money on the Table! Optimizing your Site for Users and Revenue
Stop Leaving Money on the Table! Optimizing your Site for Users and RevenueJosh Patrice
 

Viewers also liked (20)

How to Plug a Leaky Sales Funnel With Facebook Retargeting
How to Plug a Leaky Sales Funnel With Facebook RetargetingHow to Plug a Leaky Sales Funnel With Facebook Retargeting
How to Plug a Leaky Sales Funnel With Facebook Retargeting
 
10 Mobile Marketing Campaigns That Went Viral and Made Millions
10 Mobile Marketing Campaigns That Went Viral and Made Millions10 Mobile Marketing Campaigns That Went Viral and Made Millions
10 Mobile Marketing Campaigns That Went Viral and Made Millions
 
Intro to Facebook Ads
Intro to Facebook AdsIntro to Facebook Ads
Intro to Facebook Ads
 
The Beginners Guide to Startup PR #startuppr
The Beginners Guide to Startup PR #startupprThe Beginners Guide to Startup PR #startuppr
The Beginners Guide to Startup PR #startuppr
 
Lean Community Building: Getting the Most Bang for Your Time & Money
Lean Community Building: Getting the Most Bang for  Your Time & MoneyLean Community Building: Getting the Most Bang for  Your Time & Money
Lean Community Building: Getting the Most Bang for Your Time & Money
 
Some Advanced Remarketing Ideas
Some Advanced Remarketing IdeasSome Advanced Remarketing Ideas
Some Advanced Remarketing Ideas
 
The Science behind Viral marketing
The Science behind Viral marketingThe Science behind Viral marketing
The Science behind Viral marketing
 
Google Analytics Fundamentals: Set Up and Basics for Measurement
Google Analytics Fundamentals: Set Up and Basics for MeasurementGoogle Analytics Fundamentals: Set Up and Basics for Measurement
Google Analytics Fundamentals: Set Up and Basics for Measurement
 
HTML & CSS Masterclass
HTML & CSS MasterclassHTML & CSS Masterclass
HTML & CSS Masterclass
 
How Top Brands Use Referral Programs to Drive Customer Acquisition
How Top Brands Use Referral Programs to Drive Customer AcquisitionHow Top Brands Use Referral Programs to Drive Customer Acquisition
How Top Brands Use Referral Programs to Drive Customer Acquisition
 
LinkedIn Ads Platform Master Class
LinkedIn Ads Platform Master ClassLinkedIn Ads Platform Master Class
LinkedIn Ads Platform Master Class
 
The Science of Marketing Automation
The Science of Marketing AutomationThe Science of Marketing Automation
The Science of Marketing Automation
 
Mastering Google Adwords In 30 Minutes
Mastering Google Adwords In 30 MinutesMastering Google Adwords In 30 Minutes
Mastering Google Adwords In 30 Minutes
 
A Guide to User Research (for People Who Don't Like Talking to Other People)
A Guide to User Research (for People Who Don't Like Talking to Other People)A Guide to User Research (for People Who Don't Like Talking to Other People)
A Guide to User Research (for People Who Don't Like Talking to Other People)
 
Brenda Spoonemore - A biz dev playbook for startups: Why, when and how to do ...
Brenda Spoonemore - A biz dev playbook for startups: Why, when and how to do ...Brenda Spoonemore - A biz dev playbook for startups: Why, when and how to do ...
Brenda Spoonemore - A biz dev playbook for startups: Why, when and how to do ...
 
The Essentials of Community Building by Mack Fogelson
The Essentials of Community Building by Mack FogelsonThe Essentials of Community Building by Mack Fogelson
The Essentials of Community Building by Mack Fogelson
 
User experience doesn't happen on a screen: It happens in the mind.
User experience doesn't happen on a screen: It happens in the mind.User experience doesn't happen on a screen: It happens in the mind.
User experience doesn't happen on a screen: It happens in the mind.
 
No excuses user research
No excuses user researchNo excuses user research
No excuses user research
 
10 Ways You're Using AdWords Wrong and How to Correct Those Practices
10 Ways You're Using AdWords Wrong and How to Correct Those Practices 10 Ways You're Using AdWords Wrong and How to Correct Those Practices
10 Ways You're Using AdWords Wrong and How to Correct Those Practices
 
Stop Leaving Money on the Table! Optimizing your Site for Users and Revenue
Stop Leaving Money on the Table! Optimizing your Site for Users and RevenueStop Leaving Money on the Table! Optimizing your Site for Users and Revenue
Stop Leaving Money on the Table! Optimizing your Site for Users and Revenue
 

Similar to An Interactive Introduction To R (Programming Language For Statistics)

ITB Term Paper - 10BM60066
ITB Term Paper - 10BM60066ITB Term Paper - 10BM60066
ITB Term Paper - 10BM60066rahulsm27
 
software engineering modules iii & iv.pptx
software engineering  modules iii & iv.pptxsoftware engineering  modules iii & iv.pptx
software engineering modules iii & iv.pptxrani marri
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Charles Givre
 
RDataMining slides-regression-classification
RDataMining slides-regression-classificationRDataMining slides-regression-classification
RDataMining slides-regression-classificationYanchang Zhao
 
Efficient equity portfolios using mean variance optimisation in R
Efficient equity portfolios using mean variance optimisation in REfficient equity portfolios using mean variance optimisation in R
Efficient equity portfolios using mean variance optimisation in RGregg Barrett
 
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Amazon Web Services
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures Pradipta Mishra
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structuresPradipta Mishra
 
Econometria aplicada com dados em painel
Econometria aplicada com dados em painelEconometria aplicada com dados em painel
Econometria aplicada com dados em painelAdriano Figueiredo
 
Chris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql PortfolioChris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql Portfolioclmcglothen
 
PorfolioReport
PorfolioReportPorfolioReport
PorfolioReportAlbert Chu
 
Pumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency AnalysisPumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency AnalysisUniversity of Illinois,Chicago
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with RYanchang Zhao
 
Buenos Aires Drools Expert Presentation
Buenos Aires Drools Expert PresentationBuenos Aires Drools Expert Presentation
Buenos Aires Drools Expert PresentationMark Proctor
 
Pumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency AnalysisPumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency AnalysisUniversity of Illinois,Chicago
 

Similar to An Interactive Introduction To R (Programming Language For Statistics) (20)

Rclass
RclassRclass
Rclass
 
R decision tree
R   decision treeR   decision tree
R decision tree
 
ITB Term Paper - 10BM60066
ITB Term Paper - 10BM60066ITB Term Paper - 10BM60066
ITB Term Paper - 10BM60066
 
Decision Tree.pptx
Decision Tree.pptxDecision Tree.pptx
Decision Tree.pptx
 
software engineering modules iii & iv.pptx
software engineering  modules iii & iv.pptxsoftware engineering  modules iii & iv.pptx
software engineering modules iii & iv.pptx
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2
 
R studio
R studio R studio
R studio
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 
RDataMining slides-regression-classification
RDataMining slides-regression-classificationRDataMining slides-regression-classification
RDataMining slides-regression-classification
 
Efficient equity portfolios using mean variance optimisation in R
Efficient equity portfolios using mean variance optimisation in REfficient equity portfolios using mean variance optimisation in R
Efficient equity portfolios using mean variance optimisation in R
 
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Econometria aplicada com dados em painel
Econometria aplicada com dados em painelEconometria aplicada com dados em painel
Econometria aplicada com dados em painel
 
Chris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql PortfolioChris Mc Glothen Sql Portfolio
Chris Mc Glothen Sql Portfolio
 
PorfolioReport
PorfolioReportPorfolioReport
PorfolioReport
 
Pumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency AnalysisPumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency Analysis
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
 
Buenos Aires Drools Expert Presentation
Buenos Aires Drools Expert PresentationBuenos Aires Drools Expert Presentation
Buenos Aires Drools Expert Presentation
 
Pumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency AnalysisPumps, Compressors and Turbine Fault Frequency Analysis
Pumps, Compressors and Turbine Fault Frequency Analysis
 

Recently uploaded

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxElton John Embodo
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxJanEmmanBrigoli
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 

Recently uploaded (20)

How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
EMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docxEMBODO Lesson Plan Grade 9 Law of Sines.docx
EMBODO Lesson Plan Grade 9 Law of Sines.docx
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Millenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptxMillenials and Fillennials (Ethical Challenge and Responses).pptx
Millenials and Fillennials (Ethical Challenge and Responses).pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 

An Interactive Introduction To R (Programming Language For Statistics)

  • 1. An Interactive Introduction to R November 2009 Michael E. Driscoll, Ph.D. med@dataspora.com http://www.dataspora.com Daniel Murphy FCAS, MAAA dmurphy@trinostics.com
  • 3.
  • 4. R is a tool for… Data Manipulation connecting to data sources slicing & dicing data Modeling & Computation statistical modeling numerical simulation Data Visualization visualizing fit of models composing statistical graphics
  • 5. R is an environment
  • 7. Let’s take a tour of some claim datain R
  • 8. Let’s take a tour of some claim datain R ## load in some Insurance Claim data library(MASS) data(Insurance) Insurance <- edit(Insurance) head(Insurance) dim(Insurance) ## plot it nicely using the ggplot2 package library(ggplot2) qplot(Group, Claims/Holders, data=Insurance, geom="bar", stat='identity', position="dodge", facets=District ~ ., fill=Age, ylab="Claim Propensity", xlab="Car Group") ## hypothesize a relationship between Age ~ Claim Propensity ## visualize this hypothesis with a boxplot x11() library(ggplot2) qplot(Age, Claims/Holders, data=Insurance, geom="boxplot", fill=Age) ## quantify the hypothesis with linear model m <- lm(Claims/Holders ~ Age + 0, data=Insurance) summary(m)
  • 9. R is “an overgrown calculator” sum(rgamma(rpois(1,lambda=2),shape=49,scale=.2)))
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. let’s simulate 10,000 trials of 100 coin flips. what’s the distribution of heads?> heads <- rbinom(10^5,100,0.50) > hist(heads)
  • 15. Functions for Probability Distributions > pnorm(0) 0.05 > qnorm(0.9) 1.28 > rnorm(100) vector of length 100
  • 16. Functions for Probability Distributions How to find the functions for lognormal distribution? 1) Use the double question mark ‘??’ to search > ??lognormal 2) Then identify the package > ?Lognormal 3) Discover the dist functions dlnorm, plnorm, qlnorm, rlnorm
  • 17.
  • 18. Getting Data In - from Files > Insurance <- read.csv(“Insurance.csv”,header=TRUE) from Databases > con <- dbConnect(driver,user,password,host,dbname) > Insurance <- dbSendQuery(con, “SELECT * FROM claims”) from the Web > con <- url('http://labs.dataspora.com/test.txt') > Insurance <- read.csv(con, header=TRUE) from R objects > load(‘Insurance.RData’)
  • 19. Getting Data Out to Files write.csv(Insurance,file=“Insurance.csv”) to Databases con <- dbConnect(dbdriver,user,password,host,dbname) dbWriteTable(con, “Insurance”, Insurance) to R Objects save(Insurance, file=“Insurance.RData”)
  • 20. Navigating within the R environment listing all variables > ls() examining a variable ‘x’ > str(x) > head(x) > tail(x) > class(x) removing variables > rm(x) > rm(list=ls()) # remove everything
  • 21.
  • 22. A Swiss-Army Knife for Data
  • 23. A Swiss-Army Knife for Data Indexing Three ways to index into a data frame array of integer indices array of character names array of logical Booleans Examples: df[1:3,] df[c(“New York”, “Chicago”),] df[c(TRUE,FALSE,TRUE,TRUE),] df[city == “New York”,]
  • 24.
  • 25. A Statistical Modeler R’s has a powerful modeling syntax Models are specified with formulae, like y ~ x growth ~ sun + water model relationships between continuous and categorical variables. Models are also guide the visualization of relationships in a graphical form
  • 26.
  • 27. A Statistical Modeler Logistic model m <- glm(Age ~ Claims/Holders, data=Insurance, family=binomial(“logit”)) ) Examine it summary(m) Plot it plot(m)
  • 28.
  • 29. Visualization: Multivariate Barplot library(ggplot2) qplot(Group, Claims/Holders, data=Insurance, geom="bar", stat='identity', position="dodge", facets=District ~ ., fill=Age)
  • 30. Visualization: Boxplots library(ggplot2) qplot(Age, Claims/Holders, data=Insurance, geom="boxplot“) library(lattice) bwplot(Claims/Holders ~ Age, data=Insurance)
  • 31. Visualization: Histograms library(ggplot2) qplot(Claims/Holders, data=Insurance, facets=Age ~ ., geom="density") library(lattice) densityplot(~ Claims/Holders | Age, data=Insurance, layout=c(4,1)
  • 32.
  • 33. Getting Help with R Help within R itself for a function > help(func) > ?func For a topic > help.search(topic) > ??topic search.r-project.org Google Code Search www.google.com/codesearch Stack Overflow http://stackoverflow.com/tags/R R-help list http://www.r-project.org/posting-guide.html
  • 34. Six Indispensable Books on R Learning R Data Manipulation Visualization Statistical Modeling
  • 35. Extending R with Packages Over one thousand user-contributed packages are available on CRAN – the Comprehensive R Archive Network http://cran.r-project.org Install a package from the command-line > install.packages(‘actuar’) Install a package from the GUI menu “Packages”--> “Install packages(s)”
  • 36.
  • 37. For as many claims as were randomly simulated, simulate a severity from a gamma distribution with shape α=49 and scale θ=0.2 (NB: mean gamma = αθ, variance gamma = αθ2)
  • 38. Is the total simulated claim amount close to expected?
  • 39. Calculate usual parameterization (μ,p,φ)of this Tweedie distribution
  • 41. Repeat the above 10000 times.
  • 42.
  • 43. P&C Actuarial Models Design • Construction Collaboration • Education Valuable • Transparent Daniel Murphy, FCAS, MAAAdmurphy@trinostics.com 925.381.9869 From Data to Decision Big Data • Analytics • Visualization www.dataspora.com Michael E. Driscoll, Ph.D. med@dataspora.com 415.860.4347 37 Contact Us
  • 44. Appendices R as a Programming Language Advanced Visualization Embedding R in a Server Environment
  • 45. R as a Programming Language fibonacci <- function(n) { fib <- numeric(n) fib [1:2] <- 1 for (i in 3:n) { fib[i] <- fib[i-1] + fib[i-2] } return(fib[n]) } Image from cover of Abelson & Sussman’stextThe Structure and Interpretation of Computer Languages
  • 46. Assignment x <- c(1,2,6) x a variable x <- R’s assignment operator, equivalent to ‘=‘ c( a function c which combines its arguments into a vector y <- c(‘apples’,’oranges’) z <- c(TRUE,FALSE) c(TRUE,FALSE) -> z These are also valid assignment statements.
  • 47.
  • 48. Data Structures in R numeric x <- c(0,2:4) vectors Character y <- c(“alpha”, “b”, “c3”, “4”) logical z <- c(1, 0, TRUE, FALSE) > class(x) [1] "numeric" > x2 <- as.logical(x) > class(x2) [1] “logical”
  • 49. Data Structures in R lists lst <- list(x,y,z) objects matrices M <- matrix(rep(x,3),ncol=3) data frames* df <- data.frame(x,y,z) > class(df) [1] “data.frame"
  • 50. Summary of Data Structures ? matrices vectors data frames* lists
  • 51. Advanced Visualization lattice, ggplot2, and colorspace
  • 54. qplot(log(carat), log(price), data = diamonds, alpha=I(1/20)) + facet_grid(. ~ color) Achieving small multiples with “facets”
  • 55. lattice = trellis (source: http://lmdvr.r-forge.r-project.org )
  • 56. list of latticefunctions densityplot(~ speed | type, data=pitch)
  • 57. visualizing six dimensions of MLB pitches with lattice
  • 58. xyplot(x ~ y | type, data=pitch, fill.color = pitch$color, panel = function(x,y, fill.color, …, subscripts) { fill <- fill.color[subscripts] panel.xyplot(x, y, fill= fill, …) })
  • 59. Beautiful Colors with Colorspace library(“Colorspace”) red <- LAB(50,64,64) blue <- LAB(50,-48,-48) mixcolor(10, red, blue)
  • 60. efficient plotting with hexbinplot hexbinplot(log(price)~log(carat),data=diamonds,xbins=40)
  • 61. Embedding R in a Web Server Using Packages & R in a Server Environment
  • 62.
  • 63.

Editor's Notes

  1. These two men can help you. They are Robert Gentleman and Ross Ihaka, the creators of R.R is:free, open sourcecreated by statisticians extensible via packages - over 1000 packagesR is an open source programming language for statistical computing, data analysis, and graphical visualization.It has one million users worldwide, and its user base is growing. While most commonly used within academia, in fields such as computational biology and applied statistics, it is gaining currency in commercial areas such as quantitative finance – it is used by Barclay’s – and business intelligence – both Facebook and Google use R within their firms.It was created by two men at the University of Auckland – pictured in the NYT article on the rightOther languages exist that can do some of what R does, but here’s what sets it apart:1. Created by StatisticiansBo Cowgill, who uses R at Google has said: “the great thing about R is that it was created by statisticians.” By this – I can’t speak for him – that R has unparalleled built-in support for statistics. But he also says “the terrible thing about R is… that it was created by statisticians.” The learning curve can be steep, and the documentation for functions is sometimes sparse. Free, open sourcethe importance of this can’t be understated. anyone can improve to the core language, and in fact, a group of few dozen developers around the world do exactly this. the language is constantly vetted, tweaked, and improved.Extensible via packagesthis is related to the open source nature of the language. R has a core set of functions it uses, but just as Excel has ‘add-ons’ and Matlab has ‘toolkits’, it is extensible with ‘packages’. This is where R is most powerful: there are over 1000 different packages that have been written for R. If there’s a new statistical technique or method that has been published, there’s a good chance it has been implemented in R.Audience survey: How many of you use R regularly? Have ever used R? Have ever heard of R?
  2. These are the three fundamental steps of a data analyst.