简体   繁体   English

从R中的混合物分布进行仿真

[英]Simulation from mixture distribution in R

I would like to simulate data set which has a decreasing and then increasing hazard from 3 weibull distributions but I would like to have this hazard function more near to zerohow can I get around 0.1 or less. 我想模拟从3个Weibull分布中有递减风险然后递增的数据集,但是我想使该风险函数更接近零,如何才能得到0.1或更少。 How can I fix my code to have this? 我该如何修复我的代码呢?

It's not necessary to use pexp and rexp , because the Exponential is a degenerate case of the Weibull distribution when the shape parameter=1. 不必使用pexprexp ,因为当形状参数= 1时,指数是威布尔分布的简并情况。 Shapes less than 1 are going to be even more "scoopy" near the origin. 小于1的形状在原点附近将更加“隐蔽”。 You could get a nice bathtubwith just two Weibull, but since you had one with three, I just made some minor alterations: 您可能会得到一个只有两个Weibull的漂亮浴缸,但是由于您只有三个,所以我做了一些小改动:

 hazmix = function(w1, w2, x) {w1*dweibull(x,.8, 1)/(1-pweibull(x, .8, 1))+ 
    + w2*dweibull(x,1,.5) + 
    ((1-(w1+w2))* dweibull(x, 6, 10)/(1-pweibull(x, 6, 10)))}

 png();plot(hazmix(.2,.4, seq(0, 10, by=.1)), ylim=c(0,1) ); dev.off()

在此处输入图片说明

I don't promise that it's normalized and if you needed a normalized distribution it would be much easier to just use two Weibulls with one mixing parameter. 我不保证将其标准化,如果您需要标准化的分布,仅使用两个带有一个混合参数的Weibulls会容易得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM