Skip to content

Two dimensional likelihood surface plot

7 messages · David Winsemius, Duncan Murdoch, Bert Gunter +1 more

#
Hi R users,
I am trying to plot two dimensional posterior likelihood surface. I have a
data like

para1     para2     likehood
.......      ........      ...........
.......      ........      ...........



I looked at contour plot but it needs a shorted values of parameters and a
matrix of likelihood values. Is there any way to get the plot? or how can I
change my likelihood values to a matrix for the function "contour"?

Any suggestions are appreciated.


GP
University of Guelph
Guelph, ON
#
On Nov 11, 2014, at 11:17 AM, Gyanendra Pokharel wrote:

            
If the data are organized in a regular manner, then this might succeed:

with( df, contour( x=unique(para1), y=unique(para2)
                   z= matrix( likehood, length(unique(para1), length(unique(para2) )
     )           )
David Winsemius
Alameda, CA, USA
#
On 11/11/2014, 2:17 PM, Gyanendra Pokharel wrote:
The interp() function in the akima package should be able to do what you
want.

Duncan Murdoch
#
... as would the loess predict() method do from a loess() fit in the
base package.

I have used loess() for this purpose primarily to take advantage of
its "robustness" capabilities. I hasten to add that the algorithm is
not infallible in this regard, as it may not recover from a
sufficiently bad set of (least squares)starting values, as ?loess
explicitly says. It can also be slow.

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Tue, Nov 11, 2014 at 12:56 PM, Duncan Murdoch
<murdoch.duncan at gmail.com> wrote:
#
Thanks David, what do you mean by organized data in regular manner?

Gyanendra Pokharel
University of Guelph
Guelph, ON

On Tue, Nov 11, 2014 at 3:53 PM, David Winsemius <dwinsemius at comcast.net>
wrote:

  
  
#
On Nov 11, 2014, at 2:53 PM, Gyanendra Pokharel wrote:

            
This  is what I meant by a regular manner:
[,1] [,2]        [,3]
  [1,]  0.0  0.0 0.048946906
  [2,]  0.1  0.0 0.332529489
  [3,]  0.2  0.0 0.967099462
  [4,]  0.3  0.0 0.565349269
  [5,]  0.4  0.0 0.024230243
  [6,]  0.5  0.0 0.421633329
  [7,]  0.6  0.0 0.965847357
  [8,]  0.7  0.0 0.719618276
  [9,]  0.8  0.0 0.948675911
 [10,]  0.9  0.0 0.180241643
 [11,]  1.0  0.0 0.804828468
 [12,]  0.0  0.1 0.713698501
 [13,]  0.1  0.1 0.991003966
 [14,]  0.2  0.1 0.936413540
 [15,]  0.3  0.1 0.941731063
 [16,]  0.4  0.1 0.373998953
 [17,]  0.5  0.1 0.988915380
 [18,]  0.6  0.1 0.500791201
 [19,]  0.7  0.1 0.070137099
 [20,]  0.8  0.1 0.968422057
 [21,]  0.9  0.1 0.827396746
snipped the remain 100 lines

with( df, contour( x=unique(V1), y=unique(V2),
                   z= matrix( V3, length(unique(V1)), length(unique(V2) )
     )           ))


df <- as.data.frame( matrix( c( rep( seq(0,1, by=.1), 11), rep( seq(0,1, by=.1),each=11) , runif(121) ), 121,3))
'data.frame':	121 obs. of  3 variables:
 $ V1: num  0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 ...
 $ V2: num  0 0 0 0 0 0 0 0 0 0 ...
 $ V3: num  0.628 0.661 0.163 0.57 0.527 ...

My original untested suggestion had some missing parentheses and a missing comma:

with( df, contour( x=unique(V1), y=unique(V2),
                   z= matrix( V3, length(unique(V1)), length(unique(V2) )
     )           ))
David Winsemius
Alameda, CA, USA
#
Thanks a lot, David !

Thats what I wanted. it is greatly helpful.



GP
University of Guelph
Guelph, ON

On Tue, Nov 11, 2014 at 7:02 PM, David Winsemius <dwinsemius at comcast.net>
wrote: