search for: rnbinom

Displaying 20 results from an estimated 74 matches for "rnbinom".

Did you mean: rbinom
2017 Jan 31
1
rnbinom Returns Error that says optional argument is missing
I am trying to reset the default arguments in the rnbinom function with the following example code: params <- c("size" = 1, "mu" = 1) formals(rnbinom)[names(params)] <- params rnbinom(n = 10) It returns the following: Error in rnbinom(n = 10) : argument "prob" is missing, with no default If I set the defaults with t...
2002 Jun 14
2
minor quirk in rnbinom
I don't want to spoil a nice joke, and recognise it's not a bug as it does have the intended effect, but the error message that is returned if rnbinom is given four parameters is slightly obscure: > rnbinom(0.5,0.5,0.5,0.5) Error in rnbinom(0.5, 0.5, 0.5, 0.5) : couldn't find function "error" > Cheers, Mike. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://w...
2014 Feb 23
1
Random Count Generation with rnbinom
The documentation states : An alternative parametrization (often used in ecology) is by the mean ?mu?, and ?size?, the dispersion parameter. However, this fails : > rnbinom(10, mu = 100, size = 0) [1] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Warning message: In rnbinom(10, mu = 100, size = 0) : NAs produced For dispersion set to 0, it should work like drawing from a Poisson distribution. It also produces incorrect draws for non-zero dispersions : > rnbinom(10, m...
2002 Jun 14
0
minor quirk in rnbinom (PR#1669)
Just for the records (was on R-help). Uwe Ligges -------- Original Message -------- Subject: Re: [R] minor quirk in rnbinom Date: Fri, 14 Jun 2002 18:47:59 +0200 From: Uwe Ligges <ligges@statistik.uni-dortmund.de> To: Mike Lonergan <mel@mcs.st-and.ac.uk> CC: r-help <r-help@stat.math.ethz.ch> References: <NEBBJLLBCLEDFLCCBKDAEEEKCGAA.mel@mcs.st-andrews.ac.uk> Mike Lonergan wrote: > > I don...
2011 Feb 13
3
How to print and save simulated data?
wanfairos wrote: > > Dear members; > > I have one problem to display my simulated data. Basically, I've generated > a set of rnorm (std.norm.mat)and rnbinom (gen.data) data to test on the > performance of FE Poisson model estimates > > ... Long self-contained example shorted > > my.data<-rep(9999,sim.size) > > for(i in 1: sim.size){ > ... > gen.data <- matrix(rnbinom(num.i * num.t, r.param,p.param),ncol=2) > &gt...
2009 Nov 20
6
How to add a top level title to multiple plots
...) title(main = list(paste("Normal"), ????????????????????????? col="black", cex = 1.0)) # Plot 2 plot(rpois(10, 4),type="l",col="blue") title(main = list(paste("Poison"), ????????????????????????? col="black", cex = 1.0)) # Plot 3 plot(rnbinom(10, mu = 4, size = 100),type="l",col="green") title(main = list(paste("Binomial"), ????????????????????????? col="black", cex = 1.0)) # Plot 4 plot(runif(10),type="l",col="black") title(main = list(paste("Uniform"), ????????????...
2005 Aug 16
1
predict nbinomial glm
Dear R-helpers, let us assume, that I have the following dataset: a <- rnbinom(200, 1, 0.5) b <- (1:200) c <- (30:229) d <- rep(c("q", "r", "s", "t"), rep(50,4)) data_frame <- data.frame(a,b,c,d) In a first step I run a glm.nb (full code is given at the end of this mail) and want to predict my response variable a. In a seco...
2005 Jan 05
3
strange behaviour of negative binomial
...iven 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");
2001 Dec 17
1
behavior of r* and d* functions at boundaries (PR#1218)
...nt, but maybe someone can make an argument for the current behavior). If people think these are really bugs I can submit them, together or separately. 1. rlnorm(n,mean,sd) gives NaN for sd=0, rather than always returning the mean. This is inconsistent with rnorm(), which returns the mean. 2. rnbinom(n,prob,size) gives NaN when prob=1; always returning 0 would be reasonable, and consistent with the output of dnbinom(). [This is equivalent to rnbinom(n,mu=0,size) in the new parameterization.] 3. rgamma(n,shape,scale) happily returns 0 when shape=0 or scale=0. However, dgamma(x,shape=0) [and...
2004 Nov 10
0
glm.nb
Hi, I make some simulations with rnbinom and try to test with glm.nb. But in some data set the glm.nb fail. Look: pop <- rnbinom(n=1000,size=1,mu=0.05) > glm.nb(pop~1,maxit=1000) Error in while ((it <- it + 1) < limit && abs(del) > eps) { : missing value where TRUE/FALSE needed look some pop charactetistics: &...
2006 Jul 14
2
Negative Binomial: Simulation
Hi R-Users! I fitted a negative binomial distribution to my count data using the function glm.nb() and obtained the calculated parameters theta (dispersion) and mu. I would like to simulate values from this negative binomial distribution. Looking at the function rnbinom() I was looking at the relationship between the two possible parametrizations of the negative binomial and found that for this fuction I must use: prob = theta/(theta+mu) and size = theta Theta, however, is not an integer. So how can size (which is the number of successes) equal theta?...
2007 Oct 23
1
How to avoid the NaN errors in dnbinom?
...bayes) old.parms=new.parms new.parms=c(k1,mu1,k2,mu2,prob) err=max(abs((old.parms-new.parms)/new.parms)) iter=iter+1 } lines(xvals,prob*dnbinom(xvals,size=k1,mu=mu1)+ (1-prob)*dnbinom(xvals,size=k2,mu=mu2),col="red") print(list(k1=k1,mu1=mu1,k2=k2,mu2=mu2,p=prob,iter=iter,err=err)) } y=c(rnbinom(900,size=10,mu=5),rnbinom(100,size=15,mu=10)) vals=mixnbinom(y,10,7,20,12,0.8) -- View this message in context: http://www.nabble.com/How-to-avoid-the-NaN-errors-in-dnbinom--tf4680211.html#a13373226 Sent from the R help mailing list archive at Nabble.com.
2012 Jul 04
2
About nlminb function
Hello I want to use the nlminb function but I have the objective function like characters. I can summarize the problem using the first example in the nlminb documentation. x <- rnbinom(100, mu = 10, size = 10) hdev <- function(par) -sum(dnbinom(x, mu = par[1], size = par[2], log = TRUE)) nlminb(c(9, 12), objective=hdev) With the last instructions we obtain appropriate results. If I have the name of the objective function stored in the element name, how can modify the next t...
2008 Jul 03
2
what can we do when R gives no response
...R gives no response??? thank you in advance. here is my sessionInfo i386-apple-darwin8.10.1 locale: zh_CN.UTF-8/zh_CN.UTF-8/C/C/zh_CN.UTF-8/zh_CN.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] mclust_3.1-5 x <- rnbinom(100, mu = 10, size = 10) hdev <- function(par) { -sum(dnbinom(x, mu = par[1], size = par[2], log = TRUE)) } nlminb(c(9, 12), hdev) ----------------------------------------------- Peng Jiang 江鹏 ,Ph.D. Candidate Antai College of Economics & Management 安泰经济管理学院 Department of Mathematics 数学...
2011 Oct 26
2
gam predictions with negbin model
...work with family=negbin() definition? It seems to me that the values returned by type="response" are far off the observed values. Here is an example output from the negbin examples: > set.seed(3) > n<-400 > dat<-gamSim(1,n=n) > g<-exp(dat$f/5) > dat$y<-rnbinom(g,size=3,mu=g) > b<-gam(y~s(x0)+s(x1)+s(x2)+s(x3),family=negbin(3),data=dat) > summary(y) Min. 1st Qu. Median Mean 3rd Qu. Max. 0.6061 1.6340 2.8120 2.7970 3.9250 4.9830 > summary(predict(b,type="response")) Min. 1st Qu. Median Mean 3rd Qu. Max....
1997 Jul 09
1
R-beta: Problem with `rpois'
There is a problem with `rpois'. It does seem to take care about the order of the arguments. This is an example: > rpois(n=1,lambda=2) [1] 3 > rpois(lambda=2,n=1) [1] 2 0 It obviously uses the first argument as the number of samples to be drawn, which is wrong. I used Version 0.49 Beta (April 23, 1997). Fredrik
1997 Jul 09
1
R-beta: Problem with `rpois'
There is a problem with `rpois'. It does seem to take care about the order of the arguments. This is an example: > rpois(n=1,lambda=2) [1] 3 > rpois(lambda=2,n=1) [1] 2 0 It obviously uses the first argument as the number of samples to be drawn, which is wrong. I used Version 0.49 Beta (April 23, 1997). Fredrik
2020 Jan 20
3
[External] Re: rpois(9, 1e10)
On 1/20/20 4:26 AM, Martin Maechler wrote: > Coming late here -- after enjoying a proper weekend ;-) -- > I have been agreeing (with Spencer, IIUC) on this for a long > time (~ 3 yrs, or more?), namely that I've come to see it as a > "design bug" that rpois() {and similar} must return return typeof() "integer". > > More strongly, I'm actually pretty
2004 Jun 15
1
AIC in glm.nb and glm(...family=negative.binomial(.))
Can anyone explain to me why the AIC values are so different when using glm.nb and glm with a negative.binomial family, from the MASS library? I'm using R 1.8.1 with Mac 0S 10.3.4. >library(MASS) > dfr <- data.frame(c=rnbinom(100,size=2,mu=rep(c(10,20,100,1000),rep(25,4))), + f=factor(rep(seq(1,4),rep(25,4)))) > AIC(nb1 <- glm.nb(c~f, data=dfr)) [1] 1047 > AIC(glm(c~f, family=negative.binomial(nb1$theta), data=dfr)) [1] -431804 Actually, the difference is already apparent with the function lo...
2008 May 16
1
gam negative.binomial
...I often would like the estimate for overdispersion to depend on the covariates in the same manner as the mean. For example, #either library(mgcv) or library(gam): x <- seq(0,1,length = 100)*2*pi mu <- 4+ 2*sin(x) size <- 4 + 2*cos(x) data <- cbind.data.frame(x<- rep(x,10), y = rnbinom(10*100,mu=rep(mu,10),size=rep(size,10))) x.gam <- gam(y~s(x), data=data,family=quasipoisson()) plot(x.gam) summary(x.gam) How would I get a smooth estimate of the overdispersion ? Thanks, Markus [[alternative HTML version deleted]]