作者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