Skip to content
Prev 279561 / 398506 Next

Problem in while loop

You want a plot of s = sum(log(b^2 + (x-a)^2)) as a function of  a or
am I missing something? You do it just like any other R plot: pick
some values of a, evaluate s for each of them (a little tricky if you
use my vectorized version due to the implicit use of the recycling
rule but very easy with your looped version)and plot(a,
loglikelihood(a)). Of course, since log is monotonic, it's pretty easy
to get an analytic solution for this.

If you want to be more creative about the graph this would also work:

x.fix <- c(-4.2, -2.85, -2.3, -1.02, 0.7, 0.98, 2.72, 3.5)
b <- 0.1

curve(sum(log(b^2 + (x.fix - x)^2))) # Note that curve has to take a
function of "x" so you have to rewrite it a little.

Michael

On Tue, Dec 6, 2011 at 10:40 AM, Gyanendra Pokharel
<gyanendra.pokharel at gmail.com> wrote: