2017-06-01 44 views
0

我有一個數據集,我需要用泊松迴歸分析。 我嘗試繪製respons的histrogram在同一個情節作爲PDF文件的,但我沒有找到如何..繪製直方圖和pdf在同一圖中的泊松

我繪製我的直方圖用下面的代碼:

library(lattice) 
tot <- mydata[, 1] 
histogram(tot) 

,並得到一個不錯的直方圖。要添加PDF我已經嘗試了一些代碼躺在下面的一個:

xlines <-seq(min(tot),max(tot),length.out=100) 
lines(x = xlines,y=dpois(xlines,21)) 

我已經嘗試了一些其他法典,但無法找到一個工程......
有人有一些建議嗎?

回答

0

您就可以開始在此代碼的工作:

library(lattice) 
set.seed(1) 
tot <- rpois(100,21) 
xlines <- seq(min(tot),max(tot),by=1) 
histogram(tot, type="density", 
    panel=function(x, ...){ 
    panel.histogram(x,...) 
    panel.lines(x = xlines, y=dpois(xlines,21), lwd=2, col="red") 
    } 
) 

enter image description here

1

我覺得你的問題是,一般不正確的,只要它沒有什麼意義繪製直方圖和pdf在一起(頻率座標直方圖和密度圖是不同的)。你可以做的是讓R在概率座標中繪製直方圖。這裏是關於虹膜數據集的小例子。

data=iris 
x=iris[, 1] 
hist(x, freq=F) 
lines(density(x)) 

是什麼給了你:1

比較一下你做之前:

data=iris 
x <- iris[, 1] 
hist(x, freq=T) 
lines(density(x)) 

希望它能幫助!