lundi 16 février 2015

random numbers in R

HHello


there is a matrix with 26 columns I have. The values in each row sum up to 1 it looks like



[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 0.02105263 0.01052632 0.01052632 0.04210526 0.01052632 0.06315789 0.03157895 0.1789474 0.07368421 0.07368421 0.02105263
[2,] 0.00000000 0.01176471 0.01176471 0.00000000 0.01176471 0.18823529 0.09411765 0.1764706 0.15294118 0.07058824 0.01176471
[3,] 0.00000000 0.00000000 0.02941176 0.01470588 0.04411765 0.11764706 0.05882353 0.2058824 0.07352941 0.08823529 0.00000000
[,12] [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22]
[1,] 0.04210526 0.04210526 0.05263158 0 0.03157895 0.02105263 0.00000000 0.04210526 0.01052632 0.05263158 0.02105263
[2,] 0.00000000 0.01176471 0.00000000 0 0.03529412 0.01176471 0.04705882 0.04705882 0.02352941 0.01176471 0.00000000
[3,] 0.02941176 0.02941176 0.02941176 0 0.05882353 0.01470588 0.02941176 0.02941176 0.02941176 0.01470588 0.00000000
[,23] [,24] [,25] [,26]
[1,] 0.06315789 0.03157895 0.03157895 0.02105263
[2,] 0.05882353 0.02352941 0.00000000 0.00000000
[3,] 0.02941176 0.01470588 0.00000000 0.05882353


now I would like to alterate the values to make up some new data. This would mean changing every value in a row randomly to a value in the range of - or plus 5 percent adn then still adding up to 1 with the rowsum. So in the column2 the 6 th value is currently 0 .18 and it should be (in the new data ) somewhere between 0.171 and 0.189 ( and and plus 5%). Alternatively, the value in the column should just be drawn from a normal distribution but should not differ too much from the original value. For large values like 0.18 maybe more als for values which are smaller. If the value is 0 it would be good to randimly decide whether it shoudl stay at 0 or increase by a range between 5% or 10% (taking as inital value something like 0.0001).is there an easy way tro do that?


Aucun commentaire:

Enregistrer un commentaire