0
我在https://stats.stackexchange.com/questions/117578/density-distribution-of-outcomes-of-2-dice-rolled上發佈了以下問題,但沒有得到任何答覆。2個骰子結果的不對稱密度圖滾動
這個問題是涉及到:A histogram with a bar for each frequency value
兩個骰子旋轉和和繪製。直方圖如預期的那樣,但密度圖顯示不同的密度2和12,並且圖是不對稱的。這是爲什麼? 在2個擲骰子的結果中,2的概率等於12的概率。爲什麼密度圖的值不等?
num.dices <- 2L
num.rolls <- 100000L
outcomes <- matrix(sample(1:6, num.dices * num.rolls, replace = TRUE),
nrow = num.rolls, ncol = num.dices)
sums <- rowSums(outcomes)
柱狀圖:
ggplot(data.frame(sums), aes(x=factor(sums)))+geom_histogram()
密度圖:
ggplot(data.frame(sums), aes(x=factor(sums), fill=factor(sums)))+geom_density()
我也試過:
ggplot(data.frame(總和),AES(X =因子(總和),填充因子=(和)))+ geom_density(AES(Y = ..count ..))
它看起來像在密度內核的帶寬問題。但是,當分佈是離散的時候,爲什麼要首先使用density()? – 2014-10-02 08:36:54
我們是不是應該得到與圖12相同的對稱圖?我們如何確認和糾正帶寬問題? – rnso 2014-10-02 08:41:45
我們應該,但在我看來,總帶寬在增加。不知道如何在ggplot()中對它進行調整,但我認爲它也不合理,你可能在ggplot()中尋找類似於'plot(density(sums))'的東西。你應該能夠以某種方式對它進行評估。 – 2014-10-02 09:55:53