HTML Test – Visualizing Continuous Distributions for Severity

[raw]








This webpage illustrates how to make plots for commonly used severity distributions using R. The code and resulted plots are displayed.

Gamma

We first create a sequence, dgamma function can calculate the corresponding density of a gamma distribution for each point. As an example, set the shape parameter to be 1/3 and scale parameter to be 15. plot gives us the plot of density function.

y <- 100:10000/100
fgamma <- dgamma(y,shape=1/3,scale=15)        
plot(y,fgamma,lwd=2,type="l",ylim=c(0,0.2))

Now we plot the curves of gamma density functions with different parameters together for comparison. We define a set of scale and shape parameters. And again, we define a grid first and calculate corresponding density.

Show underlying code

We first check the effect of the shape parameter and fix scale parameter to be 100. For example, when the shape parameter takes value as the first element in the set of shape parameter set.

fgamma <- dgamma(x, shape = shapeparam[1], scale = 100)
plot(x, fgamma, type = "l", ylab = "Gamma Density")

Similarly, we plot curves with different shape parameters together with different colors.

fgamma <- dgamma(x, shape = shapeparam[1], scale = 100)
plot(x, fgamma, type = "l", ylab = "Gamma Density")
for(k in 2:length(shapeparam)){
  fgamma <- dgamma(x,shape = shapeparam[k], scale = 100)
  lines(x,fgamma, col = k)
}
legend("topright", c("shape=2", "shape=3", "shape=4", "shape=5"), lty=1, col = 1:4)
title("Gamma Density, with scale=100, and Varying Shape")

Now we let the scale parameter vary.

fgamma <- dgamma(x, shape = 2, scale = scaleparam[1])
plot(x, fgamma, type = "l", ylab = "Gamma Density")

for(k in 2:length(scaleparam)){
  fgamma <- dgamma(x,shape = 2, scale = scaleparam[k])
  lines(x,fgamma, col = k)
}

legend("topright", c("scale=100", "scale=150", "scale=200", "scale=250"), lty=1, col = 1:4)
title("Gamma Density, with shape=2, and Varying Scale")

Pareto Distribution

The functions needed for Pareto distribution are included in R package actuar.

library(actuar)

dpareto function can calculate the corresponding density of a Pareto distribution for each point.

y <- 100:10000/100
fpareto <- dpareto(y, shape = 3, scale = 10)  #Pareto density function with mean=5 and variance=75
plot(y, fpareto, lwd=2,type="l")      ## but tail behavior is different

Similar to gamma distributions, we let scale and shape parameters vary and plot different curves together.

scaleparam <- seq(2000,3500,500)
shapeparam <- 1:4

We first let the shape parameter vary.

z<- seq(0,3000,by=1)
fpareto <- dpareto(z, shape = shapeparam[1], scale = 2000)
plot(z, fpareto, ylim=c(0,0.002),type = "l", ylab = "Pareto Density")

for(k in 2:length(shapeparam)){
  fpareto <- dpareto(z,shape = shapeparam[k], scale = 2000)
  lines(z,fpareto, col = k)
}
legend("topright", c("shape=1", "shape=2", "shape=3", "shape=4"), lty=1, col = 1:4)
title("Pareto Density, with scale=2000, and Varying Shape")

Here is the code to let the scale parameter vary.

fpareto <- dpareto(z, shape = 3, scale = scaleparam[1])
plot(z, fpareto, ylim=c(0,0.002),type = "l", ylab = "Pareto Density")

for(k in 2:length(shapeparam)){
  fpareto <- dpareto(z,shape = 3, scale = scaleparam[k])
  lines(z,fpareto, col = k)
}
legend("topright", c("scale=2000", "scale=2500", "scale=3000", "scale=3500"), lty=1, col = 1:4)
title("Pareto Density, with shape=3, and Varying Scale")

Weibull Distribution

We first let the shape parameter vary.

z<- seq(0,400,by=1)

scaleparam <- seq(50,200,50)
shapeparam <- seq(1.5,3,0.5)

plot(z, dweibull(z, shape = shapeparam[1], scale = 100), ylim=c(0,0.012), type = "l", ylab = "Weibull density")

for(k in 2:length(shapeparam)){
  lines(z,dweibull(z,shape = shapeparam[k], scale = 100), col = k)
}

legend("topright", c("shape=1.5", "shape=2", "shape=2.5", "shape=3"), lty=1, col = 1:4)
title("Weibull Density, with scale=100, and Varying Shape")

Here is code to plot Weibull distributions with different scale parameters.

plot(z, dweibull(z, shape = 3, scale = scaleparam[1]), type = "l", ylab = "Weibull density")

for(k in 2:length(scaleparam)){
  lines(z,dweibull(z,shape = 3, scale = scaleparam[k]), col = k)
}
legend("topright", c("scale=50", "scale=100", "scale=150", "scale=200"), lty=1, col = 1:4)
title("Weibull Density, with shape=3, and Varying Scale")

GB2 Distribution

GB2 distributions have four parameters including three shape parameters and one scale parameter.

alpha1<-5
alpha2<-4 
alpha3<-2
theta <- seq(200,350,50)

dgenbeta function calculate the density of GB2 distribution. We let scale parameter vary.

z<- seq(0,400,by=1)
plot(z, dgenbeta(z, shape1=alpha1,shape2=alpha2,shape3=alpha3, scale = theta[1]), type = "l", ylab = "Generalized Beta Density")

for(k in 2:length(theta)){
  lines(z,dgenbeta(z,shape1=alpha1,shape2=alpha2,shape3=alpha3, scale = theta[k]), col = k)
}

legend("topright", c(expression(theta==200), expression(theta==250), expression(theta==300), expression(theta==350)), lty=1, col = 1:4)
title(main=expression(paste("GB2 Density, with ", list(alpha[1]==5,alpha[2]==4,alpha[3]==2), " and Varying Scale")))



[/raw]

[raw] [/raw]