From ripley@stats.ox.ac.uk  Tue Nov 16 11:03:08 1999
From: ripley@stats.ox.ac.uk (ripley@stats.ox.ac.uk)
Date: Tue, 16 Nov 1999 12:03:08 +0100 (MET)
Subject: spikes in contour and persp (PR#327)
Message-ID: <199911161103.MAA15162@pubhealth.ku.dk>

> From: jlindsey@alpha.luc.ac.be
> Date: Tue, 16 Nov 1999 08:57:00 +0100 (MET)
> 
> The following matrix of normed likelihoods should give a smooth
> surface but instead gives a series of spikes in both persp and contour
> (the dim labels are the axes values). I know an algorithm cannot be
> infallible but it would be nice to have some parameters to control the
> smoothing. (It takes close to an hour to produce this matrix on a
> Pentium II 300mh. It was after that that it crashed with the Inf in my
> previous bug message...)


I am sorry, but I don't understand. contour does not do any
smoothing, but interpolates assuming smoothness.  The data
appears to me to be a series of spikes just off the diagonal, and not
what contour thinks of as a smooth surface.  It is common to 
interpolate the data from such a coarse grid before contouring.

persp just plots the data with visual linear interpolation.

> round(like*100,0)
     2.32 2.345 2.37 2.395 2.42 2.445 2.47 2.495 2.52 2.545 2.57 2.595 2.62
1.4     0     0    0     0    0     0    0     0    0     0    0     0    0
1.42    0     1    0     0    0     0    0     0    0     0    0     0    0
1.44    0     1    2     0    0     0    0     0    0     0    0     0    0
1.46    0     0    2     5    0     0    0     0    0     0    0     0    0
1.48    0     0    0     7    9     0    0     0    0     0    0     0    0
1.5     0     0    0     1   17    15    1     0    0     0    0     0    0
1.52    0     0    0     0    3    34   21     1    0     0    0     0    0
1.54    0     0    0     0    0     6   57    26    1     0    0     0    0
1.56    0     0    0     0    0     0   12    79   29     1    0     0    0
1.58    0     0    0     0    0     0    0    19   95    29    1     0    0
1.6     0     0    0     0    0     0    0     1   26   100   26     1    0
1.62    0     0    0     0    0     0    0     0    1    31   93    22    0
1.64    0     0    0     0    0     0    0     0    0     1   32    77   17
1.66    0     0    0     0    0     0    0     0    0     0    2    28   59
1.68    0     0    0     0    0     0    0     0    0     0    0     2   23
1.7     0     0    0     0    0     0    0     0    0     0    0     0    1
1.72    0     0    0     0    0     0    0     0    0     0    0     0    0
1.74    0     0    0     0    0     0    0     0    0     0    0     0    0
1.76    0     0    0     0    0     0    0     0    0     0    0     0    0
1.78    0     0    0     0    0     0    0     0    0     0    0     0    0
1.8     0     0    0     0    0     0    0     0    0     0    0     0    0
     2.645 2.67 2.695 2.72 2.745
1.4      0    0     0    0     0
1.42     0    0     0    0     0
1.44     0    0     0    0     0
1.46     0    0     0    0     0
1.48     0    0     0    0     0
1.5      0    0     0    0     0
1.52     0    0     0    0     0
1.54     0    0     0    0     0
1.56     0    0     0    0     0
1.58     0    0     0    0     0
1.6      0    0     0    0     0
1.62     0    0     0    0     0
1.64     0    0     0    0     0
1.66    13    0     0    0     0
1.68    41    0     0    0     0
1.7     16    0     6    0     0
1.72     1    0    16    4     0
1.74     0    0     6   10     3
1.76     0    0     1    4     5
1.78     0    0     0    0     2
1.8      0    0     0    0     0


If I do some interpolation

library(akima)
x <- as.numeric(rownames(like))
y <- as.numeric(colnames(like))
xx <- expand.grid(x=x, y=y)
like1 <- interp(xx$x, xx$y, like, seq(1.4, 1.8, len=50), seq(2.3, 2.8, len=50))
contour(like1$x, like1$y,like1$z)

I get a slightly smoother result, but still five peaks.  (Are the
values for col=2.67 correct?)

I guess you need to evaluate this on a finer grid near the diagonal,
and probably adjust the coordinate system to get enough resolution
on the anti-diagonal.


-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


spikes in contour and persp (PR#327)
ripley@stats.ox.ac.uk