CS2 - Loss Distribution R Coding (Pareto Distribution)

Discussion in 'CS2' started by skharki1, Jul 24, 2020.

  1. skharki1

    skharki1 Member

    Dear Team,

    Hope you are doing well.

    As per Core reading, it is mentioned that
    The basic R packages do not include functions for the two‐parameter Pareto distribution. So, we are creating the below function in R.

    rpareto <- function(n,a,l){
    rp <- l*((1-runif(n))^(-1/a)-1)
    rp
    }
    However, there is an inbuilt function in R for Pareto distribution, if we install the EnvStats package in R

    dpareto(x, location, shape = 1)
    ppareto(q, location, shape = 1)
    qpareto(p, location, shape = 1)
    rpareto(n, location, shape = 1)

    Similarly, for Burr Distribution by installing the package actuar.

    So, can we use the above-inbuilt function in R during the examination?
     
    Last edited by a moderator: Jul 24, 2020
  2. yatsa

    yatsa Keen member

    Hi I would prefer creating a function myself.
    For e.g. Burr
    a=2;l=1000;g=0.75;
    rburr <- function(n){(l*((1-runif(n))^(-1/a)-1))^(1/g)}
    dburr <- function(x){x*((a*g*l^a)*x^(g-1))/((l+x^g)^(a+1))}
    pburr <- function(q){1-(l/(l+q^g))^a}
    qburr <- function(p){q <- (l*((1-p)^(-1/a)-1))^(1/g)q}
    rburr(10,a,l,g)
     
  3. Andrew Martin

    Andrew Martin ActEd Tutor Staff Member

    Hello

    You're right, there are many packages that have this functionality. However, not in the base installation of R and not in the packages that the IFoA have listed as required for the exam.

    For a definitive answer about the exam you'll need to ask the IFoA. However, in any case, it may not be a good idea to use functionality outside of what the IFoA is expecting.

    It's also worth pointing out that if, for example, the exam asks you to construct a custom function to generate a random sample from the Pareto distribution, then of course you'll need to write out a function.

    More broadly, if you wish to do any practical application of R outside the exam, then using additional packages is a great way to gain access to lots of functionality. Of course, you have to be careful that you know what the functions are doing if you didn't write them yourself.

    Andy
     

Share This Page