Question

In: Statistics and Probability

From the R, When I try to the qr.solve(crossprod(X.matrix)), it said "Error in qr.solve(crossprod(X.matrix)) : singular...

From the R,

When I try to the qr.solve(crossprod(X.matrix)), it said "Error in qr.solve(crossprod(X.matrix)) : singular matrix 'a' in solve."

How to solve it this error?

Solutions

Expert Solution

The error may be due to the following reasons:

1- X.matrix is a singular matrix.

Singular Matrix: A square matrix is singular if and only if its determinant is 0.

2- crossprod() function gives us the singular matrix when operated on X.matrix.

To resolve this you have to check that whether X.matrix is singular or not.

You can use solve() command to check whether the matrix is singular or not.

solve() command will show following error if the matrix is singular.

Error in solve.default(X.matrix) :
Lapack routine dgesv: system is exactly singular: U[3,3] = 0

You can also verify it using det() command in R. which will give you the determinant of matrix. If the determinant is 0; It means that matrix is singular.

Try following commands

det(X.matrix)

det(crossprod(X.matrix))

solve(X.matrix)

slove(crossprod(X.matrix))

If the matrix is singular try to make it non-singular. Check for other errors in the program.

Below is the code for qr.solve in R.

function (a, b, tol = 1e-07)
{
if (!inherits(a, "qr"))
a <- qr(a, tol = tol)
nc <- ncol(a$qr)
nr <- nrow(a$qr)
if (a$rank != min(nc, nr))
stop("singular matrix 'a' in solve")

if (missing(b)) {
if (nc != nr)
stop("only square matrices can be inverted")
b <- diag(1, nc)
}
res <- qr.coef(a, b)
res[is.na(res)] <- 0
res
}

See the bold part in the code. It is using Rank method of matrix to check whether a matrix is singular or not. Inverse of a singular matrix does not exist.


Related Solutions

let i be an interval in r, when is f said to be concave on i
let i be an interval in r, when is f said to be concave on i
in R To explore the characteristics of a Type I error rate, write the R code...
in R To explore the characteristics of a Type I error rate, write the R code to do the following: (a) Generate 30 values from X~N(μX =10,σX=4) and 30 values from Y~N(μY =10,σY=4). Do not print any of these values. Use a t-test to test the hypotheses given above. (You are allowed to use the built-in R function to perform the t-test.) (b) Include a comment in your code that identifies the p-value and clearly state the conclusion of the...
What is Type I error? How do we correct for Type I error? What happens when...
What is Type I error? How do we correct for Type I error? What happens when we correct for Type I error? What is Type II error? How do we correct for Type II error? What happens when we correct for Type II error? How can we correct for both Type I and Type II error at the same time? Which error is considered the worst type of error to commit?
BSTree.java:99: error: reached end of file while parsing } I get this error when i run...
BSTree.java:99: error: reached end of file while parsing } I get this error when i run this code. can someone help me out? I can't figure out how to make this work. public class BSTree<T extends Comparable<T>> { private BSTreeNode<T> root = null; // TODO: Write an addElement method that inserts generic Nodes into // the generic tree. You will need to use a Comparable Object public boolean isEmpty(){ return root == null; } public int size(){ return node;} public...
For expert using R I try to solve this question((USING DATA FAITHFUL)) but each time I...
For expert using R I try to solve this question((USING DATA FAITHFUL)) but each time I solve it, I have error , I try it many times. So,everything you write will be helpful.. Modify the EM-algorithm functions to work for a general K component Gaussian mixtures. Please use this function to fit a K= 1;2;3;4 modelto the old faithful data available in R (You need to initialize the EM-algorithm First ).    Which modelseems to t the data better? (Hint:...
This is in Python I am getting an error when I run this program, also I...
This is in Python I am getting an error when I run this program, also I cannot get any output. Please help! #Input Section def main(): name=input("Please enter the customer's name:") age=int(input("Enter age of the customer: ")) number_of_traffic_violations=int(input("Enter the number of traffic violations: ")) if age <=15 and age >= 105: print('Invalid Entry') if number_of_traffic_violations <0: print('Invalid Entry') #Poccessing Section def Insurance(): if age < 25 and number_of_tickets >= 4 and riskCode == 1: insurancePrice = 480 elif age >=...
hello! So I have this CIS assignment lab but when I try to make the code...
hello! So I have this CIS assignment lab but when I try to make the code I don't really know where to start from. My professor is very hard and he likes to see the outcomes as they are shown in the problem. Please help me! Write a program that can be used as a math helper for an elementary student. The program should display two random integer numbers that are to be added, such as:     247 + 129...
When solving for the Ksp of calcium hydroxide, I had a very large percent error. I...
When solving for the Ksp of calcium hydroxide, I had a very large percent error. I was wondering if someone could give me examples of what could cause such a high percent error when titrating Ca(OH)2 with HCl and phenolphthalein indicator. Any help would be appreciated!
I get an error when im trying to run this java program, I would appreciate if...
I get an error when im trying to run this java program, I would appreciate if someone helped me asap, I will make sure to leave a good review. thank you in advance! java class Node public class Node { private char item; private Node next; Object getNext; public Node(){    item = ' '; next = null; } public Node(char newItem) { setItem(newItem); next = null; } public Node(char newItem, Node newNext){ setItem(newItem); setNext(newNext); } public void setItem(char newItem){...
Can anyone explain to me why I am getting an access violation when I try to...
Can anyone explain to me why I am getting an access violation when I try to add notes? It occurs when I try to set the "pLast" pointer to the previous node (for a doubly linked list). The code worked as singly linked list. When I added a "pLast" pointer and the needed code to make it a doubly linked list everything broke. #include <iostream> #include <stdlib.h> using namespace std; //build class that has a private function to inc count....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT