Fiona
Fiona

Reputation: 477

Combining two Weibull distributions in R

I am working on a project which involves combining two Weibull distributions and thus creating a double peaked curve. I then aim to make predictions using this. I have searched online and I can't seem to find anything on this or if R has a function that allows me to combine two Weibulls. Below shows the code I have used to create the two Weibull distributions I wish to combine to make one single probability density function.

curve(dweibull(x, scale=30.59898985, shape=2.27136646),from=0, to=70, main="Weibull distribution")
curve(dweibull(x, scale=19.39743639, shape=1.22800332),from=0, to=70, main="Weibull distribution")

Any help would be amazing.

Thanks!

Upvotes: 3

Views: 1140

Answers (1)

Damiano Fantini
Damiano Fantini

Reputation: 1975

Would it make sense to combine the probability distributions and then use the element "y" of your final list to make predictions? If so, this should work. The final AUC is still ~1.

dwb1 <- curve(dweibull(x, scale=30.59898985, shape=2.27136646),from=0, to=70, main="Weibull distribution")
dwb2 <- curve(dweibull(x, scale=19.39743639, shape=1.22800332),from=0, to=70, main="Weibull distribution")

# combine
final.dwb <- lapply(c("x", "y"), (function(i){
  (dwb1[[i]] + dwb2[[i]])/2
}))
names(final.dwb) <- c("x", "y")

# plot
plot(final.dwb$y ~ final.dwb$x, xlim=c(0,70), main = "combined Weibull distributions", type = "n", las = 2)
lines(final.dwb$y ~ final.dwb$x, xlim=c(0,70), main = "combined Weibull distributions")

Combined distribution plot

Say you want the probability at a time of interest

t1 = 30

Search among the x you have and find the closest to t1 and then return the corresponding y

id <- which.min(abs(t1 - final.dwb$x))
final.dwb$y[id]

Upvotes: 3

Related Questions