[R] Two dimensional likelihood surface plot

David Winsemius dwinsemius at comcast.net
Wed Nov 12 01:02:02 CET 2014


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

> Thanks David, what do you mean by organized data in regular manner?

This  is what I meant by a regular manner:

> matrix( c( rep( seq(0,1, by=.1), 11), rep( seq(0,1, by=.1),each=11) , runif(121) ), 121,3)
       [,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))
> str(df)
'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) )
     )           ))


> 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 11:17 AM, Gyanendra Pokharel wrote:
> 
> > 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"?
> 
> 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) )
>      )           )
> 
> >
> > Any suggestions are appreciated.
> >
> >
> > GP
> > University of Guelph
> > Guelph, ON
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius
> Alameda, CA, USA
> 
> 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list