I'm working through the  course Bayesian Statistics: From Concept to Data Analysis by the University of California, Santa Cruz and there is a  that requires me to use R or Excel to find the answer to this:  Let $Y ∼ Gamma(2, 1/3)$. Find $P(0.5 &lt; Y &lt; 1.5)$. The answer is given as 0.078.   I would like to calculate this using Python. I have tried  from scipy import stats stats.gamma.cdf(1.5,1/3,scale=2) - stats.gamma.cdf(0.5,1/3,scale=2)   which returns 0.197. I've also tried switching the 2 and the 1/3.  Note I am using  Python 3.5.3 |Anaconda 2.5.0 (64-bit)| (default, May 15 2017, 10:43:23) [MSC v.1900 64 bit (AMD64)] on win32   What am I doing wrong?
123783
There is something that I am doing wrong in the exercise below and I would appreciate some help figuring it out.  Let $X_1, X_2, \ldots, X_5$ be a random sample from a $\Gamma \left(3,3 \right)$ distribution . Define $W=\sum_{i=1}^5 X_i $.    Obtain the distribution of $W$ and of $2W/3$ Find $c_1$ and $c_2$ such that $P \left( c_1 &lt; W &lt;c_2 \right)=0.95 $     Since $W$ is the sum of iid gamma variables, $W \sim \Gamma \left(15,3 \right)$ and now a straightforward transformation argument shows that $Y=\frac{2}{3} W \sim \chi^2 \left(30 \right) $. This completes question 1.  Now for question 2, my thoughts were to transform these probabilities using the result from question 1, namely that $\frac{2}{3} W \sim \chi^2 \left(30 \right) $. Hence, unless I have made a horrible mistake here:  $$P \left( \frac{2}{3} c_1 &lt; Y &lt; \frac{2}{3} c_2 \right)=0.95 $$  We can find the constants from a chisquare table for $30$ degrees of freedom. In my case, they are $16.791$ for the lower bound and $46.979$ for the upper one.   Then if we equate $\frac{2}{3}c_1=16.791$ and solve for $c_1$ we should be able to find the constant for the above gamma confidence interval, right?   The problem is that according to $R$, $P \left( W&lt;c_1 \right) =1 $, instead of  the desired $0.025$ which means I have gone wrong somewhere. I do not think it is in question though $1$ as I have verified the result many times.   Thank you.
109798
It's clear to me by inspection that if we fix $\beta = \frac{1-\mu}{\mu} \alpha$ (thereby fixing the mean) and let $\alpha \rightarrow 0$, the Beta distribution approaches a Bernoulli($\mu$) distribution.  For example:  par(mfrow = c(1, 2),     oma = c(0, 0, 1.5, 0)) xx = seq(0, 1, length.out = 1000) mus = c(.2, .7) for (ii in 1:2) {   mu = mus[ii]   matplot(xx, sapply(10^(-1:-5), function(al)      pbeta(xx, al, (1-mu)/mu * al)),     type = 'l', lty = ii,     main = paste('Mean:', mu),     ylab = 'Cumulative Probability', xlab = 'x') } title('Beta Approaches Bernoulli', outer = TRUE)     That is, if $X \sim B(\alpha, \frac{1-\mu}{\mu} \alpha)$, its CDF $F_X(x; \alpha, \mu)$, satisfies  $$ \lim_{\alpha \rightarrow 0} F_X(x; \alpha, \mu) = 1 - \mu = F_Y(x) \quad \forall x \in (0, 1)$$  Where $Y \sim$ Bernoulli($\mu$), and the convergence is non-uniform. I tried to do a more formal proof of this but couldn't make any progress, even in simple cases (like $\mu = \frac12$). The  makes reference to the $\mu = \frac12$ case several times without proof. Perhaps I'm missing something easy about doing the integral, or some fact about the Beta/incomplete Beta function. Any help would be appreciated!
766
X has a Uniform distribution $U(0,1)$. I have to find the distribution of the variable $U =|X-1/3|$.  This is what i can get so far :  $F(U) \;{= P\{U &lt; u\} \\ = P\{| X-1/3 | &lt; u\} \\ \ddots}$  I know that i shall get something like $P\{-(U-1/3) &lt; X &lt; U -1/3\}$. Could anyone explain how to get the PDF and the CDF for this problem and explain how can i easily change this absolute values for other problems ( other examples $Z=1-|X|,~~G=|X|-1$ etc..).
62396
I have been reading Geoff Cumming's 2008 paper  [~200 citations in Google Scholar] -- and  am confused by one of its central claims. This is one in the series of papers where Cumming argues against $p$-values and in favour of confidence intervals; my question, however, is not about this debate and only concerns one specific claim about $p$-values.   Let me quote from the abstract:     This article shows that, if an initial   experiment results in two-tailed $p= .05$, there is an $80\%$   chance the one-tailed $p$-value from a replication will fall in   the interval $(.00008, .44)$, a $10\%$ chance that $p &lt; .00008$,   and fully a $10\%$ chance that $p &gt; .44$. Remarkably, the   interval—termed a $p$ interval—is this wide however large   the sample size.   Cumming claims that this "$p$ interval", and in fact the whole distribution of $p$-values that one would obtain when replicating the original experiment (with the same fixed sample size), depend only on the original $p$-value $p_\mathrm{obt}$ and do not depend on the true effect size, power, sample size, or anything else:     [...] the probability distribution of $p$ can be derived without   knowing or assuming a value for $\delta$ (or power). [...] We do not assume any prior knowledge   about $\delta$, and we use only the information $M_\mathrm{diff}$ [observed between-group difference] gives about $\delta$ as   the basis for the calculation for a given $p_\mathrm{obt}$ of the distribution of   $p$ and of $p$ intervals.      $\quad\quad\quad$    I am confused by this because to me it seems that the distribution of $p$-values strongly depends on power, whereas the original $p_\mathrm{obt}$ on its own does not give any information about it. It might be that the true effect size is $\delta=0$ and then the distribution is uniform; or maybe the true effect size is huge and then we should expect mostly very small $p$-values. Of course one can start with assuming some prior over possible effect sizes and integrate over it, but Cumming seems to claim that this is not what he is doing.  Question: What exactly is going on here?    Note that this topic is related to this question:  with an excellent answer by @whuber. Cumming has a paper on this topic to:  -- but that one is clear and unproblematic.  I also note that Cumming's claim is repeated several times in the 2015 Nature Methods paper  that some of you might have come across (it already has ~100 citations in Google Scholar):     [...] there will be substantial variation in the $P$ value of repeated experiments. In reality, experiments are rarely repeated; we do not know how different the next $P$ might be. But it is likely that it could be very different. For example, regardless of the statistical power of an experiment, if a single replicate returns a $P$ value of $0.05$, there is an $80\%$ chance that a repeat experiment would return a $P$ value between $0$ and $0.44$ (and a $20\%$ change [sic] that $P$ would be even larger).   (Note, by the way, how, irrespective of whether Cumming's statement is correct or not, Nature Methods paper quotes it inaccurately: according to Cumming, it's only $10\%$ probability above $0.44$. And yes, the paper does say "20% change". Pfff.)
47506
Suppose I'm given the mean and one quantile (e.g. the 20% quantile) of a random variable $x$, and I want to find the parameters $\alpha$ and $\beta$ of a Beta distribution that has the same mean and quantile.  Is there an efficient way to do it?    Using just the mean, I know that since $\bar{x} = \frac{\alpha}{\alpha+\beta}$, we have $\beta = \frac{\alpha}{\bar{x}} - \alpha$.  So we only really have one parameter to estimate.  But I'm unsure how to use the quantile information to take the next step.  Maybe there's something I can do with the Incomplete Beta when I know the ratio $\frac{\beta}{\alpha} = \frac{1-\bar{x}}{\bar{x}}$?  I have access to R myself, so I could use a numerical optimizer for this, but ideally I need a method that can be carried out in Excel in someone else's environment.  Excel does have BETA.DIST() and BETA.INV() functions available.  A look-up table would be fine, but a closed-form formula would be better if it's possible.
49544
The data I'm working with are highly skewed, with the vast majority of data concentrated at 0. It seems really hard to highlight the differences between these kind of distributions:  gamma1 &lt;- rgamma(10000, shape=0.05, rate=1) gamma2 &lt;- rgamma(10000, shape=0.055, rate=0.98) gamma3 &lt;- rgamma(10000, shape=0.06, rate=0.95)  c(mean(gamma1), mean(gamma2), mean(gamma3))  [1] 0.04845668 0.05253655 0.05797983  ks.test(gamma1, gamma2)   Two-sample Kolmogorov-Smirnov test    data:  gamma1 and gamma2     D = 0.0433, p-value = 1.44e-08     alternative hypothesis: two-sided  ks.test(gamma2, gamma3)   Two-sample Kolmogorov-Smirnov test   data:  gamma2 and gamma3    D = 0.0456, p-value = 1.864e-09    alternative hypothesis: two-sided    ks.test(gamma1, gamma3)  Two-sample Kolmogorov-Smirnov test   data:  gamma1 and gamma3    D = 0.0798, p-value &lt; 2.2e-16    alternative hypothesis: two-sided   As most of the data is at 0, histograms are not very helpful for seeing the differences between the distributions (not to mention the fact there doesn't seem to be a convenient way to plot a histogram with multiple distributions in R, see ):    Violin plots seem to misrepresent the shape of the distributions (they look a lot more normal-like than they really are) and since the means are very low, the boxes are almost invisible:    Since these plot aren't really showing anything useful, I was wondering if there is a better way to visualise skewed distributions?
21116
Let ${Y_1,...,Y_n}$ be independent random variables and $Y_i$~$N(\beta x_i, 1)$ where $x_1,...,x_n$ are fixed known constants, and $\beta$ is an unknown parameter.  I'm looking to find the p-value or rejection region for  the test  $$H_0: \beta=0 \quad \text{vs} \quad H_1:\beta\ne0$$  The Likelihood Ratio Test statistic $\Lambda$ is  $$e^{-1/2\left(\frac{\sum_{i=1}^n y_i x_i}{\sum_{i=1}^n x_i^2}\right)^2\sum_{i=1}^n x_i^2}$$  I have already asked a similar question with $H_1: \beta&gt;0$ here: .   After setting $\Lambda &lt; k$ I'm left with $\sum x_iy_i$ after removing constants to the right, which is the same as my previous question. How will finding the p-value or rejection region for this test differ?
124081
This is clearly just a matter of definition or convention, and of almost no practical importance. If $\alpha$ is set to its traditional value of 0.05, is a $p$ value of 0.0500000000000... considered to be statistically significant or not? Is the rule to define statistical significance usually considered to be $p &lt; \alpha$ or $p \leq \alpha$??
110112
What methods can I use to infer a distribution if I know only three percentiles?  For example, I know that in a certain data set, the fifth percentile is 8,135, the 50th percentile is 11,259, and the 95th percentile is 23,611.  I want to be able to go from any other number to its percentile.  It's not  my data, and those are all the statistics I have.  It's clear that the distribution isn't normal.  The only other information I have is that this data represents government per-capita funding for different school districts.  I know enough about statistics to know that this problem has no definite solution, but not enough to know how to go about finding good guesses.  Would a lognormal distribution be appropriate?  What tools can I use to perform the regression (or do I need to do it myself)?
108804
So basically the question is to find the CDF of $Z$ where $Z$ is the random variable that signifies the distance from a point in a square(sides 1 length) to a fixed vertex of the square. I do not understand the calculation of the geometry in the following picture :
13504
I am having difficulty in how to calculate the Pearson's $\chi^2$ statistic for a contingency table with entries: (3, 0) and (0, 3) (row-wise).  I was studying Agresti's categorical data analysis and found this table. He calculated it as 6.  Through what calculation did he reach this answer?
43311
If $X \sim \text{Gamma}(\alpha,\beta)$, how would I go about finding $E\left(\frac 1{X^2}\right)$?
86320
My lecturer posed a question where we derive the density function of the student t-distribution from the Chi-square and Standard normal distribution. I worked on this question for days, and I am pretty sure the below integral is correct (Verified by others)  $$f_T(t)=\int_{-\infty}^\infty|x|2nx\times \frac{\frac{1}{2}^{\frac{n}{2}}}{\Gamma\left(\frac{n}{2}\right)}(x^2n)^{\frac{n}{2}-1}e^{-\frac{1}{2}x^2n}\frac{1}{\sqrt{2\pi}}e^{-\frac{(xt)^2}{2}}dx$$ where n is the degree of freedom of the t-distribution and $\Gamma$ is the gamma function from the Gamma distribution. My goal is $$f_T(t)=\frac{\Gamma[(n+1)/2]}{\sqrt{n\pi}\Gamma(n/2)}\left(1+\frac{t^2}{n}\right)^{-(n+1)/2}$$  I was given 2 hints. To proceed, I need to do integration by parts first, then I should use the fact that the Gamma d.f integrates to 1. From this point on, I am unsure, but I shall show you my steps.  We know that the d.f of the Gamma density with parameters $\alpha=\frac{n+1}{2} \lambda=\frac{1}{2}$ integrates to $1$, that is $\int_{0}^{\infty}g(t)dt= \int_{0}^{\infty}\frac{\frac{1}{2}^{\frac{n+1}{2}}}{\Gamma\left(\frac{n+1}{2}\right)}t^{\frac{n+1}{2}-1}e^{-\frac{1}{2}t}dt=1$ Let $t=x^2n$.  Therefore,      $dt=2xn\,dx$ We have $\int_{0}^{\infty}g(t)dt=\int_{0}^{\infty}g(x^2n)2xn\,dx=\int_{0}^{\infty}\frac{\frac{1}{2}^{\frac{n+1}{2}}}{\Gamma\left(\frac{n+1}{2}\right)}(x^2n)^{\frac{n+1}{2}-1}e^{-\frac{1}{2}(x^2n)}2xn\,dx=1$ This should be useful because I noticed the $\Gamma[(n+1)/2]$ in the end result.  Working on the big integral now... $f_T(t)=\int_{-\infty}^\infty|x|2nx\times \frac{\frac{1}{2}^{\frac{n}{2}}}{\Gamma\left(\frac{n}{2}\right)}(x^2n)^{\frac{n}{2}-1}e^{-\frac{1}{2}x^2n}\frac{1}{\sqrt{2\pi}}e^{-\frac{(xt)^2}{2}}$ $=\frac{\Gamma[(n+1]/2)]}{\sqrt{n\pi}\Gamma(n/2)}\int_{-\infty}^\infty \frac{\sqrt{n\pi}\Gamma(n/2)}{\Gamma[(n+1]/2)]}|x|2nx\times \frac{\frac{1}{2}^{\frac{n}{2}}}{\Gamma\left(\frac{n}{2}\right)}(x^2n)^{\frac{n}{2}-1}e^{-\frac{1}{2}x^2n}\frac{1}{\sqrt{2\pi}}e^{-\frac{(xt)^2}{2}}dx$ After a load of manipulation, $=\frac{\Gamma[(n+1]/2)]}{\sqrt{n\pi}\Gamma(n/2)}\int_{-\infty}^\infty 2nx \frac{(\frac{1}{2})^{\frac{n+1}{2}}}{\Gamma [(n+1)/2)] }(x^2n)^{\frac{n-1}{2}}e^{-\frac{1}{2}(x^2n)}\times2n|x|e^{-\frac{(xt)^2}{2}}dx$ Note that the first half is integrate to 1. Hence I do by parts.  But I still cannot get to my goal. I had tried this question for at least 6 times already now. Can I get some help? I tried to type these out as neatly as I knew how.
95747
Suppose we have $\mu = 19.1$ and $\sigma = 1.7$.  I need to find $a \in \mathbb{R}$ such that: $P(|X-19.1|\leq a) = 0.98$ Now in the correction it is given that:  $$P(|X-19.1|\leq a) = 0.98 \iff P(\frac{-a}{1.7} \leq \frac{X - 19.1}{1.7} \leq \frac{a}{1.7})=0.98 \iff P(\frac{X-19.1}{1.7} \leq \frac{a}{1.7})=0.99$$  Can someone explain to me why is the last equality correct?
70944
I often find myself asking questions like, "I know this variable $x$  lies in $(0,1)$ and most of the mass lies in $(0,.20)$ and then declines continuously towards 1.  What distribution can I use to model it?"  In practice, I wind up using the same few distributions over and over again simply because I know them.  Instead, I'd like to look them up in a more systematic way.  How do I go about accessing the wealth of work that probabilitists have done developing all of these distributions?  Ideally I'd like a reference organized by properties (region of support, etc.), so I can find distributions by their characteristics and then learn more about each distribution based on the tractability of the pdf/cdf and how closely the theoretical derivation fits the problem I'm working on.  Does such a reference exist, and if not, how do you go about choosing distributions?
66210
I have gone through various formulas but all were used for a small data set like 100, 200 rows, but I want to know how to calculate critical values of r for a large data set containing >5000 rows.   I have calculated using T.INV(1-alpha/2,df)/((sqrt(T.INV(1-alpha/2)^2+df)), but this formula is for small data sets, when I used it for a large data set, mentioned above, I got results which were not expected.
64658
I am using the epitools in R for calculating the confidence interval of relative risk.    There are three methods inside for calculations: namely Wald, Small and Boot.  I want to find some article describing the three methods, but I can't find any, can anyone help? Thanks!