[R] < 0 x 0 matrix >

Markku Karhunen markku.karhunen at helsinki.fi
Sat Sep 5 12:00:26 CEST 2009



> On 04-Sep-09 10:45:27, Markku Karhunen wrote:
>> True. Should have read ?diag.
>>
>> However, this provokes a more general question: Is there some way I
>> can declare some scalar and _all its functions_ as matrices?
>>
>> For instance, I would like to
>>
>> A = as.matrix(0.98)
>> B = function(A)
>> C = diag(sqrt(B))
>>
>> so that all scalars are explicitly [1,1] matrices.
>> BR, Markku
>
> Hmmm, it might be a good idea to explain why you want to do this.
> For instance:
>
>   M <- matrix(c(1,2,3,4),nrow=2)
>   c <- matrix(2,nrow=1)
>   c%*%M
>   # Error in c %*% M : non-conformable arguments
>   c*M
>   # Error in c * M : non-conformable arrays
>   c+M
>   # Error in c + M : non-conformable arrays
>
> So what would you want to use the [1,1]-matrix scalars for, that
> cannot be done just using them as numbers?
>
> Ted.

Broadly speaking, I would like to use the same code for multivariate  
and univariate cases. For instance, I use the inverse Wishart  
densities of MCMCpack. If I take diwish(x) of a scalar x, the  
programme crashes, because diwish() by default checks  
ncol(x)==nrow(x). However, I would like to have an inverse gamma  
density.

Best,
Markku




More information about the R-help mailing list