[R] Quantiles of sums of independent discrete random variables
Michael Meyer
@pyqqqd|@ @end|ng |rom y@hoo@com
Wed Jan 24 09:47:09 CET 2024
Greetings,
Minimal reproducible example as requested by the technical expert Jeff Newmiller:
library(bayesmeta)
# density of $(1/10)*\sum_{j=1}{10}N(j,0.01$
# (convex sum of normal distributions)
#
f <- Vectorize(function(s) sum(vapply(1:10,
FUN = function(j) dnorm(s,mean=j,sd=0.01)/10, FUN.VALUE=0
)))
g <- function(s) dnorm(s,mean=0,sd=0.01)
cat("\n\n")
for(i in 1:5){
cat("Doing convolution ",i,"\n")
g <- convolve(g,f)$density
}
cat("\nConvolutions finished, plotting density.")
s <- seq(0,100,length.out=1024)
matplot(s,g(s),type="l")
Michael Meyer
[[alternative HTML version deleted]]
More information about the R-help
mailing list