From: Firat on
Hi all,
I have 4 sets of 50 values. I want to generate, let's say 1000 random numbers, based on this data set , I know that these 4 sets are correlated with each other and I want it to be distributed with t-distribution. I can use mvtrnd function
r = mvtrnd(co,50,1000)

but that gives me mean of zero. Is there any way to add a mean for this function so that I can get my random numbers based on t-distribution, but around my data mean instead of zero ? or is there any method like scaling, or translation to do that ?

Hope it is clear,
Firat
From: Peter Perkins on
On 4/7/2010 7:55 PM, Firat wrote:

> Is there any way to add a mean for this
> function so that I can get my random numbers based on t-distribution,
> but around my data mean instead of zero ? or is there any method like
> scaling, or translation to do that ?

Firat, MVTRND won't do that, but it's easy to do:

mu = [row vector of component-wise means];
sigma = [row vector of component-wise scale factors];
t = bsxfun(@sum,mu,bsxfun(@times,sigma,mvtrnd(C,df,n)));

That probably looks a bit cryptic; you could also do this

mu = repmat([row vector of component-wise means],n,1);
sigma = repmat([row vector of component-wise scale factors],n,1);
t = mu + sigma.*mvtrnd(C,df,n);

Hope this helps.
From: Firat on
Thank you so much Peter. It worked.
At first it gave an error

??? Error using ==> bsxfun
Unsupported builtin function.

Error in ==> tdist at 8
t = bsxfun(@sum,mu,bsxfun(@times,sigma,mvtrnd(C,df,n)));

I assumed it was due to "sum" and changed it to "plus" and now it works. Thank you so much again!

Firat

Peter Perkins <Peter.Perkins(a)MathRemoveThisWorks.com> wrote in message <hpj8gm$mul$1(a)fred.mathworks.com>...
> On 4/7/2010 7:55 PM, Firat wrote:
>
> > Is there any way to add a mean for this
> > function so that I can get my random numbers based on t-distribution,
> > but around my data mean instead of zero ? or is there any method like
> > scaling, or translation to do that ?
>
> Firat, MVTRND won't do that, but it's easy to do:
>
> mu = [row vector of component-wise means];
> sigma = [row vector of component-wise scale factors];
> t = bsxfun(@sum,mu,bsxfun(@times,sigma,mvtrnd(C,df,n)));
>
> That probably looks a bit cryptic; you could also do this
>
> mu = repmat([row vector of component-wise means],n,1);
> sigma = repmat([row vector of component-wise scale factors],n,1);
> t = mu + sigma.*mvtrnd(C,df,n);
>
> Hope this helps.
From: Peter Perkins on
On 4/7/2010 9:30 PM, Firat wrote:
> Thank you so much Peter. It worked. At first it gave an error
>
> ??? Error using ==> bsxfun
> Unsupported builtin function.
>
> Error in ==> tdist at 8
> t = bsxfun(@sum,mu,bsxfun(@times,sigma,mvtrnd(C,df,n)));
>
> I assumed it was due to "sum" and changed it to "plus" and now it works.
> Thank you so much again!

Yes, thank you, I always get that wrong and I didn't run this code.