I'm wanting to create a series of near-identical matrices via the addition of "white noise" to my starting matrix. Is there a function within R which will allow me to do this? Thank you Laura Quinn Institute of Atmospheric Science School of Earth and Environment University of Leeds Leeds LS2 9JT tel: +44 113 343 1596 fax: +44 113 343 6716 mail: laura at env.leeds.ac.uk
Is this what you want by adding a random number to the values?> x <- matrix(1:9, ncol=3) > x[,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9> x + runif(9, -.1, .1)[,1] [,2] [,3] [1,] 0.9577315 3.927673 6.953332 [2,] 2.0530684 5.072495 8.076258 [3,] 2.9885848 5.987975 8.936416>On 1/22/06, Laura Quinn <laura@env.leeds.ac.uk> wrote:> > I'm wanting to create a series of near-identical matrices via the addition > of "white noise" to my starting matrix. Is there a function within R which > will allow me to do this? > > Thank you > > Laura Quinn > Institute of Atmospheric Science > School of Earth and Environment > University of Leeds > Leeds > LS2 9JT > > tel: +44 113 343 1596 > fax: +44 113 343 6716 > mail: laura@env.leeds.ac.uk > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Jim Holtman Cincinnati, OH +1 513 247 0281 What the problem you are trying to solve? [[alternative HTML version deleted]]
On 22-Jan-06 Laura Quinn wrote:> I'm wanting to create a series of near-identical matrices > via the addition of "white noise" to my starting matrix. > Is there a function within R which will allow me to do this? > > Thank you > > Laura QuinnThe short ansdwer is: Yes, just do it as you descibe! For example: M<-matrix(c(2,4,6,1,3,5),nr=2) M # [,1] [,2] [,3] # [1,] 2 6 3 # [2,] 4 1 5 M + 0.01*runif(6) # [,1] [,2] [,3] # [1,] 2.009196 6.000863 3.009307 # [2,] 4.000973 1.008916 5.006934 You have certainly added "white noise" since, considered as a sequence, the elements of runif(6) are independent. It gets more interesting, however, if you want the result to be more constrained then you have stated in your query. Ensuring that the expected result is equal to the starting matrix, or that the added noise has a specified distribution (e.g. gaussian) is easy: just change the "0.01*runif()". But if you want to ensure that (e.g.) the elements of the result are positive, or that the result (if square) is positive definite, or is symmetric, or is a correlation matrix, then some further thought would have to be given to just how best to proceed. The resulting "tuned" procedure would then be better wrapped in a function. If you would, perhaps, state more fully what you want to achieve it may be possible to suggest something. I'm not, myself, aware of a function in R which is designed to do this job under the sort of constraints above, or others (and, if unconstrained, you hardly need a special function for it). Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 22-Jan-06 Time: 16:54:15 ------------------------------ XFMail ------------------------------
At 1:38 PM +0000 1/22/06, Laura Quinn wrote:>I'm wanting to create a series of near-identical matrices via the addition >of "white noise" to my starting matrix. Is there a function within R which >will allow me to do this? > >Thank youIf the starting matrix is symmetric, see mvrnorm in the MASS package. -- William Revelle http://pmc.psych.northwestern.edu/revelle.html Professor http://personality-project.org/personality.html Department of Psychology http://www.wcas.northwestern.edu/psych/ Northwestern University http://www.northwestern.edu/
Reasonably Related Threads
- diag(-1) produces weird result
- Simulating dataset using Parallel Latent CTT model?
- CRAN submit page down
- Psych package: fa.diagram, how to re-arrange layout so numbers do not over-write each other
- Plotting confidence intervals of two response on same graph (panel).