class: center, middle, inverse, title-slide # Statistics with R ## Statistical Modelling with R for Actuarial Students --- <style type="text/css"> pre { background: #ADD8E6; max-width: 100%; overflow-x: scroll; } </style> ***CS2B – Risk Modelling and Survival Analysis *** * The emphasis is placed on being able to apply statistical methods to actuarial problems using real data sets and the open-source software environment R. * Time Series. Probability Distributions, Survival Analysis --- Suppose the transition probabilities are a function of the age of a person. The transition probability of a person aged x moving: * from Healthy to Sick state is 0.007x * from Healthy to Death state is 0.001x * from Sick to Death state is 0.002(100-x) * from Sick to Healthy is 0.006(100-x). #### Exercises Assuming 100 is the maximum age. Calculate the probability of: 1. Healthy person aged 30 will be in Sick state after 4 years. 2. Sick person aged 25 will be in Death state after 7 years. --- The transition matrix can be characterized as follows: $$ `\begin{pmatrix} 1-H2S(x)-H2D(x) & H2S(x) & H2D(x) \\ S2H(x) & 1-S2H(x)-S2D(x) & S2D(x) \\ 0 & 0 & 1 \\ \end{pmatrix}` $$ N.B. This matrix varies for differing values of `\(x\)`, and hence the process is not a Markov Process. --- ### Functions Transition Matrix is a function of age (x) ```r H2S<-function(x){ 0.007*x} H2D<-function(x){ 0.001*x} S2H<-function(x){ 0.006*(100-x)} S2D<-function(x){ 0.002*(100-x)} ``` ```r transmat<-function(x){ M<-matrix(0,nrow=3,ncol=3) M[1,1] <- 1 - H2S(x) - H2D(x) M[1,2] <- H2S(x) M[1,3] <- H2D(x) M[2,1] <- S2H(x) M[2,2] <- 1 - S2H(x) - S2D(x) M[2,3] <- S2D(x) M[3,1] <- 0 M[3,2] <- 0 M[3,3] <- 1 M } ``` --- Transition Matrix at 30 Years ```r transmat(30) ``` ``` ## [,1] [,2] [,3] ## [1,] 0.76 0.21 0.03 ## [2,] 0.42 0.44 0.14 ## [3,] 0.00 0.00 1.00 ``` Transition Matrix at 25 Years ```r transmat(25) ``` ``` ## [,1] [,2] [,3] ## [1,] 0.80 0.175 0.025 ## [2,] 0.45 0.400 0.150 ## [3,] 0.00 0.000 1.000 ``` --- #### Exercise 1 Healthy person aged 30 will be in Sick state after 4 years. ```r n <- 30 B <- c(1,0,0) ``` ```r i<- 1:4 n +i-1 ``` ``` ## [1] 30 31 32 33 ``` ```r for (i in 1:4){ B=B%*%transmat(n+i-1) } ``` --- ```r B ``` ``` ## [,1] [,2] [,3] ## [1,] 0.545 0.261 0.194 ``` Hence the probability of Healthy person aged 30 will be in Sick state after 4 years is 0.2608. --- #### Exercise 2. Sick person aged 25 will be in Death state after 7 years. ```r n <- 25 C <- c(0,1,0) for (i in 1:7){ C=C%*%transmat(n+i-1) } ``` ```r C ``` ``` ## [,1] [,2] [,3] ## [1,] 0.395 0.172 0.433 ``` Hence the probability of sick person aged 25 will be in Death state after 7 years is 0.4333. --- ---