Skip to content
Prev 333908 / 398525 Next

generate multiple probability distributions

On 12/2/2013 10:12 AM, Duncan Murdoch wrote:
Thanks, Duncan

What I was missing was how dbinom() could use vector inputs for both x & p.
Using expand.grid() gives me what I want and is more
general for my purposes.  The main purpose of making p a factor is to 
facilitate
plots of prob ~ x|p.


XP <-expand.grid(x=0:12, p=c(1/6, 1/3, 1/2, 2/3))
bin.df <- data.frame(XP, prob=dbinom(XP[,"x"], 12, XP[,"p"]))
bin.df$p <- factor(bin.df$p, labels=c("1/6", "1/3", "1/2", "2/3"))
str(bin.df)

-Michael