From: jenya polyakova on 23 Oct 2009 15:19 I have a vector x. I did gamma fitting by: [phat]=gamfit(x); Note now phat has two elements in it. Now I want to plot the histogram of x by hist(x) Then I also want to plot on top that histogram a curve of my gamma distribution that is specified by parameter phat. How do I do that? THANKS
From: Wayne King on 23 Oct 2009 15:47 "jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hbsvjo$f61$1(a)fred.mathworks.com>... > I have a vector x. > I did gamma fitting by: > [phat]=gamfit(x); > Note now phat has two elements in it. > Now I want to plot the histogram of x by > hist(x) > Then I also want to plot on top that histogram a curve of my gamma distribution >that is specified by parameter phat. How do I do that? THANKS Hi Jenya, one way is to construct a "probability" histogram of your data and then use gampdf() with the estimated alpha and beta parameters and overlay the pdf for that on your data. Here I just generate some gamma-distributed random numbers. Obviously, you would use your data. R = gamrnd(2,2,100,1); binWidth = 2; %These aren't hard and fast binCtrs = 1:binWidth:19; %These aren't hard and fast n=length(R); counts = hist(R,binCtrs); prob = counts / (n * binWidth); h = bar(binCtrs,prob,'hist'); set(h,'FaceColor',[.9 .9 .9]); x=0:.01:19; hold on; y = gampdf(x,2,2); %gamma pdf plot(x,y,'k','linewidth',2); Hope that helps, wayne
From: jenya polyakova on 23 Oct 2009 15:58 "Wayne King" <wmkingty(a)gmail.com> wrote in message <hbt17o$sfp$1(a)fred.mathworks.com>... > "jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hbsvjo$f61$1(a)fred.mathworks.com>... > > I have a vector x. > > I did gamma fitting by: > > [phat]=gamfit(x); > > Note now phat has two elements in it. > > Now I want to plot the histogram of x by > > hist(x) > > Then I also want to plot on top that histogram a curve of my gamma distribution >that is specified by parameter phat. How do I do that? THANKS > > Hi Jenya, > one way is to construct a "probability" histogram of your data and then use gampdf() with the estimated alpha and beta parameters and overlay the pdf for that on your data. Here I just generate some gamma-distributed random numbers. Obviously, you would use your data. > > R = gamrnd(2,2,100,1); > binWidth = 2; %These aren't hard and fast > binCtrs = 1:binWidth:19; %These aren't hard and fast > n=length(R); > counts = hist(R,binCtrs); > prob = counts / (n * binWidth); > h = bar(binCtrs,prob,'hist'); > set(h,'FaceColor',[.9 .9 .9]); > x=0:.01:19; hold on; > y = gampdf(x,2,2); %gamma pdf > plot(x,y,'k','linewidth',2); > > Hope that helps, > wayne Dear Wayne, thanks...but where does my data come in? Thanks JEnya
From: jenya polyakova on 23 Oct 2009 16:09 "jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hbt1se$a77$1(a)fred.mathworks.com>... > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hbt17o$sfp$1(a)fred.mathworks.com>... > > "jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hbsvjo$f61$1(a)fred.mathworks.com>... > > > I have a vector x. > > > I did gamma fitting by: > > > [phat]=gamfit(x); > > > Note now phat has two elements in it. > > > Now I want to plot the histogram of x by > > > hist(x) > > > Then I also want to plot on top that histogram a curve of my gamma distribution >that is specified by parameter phat. How do I do that? THANKS > > > > Hi Jenya, > > one way is to construct a "probability" histogram of your data and then use gampdf() with the estimated alpha and beta parameters and overlay the pdf for that on your data. Here I just generate some gamma-distributed random numbers. Obviously, you would use your data. > > Dear W > > R = gamrnd(2,2,100,1); > > binWidth = 2; %These aren't hard and fast > > binCtrs = 1:binWidth:19; %These aren't hard and fast > > n=length(R); > > counts = hist(R,binCtrs); > > prob = counts / (n * binWidth); > > h = bar(binCtrs,prob,'hist'); > > set(h,'FaceColor',[.9 .9 .9]); > > x=0:.01:19; hold on; > > y = gampdf(x,2,2); %gamma pdf > > plot(x,y,'k','linewidth',2); > > > > Hope that helps, > > wayne > > > Dear Wayne, > thanks...but where does my data come in? Thanks > JEnya Dear Wayne, I tried to do it. But what I need is really a vector y of the same size as x but that has estimated values coming from Gamma. THANKS
From: Wayne King on 23 Oct 2009 16:38
"jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hbt2hf$mhn$1(a)fred.mathworks.com>... > "jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hbt1se$a77$1(a)fred.mathworks.com>... > > "Wayne King" <wmkingty(a)gmail.com> wrote in message <hbt17o$sfp$1(a)fred.mathworks.com>... > > > "jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hbsvjo$f61$1(a)fred.mathworks.com>... > > > > I have a vector x. > > > > I did gamma fitting by: > > > > [phat]=gamfit(x); > > > > Note now phat has two elements in it. > > > > Now I want to plot the histogram of x by > > > > hist(x) > > > > Then I also want to plot on top that histogram a curve of my gamma distribution >that is specified by parameter phat. How do I do that? THANKS > > > > > > Hi Jenya, > > > one way is to construct a "probability" histogram of your data and then use gampdf() with the estimated alpha and beta parameters and overlay the pdf for that on your data. Here I just generate some gamma-distributed random numbers. Obviously, you would use your data. > > > > > > Dear W > > > R = gamrnd(2,2,100,1); > > > binWidth = 2; %These aren't hard and fast > > > binCtrs = 1:binWidth:19; %These aren't hard and fast > > > n=length(R); > > > counts = hist(R,binCtrs); > > > prob = counts / (n * binWidth); > > > h = bar(binCtrs,prob,'hist'); > > > set(h,'FaceColor',[.9 .9 .9]); > > > x=0:.01:19; hold on; > > > y = gampdf(x,2,2); %gamma pdf > > > plot(x,y,'k','linewidth',2); > > > > > > Hope that helps, > > > wayne > > > > > > Dear Wayne, > > thanks...but where does my data come in? Thanks > > JEnya > > > Dear Wayne, > I tried to do it. But what I need is really a vector y of the same size as x but that has estimated values coming from Gamma. THANKS Hi Jenya, I'm sorry I don't understand. You get an alpha and a beta parameter from your data, x, from the gamfit function. You can use that alpha and beta along with gampdf() to get the appropriate gamma probability density function. Then you make a histogram of your x data as I have done above (you're just substituting your data for the random numbers I've used) and overlay your gamma pdf parametrized by the alpha and beta parameters. Isn't that what you are trying to do? Going back to your question: "Now I want to plot the histogram of x by " hist(x). Then I also want to plot on top that histogram a curve of my gamma distribution that is specified by parameter phat. How do I do that? THANKS" wayne |