I have an extended binomial distribution which has the following form: http://r.789695.n4.nabble.com/file/n4635699/kb.png Here alpha and beta are two parameters and x=0,1,2,3,...n (alike the binomial distribution) I am writing a function to find out the densities (probabilities) of this distribution for given values of alpha and beta. The below is the my function... *dnewdis<-function(x,a,b,n) { term<-0 for (j in 0:exp(10)) { term=term+(((-1)**i)*(choose(b-1,i))*(beta(x+a+a*i,n-x+1))) } s=a*b*choose(n,x)*term return(s) }* Since the sum inside the pdf runs from 0 to infinity, i restrict it to exp(10)[a large number).... My questions are: 1. Does the above function correct for the given pdf? In a journal paper, this distribution is evaluated for x=0,1,2...7 and n=7 and alpha=0.7 and beta=0.59 so I used my function and got densities as: /> dnewdis(0,0.7,0.59,7) [1] 0.9527325> dnewdis(1,0.7,0.59,7)[1] 4.001476> dnewdis(2,0.7,0.59,7)[1] 10.40384> dnewdis(3,0.7,0.59,7)[1] 21.50127> dnewdis(4,0.7,0.59,7)[1] 38.70228> dnewdis(5,0.7,0.59,7)[1] 63.47174> dnewdis(6,0.7,0.59,7)[1] 97.32334> dnewdis(7,0.7,0.59,7)[1] 141.814/ which are very contradiction to the values provided in the paper!!! 0.136090 0.104612 0.097393 0.096992 0.101203 0.111303 0.134110 0.218296 Also I am getting probabilities greater than 1 too?? Can you please tell me where am I doing wrong and I the function should be corrected? I am a new R user!! Thank you very much for your kind help! -- View this message in context: http://r.789695.n4.nabble.com/Declaring-a-density-function-with-for-loop-tp4635699.html Sent from the R help mailing list archive at Nabble.com.
chamilka wrote> > I have an extended binomial distribution which has the following form: > > http://r.789695.n4.nabble.com/file/n4635699/kb.png > > Here alpha and beta are two parameters and x=0,1,2,3,...n (alike the > binomial distribution) > I am writing a function to find out the densities (probabilities) of this > distribution for given values of alpha and beta. The below is the my > function... > > dnewdis<-function(x,a,b,n) { > term<-0 > for (j in 0:exp(10)) { > term=term+(((-1)**i)*(choose(b-1,i))*(beta(x+a+a*i,n-x+1))) > } > s=a*b*choose(n,x)*term > return(s) > } >The error is the line for (j in 0:exp(10)) { Shouldn't that be for (i in 0:exp(10)) { When I use this line results appear to be more in line with what you are expecting. Berend -- View this message in context: http://r.789695.n4.nabble.com/Declaring-a-density-function-with-for-loop-tp4635699p4635706.html Sent from the R help mailing list archive at Nabble.com.
Thank you very much for you kind explanation Berend Hasselman!! Is it possible to declare this probability density function without looping? -- View this message in context: http://r.789695.n4.nabble.com/Declaring-a-density-function-with-for-loop-tp4635699p4635720.html Sent from the R help mailing list archive at Nabble.com.
dnewdis <- function(x, a, b, n) { i <- 0:exp(10) term <-sum((((-1)**i)*(choose(b-1,i))*(beta(x+a+a*i,n-x+1)))) a*b*choose(n,x)*term } ---------------------------------------------- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of chamilka > Sent: Saturday, July 07, 2012 10:21 AM > To: r-help at r-project.org > Subject: Re: [R] Declaring a density function with for loop > > Thank you very much for you kind explanation Berend Hasselman!! > > Is it possible to declare this probability density function without > looping? > > -- > View this message in context: http://r.789695.n4.nabble.com/Declaring- > a-density-function-with-for-loop-tp4635699p4635720.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
Thank you very much Professor. David L Carlson .. This method saves my time!! -- View this message in context: http://r.789695.n4.nabble.com/Declaring-a-density-function-with-for-loop-tp4635699p4635795.html Sent from the R help mailing list archive at Nabble.com.