Here's an R efficiency question.
The manner in which I am sampling from my beta distribution is via the
sample() function, where I define x to be a vector (.01,.02,.03, ... 1.0)
(the possible values of pi), and p the vector that contains the probability
values for each ordinate in the vector x. So, my sample function looks
something like:
pi <- sample(x=all.pi, n=N, replace=T, p=beta.prob)
Is there a different way to accomplish this that does not require
constructing the vectors of possible pi's and their corresponding
probabilities explicitly?
Thanks,
John.
Problem 2c asks to write a function which generates iid draws from the
beta-binomial distribution.
Slide 47 of the lectures notes says to ``Begin with N Bernoulli trials
with parameter pi_j,j=1,...,N(not necessarily iid).''
Are Bernoulli trials not iid? Could someone perhaps clarify this concept?
Thanks,
Andrew
--
Andrew Reeves
reeves(a)fas.harvard.edu
617.493.3485 tel.
301.639.8369 cell.
http://people.fas.harvard.edu/~reeves/
no. you have to do the numerical integration as I explained in the
section.
Kosuke
On Sun, 23 Feb 2003, Ryan Davies wrote:
> Can we use the R function integrate() for our integration in problem 4?
>
> -Ryan
>
We're running into trouble with taking draws from the beta distribution on 2c.
Our function for 2b gives us nice looking curves, but when alpha & beta < 1,
the curve goes to infinity at the extremes. So when we take draws from the
beta distribution, how are we to weigh the probability of those infinite
extremes? rbeta() seems to give a result consistent with the shape of the
curves - i.e.
for (alpha & beta = really small) --> returns 0 and 1s
for (alpha & beta = really big) --> returns values very close to 0.5
Or, basically, is there a forumla for the probability mass function for a beta
distribution?
Thanks,
Phillip
-------------------------------------------------
Phillip Y. Lipscy
Perkins Hall Room #129
35 Oxford Street
Cambridge, MA 02138
(617)493-4893 DORM
(617)851-8220 CELL
lipscy(a)fas.harvard.edu
http://www.people.fas.harvard.edu/~lipscy/
First Year Student, Ph.D. Program
Harvard University, FAS, Department of Government
-------------------------------------------------
For 2c, that's fine.
Kosuke
---------- Forwarded message ----------
Date: Sun, 23 Feb 2003 20:26:28 -0500
From: Chester Lee <lee57(a)fas.harvard.edu>
To: Kosuke Imai <kimai(a)fas.harvard.edu>
Subject: Beta Bionomial
Hey Kosuke,
For 2c, can I just use rbeta and rbinom or do you want us to write it
out?
Thanks!
Chester
Hi Nirmala,
Yes, I wrote a function that computes the probabilities for all possible
values of pi that I am concerned with (.01, .02, .03, ... 1.0). I wrote
these probabilities into the vector beta.prob (dependent upon mu and gamma).
Again, I'm not sure if there is a more efficient way to do this.
Then, I check to make sure that your probability distribution is a "real"
one in that sum(probability distribution)=1. I do this by
beta.prob <- beta.prob/sum(beta.prob)
to automatically normalize the probability distribution. I don't think it
will effect your results for drawing if you use a "non-normalized"
probability distribution, but it's not an "official" probability
distribution.
Did you also use the sample function to draw from your beta distribution?
John.
On 2/23/03 5:30 PM, "Nirmala Ravishankar" <ravishan(a)fas.harvard.edu> wrote:
> hey John,
>
> What is beta.prob in your sample statement? Is it something generated
> from rbeta, or did you write a function yourself. The reason I ask is, I
> generated the beta function, but some of the probabilities tend to
> infinity. Is that a problem?
>
> -
>
> On Sun, 23 Feb 2003, John Bright wrote:
>
>> Here's an R efficiency question.
>>
>> The manner in which I am sampling from my beta distribution is via the
>> sample() function, where I define x to be a vector (.01,.02,.03, ... 1.0)
>> (the possible values of pi), and p the vector that contains the probability
>> values for each ordinate in the vector x. So, my sample function looks
>> something like:
>>
>> pi <- sample(x=all.pi, n=N, replace=T, p=beta.prob)
>>
>> Is there a different way to accomplish this that does not require
>> constructing the vectors of possible pi's and their corresponding
>> probabilities explicitly?
>>
>> Thanks,
>> John.
>>
>> _______________________________________________
>> gov2001-l mailing list
>> gov2001-l(a)fas.harvard.edu
>> http://www.fas.harvard.edu/mailman/listinfo/gov2001-l
>>
>
>
On Sun, 23 Feb 2003, Ryan Davies wrote:
> > On Sun, 23 Feb 2003, Ryan Davies wrote:
> >
> > > Hey Professor King,
> > >
> > > I'm a little confused about by the way you define the negative
> > > binomial distribution in your lecture notes. Sheldon Ross gives
> > >
> > > P{X = n} = ((n - 1) choose (r - 1))*p^r*(1-p)^(n-r)
> > >
> > > and the intuitive explanation that n is the number of trials of a
> > > binomial variable until r sucesses are attained. I can't see how this
> > > is equivalent to the distribution you give in your lecture notes. So I
> > > was wondering if they are in fact the same and I just can't spot how, or
> > > if they're different (and if so, why they're called the same thing).
> > >
> > > Thanks,
> > > Ryan
> > >
> >
> > its a good question. these distributions can often be used for different
> > purposes, and Ross gives probably the more common usage, but less useful
> > for us. what I did in my notes and in my book was to find the mean of the
> > distribution E(Y) and called that mu and the variance E(Y) and called that
> > mu*sigma^2. then i set the mean (a function of p,r,n) equal to the mu and
> > the variance (also a fucntion of p,r,n) equal to mu*sigma^2. then fixing
> > n, I solved for p and r. finally, i substituted the right side of these
> > eqns in for p and r, and the result was what I give. (I might have r and
> > n switched; i don;t have his book in front of me at the moment.) Give it
> > a try if you have time; this is exactly the kind of thing you will often
> > need to do if you are trying to adapt a distribution for a new purpose.
>
> I'm a little confused about "setting the variance to mu*sigma^2" - isn't
> sigma^2 the old variance, or r(1-p)/p^2? Also, do you think you could help
> me to understand why the gamma distribution is the proper distribution to
> draw ~lambda from? (also, why the beta is chosen for the beta-binomial for
> the similar purpose)
sorry, i still don't have it all in front of me. but let me explain this
way:
in one parmaeterization, suppose its P(y|a), and E(Y)=1/a. so we define
mu=E(Y) and mu=1/a, which implies that a=1/mu. that means that
P(y|a)=P(y|1/mu). so take the formula for P(y|a) and wherever you see a
substitute in 1/mu, which will give exactly P(y|mu), an alternative
parameterization that you were shooting for.
the only difference that you have is that you have 2 parameters, so you
will wind up solving 2 equations for 2 unknowns.
Gary
This is a multi-part message in MIME format.
------=_NextPart_000_0042_01C2DB2F.AAC0E7B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Does anyone know of a function in R that multiplies all of the elements =
of a vector together (kinda like sum(), except for multiplication =
instead of addition)? Or is there any other clever way people have come =
up with to do the products in 2c?
-Ryan
------=_NextPart_000_0042_01C2DB2F.AAC0E7B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Does anyone know of a function in R =
that multiplies=20
all of the elements of a vector together (kinda like sum(), except for=20
multiplication instead of addition)? Or is there any other clever =
way=20
people have come up with to do the products in 2c?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>-Ryan</FONT></DIV></BODY></HTML>
------=_NextPart_000_0042_01C2DB2F.AAC0E7B0--
This is a multi-part message in MIME format.
------=_NextPart_000_0070_01C2DB30.860E6A40
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
What is the Student t distribution?
-Ryan
------=_NextPart_000_0070_01C2DB30.860E6A40
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>What is the Student t =
distribution?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>-Ryan</FONT></DIV></BODY></HTML>
------=_NextPart_000_0070_01C2DB30.860E6A40--
This is a multi-part message in MIME format.
------=_NextPart_000_0060_01C2DB30.24A43690
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
How do you plot in R with one or both axes as a log scale, instead of a =
linear scale? (can you do it with the plot() command?)
-Ryan
------=_NextPart_000_0060_01C2DB30.24A43690
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>How do you plot in R with one or =
both axes as=20
a log scale, instead of a linear scale? (can you do it with the =
plot()=20
command?)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>-Ryan</FONT></DIV></BODY></HTML>
------=_NextPart_000_0060_01C2DB30.24A43690--