4
我正在嘗試使用rpois()
創建泊松模擬。我有兩個小數位利率的分佈,我想知道這些是否具有泊松而不是正態分佈。從rpois生成正實數()
rpois()
函數返回正整數。我希望它返回兩位小數位的正數。我曾嘗試以下
set.seed(123)
trialA <- rpois(1000, 13.67) # generate 1000 numbers
mean(trialA)
13.22 # Great! Close enough to 13.67
var(trialA)
13.24 # terrific! mean and variance should be the same
head(trialA, 4)
6 7 8 14 # Oh no!! I want numbers with two decimals places...??????
# Here is my solution...but it has a problem
# 1) Scale the initial distribution by multiplying lambda by 100
trialB <- rpois(1000, 13.67 * 100)
# 2) Then, divide the result by 100 so I get a fractional component
trialB <- trialB/100
head(trialB, 4) # check results
13.56 13.62 13.26 13.44 # terrific !
# check summary results
mean(trialB)
13.67059 # as expected..great!
var(trialB)
0.153057 # oh no!! I want it to be close to: mean(trialB) = 13.67059
如何使用rpois()
生成具有泊松分佈至正二位小數號碼。
我知道泊松分佈用於計數,計數是正整數,但我也相信泊松分佈可以用來模擬速率。這些利率可能只是正數,而不是標量。
非常感謝Ben這麼全面的回答。非常感激 !問候,馬克。 – markthekoala
如果答案解決了您的問題,建議您點擊複選標記以接受它。 –