I want to define (implement) the probability mass function into the R environment when dealing with another calculation. Since not having much R experience, I do not know how to translate the equation with these parameters into code (already tried to search everywhere). Thanks for help. [![probability mass function given by this equation][1]][1]
It's already a built in pmf in R - its there when you install R. If you have r
and theta
already defined, just call dnbinom
dnbinom(x, size=r, prob=theta)
See the help ?dnbinom
Don't waste your time debugging your own code when there's code that's already debugged and which is tested daily by large numbers of highly knowledgeable users (many research statisticians use it for example) - who should certainly have spotted anything but very rare problems by now. It will also likely be considerably more numerically stable and more efficiently implemented than you will write.