hello,
please can anyone help me out. Am a new user of R program. Am having problem
with this code below, not getting the expected results.
1. Each m, the cumulative sum should be 1.000 but the 2nd and 3rd m returned
2.000 and 3.000
instead of 1.000.
2. to get the LCL(m) and UCL(m) for each m base on these instructions
if out.cum > 0.025 then LCL(m)= y-1
if out.cum >0.975 then ucl(m)= y-1
how do I code these instructions into this code.
thanks
Aruike
pp=function(x,n,M){z=1.0;a=2.3071430;b=7.266064;H=3
out.h=c()
out.y=c()
out.m=c()
out.prob=c()
for(h in 1:H){
for(m in 1:M){
for(y in
0:m){
g=lgamma(m+z)+lgamma(n[h]+a+b)+lgamma(x[h]+y+a)+lgamma(n[h]+m+b-x[h]-y)
g=g-lgamma(y+z)-lgamma(m-y+z)-lgamma(x[h]+a)-lgamma(n[h]+b-x[h])-
lgamma(n[h]+m+a+b)
out.h=c(out.h,h)
out.y=c(out.y,y)
out.m=c(out.m,m)
out.prob=c(out.prob, exp(g))
out.cum=c(cumsum(out.prob))
Result=data.frame(out.h,out.y,out.m,out.prob,out.cum)
}}}}
Kings=pp(x=c(19,20,30), n=c(52,60,80),3)
Kings
out.h out.y out.m
out.prob out.cum
1 1 0
1 0.65395431 0.6539543
2 1 1 1
0.34604569 1.0000000
3 1 0
2 0.43127277 1.4312728
4 1 1
2 0.44536308 1.8766358
5 1 2
2 0.12336415 2.0000000
6 1 0
3 0.28672775 2.2867277
7 1 1
3 0.43363507 2.7203628
8 1 2 3 0.23440955 2.9547724
9 1 3
3 0.04522764 3.0000000
Send instant messages to your online friends http://uk.messenger.yahoo.com