loading

Logout succeed

Logout succeed. See you again!

ebook img

An Interactive Introduction to R for Actuaries PDF

pages59 Pages
release year2009
file size2.78 MB
languageEnglish

Preview An Interactive Introduction to R for Actuaries

An Interactive Introduction to R for Actuaries CAS Conference November 2009 Michael E. Driscoll, Ph.D. Daniel Murphy FCAS, MAAA 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 simple Let’s take a tour of some claim data in R R is “an overgrown calculator” • simple math > 2+2 4 • storing results in variables > x <- 2+2 ## „<-‟ is R syntax for „=‟ or assignment > x^2 16 • vectorized math > 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” • basic statistics mean(weight) sd(weight) sqrt(var(weight)) 176.6 65.0 65.0 # same as sd • set functions union intersect setdiff • advanced statistics > 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 • basic calculations > 2 + 2 [Hit ENTER] > log(100) [Hit ENTER] • calculate the value of $100 after 10 years at 5% > 100 * exp(0.05*10) [Hit ENTER] • construct a vector & do a vectorized calculation > 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]

See more

The list of books you might like