Re: [R] Beta distribution- help needed

2011-07-26 Thread Daniel Malter
This is a theoretical issue. It is impossible for beta-distributed values to
take the value of 0 or 1. Hence, an attempt to fit a beta distribution to a
vector containing these values fails.

HTH,
Daniel



baxy77 wrote:
 
 Hi, 
 
 Well, i need some help, practical and theoretical. I am wondering why the
 fitdistplus (mle function) is returning an error for this code:
 
 [code]
 x1 - c(100,200,140,98,97,56,42,10,2,2,1,4,3,2,12,3,1,1,1,1,0,0);
 plotdist(x1);
 descdist(x1, boot =1000);
 y- sum(x1);
 d= as.vector(length(x1));
 for(i in 1:length(x1)){
   d[i] = x1[i]/y;
 }
 fitdist(d, beta)
 
 [/code] 
 
 Error: 
 
 Error in fitdist(d, beta) : 
   the function mle failed to estimate the parameters, 
 with the error code 100
 
 and what should i do to fix this ??
 
 Thank you
 

--
View this message in context: 
http://r.789695.n4.nabble.com/Beta-distribution-help-needed-tp3695076p3695113.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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.


Re: [R] Beta distribution- help needed

2011-07-26 Thread Daniel Malter
This is not very confusing. It is the exact same error in the sense that this
time the values of x1 are not only outside the interval (0-1) but within
[0-1] as in your first example, but this time they are also outside [0-1].
The reason is that you did not divide x1 by sum(x1) this time. In other
words, the problem that the values you supply to fitdist() are not
permissible by the definition of the distribution got even worse if one
may say so. For fitdist() to estimate the parameters of a beta distribution
it needs the values to be in the open interval (0-1).

Read up on http://en.wikipedia.org/wiki/Beta_distribution where the first
sentence says: In probability theory and statistics, the beta distribution
is a family of continuous probability distributions defined on the interval
(0, 1)...

HTH,
Daniel


baxy77 wrote:
 
 ok then this is confusing 
 
 if i do it like this:
 
 x1 - c(100,200,140,98,97,56,42,10,2,2,1,4,3,2,12,3,1,1,1,1,0,0);
 k -fitdist(x1, beta)
 plot(k)
 
  it says 
 
 
 Error in mledist(data, distname, start, fix.arg, ...) : 
   values must be in [0-1] to fit a beta distribution
 Calls: fitdist - mledist
 
 
 I mean the real problem is the Cullen-Frey plot says it is a beta
 distribution and i want to see its function . how do i do this
 

--
View this message in context: 
http://r.789695.n4.nabble.com/Beta-distribution-help-needed-tp3695076p3695639.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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.


Re: [R] Beta distribution- help needed

2011-07-26 Thread Ted Harding
On a point of information, the beta distribution is indeed
defined for x = 0 and, respectively, for x = 1 so long as
the parameters a=shape1 and b=shape2 are respectively
not less than 1:

  dbeta(x,a,b) = (x^(a-1))*((1-x)^(b-1))/Beta(a,b)

When a=1 and b=1 we have the uniform distribution on [0,1]
which certainly allows x=0 or x=1.

If a1 then the density -- Inf as x -- 0.
If b1 then the density -- Inf as x -- 1.
In these cases the density does not have a finite value
for x=0 respectively x=1. For a =1 and b = 1, the density
is finite at x=0 and at x=1, so either is a legitimate value.

The help info '?dbeta' says:

  The Beta distribution with parameters 'shape1' = a and
  ?shape2' = b has density
Gamma(a+b)/(Gamma(a)Gamma(b))x^(a-1)(1-x)^(b-1)  
  for a  0, b  0 and 0 = x = 1 where the boundary values
  at x=0 or x=1 are defined as by continuity (as limits).

So R itself has no problem with x=0 or x=1 when the density
makes sense mathematically. Indeed, it also gives the expected
results when a1 and/or b1:

  dbeta(0,0.5,0.5)
  # [1] Inf

I don't know how fitdist() works: maybe it automatically
rejects x=0 and x=1 whatever the values of a and b if  1.
Possibly, however, in baxy77's example fitdist() was trying
to use values of a or b which are less that 1, and fitdist
threw an error because of the infinity.

Hoping this helps,
Ted.


On 26-Jul-11 13:12:36, Daniel Malter wrote:
 This is not very confusing. It is the exact same error in
 the sense that this time the values of x1 are not only
 outside the interval (0-1) but within [0-1] as in your
 first example, but this time they are also outside [0-1].
 The reason is that you did not divide x1 by sum(x1) this
 time. In other words, the problem that the values you
 supply to fitdist() are not permissible by the definition
 of the distribution got even worse if one may say so.
 For fitdist() to estimate the parameters of a beta
 distribution it needs the values to be in the open interval (0-1).
 
 Read up on http://en.wikipedia.org/wiki/Beta_distribution
 where the first sentence says: In probability theory and
 statistics, the beta distribution is a family of continuous
 probability distributions defined on the interval (0, 1)...
 
 HTH,
 Daniel
 
 
 baxy77 wrote:
 
 ok then this is confusing 
 
 if i do it like this:
 
 x1 - c(100,200,140,98,97,56,42,10,2,2,1,4,3,2,12,3,1,1,1,1,0,0);
 k -fitdist(x1, beta)
 plot(k)
 
  it says 
 
 
 Error in mledist(data, distname, start, fix.arg, ...) : 
   values must be in [0-1] to fit a beta distribution
 Calls: fitdist - mledist
 
 
 I mean the real problem is the Cullen-Frey plot says it is a beta
 distribution and i want to see its function . how do i do this
 
 
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Beta-distribution-help-needed-tp3695076p36
 95639.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 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.


E-Mail: (Ted Harding) ted.hard...@wlandres.net
Fax-to-email: +44 (0)870 094 0861
Date: 26-Jul-11   Time: 15:42:33
-- XFMail --

__
R-help@r-project.org mailing list
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.