[R] expm() within the Matrix package
Martin Maechler
maechler at stat.math.ethz.ch
Mon Mar 19 08:37:06 CET 2007
>>>>> "Gad" == Gad Abraham <g.abraham at ms.unimelb.edu.au>
>>>>> on Mon, 19 Mar 2007 09:36:15 +1100 writes:
Gad> If you convert to numeric, you can then assign it to Loglik:
>> >> Loglik[1] <- as.numeric(log(p %*% expm(Q * y[i]) %*% q))
>> >> Loglik[1]
Gad> [1] 134.5565
>>
>>
>> Hmm, I don't think that's Laura's problem
>> (and actually I don't know what her problem is) :
>>
>> Assignment of a 1 x 1 matrix to a vector is not a problem,
>> and hence the as.numeric(.) above really has no effect :
>>
>>> ll <- 1:2
>>> (m <- matrix(pi, 1,1))
>> [,1]
>> [1,] 3.141593
>>> ll[1] <- m
>>> ll
>> [1] 3.141593 2.000000
Gad> Ah but you're using 'matrix' while she's using 'Matrix'
Gad> (AFAIK there is no expm for matrix):
Yes, of course, you are absolutely right
(and I'm pretty embarrassed).
Martin
>> library(Matrix)
Gad> Loading required package: lattice
>> m <- Matrix(1, nrow=1, ncol=1)
>> m
Gad> 1 x 1 diagonal matrix of class "ddiMatrix"
Gad> [,1]
Gad> [1,] 1
Gad> Warning message:
Gad> Ambiguous method selection for "diag", target "ddiMatrix" (the first of
Gad> the signatures shown will be used)
Gad> diagonalMatrix
Gad> ddenseMatrix
Gad> in: .findInheritedMethods(classes, fdef, mtable)
>> a <- vector("numeric", 0)
>> a[1] <- m
Gad> Error in a[1] <- m : incompatible types (from S4 to double) in
Gad> subassignment type fix
>> a[1] <- as.numeric(m)
>> a
Gad> [1] 1
[.........]
More information about the R-help
mailing list