作者libertarian (我的昵称)
看板Statistics
标题[问题] [R] 标准常态分布cdf 求解
时间Sat Oct 27 21:01:52 2007
不好意思 ,实在没什麽统计背景, 可能要让版大们见笑了
小弟目前正用牛顿法求 f(x) = phi(x)-0.1 的解 phi(x) = 标准常态分布的cdf
写了一些R但只有在x的初始值与解够近的时候 , 我的 while回圈 才可以跑
要不然会得到错误讯息:错误在while ((target(initialX, setAlpha) != 0) && maxIter > 0) { :
需要 TRUE/FALSE 值的地方有缺值
拜托版大指点迷津 , 感恩 ~~
#code
#generate target function (phi(x)-alpha) (allow input x and alpha)
target<-function(x,alpha){
pnorm(x)-alpha
}
#generate the first derivative of the of the target function
firstDerivative<-function(x){
exp(-(x^2)/2)/sqrt(2*pi)
}
# Finding the root by Newton method
rootFinding<-function(initialX,setAlpha,maxIter){
while((target(initialX,setAlpha)!=0) && maxIter>0){
initialX<-initialX-(target(initialX,setAlpha)/firstDerivative(initialX))
maxIter<-maxIter-1
}
initialX
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 76.99.44.184