作者aflilfesy (...)
看板Statistics
標題[程式] R程式錯? 還是我哪裡錯?
時間Thu May 23 10:56:08 2013
我想自己寫一個P(X>x)的函數也就是1-pnorm
此函數為A函數
A=function()
{
InteOut = integrate( function(x)
{
dnorm(x,10,sqrt(0.24))
},0,Inf)$value
InteOut
}
A()
1-pnorm(0,10,sqrt(0.24))
----
A() 結果是 1
1-pnorm(0,10,sqrt(0.24)) 結果是 1
----
B=function()
{
InteOut = integrate( function(x)
{
dnorm(x,
11,sqrt(0.24))
},0,Inf)$value
InteOut
}
B()
1-pnorm(0,
11,sqrt(0.24))
----
B() 結果是 3.707784e-05
1-pnorm(0,11,sqrt(0.24)) 結果是 1
A()函數與B()函數的結果照理說要非常接近,但答案卻完全相反。
高手們,可以解釋一下 B()這地方結果怎麼變成這樣嗎?
我只有更改黃色部份而已
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.76.175.169
1F:→ phantomspank:0<= pnorm=dist. func. <=1 阿值就很小 你1-很小=1 05/23 11:18
2F:→ phantomspank:是在大驚小怪什麼 05/23 11:19
3F:→ phantomspank:多善用 help(pnorm) 05/23 11:23
4F:→ aflilfesy:樓上誤會了,照理說A()要等於B(),但程式結果不是 05/23 11:36
※ 編輯: aflilfesy 來自: 211.76.175.169 (05/23 11:38)
※ 編輯: aflilfesy 來自: 211.76.175.169 (05/23 11:38)
5F:→ clickhere:integrate(...., rel.tol=1e-8, ...) 就會一樣了. 05/24 02:13
6F:→ clickhere:這是數值計算所造成的誤差. integrate的default給太大了 05/24 02:14