knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

In this vignette you will learn how to use robuni package to compute MI-estimators. MI-estimators are robust estimators for univariate distributions.

We first load the package

library(robuni)

Poisson

We generate a Poisson sample, we compute the MI-estimator and compare it with the maximum likelihood (ML) estimator, that is the mean.

set.seed(1000)
x <- rpois(100,2)
mi_estimate_poisson(x)
mean(x)

MI-estimator is better than ML for this sample. Let us try another seed.

set.seed(1010)
x <- rpois(100,2)
mi_estimate_poisson(x)
mean(x)

MI-estimator is highly efficient in the Poisson case.

We now contaminate the sample with some outliers and recompute both estimators, MI and ML.

x[1:10] <- rep(10,10) 
mi_estimate_poisson(x)
mean(x)

Notice that ML estimator is much more affected by the outliers than MI.

Exponential

We generate an exponential sample, we compute the MI-estimator and compare it with the maximum likelihood (ML) estimator.

set.seed(1000)
x <- rexp(100,2)
mi_estimate_exp(x)
1/mean(x)

We now contaminate the sample with some outliers and recompute both estimators, MI and ML.

x[1:10] <- rep(10,10) 
mi_estimate_exp(x)
1/mean(x)

Notice that ML estimator is much more affected by the outliers than MI.

Geometric

We generate a geometric sample, we compute the MI-estimator and compare it with the maximum likelihood (ML) estimator.

set.seed(1000)
x <- rgeom(100,1/2)
mi_estimate_geom(x)
MASS::fitdistr(x,dens="geometric")
 ```

We now contaminate the sample with some outliers and recompute both estimators, MI and ML.

```r
x[1:10] <- rep(10, 10) 
mi_estimate_geom(x)
MASS::fitdistr(x, dens = "geometric")

Notice that ML estimator is much more affected by the outliers than MI.

Negative binomial

We now compute estimators of both parameters of a negative binomial random sample.

set.seed(1000)
x <- rnbinom(500, mu = 1, size = 2)
mi_estimate_negbin(x)
MASS::fitdistr(x, dens = "negative binomial")

For this sample MI-estimator is better than ML. Notice that the output of mi_estimate_negbin is a vector whose first entry is the estimate of mu and whose second entry is the estimate of 1/size.

x[1:50] <- rep(10, 50) 
mi_estimate_negbin(x)
MASS::fitdistr(x, dens = "negative binomial")

MI-estimator is not as affected by outliers as ML.

LOS example

The LOS data set contains 32 lengths of hospital stay from a Swiss hospital. This data set was introduced and analyzed in @marazzi2010optimal.

mi_estimate_poisson(LOS)
mi_estimate_negbin(LOS)
mean(LOS)
MASS::fitdistr(LOS, dens = "negative binomial")


mvaldora/robuni documentation built on Nov. 4, 2019, 8:32 p.m.