Learn R Programming

maxLik (version 1.5-2.1)

condiNumber: Print matrix condition numbers column-by-column

Description

This function prints the condition number of a matrix while adding columns one-by-one. This is useful for testing multicollinearity and other numerical problems. It is a generic function with a default method, and a method for maxLik objects.

Usage

condiNumber(x, ...)
# S3 method for default
condiNumber(x, exact = FALSE, norm = FALSE,
   printLevel=print.level, print.level=1, digits = getOption( "digits" ), ... )
# S3 method for maxLik
condiNumber(x, ...)

Value

Invisible vector of condition numbers by column. If the start values for maxLik are named, the condition numbers are named accordingly.

Arguments

x

numeric matrix, condition numbers of which are to be printed

exact

logical, should condition numbers be exact or approximations (see kappa)

norm

logical, whether the columns should be normalised to have unit norm

printLevel

numeric, positive value will output the numbers during the calculations. Useful for interactive work.

print.level

same as ‘printLevel’, for backward compatibility

digits

minimal number of significant digits to print (only relevant if argument print.level is larger than zero).

...

Further arguments to condiNumber.default are currently ignored; further arguments to condiNumber.maxLik are passed to condiNumber.default.

Author

Ott Toomet

Details

Statistical model often fail because of a high correlation between the explanatory variables in the linear index (multicollinearity) or because the evaluated maximum of a non-linear model is virtually flat. In both cases, the (near) singularity of the related matrices may help to understand the problem.

condiNumber inspects the matrices column-by-column and indicates which variables lead to a jump in the condition number (cause singularity). If the matrix column name does not immediately indicate the problem, one may run an OLS model by estimating this column using all the previous columns as explanatory variables. Those columns that explain almost all the variation in the current one will have very high \(t\)-values.

References

Greene, W. (2012): Econometrics Analysis, 7th edition, p. 130.

See Also

Examples

Run this code
   set.seed(0)
   ## generate a simple nearly multicollinear dataset
   x1 <- runif(100)
   x2 <- runif(100)
   x3 <- x1 + x2 + 0.000001*runif(100) # this is virtually equal to x1 + x2
   x4 <- runif(100)
   y <- x1 + x2 + x3 + x4 + rnorm(100)
   m <- lm(y ~ -1 + x1 + x2 + x3 + x4)
   print(summary(m)) # note the outlandish estimates and standard errors
                     # while R^2 is 0.88. This suggests multicollinearity
   condiNumber(model.matrix(m))   # note the value 'explodes' at x3
   ## we may test the results further:
   print(summary(lm(x3 ~ -1 + x1 + x2)))
   # Note the extremely high t-values and R^2: x3 is (almost) completely
   # explained by x1 and x2

Run the code above in your browser using DataLab