obs2remove {FENmlm} | R Documentation |
Finds observations to be removed from ML estimation with factors/clusters
Description
For Poisson, Negative Binomial or Logit estimations with fixed-effects, when the dependent variable is only equal to 0 (or 1 for Logit) for one cluster value this leads to a perfect fit for that cluster value by setting its associated cluster coefficient to -Inf
. Thus these observations need to be removed before estimation. This function gives the observations to be removed. Not that by default the function femlm
drops them before performing the estimation.
Usage
obs2remove(fml, data, family = c("poisson", "negbin", "logit"))
Arguments
fml |
A formula contaning the dependent variable and the clusters. It can be of the type: |
data |
A data.frame containing the variables in the formula. |
family |
Character scalar: either “poisson” (default), “negbin” or “logit”. |
Value
It returns an integer vector of observations to be removed. If no observations are to be removed, an empty integer vector is returned. In both cases, it is of class femlm.obs2remove
.
The vector has an attribut cluster
which is a list giving the IDs of the clusters that have been removed, for each cluster dimension.
Examples
base = iris
# v6: Petal.Length with only 0 values for 'setosa'
base$v6 = base$Petal.Length
base$v6[base$Species == "setosa"] = 0
(x = obs2remove(v6 ~ Species, base))
attr(x, "cluster")
# The two results are identical:
res_1 = femlm(v6 ~ Petal.Width | Species, base)
# => warning + obsRemoved is created
res_2 = femlm(v6 ~ Petal.Width | Species, base[-x, ])
# => no warning because observations are removed before
res2table(res_1, res_2)
all(res_1$obsRemoved == x)