exactMeDb {dbd}R Documentation

Exact moment estimates for the db distribution.

Description

Attempts to calculate “exact” moment estimates of the parameters of a db distribution. This is done by minimising the sum of squared differences between the sample mean and variance (xbar and s2) and the theoretical mean and variance. Calls upon optim() with the "BFGS" method.

Usage

exactMeDb(x, ntop, zeta=FALSE, par0 = NULL, maxit = 1000)

Arguments

x

A random sample from the db distribution whose parameters are being estimated. Missing values are allowed.

ntop

The ntop parameter of the db distribution whose parameters are being estimated. I.e. it is the maximum possible value of the distribution, whose values are integers between 1 and ntop, or between 0 and ntop if zeta (see below) is TRUE.

zeta

See ddb().

par0

Optional starting values for the iterative estimation procedure. A vector with entries alpha and beta. Ideally this vector should be named; if not it is assumed that the entries are in the order alpha, beta. If not supplied starting values are calculated using the undocumented function meDb().

maxit

Integer scalar. The maximum number of iterations to be undertaken by optim(). What happens if this number is exceeded depends on the value of options()[["maxitErrorOrWarning"]]. This may be "error" (in which case an error is thrown if maxit is exceeded) or "warning" (in which case a warning is issued). The values is set equal to "error" at startup. It may be switched, from on possibility to the other, by means of the function set.eow().

Details

This function is really an “intellectual curiosity”. The results produced may be compared with those produced via maximum likelihood (using mleDb()) which in theory should be “better”. Since numerical optimisation has to be applied to calculate the “exact” moment estimates, there is no real saving in terms of computation cost.

Value

An object of class "exactMeDb". Such an object consists of a named vector with entries "alpha" and "beta", which are the “exact” moment estimates of the corresponding parameters. It has a number of attributes:

Author(s)

Rolf Turner r.turner@auckland.ac.nz

See Also

ddb meDb() mleDb() expValDb() varDb() optim()

Examples

set.seed(42)
x <- rdb(500,3,5,2)
eMom <- exactMeDb(x,ntop=2,zeta=FALSE)
eMle <- mleDb(x,ntop=2)

# Get much better results using true parameter values
# as starting values; pity we can't do this in real life!
eMom <- exactMeDb(x,ntop=2,zeta=FALSE,par0=c(alpha=3,beta=5))
eMle <- mleDb(x,2,par0=c(alpha=3,beta=5))

# Larger ntop value
x <- rdb(500,3,5,20)
eMom <- exactMeDb(x,ntop=20,zeta=FALSE)
eMle <- mleDb(x,ntop=20)

# Binomial, n = 10, p = 0.3.
set.seed(42)
x    <- rbinom(1000,10,0.3)
eMom <- exactMeDb(x,ntop=10,zeta=TRUE)
eMle <- mleDb(x,ntop=10,zeta=TRUE)
p1   <- dbinom(0:10,10,0.3)
p2   <- dbinom(0:10,10,mean(x)/10)
p3   <- table(factor(x,levels=0:10))/1000
p4   <- ddb(0:10,alpha=eMom["alpha"],beta=eMom["beta"],ntop=10,zeta=TRUE)
plot(eMle,obsd=x,legPos=NULL,ylim=c(0,max(p1,p2,p3,p4)))
lines(0.2+(0:10),p1,col="orange",type="h",ylim=c(0,max(p1,p2)))
lines(0.3+(0:10),p2,col="green",type="h")
legend("topright",lty=1,col=c("red","blue","orange","green","black"),
       legend=c("dbMle","observed","true binomial","fitted binomial","dbMom"),bty="n")

[Package dbd version 0.0-22 Index]