From: Pete Dorothy <croero_at_gmail.com>

Date: Tue, 04 Mar 2008 19:17:35 +0100

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. Received on Tue 04 Mar 2008 - 18:20:18 GMT

Date: Tue, 04 Mar 2008 19:17:35 +0100

Thank you very much to both of you, and especially you Phil.

I will tell you if it works.

2008/3/4, Phil Spector <spector_at_stat.berkeley.edu>:

*>
**> Pete -
**> As others have told you, outer only works with vectorized
**> functions. An alternative is to use expand.grid to find all
**> the combinations of beta and zeta, and then use apply to
**> calculate your likelihood for each row. I believe that this
**> will work:
**>
**> allvals = expand.grid(beta=seq(0.1,0.5,by=10^(-1)),zeta=seq(0.1,0.5
**> ,by=10^(-1)))
**> answer = cbind(allvals,result =
**> apply(allvals,1,function(x)logl(x[1],x[2])))
**>
**> The columns of answer will be named beta, zeta and result, with
**> (hopefully) obvious meanings.
**>
**> - Phil Spector
**> Statistical Computing Facility
**> Department of Statistics
**> UC Berkeley
**> spector_at_stat.berkeley.edu
**>
**>
**>
**>
**> On Tue, 4 Mar 2008, Pete Dorothy wrote:
**>
*

> > Hello,

*> >
**> > I have simulated a set of data which i called "nir" (a vector).
**> >
**> > I have created a function "logl" which calculates the log-likelihood.
**> >
**> > logl is a function of 2 real parameters : "beta" and "zeta" (of length
**> 1).
**> >
**> > This function works perfectly well when I try for example "logl(0.1,0.2
**> )"
**> >
**> > Now if I try :
**> >
**> > "x=seq(0.1,0.5,by=10^(-1))
**> > y=seq(0.1,0.5,by=10^(-1))
**> > z=outer(x,y,logl)"
**> >
**> > I get an error.
**> >
**> > The problem seems to be that inside "logl", the following expression is
**> > calculated : "sum( log( beta+(nir-1)*zeta ) )". So it is a vector
**> > manipulation. The error tells me that "nir" is not the size of "zeta".
**> Yet
**> > usually it is no problem since "length(zeta)=1".
**> >
**> > When I replace "sum( log( beta+(nir-1)*zeta ) )" by a loop, I get no
**> > mistake. But I think it slows down the program.
**> >
**> > Do you have an idea where the problem is ?
**> >
**> > Thank you very much.
**> >
**>
**> > [[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.
**> >
**>
*

[[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. Received on Tue 04 Mar 2008 - 18:20:18 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 04 Mar 2008 - 18:30:19 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*