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 |
zeta |
See |
par0 |
Optional starting values for the iterative estimation procedure.
A vector with entries |
maxit |
Integer scalar. The maximum number of iterations to be undertaken
by |
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:
-
"ntop"
The value of thentop
argument. -
"zeta"
The value of thezeta
argument. -
"minSqDiff"
The (minimised) value of the sum of the squared differences between the sample mean and variance (xbar
ands2
) and the theoretical mean and variance. Ideally this minimised value should be zero. -
ndata
The number of non-missing values in the data set for which the likelihood was maximised, i.e.sum(!is.na(x))
.
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")