On 25.11.2012 19:44, arun4 wrote:
Thank you Michael Weylandt. Let me to describe my problem fully, I have developed a new discrete probability distribution which has the following Probability mas function( as an alternative to binomial distribution) <http://r.789695.n4.nabble.com/file/n4650759/newdist.jpg> Where n= number of trials x are the binomial values a and b are the two parameters to be estimated (I use MLE method by calling mle2 from bbmle package) As you can see, there is an inner summation which runs from zero to (n-x) The below is the R functions I have written to define Negative Loglikelihood and estimate parameters: library(bbmle) * ###Define Negative LL Dist.NLL<-function(x,a,b,fre,n) { term<-0 for (j in 0:(n-x)) { term=term+(((-1)**j)*(choose(n-x,j))*(beta(((x/a)+1+(j/a)),b))) } density=b*choose(n,x)*term LL<-sum(fre*log(density)) return(-LL) } ##an example dataset x.values<-0:7 ##x values (here 7 trials) frequency<-c(47,54,43,40,40,41,39,95) ##Observed frequencies of x values ##Now use mle2 to estimate parameters. mle2(Dist.NLL, start=list(a=22,b=22), data=list(x=values ,fre=frequency, n=7)) * This is what I have done, bow I am getting "In 0:(n - x) : numerical expression has 8 elements: only the first used" error messages, which I afraid serious errors.
Dist.NLL obviously does not work for a vector of x values. You have to vectorize it.
Uwe Ligges
Thanks again. -- View this message in context: http://r.789695.n4.nabble.com/bbmle-Warning-optimization-did-not-converge-tp4650730p4650759.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.