[R] creating a grid of function values

Chong Gu chong at stat.purdue.edu
Thu Feb 10 23:47:30 CET 2000


   From: Douglas Bates <bates at stat.wisc.edu>
   Date: 10 Feb 2000 14:28:49 -0600
   Lines: 21
   X-Mailer: Gnus v5.5/Emacs 20.3
   Sender: owner-r-help at stat.math.ethz.ch
   Precedence: bulk

   I want to create a grid of function values for use in `contour' or
   `persp'.  The function is the log-likelihood for the gamma.  The
   sample is stored as vector of length 20 called `Survival'.

   A single evaluation of the log-likelihood at, say, scale = 9 and shape
   = 10 would be obtained by
    sum(dgamma(Survival, scale = 9, shape = 10, log = TRUE))
   (This may work only 0.99.0, I'm not sure.)

   I would like to evaluate such a function on a grid of scale and shape
   values.  I don't think I can use `outer' because of the way the
   evaluation of the dgamma function would vectorize.  Although I could
   write the calculation for the grid in `for' loops, I have a nagging
   suspicion that there is a cleaner way that I have forgotten.

   Can anyone remind me of a slick way of generating the grid?

   -- 
   Douglas Bates                            bates at stat.wisc.edu
   Statistics Department                    608/262-2598
   University of Wisconsin - Madison        http://www.stat.wisc.edu/~bates/
   -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
   r-help 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-help-request at stat.math.ethz.ch
   _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Doug,

I don't quite understand what you meant about outer.  The first thing
I would try is

    dgamma.grid<-function(x,y,z) sum(dgamma(z,scale=x,shape=y,log=TRUE))
    outer(xgrid,ygrid,dgamma.grid,Survival)

Chong
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list