Displaying 4 results from an estimated 4 matches for "invx".
Did you mean:
intx
2010 Sep 22
1
Newey West and Singular Matrix
...RUE, nrow=m, ncol=m )
mm[1:nomit,(ncol(mm)-nomit+1):ncol(mm)] <- (lower.tri(
matrix(TRUE, nrow=nomit, ncol=nomit) ))
mm[(ncol(mm)-nomit+1):ncol(mm),1:nomit] <- (upper.tri(
matrix(TRUE, nrow=nomit, ncol=nomit) ))
mm
}
## V(b) = inv(X'X) X' diag(e^2) X inv(X'X)
invx <- qr.solve( crossprod( x.na.omitted, x.na.omitted ) )
if (!ar.terms) resid.matrix <- diag( r.na.omitted^2 ) else {
full <- r.na.omitted %*% t(r.na.omitted)
## the following is not particularly good. see, we could zero out also
## items which are multiplications with a miss...
2010 Sep 23
1
Newey West and Singular Matrix + library(sandwich)
...] <- (lower.tri(
>> matrix(TRUE, nrow=nomit, ncol=nomit) ))
>> ? mm[(ncol(mm)-nomit+1):ncol(mm),1:nomit] <- (upper.tri(
>> matrix(TRUE, nrow=nomit, ncol=nomit) ))
>> ? mm
>> ?}
>>
>> ?## ? ?V(b) = inv(X'X) X' diag(e^2) X inv(X'X)
>> ?invx <- qr.solve( crossprod( x.na.omitted, x.na.omitted ) )
>> ?if (!ar.terms) resid.matrix <- diag( r.na.omitted^2 ) else {
>> ? full <- r.na.omitted %*% t(r.na.omitted)
>>
>> ? ## the following is not particularly good. ?see, we could zero out also
>> ? ## items...
2000 Feb 14
2
Error in the inverse of a diagonal matrix?
...not read the complete set of past messages sent to the list.
I found a weird behabiour that I will explain with a simple example. Lets consider the following block of commands:
> x <- diag(c(1,4,10))
> x
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 4 0
[3,] 0 0 10
> invx <- x^-1
> invx
[,1] [,2] [,3]
[1,] 1 Inf Inf
[2,] Inf 0.25 Inf
[3,] Inf Inf 0.1
I would really appreciate if the result would have been
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 0.25 0
[3,] 0 0 0.1
most of all because
> x %*% invx
[,1] [,2] [,3]
[1,] NaN...
2012 Dec 11
2
Catching errors from solve() with near-singular matrices
...: Some code like this:
if (det(X) < epsilon) {
warning("Near singular matrix")
return(NULL)
}
return(solve(X))
The problem is then to find what epsilon should be.
Strategy 2: Catch the error thrown by solve(X) like this:
f <- function(X) {
invX <- tryCatch(solve(X), error=function(e) {
warning(e)
error.flag <<- TRUE})
if (error.flag) return(NULL)
return(invX)
}
This works OK if called without a surrounding try()
ret <- f(matrix(0, 2, 2)) ## Gi...