Hello, I have data; one column and 310 rows. When I plot the histogram, it has two peaks; please see the attachment. I would like to find appropriate distribution that fits the data. I tried to mixtools in R, but it did not fit well. I want to mix two beta distribution. I found that there is betareg package in R but the shape1,shape2 were known or there were two different data in the all examples. I do not know where to start. How can I use betamix in R to fit the data? Any hint? I really appreciate. Thank you -------------- next part -------------- A non-text attachment was scrubbed... Name: histogram.png Type: image/png Size: 16608 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20151228/be516049/attachment.png>
On 29/12/15 08:40, mesude bayrakci wrote:> Hello, > > I have data; one column and 310 rows. When I plot the histogram, it has two > peaks; please see the attachment. I would like to find appropriate > distribution that fits the data. I tried to mixtools in R, but it did not > fit well. > > I want to mix two beta distribution. I found that there is betareg package > in R but the shape1,shape2 were known or there were two different data in > the all examples. > > I do not know where to start. How can I use betamix in R to fit the data? > Any hint? > > I really appreciate. > > > Thank youGIYF Searching on "beta mixture model in r" leads to a number of hits, the most relevant one (it seems to me) being: r - Mixture of beta distributions: full example - Cross Validated which leads to http://stats.stackexchange.com/questions/114959/mixture-of-beta-distributions-full-example A fully worked example is provided. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Thank you for your response. I saw already that example and some others too. However, they defined alpha and beta in the examples or use two different dataset. I did not know alpha and beta values and have only one data set. I could calculate alpha and beta by using variance and means for the data has one peaks. How can I calculate alpha and beta for two peak distributions? Thanks> On Dec 28, 2015, at 6:21 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote: > >> On 29/12/15 08:40, mesude bayrakci wrote: >> Hello, >> >> I have data; one column and 310 rows. When I plot the histogram, it has two >> peaks; please see the attachment. I would like to find appropriate >> distribution that fits the data. I tried to mixtools in R, but it did not >> fit well. >> >> I want to mix two beta distribution. I found that there is betareg package >> in R but the shape1,shape2 were known or there were two different data in >> the all examples. >> >> I do not know where to start. How can I use betamix in R to fit the data? >> Any hint? >> >> I really appreciate. >> >> >> Thank you > > > GIYF > > Searching on "beta mixture model in r" leads to a number of hits, the most relevant one (it seems to me) being: > > r - Mixture of beta distributions: full example - Cross Validated > > which leads to > > http://stats.stackexchange.com/questions/114959/mixture-of-beta-distributions-full-example > > A fully worked example is provided. > > cheers, > > Rolf Turner > > -- > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276
Hi mesude, Achim's example seems particularly clear. Install the "betareg" and "flexmix" packages. I obtain a reasonable looking result for alpha and beta for a simulated dataset very similar to yours.> aComp.1 Comp.2 10.0674445 0.6452801> bComp.1 Comp.2 2.830934 0.769768 Jim On Tue, Dec 29, 2015 at 6:40 AM, mesude bayrakci <mesudebayrakci at gmail.com> wrote:> Hello, > > I have data; one column and 310 rows. When I plot the histogram, it has two > peaks; please see the attachment. I would like to find appropriate > distribution that fits the data. I tried to mixtools in R, but it did not > fit well. > > I want to mix two beta distribution. I found that there is betareg package > in R but the shape1,shape2 were known or there were two different data in > the all examples. > > I do not know where to start. How can I use betamix in R to fit the data? > Any hint? > > I really appreciate. > > > Thank you > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Hello all, This would be my last comments on "politeness" discussion started after my email, and do not want to keep the forum busy with this. Please do not continue writing on this matter to the forum. First of all, I just started using R for a short period of time, and using it for a small part of my research, given that I am coming from different technical background. 1) It is my understanding that the some of experts on this forum are expecting high quality questions from people who have just started learning things 2) It seems that Rolf's email has custom "cheer" signature. 3) In my first email, I thank him for his response and tried to explain him that I am aware of that example and did not think it would help me and thus asked second question and did not claim that he would not answer my question, my second response to Rolf's email was just basically reaction to his first paragraph. 4) I think Oliver's comment is the most important one among the points I stated here. Thank you for your support and suggestions, Oliver. It is greatly appreciated. Thank you for your response, Jim. Best, Mesude On Mon, Dec 28, 2015 at 9:58 PM, Jim Lemon <drjimlemon at gmail.com> wrote:> Hi mesude, > Achim's example seems particularly clear. Install the "betareg" and > "flexmix" packages. I obtain a reasonable looking result for alpha and beta > for a simulated dataset very similar to yours. > > > a > Comp.1 Comp.2 > 10.0674445 0.6452801 > > b > Comp.1 Comp.2 > 2.830934 0.769768 > > Jim > > > On Tue, Dec 29, 2015 at 6:40 AM, mesude bayrakci <mesudebayrakci at gmail.com > > wrote: > >> Hello, >> >> I have data; one column and 310 rows. When I plot the histogram, it has >> two >> peaks; please see the attachment. I would like to find appropriate >> distribution that fits the data. I tried to mixtools in R, but it did not >> fit well. >> >> I want to mix two beta distribution. I found that there is betareg package >> in R but the shape1,shape2 were known or there were two different data in >> the all examples. >> >> I do not know where to start. How can I use betamix in R to fit the data? >> Any hint? >> >> I really appreciate. >> >> >> Thank you >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > >[[alternative HTML version deleted]]
I am working to understand the same issues with my datasets. Adapting Dr Zeileis' posting I have written a humble function. It creates a two cluster beta mix on a vector of data. It seems to be working well on my datasets. You are welcome to try on yours. regards, Bob _____ bi.modal.beta<-function (vals){ # vals is a vector data points in range (0,1). There should not be any 0,1, or NA in vals library(betareg) library(flexmix) d <- data.frame(y = vals) #create bimodal beta model m <- betamix(y ~ 1 | 1, data = d, k = 2) #extract beta parameters (mean and precision) with anti-link functions mu <- plogis(coef(m)[,1]) phi <- exp(coef(m)[,2]) #convert mean & precision to alpha & beta a <- mu * phi b <- (1 - mu) * phi #report parameters print("alpha:") print( a) print("beta:") print(b) #plot in order to inspect result ys <- seq(0, 1, by = 0.01) p <- prior(m$flexmix) # p is equivalent to the percentage of each distribution hist(d$y, breaks = 0:25/25, freq = FALSE, main = "Bimodal Betamix", xlab = "values") lines(ys, p[1] * dbeta(ys, shape1 = a[1], shape2 = b[1]) , lwd = 2, col="red") lines(ys, p[2] * dbeta(ys, shape1 = a[2], shape2 = b[2]) , lwd = 2,col="blue") } ____
Thank you Bob. I already had it worked. Best, M. On Wed, Jan 6, 2016 at 1:19 PM, Bob Aronoff <bobaronoff at gmail.com> wrote:> I am working to understand the same issues with my datasets. > Adapting Dr Zeileis' posting I have written a humble function. > It creates a two cluster beta mix on a vector of data. > It seems to be working well on my datasets. > You are welcome to try on yours. > > regards, > Bob > > _____ > > bi.modal.beta<-function (vals){ > > # vals is a vector data points in range (0,1). There should not be any > 0,1, or NA in vals > > library(betareg) > library(flexmix) > > d <- data.frame(y = vals) > > #create bimodal beta model > m <- betamix(y ~ 1 | 1, data = d, k = 2) > > #extract beta parameters (mean and precision) with anti-link functions > mu <- plogis(coef(m)[,1]) > phi <- exp(coef(m)[,2]) > > #convert mean & precision to alpha & beta > a <- mu * phi > b <- (1 - mu) * phi > > #report parameters > print("alpha:") > print( a) > print("beta:") > print(b) > > #plot in order to inspect result > ys <- seq(0, 1, by = 0.01) > p <- prior(m$flexmix) > # p is equivalent to the percentage of each distribution > > hist(d$y, breaks = 0:25/25, freq = FALSE, > main = "Bimodal Betamix", xlab = "values") > lines(ys, p[1] * dbeta(ys, shape1 = a[1], shape2 = b[1]) , lwd = 2, > col="red") > lines(ys, p[2] * dbeta(ys, shape1 = a[2], shape2 = b[2]) , lwd > 2,col="blue") > } > > ____ > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]