# R/MLfullGB2.R In GB2: Generalized Beta Distribution of the Second Kind: Properties, Likelihood, Estimation

```# Maximum likelihood based on the full log-likelihood (personal level)
ml.gb2 <- function (z, w=rep(1, length(z)), method = 1, hess = FALSE){
fn <- function(x, z, w) {
a <- x
b <- x
p <- x
q <- x
return(-loglp.gb2(z, a, b, p, q, w))
}
gr <- function(x, z, w) {
a <- x
b <- x
p <- x
q <- x
return(-scoresp.gb2(z, a, b, p, q, w))
}

x0 <- fisk(z, w)

opt1 <- optim(x0, fn, gr, z, w, method = "BFGS", control = list(parscale = x0,
pgtol = 1e-08), hessian = hess)
if (method != 2)
return(list(opt1 = opt1))
if (method == 2) {
opt2 <- optim(x0, fn, gr, z, w, method = "L-BFGS-B",
lower = 0, control = list(parscale = x0, pgtol = 1e-08),
hessian = hess)
return(list(opt2 = opt2))
}
}

# Maximum likelihood based on the full log-likelihood (household level)
mlh.gb2 <- function (z, w=rep(1, length(z)), hs=rep(1, length(z)), method = 1, hess = FALSE)
{
fn <- function(x, z, w, hs) {
a <- x
b <- x
p <- x
q <- x
return(-loglh.gb2(z, a, b, p, q, w, hs))
}
gr <- function(x, z, w, hs) {
a <- x
b <- x
p <- x
q <- x
return(-scoresh.gb2(z, a, b, p, q, w, hs))
}

x0 <- fiskh(z, w, hs)

opt1 <- optim(x0, fn, gr, z, w, hs, method = "BFGS", control = list(parscale = x0,
pgtol = 1e-08), hessian = hess)
if (method != 2)
return(list(opt1 = opt1))
if (method == 2) {
opt2 <- optim(x0, fn, gr, z, w, hs, method = "L-BFGS-B",
lower = 0, control = list(parscale = x0, pgtol = 1e-08),
hessian = hess)
return(list(opt2 = opt2))
}
}
```

## Try the GB2 package in your browser

Any scripts or data that you put into this service are public.

GB2 documentation built on May 2, 2019, 5:53 a.m.