From murdoch@dunc@n @ending from gm@il@com  Mon Sep 17 18:22:13 2018
From: murdoch@dunc@n @ending from gm@il@com (Duncan Murdoch)
Date: Mon, 17 Sep 2018 12:22:13 -0400
Subject: [Rd] diag(-1) produces weird result
In-Reply-To: <C9E6B4F9-DA68-457F-A99A-1D371E4BDE93@revelle.net>
References: <C9E6B4F9-DA68-457F-A99A-1D371E4BDE93@revelle.net>
Message-ID: <c78c0e66-ce2a-f036-690f-a9145be1c68b@gmail.com>

On 17/09/2018 12:14 PM, William Revelle wrote:
> Dear list
> 
> A strange bug in the psych package is due to the behavior of the diag function:
> 
> It gives the expected values for 1, a vector (-1,1), but not for -1
> 
> Is this a known feature?

It is pretty clearly documented:

"diag has four distinct usages:

...

3.  x is a scalar (length-one vector) and the only argument, it returns 
a square identity matrix of size given by the scalar."

Duncan Murdoch

> 
> 
>> diag(1)
>       [,1]
> [1,]    1
>> diag(c(-1,1))
>       [,1] [,2]
> [1,]   -1    0
> [2,]    0    1
>> diag(-1)
> Error in diag(-1) : invalid 'nrow' value (< 0)
> 
> 
> Bill
> 
> 
> William Revelle		   personality-project.org/revelle.html
> Professor			          personality-project.org
> Department of Psychology www.wcas.northwestern.edu/psych/
> Northwestern University	   www.northwestern.edu/
> Use R for psychology         personality-project.org/r
> It is 2   minutes to midnight   www.thebulletin.org
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] diag(-1) produces weird result
Duncan Murdoch