Model fitting

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  dpi = 300
)
library(melt, warn.conflicts = FALSE)

Fitting an EL object

The melt package provides several functions to construct an EL object or an object that inherits from EL:

We illustrate the usage of el_mean() with the faithful data set.

data("faithful")
str(faithful)
summary(faithful)

Suppose we are interested in evaluating empirical likelihood at (3.5, 70).

fit <- el_mean(faithful, par = c(3.5, 70))
class(fit)
showClass("EL")

The faithful data frame is coerced to a numeric matrix. Simple print method shows essential information on fit.

fit

Note that the maximum empirical likelihood estimates are the same as the sample average. The chi-square value shown corresponds to the minus twice the empirical log-likelihood ratio. It has an asymptotic chi-square distribution of 2 degrees of freedom under the null hypothesis. Hence the $p$-value here is not exact. The convergence status at the bottom can be used to check the convex hull constraint.

Weighted data can be handled by supplying the weights argument. For non-NULL weights, weighted empirical likelihood is computed. Any valid weights is re-scaled for internal computation to add up to the total number of observations. For simplicity, we use faithful$waiting as our weight vector.

w <- faithful$waiting
(wfit <- el_mean(faithful, par = c(3.5, 70), weights = w))

We get different results, where the estimates are now the weighted sample average. The chi-square value and the associated $p$-value are based on the same limit theorem, but care must be taken when interpreting the results since they are largely affected by the limiting behavior of the weights.



Try the melt package in your browser

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

melt documentation built on May 31, 2023, 7:12 p.m.