I want to generate random numbers. But i want it like this. for example i want to generate random numbers for The gamma distribution coefficient of skewness 2.
How can i do this?

 채택된 답변

José-Luis
José-Luis 2012년 12월 6일
편집: José-Luis 2012년 12월 6일

0 개 추천

doc gamrnd
The skewness is a function of one of the two parameters of the distribution, that you can set as you see fit. You just need to set it so the skewness is two (look at the wikipedia article on the gamma distribution).

댓글 수: 5

eren eren
eren eren 2012년 12월 6일
Sorry i dont understand. what is doc gamrnd ?
José-Luis
José-Luis 2012년 12월 6일
There is already a function that does what you ask. Look at the documentation for gamrnd
I was suggesting that you type doc gamrnd in the prompt to browse the documentation. Read it and you'll hopefully understand.
eren eren
eren eren 2012년 12월 6일
no i understood that but in gamrnd don't have skewness a place to enter.
José-Luis
José-Luis 2012년 12월 13일
편집: José-Luis 2012년 12월 13일
From one of your comments.
When you do this:
i write this on matlab skewness = 2; scale = 1; shape = 2./sqrt(skewness); x=gamrnd(shape,scale) s=skewness(x)
Skewness becomes a variable, and overshadows the built-in skewness function in Matlab. It is good practice not to do that, as problems as the one got might pop-up (you think you are calling a function but you are in fact trying to access a variable).
After clearing your work space to make sure there is no variable called skweness in it, do this instead:
ske = 2;
sca = 1;
shap = 1/sqrt(2);
x = gamrnd(shap,sca,[1000 1]);
your_skew = skewness(x);
Please accept an answer if it helped you.
eren eren
eren eren 2012년 12월 13일
yes it is working. can i use this, beta, chi squre etc. distributions?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jonathan Sullivan
Jonathan Sullivan 2012년 12월 6일

0 개 추천

skewness is simple 2 divided by the square root of the shape parameter for gamma distributions. Here's an example.
skewness = 2;
scale = 1;
shape = 2./sqrt(skewness);
gamrnd(shape,scale)

댓글 수: 9

eren eren
eren eren 2012년 12월 7일
if i use this, do the random numbers of gamma distrubition have the 2 skewness?
eren eren
eren eren 2012년 12월 7일
This isn't working
José-Luis
José-Luis 2012년 12월 8일
It is not working how?
eren eren
eren eren 2012년 12월 8일
i generated numbers but i dont be sure skewness=2. x=gamrnd(shape,scale) and i use A=skewness(x) code, the code not working.
José-Luis
José-Luis 2012년 12월 9일
편집: José-Luis 2012년 12월 9일
Since it's a random sample, it might not be exactly equal to 2. Also, there might be some bias. "The code not working" is not a very useful statement for those that are trying to help you. An example showing what you get/what you expect would be more helpful.
eren eren
eren eren 2012년 12월 12일
no no, the skewness code does not works. it returns an error. i know there might be some bias
José-Luis
José-Luis 2012년 12월 13일
편집: José-Luis 2012년 12월 13일
What does your code look like? And the error is? It is hard to help you without details.
eren eren
eren eren 2012년 12월 13일
i write this on matlab skewness = 2; scale = 1; shape = 2./sqrt(skewness); x=gamrnd(shape,scale) s=skewness(x)
and error is;
??? Attempted to access skewness(0.412164); index must be a positive integer or logical.
José-Luis
José-Luis 2012년 12월 13일
Please see the comment to my original answer.

댓글을 달려면 로그인하십시오.

질문:

2012년 12월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by