[R] help

Ben Bolker bolker at ufl.edu
Sun Oct 28 18:59:28 CET 2007




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.
> 
> 

     I wrote a function that replicates your results
and would probably be a little more efficient
(see Uwe's reply), but it replicates your results --
without "fixing" them.  I think the real problem
here is that we're not sure what you want
(especially for query #1).  (I assume LCL/UCL
are "lower/upper confidence limit".)  I can
see that you're coding some kind of combinatoric
probability (all those lgamma() calls), but I haven't
taken the time to puzzle through and figure out
what it is.  Perhaps there's a typo in your
formula somewhere?

  Ben Bolker



pfun = function(m,n,a,b,x,y,z) {
  lgamma(m+z)+lgamma(n+a+b)+
    lgamma(x+y+a)+lgamma(n+m+b-x-y)-
      lgamma(y+z)-lgamma(m-y+z)-lgamma(x+a)-
        lgamma(n+b-x)-lgamma(n+m+a+b)
}

pp=function(x,n,M,z=1.0,a=2.3071430,b=7.266064,H=3) {
  Mm_mat = matrix(nrow=M+1,ncol=M)
  w = row(Mm_mat)<=col(Mm_mat)+1
  y_vals = (row(Mm_mat)-1)[w]
  ny = length(y_vals)
  y_vals = rep(y_vals,H)
  m_vals = (col(Mm_mat))[w]
  m_vals = rep(m_vals,H)
  h_vals = rep(1:H,each=ny)
  lprob = pfun(m_vals,n[h_vals],a,b,x[h_vals],y_vals,z)
  prob=exp(lprob)
  data.frame(h=h_vals,y=y_vals,m=m_vals,
             lprob,prob,cumsum(prob))
}
## 

-- 
View this message in context: http://www.nabble.com/help-tf4700397.html#a13456000
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list