You got at least two answers on this yesterday. If you want more precise answers, please tell us what your expected result is.
Uwe Ligges osita k ezeh wrote: > 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. > > 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. > > > > 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), n=c(52,60),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 > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.