[R] Three-component Negative Binomial Mixture: R code

danilo.carita at uniparthenope.it danilo.carita at uniparthenope.it
Tue Nov 8 16:18:50 CET 2016


I tried the function flexmix() with the driver FLXMRnegbin() with two  
components first, in order to compare its results with those provided  
by my function mixnbinom(). In particular, I ran the following code:


> fm0 <- flexmix(y ~ 1, data = data.frame(y), k = 2, model = FLXMRnegbin())


where "y" is my vector of counts. The previous function provided me  
the following parameters:


>                    Comp.1   Comp.2
> coef.(Intercept) 1.2746536 1.788578
> theta            0.1418201 5.028766


with priors 0.342874 and 0.657126, respectively. I assume that the  
coefficients "Intercept" represent the two means of the model (mu1 and  
mu2), while the "theta" coefficients are the size parameters (size1  
and size2).

Unfortunately, unlike my function mixnbinom(), the model computed with  
flexmix() did not provide a good fit to my data (p-value ~0).

Is there something wrong in the process above?



Achim Zeileis <Achim.Zeileis a uibk.ac.at> ha scritto:

> On Mon, 7 Nov 2016, danilo.carita a uniparthenope.it wrote:
>
>> I need a function for R software which computes a mixture of Negative
>> Binomial distributions with at least three components.
>
> The package "countreg" on R-Forge provides a driver FLXMRnegbin()  
> that can be combined with the "flexmix" package (i.e., functions  
> flexmix() and stepFlexmix()). The manual page provides some worked  
> illustrations in example("FLXMRnegbin", package = "countreg").
>
> Note that the driver is mainly designed for negative binomial  
> _regression_ models. But if you just regress on a constant (y ~ 1)  
> you can also get negative binomial mixture distributions without  
> covariates.


-------------------------------------------------------------
Danilo Carità

PhD Candidate
University of Naples "Parthenope"
Dipartimento di Studi Aziendali e Quantitativi
via G. Parisi, 13, 80132 Napoli - Italy



More information about the R-help mailing list