[R] expm() within the Matrix package
Gad Abraham
g.abraham at ms.unimelb.edu.au
Sun Mar 18 23:36:15 CET 2007
> 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
Ah but you're using 'matrix' while she's using 'Matrix' (AFAIK there is
no expm for matrix):
> library(Matrix)
Loading required package: lattice
> m <- Matrix(1, nrow=1, ncol=1)
> m
1 x 1 diagonal matrix of class "ddiMatrix"
[,1]
[1,] 1
Warning message:
Ambiguous method selection for "diag", target "ddiMatrix" (the first of
the signatures shown will be used)
diagonalMatrix
ddenseMatrix
in: .findInheritedMethods(classes, fdef, mtable)
> a <- vector("numeric", 0)
> a[1] <- m
Error in a[1] <- m : incompatible types (from S4 to double) in
subassignment type fix
> a[1] <- as.numeric(m)
> a
[1] 1
> sessionInfo()
R version 2.4.1 (2006-12-18)
i486-pc-linux-gnu
locale:
LC_CTYPE=en_AU.UTF-8;LC_NUMERIC=C;LC_TIME=en_AU.UTF-8;LC_COLLATE=en_AU.UTF-8;LC_MONETARY=en_AU.UTF-8;LC_MESSAGES=en_AU.UTF-8;LC_PAPER=en_AU.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_AU.UTF-8;LC_IDENTIFICATION=C
attached base packages:
[1] "stats" "graphics" "grDevices" "utils" "datasets" "methods"
[7] "base"
other attached packages:
Matrix lattice
"0.9975-11" "0.14-16"
--
Gad Abraham
Department of Mathematics and Statistics
The University of Melbourne
Parkville 3010, Victoria, Australia
email: g.abraham at ms.unimelb.edu.au
web: http://www.ms.unimelb.edu.au/~gabraham
More information about the R-help
mailing list