Re: [R] Singular matrix

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Thu 06 Oct 2005 - 23:41:16 EST


Don't you have the dimension of x backward? Try:

> set.seed(1)
> x <- matrix(rnorm(50, 3, 3), 10, 5)
> vinv <- solve(crossprod(x))
> vinv

             [,1] [,2] [,3] [,4] [,5]

[1,]  0.019918251 -0.006247646  0.006600209  0.003687249 -0.018670806
[2,] -0.006247646  0.018121025 -0.014815905 -0.005647350  0.003434065
[3,]  0.006600209 -0.014815905  0.023411617 -0.002250342 -0.003258960
[4,]  0.003687249 -0.005647350 -0.002250342  0.025168959 -0.020070844
[5,] -0.018670806  0.003434065 -0.003258960 -0.020070844  0.039593016

If you really have 5 cases and 10 variables, the covariance matrix will have to be singular.

Andy

> From: Marc Bernard
>
> Dear All,
>
> I have written the following programs to find a
> non-singular (10*10) covariance matrix.
> Here is the program:
>
> nitems <- 10
>
> x <- array(rnorm(5*nitems,3,3), c(5,nitems))
>
> sigma <- t(x)%*%x
>
> inverse <- try(solve(sigma), TRUE)
>
>
>
> while(inherits(inverse, "try-error"))
>
> {
>
> x <- array(rnorm(5*nitems,3,3), c(5,nitems))
>
> sigma <- t(x)%*%x
>
> inverse <- try(solve(sigma), TRUE)
>
> }
>
>
>
> The loop doesn't stop ... This means that no "non-singular"
> matrix was found!!!
>
> some thing wrong !!
>
>
>
> Thanks a lot for any reply
>
>
>
> Bernard
>
>
>
>
>
>
>
>
>
> ---------------------------------
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Oct 06 23:44:52 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:25:10 EST