I'm using MikTeX 2.7. Do you know where I am supposed to store the pdf files created from R that I want to bring into my LaTeX document when I build it.
I've stored them in a folder of my choice within My Documents, but the LaTeX compilation seems to bomb out when it gets to including the PDF picture and doesn't include any thing below that line in my LaTeX file when I build it.
If I put it in MyDocuments directly, LaTeX doesn't bomb out on the Building of the file but doesn't include the PDF picture into my LaTeX document when I build it.
Any help gratefully received.
Thanks.
Tom
Hi everyone,
I have a very basic question about plotting in 1f.
In the past, to plot a function I've done the following:
# Plot a divide function
divide <- function(x, y){
out <- x/y
return(out)
}
x <- seq(.01, .99, .01)
y <- divide(x = seq(.01, .99, .01), y = 2)
plot(x, y, type="l")
This doesn't work for my Log-Likelihood function because
ll.binomial(par = seq(.01, .99, .01), y = y, N = 10)
[1] -595.2
returns a single number and this error message:
Warning messages:
1: In y * log(binompi) :
longer object length is not a multiple of shorter object length
2: In (N - y) * log(1 - binompi) :
longer object length is not a multiple of shorter object length
Any thoughts about how to remedy this? Are there alternative ways to plot?
Thanks,
chris
> ---------- Forwarded message ----------
> From: Lai, Ronald <rolai at hbs.edu>
> Date: Mon, Mar 2, 2009 at 9:08 AM
> Subject: Re: [gov2001-l] PS4#2 & 1f
> To: "gov2001-l at lists.fas.harvard.edu" <gov2001-l at lists.fas.harvard.edu>
>
>
> Thanks all. I get it!
>
>
> Best.
>
>
>
> *From:* gov2001-l-bounces at lists.fas.harvard.edu [mailto:
> gov2001-l-bounces at lists.fas.harvard.edu] *On Behalf Of *Patrick Lam
> *Sent:* Monday, March 02, 2009 3:11 AM
> *To:* gov2001-l at lists.fas.harvard.edu
> *Subject:* Re: [gov2001-l] PS4#2 & 1f
>
>
>
> whoops, John-Paul is also right, the y-axis should be on the same scale.
>
> On Mon, Mar 2, 2009 at 3:06 AM, Patrick Lam <plam at fas.harvard.edu> wrote:
>
> It is actually the x-axis that needs to be scaled the same. Ronald, you're
> right that technically you can do the same by plotting the two curves on two
> different graphs and then eyeballing them, as long as the x-axis is the
> same. However, since we can shift likelihoods up and down, it's easier to
> compare by putting them on the same graph, which is what the problem is
> asking.
>
>
>
> On Sun, Mar 1, 2009 at 11:05 PM, John-Paul Ferguson <jpferg at mit.edu> wrote:
>
> >2) Vertical shifts? Is it not the same as using >par(mfrow=c(2,1)) and
> eyeballing the results?
>
> If you plot the two using par(mfrow=c(2,1)), the curvature will look almost
> the same, but the scale of the y-axis will be quite different. You have to
> plot them on the same scale in order to compare the curvature. Shifting one
> of them vertically so that their maxima have the same y-value makes it easy
> to plot them on the same graph.
>
> --John-Paul
>
> On Sun, Mar 1, 2009 at 9:53 PM, Lai, Ronald <rolai at hbs.edu> wrote:
>
> All,
>
>
>
> Since both distributions are Binomials with N=10, the log likelihood f(x)
> would be the same for both. Why is it necessary to even have an indicator
> variable? Essentially f(x)^d * f(x)^(1-d) = f(x).. I guess if one distr was
> Bin w/ N=10 and the other was N<>10, having the indicator variable makes
> sense. I'll operate on the assumption that the user of my R code can alter
> Ns for the two distributions.
>
>
>
> I'm a bit confused about PS4#1f
>
> 1) I'm assuming reparameterization is not necessary for plotting so I
> rewrote the f(x) to deal w/ this
>
> 2) Vertical shifts? Is it not the same as using par(mfrow=c(2,1)) and
> eyeballing the results?
>
>
>
> Feel like I'm missing something.
>
>
>
> Best.
>
>
>
> PS.
>
> Sparsha, in your f(x) below, you have not defined n or g. to my knowledge,
> the function also does not require an iterative process (per your for-loop)
>
>
>
> *From:* gov2001-l-bounces at lists.fas.harvard.edu [mailto:
> gov2001-l-bounces at lists.fas.harvard.edu] *On Behalf Of *sparsha saha
> *Sent:* Friday, February 27, 2009 3:41 PM
> *To:* gov2001-l at lists.fas.harvard.edu
> *Subject:* [gov2001-l] R hates me
>
>
>
> is anyone getting this error message for problem 2 on this week's problem
> set
>
>
> Error in pnorm(pa3) : element 1 is empty;
> the part of the args list of '.Internal' being evaluated was:
> (q, mean, sd, lower.tail, log.p)
>
>
>
> I get this when I run my log likelihood function in R and then try to use
> optim on it:
>
>
> > binomial.second <- function(pa2, pa3, y2, n2) {
> + pies2 <- pnorm(pa2)
> + pies3 <- pnorm(pa3)
> + for (i in 1:n) {
> + blaba <- ifelse(g > 0, sum(y2 * log(pies2) + (n - y2) * log(1 - pies2)),
> sum(y2 * log(pies3) + (n - y2) * log(1 - pies3)))
> + }
> + roe <- sum(blaba) / n
> + return(roe)
> + }
> >
> > opt123 <- optim(par = 0.25, fn = binomial.second, method = "BFGS", control
> = list(fnscale = -1), y = data, n = 10)
> Error in pnorm(pa3) : element 1 is empty;
> the part of the args list of '.Internal' being evaluated was:
> (q, mean, sd, lower.tail, log.p)
>
>
>
> _______________________________________________
> gov2001-l mailing list
>
>
> gov2001-l at lists.fas.harvard.edu
>
> http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
>
>
>
> _______________________________________________
> gov2001-l mailing list
> gov2001-l at lists.fas.harvard.edu
> http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
>
>
>
> --
> Patrick Lam
> Department of Government and Institute for Quantitative Social Science,
> Harvard University
>
http://www.people.fas.harvard.edu/~plam<http://www.people.fas.harvard.edu/%7Eplam>
>
>
>
>
> --
> Patrick Lam
> Department of Government and Institute for Quantitative Social Science,
> Harvard University
>
http://www.people.fas.harvard.edu/~plam<http://www.people.fas.harvard.edu/%7Eplam>
>
> _______________________________________________
> gov2001-l mailing list
> gov2001-l at lists.fas.harvard.edu
> http://lists.fas.harvard.edu/mailman/listinfo/gov2001-l
>
Dear all,
After cruising through the earlier problem sets with relative ease, I
can't even get started with this one. Can anyone help me with some
embarrassing basics?
(1c) In seeking to derive the MLE (which I'm trying to do by finding
the value(s) of pi where the slope of the likelihood function is
zero), in taking the derivative of the logs (produced by taking the
log of the function), I keep getting pi in the denominator, and when I
set the first derivative to zero, I then can't find a critical point
for pi. Can anyone help me see where I'm going wrong? Should I be
getting y/n as the answer?
(1d) Setting aside the above problem, I've tried to figure out how to
do this in R. However, I've gotten nowhere. My code and the error term
I'm getting are below. Again, can anyone give me a hint about what I'm
doing wrong? I tried to do this by mimicking what Patrick did in the
section for the Poisson distribution, but clearly I'm not getting the
differences between the Poisson and the Binomial.
Thanks in advance,
Malcolm
> ps4.binomial <- function(pi, x) {
+ xe <- factorial(x)
+ ne <- factorial(10)
+ out <- (ne/xe*factorial(10-x))*(pi^x)*((1-pi)^(10-x))
+ return(out)
+ }
> data <- rbinom(1000, 10, 0.75)
> opt <- optim(par = 0.5, fn = ps4.binomial, method = "BFGS", control
= list(fnscale = -1),x = data)$par
Error in optim(par = 0.5, fn = ps4.binomial, method = "BFGS", control
= list(fnscale = -1), :
objective function in optim evaluates to length 1000 not 1
Does anyone know what these warnings mean and how to fix this?
> optim(par, fn=ll.binomial, method="BFGS", control=list(fnscale=-1), y=y, N=10)$par
[1] 0.7759998
Warning messages:
1: In log(1 - p) : NaNs produced
2: In log(1 - p) : NaNs produced
3: In log(1 - p) : NaNs produced
4: In log(1 - p) : NaNs produced
5: In log(1 - p) : NaNs produced
6: In log(1 - p) : NaNs produced
7: In log(1 - p) : NaNs produced
8: In log(1 - p) : NaNs produced
9: In log(1 - p) : NaNs produced
Thanks!
Sincerely,
Olena Ageyeva
_________________________________________________________________
Windows Live?: Life without walls.
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_allup_1a_explore_032009
Hi Folks,
The reading for this week is: (1) UPM Chapter 5: from the beginning through
and including section 5.3; (2) King, Tomz, and Wittenberg, 2000 (available
at http://gking.harvard.edu/files/making.pdf)
See most of you on Thursday!
Best,
Miya
--
Miya Woolfalk
Ph.D. Student
Harvard University
Government and Social Policy
Please help me!
I am stuck and can not move any further. I tried classic binomial model and after deriving the log-likelihood I found that I could not find maximum analytically. I know that there must be an error or I am moving in totally wrong direction. Any advice is highly appreciated.
I will try to attach pdf-file with my formulas - not sure if it's allowed.
Sincerely,
Olena Ageyeva
_________________________________________________________________
Hotmail? is up to 70% faster. Now good news travels really fast.
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_70faster_032009
is anyone getting this error message for problem 2 on this week's problem
set
Error in pnorm(pa3) : element 1 is empty;
the part of the args list of '.Internal' being evaluated was:
(q, mean, sd, lower.tail, log.p)
I get this when I run my log likelihood function in R and then try to use
optim on it:
> binomial.second <- function(pa2, pa3, y2, n2) {
+ pies2 <- pnorm(pa2)
+ pies3 <- pnorm(pa3)
+ for (i in 1:n) {
+ blaba <- ifelse(g > 0, sum(y2 * log(pies2) + (n - y2) * log(1 - pies2)),
sum(y2 * log(pies3) + (n - y2) * log(1 - pies3)))
+ }
+ roe <- sum(blaba) / n
+ return(roe)
+ }
>
> opt123 <- optim(par = 0.25, fn = binomial.second, method = "BFGS", control
= list(fnscale = -1), y = data, n = 10)
Error in pnorm(pa3) : element 1 is empty;
the part of the args list of '.Internal' being evaluated was:
(q, mean, sd, lower.tail, log.p)