How do I plot loglikelihood functions of the Cauchy distribution in R? I need to determine whether or not there is always a unique root of the log-likelihood equation l'(x,0)=0 for different samples sizes of the Cauchy distribution. 
But I am unsure about how to actually define the log-likelihood function R and about actually being able to plot these graphs. Any advice would be appreciated!
 A: "The" Cauchy distribution is a misnomer: it is intended to refer to a family of distributions.
As an example, let's consider the location-scale family of distributions whose PDFs are given by
$$f(x; \mu, \sigma) = \frac{1}{\pi \sigma}\left(1 + \left(\frac{x-\mu}{\sigma}\right)^2\right)^{-1}.$$
(The special case $\mu=0, \sigma=1$ is the Cauchy distribution.)
By definition, the log likelihood $\Lambda$ of a batch of $n$ data $(x_i)$, $i=1, 2, \ldots, n$, is the logarithm of their probability, assuming the data are independently and identically distributed according to $f(x;\mu,\sigma)$.  The independence assumption implies the probability is the product of individual probabilities, whence
$$\Lambda(\mu,\sigma; x) = \log \prod_{i=1}^n f(x_i;\mu,\sigma) = -\sum_{i=1}^n\log\left(1 + \left(\frac{x_i-\mu}{\sigma}\right)^2\right) -n \log(\pi \sigma).$$
This must be plotted as the parameters $\mu$ and $\sigma$ vary.
In R, use contour or filled.contour to make such a plot.  As with many scale families, it will be clearer to plot $\sigma$ on a logarithmic scale.  So, we estimate a reasonable range for $\mu$, a reasonable range for $\log(\sigma)$, divide those ranges into little pieces, evaluate  $\Lambda$ at each possible combination of those pieces, and contour the results:
logLikelihood <- function(median, scale, x) {
  -sum(log(1 + ((x-median)/scale)^2)) - length(x)*log(pi*scale)
}

set.seed(17)
data <- rnorm(3) # Sample data (not drawn from a Cauchy distribution!)

medians <- seq(-3, 3, 1/50)                       # Range of medians to plot
scales <- seq(-1.5, 2, 1/50)                      # Range of (log) scales to plot
u <- as.matrix(expand.grid(medians, exp(scales))) # Points to evaluate
z <- matrix(apply(u, 1, function(v) logLikelihood(v[1], v[2], data)),
       nrow = length(medians))                    # Values of Lambda on the grid
filled.contour(medians, scales, z, color.palette=terrain.colors, 
               xlab="Median", ylab="Log(scale)",
               main="Cauchy Log Likelihood")


