This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(jpeg) | |
library(RCurl) | |
url <-"https://raw.githubusercontent.com/mages/diesunddas/master/Blog/LloydsBuilding.jpg" | |
readImage <- readJPEG(getURLContent(url, binary=TRUE)) | |
dm <- dim(readImage) | |
rgbImage <- data.frame( | |
x=rep(1:dm[2], each=dm[1]), | |
y=rep(dm[1]:1, dm[2]), | |
r.value=as.vector(readImage[,,1]), | |
g.value=as.vector(readImage[,,2]), |
- Intro to Stan, including:
- Coding linear regression to assess wine quality
- Demonstrating important parts of the Stan program
- Doing some basic posterior predicting checking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using R in Insurance | |
============================== | |
```{r wordcloud, echo=FALSE, message=FALSE, fig.cap='Markus Gesmann, GIRO Brussels, 19 September 2012'} | |
library(ChainLadder) | |
library(googleVis) | |
library(wordcloud) | |
library(tm) | |
## About GIRO, sourced from: | |
## http://www.actuaries.org.uk/events/residential/giro-conference-and-exhibition-2012/about |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Markus Gesmann, January 2012 | |
## Please install the following R packages first: | |
## data.table, doBy, plyr, reshape, sqldf, e.g. via | |
## install.packages(c("data.table", "doBy", "plyr", "reshape", "sqldf")) | |
f <- function(x) x^2 | |
sapply(1:10, f) | |
do.call("rbind", as.list( | |
by(iris, list(Species=iris$Species), function(x){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stanmodel <- " | |
data { | |
int<lower=0> N; | |
real x[N]; | |
real Y[N]; | |
} | |
parameters { | |
real alpha; | |
real beta; | |
real<lower=.5,upper= 1> lambda; // original gamma in the JAGS example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create some sample data | |
CV_1 <- 0.2 | |
CV_2 <- 0.3 | |
Mean <- 65 | |
sigma_1 <- sqrt(log(1 + CV_1^2)) | |
mu_1 <- log(Mean) - sigma_1^2 / 2 | |
sigma_2 <- sqrt(log(1 + CV_2^2)) | |
mu_2 <- log(Mean) - sigma_2^2 / 2 | |
q <- c(0.25, 0.5, 0.75, 0.9, 0.95) | |
SummaryTable <- data.frame( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
checkModelPlot <- function(x, data, delta, company_code, col=c(1,2), | |
main="Reported incurred loss development by accident year", | |
ylab="Loss ratio (%)", xlab="Development year",...){ | |
library(latticeExtra) | |
my.settings <- list( | |
strip.background=list(col="#CBDDE6"), | |
par.main.text = list(font = 2, # make it bold | |
just = "left", | |
x = grid::unit(5, "mm")), | |
par.sub.text = list(font = 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Copyright Markus Gesmann, January 2013 | |
## See: http://lamages.blogspot.co.uk/2013/01/reserving-based-on-log-incremental.html | |
## Also: www.actuaries.org.uk/system/files/documents/pdf/crm2-D5.pdf | |
## | |
## Incremental claims triangle | |
tri <- t(matrix( | |
c(11073, 6427, 1839, 766, | |
14799, 9357, 2344, NA, | |
15636, 10523, NA, NA, | |
16913, NA, NA, NA), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n <- 50 | |
m <- 50 | |
set.seed(1) | |
mu <- -0.4 | |
sig <- 0.12 | |
x <- matrix(data=rlnorm(n*m, mu, sig), nrow=m) | |
library(fitdistrplus) | |
## Fit a log-normal distribution to the 50 random data set | |
f <- apply(x, 2, fitdist, "lnorm") |