\HeaderA{logLik-methods}{Calculate the log likelihood and its gradient for
the vsn model}{logLik.Rdash.methods}
\aliasA{logLik,vsnInput-method}{logLik-methods}{logLik,vsnInput.Rdash.method}
\aliasA{plotVsnLogLik}{logLik-methods}{plotVsnLogLik}
\begin{Description}\relax
\code{logLik} calculates the log likelihood and its gradient
for the vsn model. \code{plotVsnLogLik} makes a false color plot for
a 2D section of the likelihood landscape.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S4 method for signature 'vsnInput':
logLik(object, p, refh=numeric(0), refsigma=as.numeric(NA))

plotVsnLogLik(object, p, whichp=1:2, expand=1, ngrid=31, fun=logLik, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{object}] A \code{\LinkA{vsnInput}{vsnInput}} object.
\item[\code{p}] A matrix whose columns are the set of parameters at which
the likelihoods are to be evaluated.
\item[\code{refh}] Numeric vector of length 0 or \code{nrow(object)}.
If the length is 0, there is no reference and and \code{refsigma} must be
missing. See \code{\LinkA{vsn2}{vsn2}}.
\item[\code{refsigma}] Numeric scalar.
\item[\code{whichp}] Numeric vector of length 2, with the indices of those
two parameters in \code{p} along which the section is to be taken.
\item[\code{expand}] Numeric vector of length 1 or 2 with expansion factors
for the plot range. The range is auto-calculated using a heuristic,
but that heuristic is not very good in particular for the offset (a)
parameters; see example.
\item[\code{ngrid}] Grid size.
\item[\code{fun}] Function to use for log-likelihood calculation. This
parameter is exposed only for testing purposes.
\item[\code{...}] Arguments that get passed on to \code{fun}, use this for
\code{refh} and \code{refsigma}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{logLik} is an R interface to the likelihood computations in vsn (which are done in C).
\end{Details}
\begin{Value}
For \code{logLik}, a numeric matrix of size \code{nrow(p)+1} by \code{ncol(p)}.
Its columns correspond to the columns of \code{p}.
Its first row are the likelihood values, its rows \code{2...nrow(p)+1}
contain the gradients.
If \code{refh} and \code{refsigma} are
specified, the ordinary negative log likelihood is calculated using these
parameters as given. If they are not specified, the profile negative log likelihood
is calculated.

For \code{plotVsnLogLik}, a dataframe with the 2D grid coordinates and
log likelihood values.
\end{Value}
\begin{Author}\relax
Wolfgang Huber \url{http://www.ebi.ac.uk/huber}
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{vsn2}{vsn2}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}

data("kidney")

v = new("vsnInput", x=exprs(kidney),
  pstart=array(as.numeric(NA), dim=c(1, ncol(kidney), 2)))
 
fit = vsn2(kidney)

p = sapply(exp(seq(-1, 1, length=31)), function(f) fit@par*c(1,1,f,1))

ll = logLik(v, p)

plot(p[3, ], ll[1, ], type="l", xlab=expression(b[1]), ylab=expression(-log(L)), log="x")
abline(v=fit@par[3], col="red")

plotVsnLogLik(v, fit@par, whichp=c(1,3), expand=c(0.01, 1))
\end{ExampleCode}
\end{Examples}

