Dear list, I ran into a strange behaviour of the pnbinom function - or maybe I just made a stupid mistake. First thing is that pnbinom seems to be very slow. The other - more interesting one - is that I get two different curves when I plot the estimated density and the density given by pnbinom. Shouldn't it be the same? This is only the case, I think, if I use the parameter size = 1. I just tried it for size = 2 and the result seemed correct.. Anyways, this is what I tried: #parameters proba<-0.001039302; s<-1; #random numbers with this distribution dom<-rnbinom(10000,s,proba); #first plot plot(ecdf(dom),do.points=FALSE); #second plot x<-seq(0,8700,0.5); lines(x,pnbinom(x,s,proba),col="red");
On Wed, 5 Jan 2005, dax42 wrote:> Dear list, > > I ran into a strange behaviour of the pnbinom function - or maybe I just made > a stupid mistake. > First thing is that pnbinom seems to be very slow. The other - more > interesting one - is that I get two different curves when I plot the > estimated density and the density given by pnbinom. Shouldn't it be the same?Yes, up to sampling error. That's actually one of the sets of tests that R does for the random number generators (though we can't test all possible parameters).> This is only the case, I think, if I use the parameter size = 1. I just tried > it for size = 2 and the result seemed correct.. > > Anyways, this is what I tried: > > #parameters > proba<-0.001039302; > s<-1; > > #random numbers with this distribution > dom<-rnbinom(10000,s,proba); > > #first plot > plot(ecdf(dom),do.points=FALSE); > > #second plot > x<-seq(0,8700,0.5); > lines(x,pnbinom(x,s,proba),col="red"); >I get almost identical curves, on both R 2.0.0 under Linux and R-devel on Mac (and it only takes half a second on the local computer and 1.25s across a couple of miles of network, so it isn't that slow). -thomas
dax42 <Dax42 at web.de> writes:> Dear list, > > I ran into a strange behaviour of the pnbinom function - or maybe I > just made a stupid mistake. > First thing is that pnbinom seems to be very slow. The other - more > interesting one - is that I get two different curves when I plot the > estimated density and the density given by pnbinom. Shouldn't it be > the same? > This is only the case, I think, if I use the parameter size = 1. I > just tried it for size = 2 and the result seemed correct.. > > Anyways, this is what I tried: > > #parameters > proba<-0.001039302; > s<-1; > > #random numbers with this distribution > dom<-rnbinom(10000,s,proba); > > #first plot > plot(ecdf(dom),do.points=FALSE); > > #second plot > x<-seq(0,8700,0.5); > lines(x,pnbinom(x,s,proba),col="red");Errrr... What's the problem here? The two curves look quite similar to me. (And both are of course cumulative distribution functions and not densities, but it doesn't sound like that is the problem.) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
dax42 <Dax42 <at> web.de> writes: : : Dear list, : : I ran into a strange behaviour of the pnbinom function - or maybe I : just made a stupid mistake. : First thing is that pnbinom seems to be very slow. The other - more : interesting one - is that I get two different curves when I plot the : estimated density and the density given by pnbinom. Shouldn't it be the : same? : This is only the case, I think, if I use the parameter size = 1. I just : tried it for size = 2 and the result seemed correct.. : : Anyways, this is what I tried: : : #parameters : proba<-0.001039302; : s<-1; : : #random numbers with this distribution : dom<-rnbinom(10000,s,proba); : : #first plot : plot(ecdf(dom),do.points=FALSE); : : #second plot : x<-seq(0,8700,0.5); : lines(x,pnbinom(x,s,proba),col="red"); There was a change in ecdf in R 2.1.0 so try the development version of R and see if there still is a problem with that. BTW, you can omit the trailing the semicolons.