Created
May 21, 2014 18:04
-
-
Save carsten-j/a1476d179481e840d240 to your computer and use it in GitHub Desktop.
Figurer til noterne i Grundlæggende livsforsikringsmatematik (Liv1)
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
require(ggplot2) | |
require(eha) | |
library(ggplot2) | |
library(eha) | |
alpha = 5.0 * (10.0 ** -4.0) | |
beta = 7.5858 * (10.0 ** -5.0) | |
gamma = log (1.09144) | |
GompertzMakeham <- function(xvar) { | |
alpha + beta * exp(gamma * xvar) | |
} | |
GompertzMakeham70 <- function(x) ifelse(x >= 70, GompertzMakeham(x), NA) | |
xAxisBreaks = c(0,10,20,30,40,50,60,70,80,90,100) | |
yAxisBreaks = xAxisBreaks / 100 | |
ggplot(data.frame(t=c(0, 100)), aes(x=t)) + | |
stat_function(fun = pmakeham, arg=list(shape = c(beta, alpha), scale=1.0/gamma, lower.tail = FALSE), geom="line") + | |
stat_function(fun = pmakeham, arg=list(shape = c(beta, alpha), scale=1.0/gamma, lower.tail = TRUE), geom="line", linetype=2) + | |
ggtitle(expression(paste("Figure 3.1: The G82M mortality law: F broken line, ", bar(F) ," whole line"))) + | |
scale_x_continuous(breaks=xAxisBreaks) + | |
scale_y_continuous(breaks=yAxisBreaks) + | |
theme(axis.title.y=element_blank(), text = element_text(size = 8)) | |
ggsave("figure3.1.png", width=15, height=8, units="cm") | |
ggplot(data.frame(t=c(0, 100)), aes(x=t)) + | |
stat_function(fun = dmakeham, arg=list(shape = c(beta, alpha), scale=1.0/gamma), geom="line") + | |
ggtitle(expression(paste("Figure 3.2: The density ", f, " for the G82M mortality law."))) + | |
scale_x_continuous(breaks=xAxisBreaks) + | |
theme(axis.title.y=element_blank(), text = element_text(size = 8)) | |
ggsave("figure3.2.png", width=15, height=8, units="cm") | |
ggplot(data.frame(t=c(0, 100)), aes(x=t)) + | |
stat_function(fun = hmakeham, arg=list(shape = c(beta, alpha), scale=1.0/gamma), geom="line") + | |
ggtitle(expression(paste("Figure 3.3: The force of mortality ", mu, " for the G82M mortality law"))) + | |
scale_x_continuous(breaks=xAxisBreaks) + | |
theme(axis.title.y=element_blank(), text = element_text(size = 8)) | |
ggsave("figure3.3.png", width=15, height=8, units="cm") | |
ggplot(data.frame(x = c(0, 100)), aes(x)) + | |
stat_function(fun = GompertzMakeham70) + | |
ggtitle(expression(paste("Figure 3.6: The force of mortality", mu, "(t|70) = ", mu,"(70 + t), t > 0, for the G82M mortality law."))) + | |
scale_x_continuous(breaks=xAxisBreaks) + | |
theme(axis.title.y=element_blank(), text = element_text(size = 8)) | |
ggsave("figure3.6.png", width=15, height=8, units="cm") | |
(xmax <- qexp(0.995, rate=0.2)) | |
xvals <- seq(0, xmax, length=100) | |
qplot(xvals, pexp(xvals, rate=0.2), geom="line") + | |
stat_function(fun=pexp, geom="line", colour="blue", arg=list(rate=2)) + | |
stat_function(fun=dexp, geom="line", arg=list(rate=0.2)) + | |
stat_function(fun=dexp, geom="line", colour="blue", arg=list(rate=2)) + | |
ggtitle(expression(paste("Figure 3.7: Two exponential laws with intensities ", lambda[1], " and ", | |
lambda[2], " such that ", lambda[1] < lambda[2], "; ", bar(F)[1], " and ", bar(F)[2], " blue line, ", | |
f[1], " and ", f[2], " black line"))) + | |
theme(axis.title.x=element_blank(), axis.title.y=element_blank(), text = element_text(size = 8)) | |
ggsave("figure3.7.png", width=15, height=8, units="cm") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment