CompoundFit | R Documentation |
Calculates the log-likelihood, the score functions of the log-likelihood, the weighted mean of scores, and fits the parameters of the Compound Distribution based on the GB2.
vofp.cgb2(pl) pofv.cgb2(vl) logl.cgb2(fac, pl, w=rep(1, dim(fac)[1])) scores.cgb2(fac, pl, w=rep(1, dim(fac)[1])) ml.cgb2(fac, pl0, w=rep(1, dim(fac)[1]), maxiter=100, fnscale=length(w))
pl0 |
numeric; vector of initial proportions defining the number of components and the weight of each component density in the decomposition. Sums to one. |
pl |
numeric; vector of fitted proportions. Sums to one. If |
fac |
numeric; matrix of Gamma factors (output of |
vl |
numeric; vector of parameters. Its length is equal to the length of |
w |
numeric; vector of weights of length the number of rows of the matrix |
maxiter |
numeric; maximum number of iterations to perform. By default |
fnscale |
numeric; an overall scaling parameter used in the function |
There are only L-1 parameters to estimate, because the probabilities p_\ell sum to 1 (L is the dimension of the vector of probailities p_\ell). Knowing this, we change the parameters p_\ell to v_\ell=log(p_\ell/p_L), \ \ell= 1, ..., L-1. This calculation is done through the function vofp.cgb2
. pofv.cgb2
calculates the p_\ell in function of the given v_\ell.
We express the log-likelihood as a weighted mean of log(f) = log(∑(p_\ell f_\ell), evaluated at the data points, where f is the GB2 compound density. If the weights are not available, then we suppose that w
= 1. Analogically, the scores are obtained as weighted sums of the first derivatives of the log-likelihood, with respect to the parameters v_\ell, \ \ell=1, ..., L-1, evaluated at the data points. Function ml.cgb2
performs maximum likelihood estimation through the general-purpose optimization function optim
from package stats
. The considered method of optimization is BFGS.
vofp.cgb2
returns a vector of length L-1, where L is the length of the vector p_\ell.
pofv.cgb2
returns a vector of length \ell.
logl.cgb2
returns the value of the pseudo log-likelihood.
scores.cgb2
returns a vector of the weighted mean of the scores of length L-1.
ml.cgb2
returns a list containing two objects - the vector of fitted proportions \hat{p_\ell} and the output of the BFGS fit.
Monique Graf and Desislava Nedyalkova
optim
## Not run: # GB2 parameters: a <- 4 b <- 1950 p <- 0.8 q <- 0.6 # Proportions defining the component densities: pl0 <- rep(1/3,3) # Mixture probabilities pl <- c(0.1,0.8,0.1) # Random generation: n <- 10000 set.seed(12345) x <- rcgb2(n,a,b,p,q,pl0,pl,decomp="l") # Factors in component densities fac <- fg.cgb2(x,a,b,p,q, pl0,decomp="l") # Estimate the mixture probabilities: estim <- ml.cgb2(fac,pl0) # estimated mixture probabilities: estim[[1]] #[1] 0.09724319 0.78415797 0.11859883 ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.