我有R。
这个功能immediate.amput.EV <- function(Dead.prob=.010,Dead.cost=40000,Alive.prob=.0990,Alive.cost=50000,high=100,p.payoff=1) {
return((Dead.prob * Dead.cost) + (Alive.prob * Alive.cost))
}
immediate.amput.EV()
It's supposed to output : (0.010 * 40000) + (0.990 * 50000) = 400 + 49500 = 49900
Instead it gives me: 5350
你能告诉我为什么吗? 感谢..
答案 0 :(得分:1)
正如Brian Hannays所说:将Alive.prob
的定义更改为1-Dead.prob
。一个好的编程习惯是尽量避免多余(然后可能相互冲突)的定义......
function(Dead.prob=.010,Dead.cost=40000,Alive.prob=1-Dead.prob,Alive.cost=50000,high=100,p.payoff=1) {
return((Dead.prob * Dead.cost) + (Alive.prob * Alive.cost))
}
答案 1 :(得分:0)
400 + 4950 NOT 49500
.01 *40000 =400 and .099*50000= 4950 and 400+4950 =5350
接受答案或删除您的问题。