[程式] R程式錯? 還是我哪裡錯?

看板Statistics作者 (...)時間11年前 (2013/05/23 10:56), 編輯推噓0(006)
留言6則, 3人參與, 最新討論串1/2 (看更多)
我想自己寫一個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

05/23 11:18, , 1F
0<= pnorm=dist. func. <=1 阿值就很小 你1-很小=1
05/23 11:18, 1F

05/23 11:19, , 2F
是在大驚小怪什麼
05/23 11:19, 2F

05/23 11:23, , 3F
多善用 help(pnorm)
05/23 11:23, 3F

05/23 11:36, , 4F
樓上誤會了,照理說A()要等於B(),但程式結果不是
05/23 11:36, 4F
※ 編輯: aflilfesy 來自: 211.76.175.169 (05/23 11:38) ※ 編輯: aflilfesy 來自: 211.76.175.169 (05/23 11:38)

05/24 02:13, , 5F
integrate(...., rel.tol=1e-8, ...) 就會一樣了.
05/24 02:13, 5F

05/24 02:14, , 6F
這是數值計算所造成的誤差. integrate的default給太大了
05/24 02:14, 6F
文章代碼(AID): #1HdOLBNh (Statistics)
文章代碼(AID): #1HdOLBNh (Statistics)