mercredi 16 août 2017

Generate N>2 series with specified correlation in Matlab

I need to build N>2 correlated series, all coming from the same distribution and with a pre-specified correlation. In my case, these come from a Weibull distribution, all with the same parameters. I can use the Choleski decomposition but I do not get the same means, and this is important for my project.

I found this, programmed in R, that allows to construct series from any distribution starting from a joint normal distribution. However, I cannot use a similar procedure as, in my case, the pre-specified correlation is always with respect to a "seed" series. In the example above, using the joint distribution, the "seed" series is changing.

This is what I'm doing and hope it clarifies what I want to do and the problems that I have.

rho=1:-0.3:-0.9 ;
sizerho=size(rho,2) ;
wind_spe=zeros(100,sizerho) ;
seed=wblrnd(1,10,100,1) ;  % this is my "seed" series for each simulation

for r=2:1:sizerho
    R = [1 rho(r) ; rho(r) 1];
    L = chol(R);
    M=[seed wblrnd(1,10,100,1)];
    F= M*L;
    wind_spe(:,r) = F(:,2);
end
wind_spe(:,1)=seed; 

%check the means and variance
means=squeeze(mean(wind_spe,1))' ;
std=std(wind_spe,1,1)' ;
c=corr(wind_spe) ;
c=c(:,1) ;
summary=[rho' c means std] %you can see the mean and std are not the same




Aucun commentaire:

Enregistrer un commentaire