https://github.com/cran/bbmle
Tip revision: 8ad8abe703f98bb6432668bf54ce2b6a3bf8708a authored by Ben Bolker on 09 December 2023, 01:00:02 UTC
version 1.0.25.1
version 1.0.25.1
Tip revision: 8ad8abe
startvals.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)
>
> ## copied from emdbook
> dbetabinom <- function (x, prob, size, theta, shape1, shape2, log = FALSE)
+ {
+ if (missing(prob) && !missing(shape1) && !missing(shape2)) {
+ prob = shape1/(shape1 + shape2)
+ theta = shape1 + shape2
+ }
+ v <- lchoose(size, x) - lbeta(theta * (1 - prob), theta *
+ prob) + lbeta(size - x + theta * (1 - prob), x + theta *
+ prob)
+ if (log)
+ v
+ else exp(v)
+ }
>
> ss <- data.frame(taken=c(0,1,2,5),available=c(5,5,5,5),
+ dist=rep(1,4))
>
> SP.bb=mle2(taken~dbetabinom(prob,theta,size=available),
+ start=list(prob=0.5,theta=1),data=ss)
Warning messages:
1: In lbeta(theta * (1 - prob), theta * prob) : NaNs produced
2: In lbeta(size - x + theta * (1 - prob), x + theta * prob) :
NaNs produced
> SP.bb.dist=mle2(taken~dbetabinom(prob,size=available,theta),
+ parameters=list(prob~dist-1,theta~dist-1),
+ start=as.list(coef(SP.bb)),data=ss)
>
> SP.bb.dist2=mle2(taken~dbetabinom(prob,size=available,theta),
+ parameters=list(prob~dist - 1,theta~dist - 1),
+ start=as.list(coef(SP.bb)),data=ss)
>
>
> proc.time()
user system elapsed
0.808 1.072 1.743