[R] Constructing a loop for a Matrix

E.Demir1 at westminster.ac.uk E.Demir1 at westminster.ac.uk
Wed Nov 1 12:47:15 CET 2006


Dear R users,

I have a Coxian Phase type Generator Matrix (Continuous time Markov chain) that
I am trying to estimate the
parameters via a Maximum Likelihood Estimation (MLE). However this markov chain
can be from 2 by 2 to 6 by 6.

Given initial set of parameters (theta), and the size of the matrix say n = 3 (3
* 3 matrix), I want to construct a for loop (or if there is something more
sophisticated) that can return combination of matrices from my initial
parameters.

Here is an example:   #This set of code cannot be compiled in R - It is for
illustrative purposes#

if (n = 3){  # 3 by 3 matrix
theta=c(lambda1, lambda2, mu2, mu3)   # my set of parameters

>From this set of parameters, I would like the following matrices:
M = [-lambda1-mu1, lambda1, 0
     0,    -lambda2,   lambda2
      0,     0,       -mu3]
and
M = [-lambda1, lambda1, 0
     0, -lambda2-mu2, lambda2
      0,     0,       -mu3]
           }

if (n = 4){  #4 by 4 matrix
theta=c(lambda1, lambda2, lambda3, mu2, mu3)
M = [-lambda1-mu1, lambda1, 0, 0
     0,    -lambda2,   lambda2, 0
     0,     0,   -lambda3, lambda3]
     0,     0,    0,     -mu3]

and
M = [-lambda1, lambda1, 0, 0
     0, -lambda2-mu2, lambda2, 0
     0,     0,   -lambda3, lambda3]
     0,     0,    0,     -mu3]

and
M = [-lambda1, lambda1, 0, 0
     0, -lambda2, lambda2, 0
     0,   0,  -lambda3-mu2, lambda3]
     0,     0,    0,     -mu3]

	   }

As the number of parameters increase, the combination of matrices will also
increase.

Is there a way of constructing such a loop, giving initial set of parameters,
that can list SPECIFIC combination of matrices which can be incoorporated in to
MLE.

Thank you all

Eren Demir



More information about the R-help mailing list