[R] Singular matrix

Liaw, Andy andy_liaw at merck.com
Thu Oct 6 15:41:16 CEST 2005


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 at 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
> 
>




More information about the R-help mailing list