2015-11-05 44 views
0

我產生200張隨機數與隨機變量Y〜指數(0.8)使用:我想計算計數器的預期數量每個箱知道如何找到垃圾箱預期值

n=rexp(200,0.8) 
bins=cut(n,breaks=c(0,1,2,3,max(n))) 

Y〜指數(0.8)。我怎樣才能做到這一點?

+1

提示:使用'dexp()'。 – Gregor

+0

@Gregor - 現在我真的很好奇如何使用'dexp'來簡單地進行排序。 – thelatemail

回答

1

可以使用同一組功能,它是?rexp從計算每個範圍的比例,並使用該值來計算預期的數字:

num <- 200 
brks=c(0,1,2,3,Inf) 

set.seed(12345) 
n <- rexp(num,0.8) 
bins <- cut(n,breaks=brks) 

expect.prop <- diff(pexp(brks, rate=0.8)) 
#[1] 0.55067104 0.24743245 0.11117856 0.09071795 

rbind(
    observed=table(bins), 
    expected=num*expect.prop 
) 
#   (0,1] (1,2] (2,3] (3,Inf] 
#observed 115.0000 42.00000 24.00000 19.00000 
#expected 110.1342 49.48649 22.23571 18.14359