Error In Solve.default
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R inverting matrix with solve returning Error up vote 2 down vote favorite I am studying R programming. I am trying to inverting matrix. Below is what I have tried. x <- matrix(1:16, 4, 4) x # [,1] [,2] [,3] [,4] # [1,] 1 5 9 13 # [2,] 2 6 10 14 # [3,] 3 7 11 15 # [4,] 4 8 12 16 solve(x) # Error in solve.default(x) : # Lapack routine dgesv: system is exactly singular: U[3,3] = 0 solve(x) %*% x # Error in solve.default(x) : # Lapack routine dgesv: system is exactly singular: U[3,3] = 0 x %*% solve(x) # Error in solve.default(x) : # Lapack routine dgesv: system is exactly singular: U[3,3] = 0 I can not understand what 'singular' means. According to this link, it is said that if solve does not have second parameter, it inverts first parameter. I am fully confused, so need some explanation with example would be wonderful. r matrix matrix-inverse share|improve this question edited May 23 '15 at 9:31 user3710546 asked May 23 '15 at 9:23 Juneyoung Oh 1,35972152 Unfortunately for you, you are using a special case with your matrix "x". You would have more luck using a more general case (x <- matrix(rnorm(16),4,4)). –user3710546 May 23 '15 at 9:51 2 Possible duplicate of R solve:system is exactly singular –zx8754 Oct 8 '15 at 9:33 add a comment| 1 Answer 1 active oldest votes up vote 8 down vote accepted If you compute the determinant of the matrix, it is 0: det(x) [1] 0 By definition, your matrix is not invertible. But before trying to invert a squared matrix, the first instinct should be to study analytically if the matrix can be invertible. The singular error you get just reflects the matrix is not invertible. share|improve this answer answered May 23 '15 at 9:43 Colonel Beauvel 20k31241 Thanks. and in additionally, I found solve can invert numeric/logical matrix only. mine was integer matrix :D –Juneyoung Oh May 23 '15 at 10:05 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign u
Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Cross Validated Questions Tags Users Badges Unanswered Ask Question _ Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask http://stackoverflow.com/questions/30411024/r-inverting-matrix-with-solve-returning-error a question Anybody can answer The best answers are voted up and rise to the top Error “system is computationally singular” when running a glm up vote 15 down vote favorite 7 I'm using the robustbase package to run a glm estimation. However when I do it, I get the following error: Error in solve.default(crossprod(X, DiagB * X)/nobs, EEq) : system is computationally singular: reciprocal condition number http://stats.stackexchange.com/questions/76488/error-system-is-computationally-singular-when-running-a-glm = 1.66807e-16 What does this mean/indicate? And how can I debug it? PS. If you need anything (the formula/specification or data) to answer, I'll gladly provide it. r generalized-linear-model robust share|improve this question asked Nov 13 '13 at 18:11 NK1 108116 add a comment| 1 Answer 1 active oldest votes up vote 13 down vote It means your design matrix is not invertible and therefore can't be used to develop a regression model. This results from linearly dependent columns, i.e. strongly correlated variables. Examine the pairwise covariance (or correlation) of your variables to investigate if there are any variables that can potentially be removed. You're looking for covariances (or correlations) >> 0. Alternatively, you can probably automate this variable selection by using a forward stepwise regression. This can also result from having more variables than observations, in which case your design matrix is probably not full rank. This is a bit trickier to fix, but there are ways. I believe lasso regression is supposed to work well when the data is "wider" than it is "long." Keep in mind: if you decide to try lasso or stepwise selection, your doing much more (in terms of variable selection) than just hand
tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site http://scicomp.stackexchange.com/questions/10433/why-lapack-routine-dgesv-doesnt-solve-this About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Computational Science beta Questions Tags Users Badges Unanswered Ask Question _ Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. Join them; it only takes a minute: Sign up Here's how it works: Anybody can error in ask a question Anybody can answer The best answers are voted up and rise to the top why Lapack routine dgesv doesn't solve this? up vote 0 down vote favorite Suppose I have the following 3 by 3 matrix: p<-3 X<-matrix(1/p,p,p) --$\pmb X$ is just a $p$ by $p$ matrix where every entry is $1/p$. Now I want to solve the system $$\pmb a\pmb X=\pmb error in solve.default 1_p$$ where $\pmb 1_p$ is a vector of 1 of length $p$. I know $\pmb 1_p$ is the solution to such a system, but when I do, in R, solve(X,rep(1,p)) I get Error in solve.default(X, rep(1, p)) : Lapack routine dgesv: system is exactly singular: U[2,2] = 0 instead of $\pmb 1_p$. My question is why r lu share|improve this question asked Dec 29 '13 at 15:58 user189035 26229 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted Your matrix does not have an inverse, which is why dgesv returns an error. share|improve this answer answered Dec 29 '13 at 17:20 Geoff Oxberry♦ 23k834103 thanks, but are you implying that dgesv computes $\pmb X^{-1}$? –user189035 Dec 29 '13 at 18:15 3 At the level of abstraction I wish to discuss this problem, yes. We could get into more technical details, but for what you're asking, they seem irrelevant. solve in R is computing something like an inverse, and the algorithm will progress to a point where it has to divide by zero, which is usually ill-defined, so the program throws an error. &ndas