我很好奇为什么,但是是的,有一种简单的方法可以生成这个分布总和的 pdf:
## install.packages("truncnorm")
## install.packages("caTools")
library(truncnorm)
x.mu <- c(12, 18, 7)
x.sd <- c(1.5, 2, 0.8)
x.a <- x.mu - 2*x.sd
x.b <- x.mu + 2*x.sd
dmulti <- function(x, a, b, mu, sd)
rowSums(
sapply(1:length(mu),
function(idx)
dtruncnorm(x, a=a[idx], b=b[idx], mean=mu[idx], sd=sd[idx])))/length(mu)
pmulti <- function(q, a, b, mu, sd)
rowSums(
sapply(1:length(mu),
function(idx)
ptruncnorm(q, a=a[idx], b=b[idx], mean=mu[idx], sd=sd[idx])))/length(mu)
pointrange <- range(c(x.a, x.b))
pointseq <- seq(pointrange[1], pointrange[2], length.out=100)
## Plot the probability density function
plot(pointseq, dmulti(pointseq, x.a, x.b, x.mu, x.sd),
type="l")
## Plot the cumulative distribution function
plot(pointseq, pmulti(pointseq, x.a, x.b, x.mu, x.sd),
type="l")