# Unable to fit Beta model to my data: SamplingError: Initial evaluation of model at starting point failed!

**URL:** <https://discourse.pymc.io/t/unable-to-fit-beta-model-to-my-data-samplingerror-initial-evaluation-of-model-at-starting-point-failed/10168>\
**Category:** v5\
**Tags:** modeling\
**Created:** [August 16, 2022, 9:12pm UTC](https://discourse.pymc.io/t/unable-to-fit-beta-model-to-my-data-samplingerror-initial-evaluation-of-model-at-starting-point-failed/10168 "2022-08-16T21:12:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![horizonbugs](https://avatars.discourse-cdn.com/v4/letter/h/9de0a6/32.png) [@horizonbugs](https://discourse.pymc.io/u/horizonbugs)\
**Post date:** [August 16, 2022, 9:12pm UTC](https://discourse.pymc.io/t/unable-to-fit-beta-model-to-my-data-samplingerror-initial-evaluation-of-model-at-starting-point-failed/10168/1 "2022-08-16T21:12:26Z")

</div>

I’m new to pymc and probabilistic programming and I’m stuck with this error message:  
Version: v4.0.0b6

```auto
SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{'alpha_interval__': array(-0.16849976), 'beta_interval__': array(-0.38707828)}

Initial evaluation results:
{'alpha': -1.39, 'beta': -1.42, 'y': -inf}

```

I have observations that fit Beta model well:

![Screen Shot 2022-08-16 at 1.34.10 PM](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/f/feb102d910fba6121c90dfa026081324c1af375e.png)

When I manually guess the alpha and beta parameters for the Beta distribution, I get a good approximation:

![Screen Shot 2022-08-16 at 1.36.14 PM](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/3/3804ae34381c7ef0ac4679cd419be64f7454aa11.png)

I have a lot of 0s in the observation data and replaced all of them with 0.0001. Min and Max values of my observations are: (1e-05, 1.0)

Now, I need to estimate the parameters with pymc, but I’m getting an error:

```auto
with pm.Model() as model:    
    alpha = pm.Uniform("alpha", lower=0.13, upper=0.15)
    beta = pm.Uniform("beta", lower=3, upper=3.5)    
    y = pm.Beta("y", alpha=alpha, beta=beta, observed=observations)
    prior = pm.sample_prior_predictive(random_seed=RANDOM_SEED)
    trace = pm.sample(tune=1000, draws=4000, chains=4, cores=-1, return_inferencedata=True)
    posterior_predictive = pm.sample_posterior_predictive(trace=trace)

```

I cannot figure out what the problem is, please help!

---

<div class="post-metadata">

**Author:** ![horizonbugs](https://avatars.discourse-cdn.com/v4/letter/h/9de0a6/32.png) [@horizonbugs](https://discourse.pymc.io/u/horizonbugs)\
**Post date:** [August 17, 2022, 12:07am UTC](https://discourse.pymc.io/t/unable-to-fit-beta-model-to-my-data-samplingerror-initial-evaluation-of-model-at-starting-point-failed/10168/2 "2022-08-17T00:07:28Z")

</div>

I figured it out. The beta model for some reason requires x = (0,1) rather than x = [0,1] which is weird, because beta distribution should represent the proportions and percentages.  
Ref: [Beta Distribution](https://en.wikipedia.org/wiki/Beta_distribution)

BUT WHY?

---

<div class="post-metadata">

**Author:** ![cluhmann](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/cluhmann/32/3083_2.png) [@cluhmann](https://discourse.pymc.io/u/cluhmann)\
**Post date:** [August 17, 2022, 12:15am UTC](https://discourse.pymc.io/t/unable-to-fit-beta-model-to-my-data-samplingerror-initial-evaluation-of-model-at-starting-point-failed/10168/3 "2022-08-17T00:15:28Z")

</div>

At the link you provided:

> However, the inclusion of _x_ = 0 and _x_ = 1 does not work for _α_, _β_ \< 1; accordingly, several other authors, including W. Feller choose to exclude the ends _x_ = 0 and _x_ = 1, (so that the two ends are not actually part of the domain of the density function) and consider instead 0 \< _x_ \< 1.

I can’t speak to the choice of how `pm.Beta` was designed, but that seems like a reasonable rationale.
