[Rd] Generate Simulation

Joris Meys jorismeys at gmail.com
Tue Nov 22 16:31:58 CET 2011


Not to be rude, but I'd suggest you first read the posting guide for
the mailing lists again. The r-devel list is not meant to be used as a
help forum.

https://stat.ethz.ch/mailman/listinfo/r-devel

This said, look at ?replicate.

Cheers
Joris

On Tue, Nov 22, 2011 at 4:08 PM, savina partheni <s2partheni at gmail.com> wrote:
> Hallo everybody,
>
> I'm new in r and I"ll appreciate some help!
>
> I have a matrix of nrow=30 and ncoll=54,and I would like to generate 50
> simulations with tha same size of the matrix!!!That is to say that I want
> to generate 50 matrices -for my 50 simulations - with the same dimensions!
> I took my 1st matrix according to the formula that I want to implement:
> D<-mean_m + U_i*mat_DELTA
> mean_m:vector
> U_I:vector
> mat_Delta:matrix(54,30)
>
> Here is the loop:
> #Define Simulations(IS)
>  #Define Time Step(IT)
>
> vec_IS<-c(1:50)
> vec_IT<-c(1:30)
> mat_delta<-matrix(nrow=54, ncol=30)
> mat_DELTA<-matrix(nrow=54, ncol=30)
> mat_Yr_m<-matrix(nrow=54, ncol=30)
> D<-matrix(nrow=30, ncol=54)
> DELTA<-(matrix(nrow=30,ncol=54))*50
>
> for (i in 1:length(vec_IS)){
>        for (j in 1:length(vec_IT)){
>                Yr_m<-rnorm(54,m=0,sd=1)
>                mat_Yr_m[,j]<-Yr_m
>                delta_i<-lower_m%*%mat_Yr_m[,j]
>                mat_delta[,j]<-as.vector(delta_i)
>        }
>        DELTA_1<-mat_delta[,1]
>        DELTA_2<-mat_delta[,2]-a_1*mat_delta[,1]
>                for (t in 3:length(vec_IT)){
>                        mat_DELTA[,t]<-mat_delta[,t] - a_1*mat_delta[,t-1]
> - a_2*mat_delta[,t-2]
>                }
>                mat_DELTA[,1]<-DELTA_1
>                mat_DELTA[,2]<-DELTA_2
>                        for (k in 1:length(nmesh)){
>                        mean_m<-as.numeric(vec_mean_col)
>                        DELTA<-U_i*mat_DELTA
>                        D<-mean_m + t(DELTA)
>                }
>
>        }
>
> I want to implement this formula for 50 simulations!
>
> any idea?
>
> Thanks a lot!
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Mathematical Modelling, Statistics and Bio-Informatics

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



More information about the R-devel mailing list