Computationally singular matrix inverse error? [closed] - r

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
This error comes up when I am dividing by the matrix inverse.
Error in solve.default(x) :
system is computationally singular: reciprocal condition number = 6.85861e-18 ```
What are the ways to solve this? I am using the matrix.inverse function to find the inverse.

Given a matrix M, I guess it would be safe to use ginv from package MASS to compute the inverse if you want to avoid the error in your post, e.g.,
MASS::ginv(M)

Related

Standard Deviation in R [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am trying to calculate the standard deviation from scratch in R (I do know R has a build-in function for that), but I'm not getting the correct results, so I don't know what I'm doing wrong.
My.SD<-function(X) {
M<-(sum(X)/length(X))
my.var<-sum((X-M)^2)
StanDev<-sqrt(my.var/length(X))
print(StanDev)
}
I guess you might need to use (length(X)-1) rather than length(x), i.e.,
My.SD<-function(X) {
M<-(sum(X)/length(X))
my.var<-sum((X-M)^2)
StanDev<-sqrt(my.var/(length(X)-1))
print(StanDev)
}
since here it should be sample standard deviation.

The R chol2inv() method gives me strange results [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
So I'm trying to invert a big (449x449) covariance matrix, which is thus symmetric and positive definite.
(What I'm trying to do is to invert this matrix as part of a Gaussian Process fitting for the Mauna Loa CO2 dataset.)
This inversion is pretty long, so I wanted to use chol2inv instead of solve.
But the chol2inv method gives me a very strange result : a matrix very close to 0 (sum of it is equal to 10^(-13)).
Why would chol2inv give me this?
Sounds like you have wrongly used chol2inv. It takes the upper triangular Cholesky factor rather than the covariance matrix as input. So if A is your covariance matrix, you want
chol2inv(chol(A))
not
chol2inv(A)
Just found out that this issue was answered twice long long ago.
Comparing matrix inversions in R - what is wrong with the Cholesky method? (in 2014)
matrix inversion R (in 2013)

Error in sort.list(y): 'x' must be atomic for sort list [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am trying to use c50 here what I did
train$default<-as.factor(train$default)
result<-C5.0(train[-17],train$default)
finalresult <- predict(result, test)
I am trying to run the following command table(test, Predicted=finalresult)in the R soft
but it is giving the following error
Error in sort.list(y): 'x' must be atomic for sort list
any suggestions?
You did not state how test looks. Since it is used for a prediction it presumably contains features and the value you want to predict. Assuming test$answer is what you want to predict. Try
table(test$answer, Predicted=finalresult)

Residuals against fitted values show pattern [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am going to fit a model using linear and quadratic model.
If the graphs of residuals against fitted values show pattern(not random pattern),what is the cause and how can i fix it?
This should be a comment, but I have insufficient rep for that.
The cause of the pattern is that your model doesn't account for something.
The fix is to find what that is, and include it in your model.

How to get the second smallest eigenvalue of the laplacian with R? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to use R to capture the second smallest eigenvalue of the Laplacian of a graph, but I just know how to do it in Matlab. I have searched in the web about it, but I just always find how to use the R-function "eigen"
Does somebody can tell me how to write such a code line, please?
In Matlab, for example, the line that I use to code is:
[~, D] = eigs(lap, 2, 'sa'); %getting the first two eigenvalues of laplacian (lap). 'sa' means Smallest Algebraic
lambda2 = D(2, 2); %getting the second smallest eigenvalue
Thanks in advance for your helpful comments.
A = cbind(c(1,-1,0), c(-1,1,1), c(0.5,0.5,0.5))
ei = eigen(A)
ei$values[length(ei$value)-1]
gives second smallest eigenvalue of matrix A

Resources