Skip to contents

In some occasions, the optimization algorithm of femlm may fail to converge, or the variance-covariance matrix may not be available. The most common reason of why this happens is collinearity among variables. This function helps to find out which set of variables is problematic.

Usage

collinearity(x, verbose)

Arguments

x

A fixest object obtained from, e.g. functions femlm, feols or feglm.

verbose

An integer. If higher than or equal to 1, then a note is prompted at each step of the algorithm. By default verbose = 0 for small problems and to 1 for large problems.

Value

It returns a text message with the identified diagnostics.

Details

This function tests: 1) collinearity with the fixed-effect variables, 2) perfect multi-collinearity between the variables, 3) perfect multi-collinearity between several variables and the fixed-effects, and 4) identification issues when there are non-linear in parameters parts.

Author

Laurent Berge

Examples


# Creating an example data base:
set.seed(1)
fe_1 = sample(3, 100, TRUE)
fe_2 = sample(20, 100, TRUE)
x = rnorm(100, fe_1)**2
y = rnorm(100, fe_2)**2
z = rnorm(100, 3)**2
dep = rpois(100, x*y*z)
base = data.frame(fe_1, fe_2, x, y, z, dep)

# creating collinearity problems:
base$v1 = base$v2 = base$v3 = base$v4 = 0
base$v1[base$fe_1 == 1] = 1
base$v2[base$fe_1 == 2] = 1
base$v3[base$fe_1 == 3] = 1
base$v4[base$fe_2 == 1] = 1

# Estimations:

# Collinearity with the fixed-effects:
res_1 = femlm(dep ~ log(x) + v1 + v2 + v4 | fe_1 + fe_2, base)
#> Warning: [femlm]: The optimization algorithm did not converge, the results are not reliable. The information matrix is singular: presence of collinearity.
collinearity(res_1)
#> Error: in message_magic(..., .sep = .sep, .end = .end, .wid...: 
#> In `string_magic`, the operator `width` must take a numeric argument.
#> PROBLEM: `min(100, .sw)` is not numeric.

# => collinearity with the first fixed-effect identified, we drop v1 and v2
res_1bis = femlm(dep ~ log(x) + v4 | fe_1 + fe_2, base)
#> Warning: [femlm]: The information matrix is singular: presence of collinearity.
collinearity(res_1bis)
#> Error: in message_magic(..., .sep = .sep, .end = .end, .wid...: 
#> In `string_magic`, the operator `width` must take a numeric argument.
#> PROBLEM: `min(100, .sw)` is not numeric.

# Multi-Collinearity:
res_2 =  femlm(dep ~ log(x) + v1 + v2 + v3 + v4, base)
#> Warning: [femlm]: The optimization algorithm did not converge, the results are not reliable. The information matrix is singular: presence of collinearity.
collinearity(res_2)
#> Error: in message_magic(..., .sep = .sep, .end = .end, .wid...: 
#> In `string_magic`, the operator `width` must take a numeric argument.
#> PROBLEM: `min(100, .sw)` is not numeric.