[R] Copying matrices with certain probabilities

William Aue william.aue at gmail.com
Sun Oct 4 15:36:55 CEST 2009


Hi all! Below is the problem I am struggling with.

Let’s say I have a matrix (x) of values:

#     [,1] [,2] [,3] [,4]
#[1,]    1    3    2    1
#[2,]    2    1    3    2

I need to copy the items into a new matrix (y) with certain
probability guidelines. I need to set it up such that:

1. for each item there is a probability (a) that the item will or will
not be copied at all from x to y. If nothing is copied then the
corresponding value in y should be 0.

2. If something is copied from x to y, then there should be a separate
probability (b) that the items will be correctly copied to y with
items that are incorrectly copied being randomly drawn from a
geometric distribution.

So y may look like the below example. Row 1 shows that [1,2] was
copied and subsequently correctly copied but nothing else in [1,] was
copied. In [2,], [2,1] was copied but subsequently incorrectly copied,
[2,2] & [2,3] were not copied at all, and [2,4] was copied and
correctly copied.

#     [,1] [,2] [,3] [,4]
#[1,]    0    3    0    0
#[2,]    5    0    0    2

I would also like to setup a loop for this process wherein if
something doesn’t get copied at all during a previous pass, then there
is the opportunity for it to be copied on a second/third/etc pass.

I hope this is clear enough. I am still a novice at R, so any
help/guidance that can be offered will be greatly appreciated.

Best,

Billy Aue




More information about the R-help mailing list