[R] how to add points/lines to a surface plot

Domenico Vistocco vistocco at unicas.it
Tue Feb 10 17:12:20 CET 2009


Dear All,
is there a way to superimpose points and/or lines on a surface plot?

Below I try to explain my problem.
Suppose I have the following surface plot (likelikood for the normal 
variable when both parameters are unknown):

-------------------------------------------------------------------------------------------------------------------------------------------
normalLike <- function(mu, sigma, sample){
    (sigma ^ - length(sample)) * exp(-0.5 * (sigma ^ -2) * sum((sample - 
mu)^2))
}
normalLikeVec <- Vectorize(normalLike,  vectorize.args = c("mu","sigma"))

teta1 <- seq(0, 6, by=0.1)
teta2 <- seq(0.1, 8, by=0.1)
matrixMuSigma <- outer(teta1, teta2, normalLikeVec, sample=c(0.88, 1.07, 
1.27,1.54, 1.91, 2.27, 3.84, 4.50, 4.64, 9.41))
matrixMuSigma <- matrixMuSigma / max(matrixMuSigma)

persp(teta1, teta2, matrixMuSigma)
-------------------------------------------------------------------------------------------------------------------------------------------

Then I would like to superimpose on the same plot points (or a line) 
corresponding to the following data:
-------------------------------------------------------------------------------------------------------------------------------------------
#x coordinates
teta1
#y coordinates
sigmaMax <- teta2[apply(matrixMuSigma, 1, which.max)]
#z coordinates
apply(matrixMuSigma, 1, max)
-------------------------------------------------------------------------------------------------------------------------------------------

Thanks in advance,
domenico

PS:
I am trying to explain the geometrical interpretation of profile 
likelihood. Any better idea?




More information about the R-help mailing list