![](/img/trans.png)
[英]Generating random variables from a mixture of Weibull(0,1) and Uniform(0,1)
[英]Mixture of 2 uniform random variables
我需要帮助来创建我使用的1/3 Unif(0,7)和2/3 Unif(9,10)的混合物
library(distr)
X <- UnivarMixingDistribution(Unif(0,7),Unif(9,10),mixCoeff = c((1/3),(2/3)))
但是我不确定是否很好,因为在绘制X时,它返回的散点实际上没有任何意义。
在此先感谢您的帮助 !
我不知道函数distr::UnivarMixingDistribution
但这很容易从头开始实现:
我们修复种子以确保可重复性
# Set fixed seed set.seed(2017);
指定采样点数
# Sample N points N <- 1000;
指定两种均匀分布的混合因子和极限
# Weights and limits of both uniform distibutions weights <- c(1/3, 2/3); range <- list(list(min = 0, max = 7), list(min = 9, max = 10));
现在我们采样N
点
# Sample x <- unlist(mapply(function(x, y) runif(x * N, y$min, y$max), weights, range))
让我们绘制x
的分布
ggplot(data.frame(x = x), aes(x)) + geom_histogram(bins = 100)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.