https://github.com/cran/bbmle
Raw File
Tip revision: a30256c01413bbf7af580b5ae24547064a7d055e authored by Ben Bolker on 18 April 2017, 12:04:25 UTC
version 1.0.19
Tip revision: a30256c
test-relist1.Rout.save

R Under development (unstable) (2012-07-27 r60013) -- "Unsuffered Consequences"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: i686-pc-linux-gnu (32-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(bbmle)
> set.seed(1001)
> f <- factor(rep(1:3,each=50))
> kvals <- c(1,2,5)
> muvals <- c(10,2,5)
> y <- rnbinom(length(f),size=kvals[f],mu=muvals[f])
> plot(y)
> 
> NLL <- function(p) {
+   kvals <- p[1:3]
+   muvals <- p[4:6]
+   -sum(dnbinom(y,size=kvals[f],mu=muvals[f],log=TRUE))
+ }
> parnames(NLL) <- c("k1","k2","k3","mu1","mu2","mu3")
> svec <- c(kvals,muvals)
> names(svec) <- parnames(NLL)
> m1 <- mle2(NLL,start=svec,vecpar=TRUE)
> 
> proc.time()
   user  system elapsed 
  0.988   1.116   1.990 
back to top