n <- 1000
set.seed(1234)
##1. Gamma
theta <- c(2, 3)
o.sample <- rgamma(n, shape=theta[1], rate=theta[2])
#Default method
onestep(o.sample, "gamma")
#User initial sequence of guess estimator
# See : Ye and Chen (2017)
qtmp <- sum(o.sample*log(o.sample))-sum(log(o.sample))*mean(o.sample)
alphastar <- sum(o.sample)/qtmp
betastar <- qtmp/length(o.sample)
thetastar <- list(shape=alphastar,rate=1/betastar)
onestep(o.sample, "gamma", init=thetastar)
#Numerical method (for comparison)
onestep(o.sample, "gamma", method="numeric")
##2.Beta
theta <- c(0.5, 1.5)
o.sample <- rbeta(n, shape1=theta[1], shape2=theta[2])
onestep(o.sample, "beta")
##3. Cauchy
theta <- c(2, 3)
o.sample <- rcauchy(n, location=theta[1], scale=theta[2])
onestep(o.sample, "cauchy")
#User initial sequence of guess estimator
#See Koutrouvelis (1982).
t <- 1/4
Phi <- mean(exp(1i*t*o.sample))
S <- Re(Phi)
Z <- Im(Phi)
thetastar <- list(location=atan(Z/S)/t,scale=-log(sqrt(S^2+Z^2))/t)
onestep(o.sample, "cauchy", init=thetastar)
##Chi2
theta <- 5
o.sample <- rchisq(n,df=theta)
onestep(o.sample,"chisq")
#User initial sequence of guess estimator
#See Grenander (1965).
p <- n^(2/7)
k <- floor(n^(3/5))
Dstar <- sort(o.sample)
Dk1 <- Dstar[(1+k):n]
Dk2 <- Dstar[1:(n-k)]
sigma.star <- 1/2*sum((Dk1+Dk2)*(Dk1-Dk2)^(-p))/sum((Dk1-Dk2)^(-p))+2
onestep(o.sample,"chisq",init=list(df=sigma.star))
#Negative Binomial
theta <- c(1, 5)
o.sample <- rnbinom(n, size=theta[1], mu=theta[2])
onestep(o.sample, "nbinom")
#Generic (dweibull2)
theta <- c(0.8, 3)
dweibull2 <- function(x, shape, scale, log=FALSE)
dweibull(x = x, shape = shape, scale = scale, log = log)
o.sample <- rweibull(n, shape = theta[1], scale = 1/theta[2])
onestep(o.sample, "weibull2", method="numeric",
init=list(shape=1, scale=1))
Run the code above in your browser using DataLab