From r-help-bounces@stat.math.ethz.ch Thu Sep 30 22:43:59 2004
X-Originating-IP: [137.132.3.6]
X-Originating-Email: [nusbj@hotmail.com]
X-Sender: nusbj@hotmail.com
From: "Zhen Pang" <nusbj@hotmail.com>
To: nusbj@hotmail.com, ggrothendieck@myway.com, r-help@stat.math.ethz.ch
Subject: Re: Vectorising and loop (was Re: [R] optim "alog-likelihoodfunction")
Date: Thu, 30 Sep 2004 18:10:52 +0800
Content-Type: text/plain; format=flowed
X-OriginalArrivalTime: 30 Sep 2004 10:11:02.0496 (UTC)
	FILETIME=[CA44AE00:01C4A6D5]
Received-SPF: none (hypatia: domain of r-help-bounces@stat.math.ethz.ch does not designate permitted sender hosts)
Received-SPF: none (hypatia: domain of nusbj@hotmail.com does not designate
	permitted sender hosts)
X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on hypatia.math.ethz.ch
X-Spam-Level: 
X-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,
	BAYES_50 autolearn=no version=2.63
Cc: sundar.dorai-raj@pdf.com
X-BeenThere: r-help@stat.math.ethz.ch
X-Mailman-Version: 2.1.5
List-Id: "Main R Mailing List: Primary help" <r-help.stat.math.ethz.ch>
List-Unsubscribe: <https://stat.ethz.ch/mailman/listinfo/r-help>,
	<mailto:r-help-request@stat.math.ethz.ch?subject=unsubscribe>
List-Archive: <https://stat.ethz.ch/pipermail/r-help>
List-Post: <mailto:r-help@stat.math.ethz.ch>
List-Help: <mailto:r-help-request@stat.math.ethz.ch?subject=help>
List-Subscribe: <https://stat.ethz.ch/mailman/listinfo/r-help>,
	<mailto:r-help-request@stat.math.ethz.ch?subject=subscribe>
Content-Length: 2080

Mr. Grothendieck does suggest me to paste the data here. I just show a small 
one here. I must metion that I made a mistake in my former email. The first 
column should be j and is greater than the second column. I have corrected 
ll.

z is the matrix below

2 1 3
3 1 1
3 3 1
5 2 4

k<-max(z[,1])
ll <- function(theta)
  {t<-0
   for (ii in 1:k)
      {t<-t+exp(theta[ii])}
   lll<-0
   x00<-1/(1+t)
   x0<-x00*exp(theta)
for (m in 1:length(z[,1]))
   {j<-z[m,1]
    i<-z[m,2]
    a<-z[m,3]
    l<-i:(k-j+i)
    s<-rep(0,k)
    s[l]<-choose(j,i)*choose((k-j),(l-i))/choose(k,l)
# we only define some of s to be non-zero, since dim(l) might be smaller 
than dim(s)
    ss<-sum(s*x0)  # ss is a weighted sum of x0
     lll<-lll+a*log(ss)
    }
-lll
# the negative sign is to find the maximum of the log-likelihood function. 
It can be omitted if we #use the finscale option in optim.
}



Then I need to optim(b0,ll,hessian=T),
where b0<-c(0.8331934, 20.8009068, -7.0893623,  1.2109221, 18.7213273).

optim(b0,ll,hessian=T)
$par
[1]  0.8331934 20.8009068 -7.0893623  1.2109221 18.7213273

$value
[1] 5.182791

$counts
function gradient
      52       NA

$convergence
[1] 0

$message
NULL

$hessian
              [,1]          [,2]          [,3]          [,4]          [,5]
[1,]  1.065814e-08 -9.325873e-09  0.000000e+00 -3.330669e-10 -2.109424e-09
[2,] -9.325873e-09  8.887936e-01 -3.330669e-10 -1.620926e-08 -8.887936e-01
[3,]  0.000000e+00 -3.330669e-10 -6.661338e-10  0.000000e+00  0.000000e+00
[4,] -3.330669e-10 -1.620926e-08  0.000000e+00  7.549517e-09  7.105427e-09
[5,] -2.109424e-09 -8.887936e-01  0.000000e+00  7.105427e-09  8.887936e-01


I have tried to use eval() and modify my function, it seems to be able to 
remove the m loop, however, optim() can not recognize it. So my main concern 
is to avoid the loop and optim() can works for my function. Thanks.

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

From r-help-bounces@stat.math.ethz.ch Thu Sep 30 22:51:27 2004
Date: Thu, 30 Sep 2004 12:41:45 +0200
From: arv@ono.com
Subject: Asunto: Re: [R] Can't load rgl library
To: "Duncan Murdoch" <murdoch@stats.uwo.ca>
Content-Type: text/plain; charset="ISO-8859-15"
Received-SPF: none (hypatia: domain of r-help-bounces@stat.math.ethz.ch does not designate permitted sender hosts)
Received-SPF: none (hypatia: domain of arv@ono.com does not designate
	permitted sender hosts)
X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by hypatia.math.ethz.ch id
	i8UAfqER009634
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on hypatia.math.ethz.ch
X-Spam-Level: 
X-Spam-Status: No, hits=0.5 required=5.0 tests=AWL, BAYES_44,
	NO_REAL_NAME autolearn=no version=2.63
Cc: r-help@stat.math.ethz.ch, Daniel Adler <dadler@uni-goettingen.de>
X-BeenThere: r-help@stat.math.ethz.ch
X-Mailman-Version: 2.1.5
List-Id: "Main R Mailing List: Primary help" <r-help.stat.math.ethz.ch>
List-Unsubscribe: <https://stat.ethz.ch/mailman/listinfo/r-help>,
	<mailto:r-help-request@stat.math.ethz.ch?subject=unsubscribe>
List-Archive: <https://stat.ethz.ch/pipermail/r-help>
List-Post: <mailto:r-help@stat.math.ethz.ch>
List-Help: <mailto:r-help-request@stat.math.ethz.ch?subject=help>
List-Subscribe: <https://stat.ethz.ch/mailman/listinfo/r-help>,
	<mailto:r-help-request@stat.math.ethz.ch?subject=subscribe>
Content-Length: 1292

Hi,

Yes I have installed xlibmesa-gl and xlibmesa-glu. Anyway I'll follow your
advice and write to the developpers

cheers,

Antonio


>-- Mensaje original --
>From: Duncan Murdoch <murdoch@stats.uwo.ca>
>To: arv@ono.com
>Cc: r-help@stat.math.ethz.ch, Daniel Adler <dadler@uni-goettingen.de>
>Subject: Re: [R] Can't load rgl library
>Date: Thu, 30 Sep 2004 06:00:51 -0400
>
>
>On Thu, 30 Sep 2004 11:40:48 +0200, arv@ono.com wrote:
>
>>Hi,
>>
>>I've installed rgl package through R CMD INSTALL on a Debian-Sarge machine
>>(PIV) without any compiling error (see attached file), but when trying
to
>>load this package within R (and also Rcmdr library) I get:
>>
>>> library(rgl)
>>RGL: GLX extension missing on server
>>Error in firstlib(which.lib.loc, package) :
>>error rgl_init
>>error in library(rgl) : .First.lib failed
>>Segmentation fault
>
>Problems about packages should be sent to the maintainer of the
>package, in this case Daniel Adler <dadler@uni-goettingen.de>.
>
>But it does sound as though you don't have OpenGL or Mesa installed on
>your machine.
>
>Duncan Murdoch

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

From r-help-bounces@stat.math.ethz.ch Thu Sep 30 22:56:31 2004
content-class: urn:content-classes:message
Content-Type: text/plain;
	charset="iso-8859-1"
Subject: RE: [R] defining a template for functions via do.call and substitute.
Date: Thu, 30 Sep 2004 11:43:30 +0100
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: RE: [R] defining a template for functions via do.call and
	substitute.
Thread-Index: AcSm2lNhgDSzfDUiToy9POs/p3gXig==
From: <john.gavin@ubs.com>
To: <r-help@stat.math.ethz.ch>
X-OriginalArrivalTime: 30 Sep 2004 10:43:30.0853 (UTC)
	FILETIME=[53945D50:01C4A6DA]
X-UBS-Disclaimer: Version $Revision: 1.26 $
Received-SPF: none (hypatia: domain of r-help-bounces@stat.math.ethz.ch does not designate permitted sender hosts)
Received-SPF: none (hypatia: domain of john.gavin@ubs.com does not designate
	permitted sender hosts)
X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by hypatia.math.ethz.ch id
	i8UAhkdr009905
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on hypatia.math.ethz.ch
X-Spam-Level: 
X-Spam-Status: No, hits=-0.2 required=5.0 tests=AWL,
	NO_REAL_NAME autolearn=no version=2.63
X-BeenThere: r-help@stat.math.ethz.ch
X-Mailman-Version: 2.1.5
List-Id: "Main R Mailing List: Primary help" <r-help.stat.math.ethz.ch>
List-Unsubscribe: <https://stat.ethz.ch/mailman/listinfo/r-help>,
	<mailto:r-help-request@stat.math.ethz.ch?subject=unsubscribe>
List-Archive: <https://stat.ethz.ch/pipermail/r-help>
List-Post: <mailto:r-help@stat.math.ethz.ch>
List-Help: <mailto:r-help-request@stat.math.ethz.ch?subject=help>
List-Subscribe: <https://stat.ethz.ch/mailman/listinfo/r-help>,
	<mailto:r-help-request@stat.math.ethz.ch?subject=subscribe>
Content-Length: 1712

Hi,

Many thanks for the responses which solved my problem.

Fyi, my actual application is

copulaClayton <- function(u, v, alpha) 
  (u^-alpha + v^-alpha - 1)^(-1/alpha)
g <- function(){}
body(g) <- do.call("substitute", list(body(copulaClayton), 
  list(u = as.name("w"), v = quote(pnorm(var - qnorm(w))))))
formals(g) <- alist(w=, var=, alpha=)
g

and the substitutions seem to be working fine.

Thanks to 
Liaw, Andy [andy_liaw@merck.com]
Dimitris Rizopoulos [dimitris.rizopoulos@med.kuleuven.ac.be]
Bert Gunter [gunter.berton@gene.com] and
Thomas Lumley [tlumley@u.washington.edu],
Gabor Grothendieck <ggrothendieck@myway.com>

Regards,

John.

-----Original Message-----
From: Gavin, John 
Sent: 29 September 2004 12:17
To: 'r-help@stat.math.ethz.ch'
Subject: defining a template for functions via do.call and substitute.

Hi,

Given a function

  fun <- function(a, b) a + b

how do I generate the function 'function(x, y) x + y'?

Working from the help files and Bill Venables' R-news article (June 2002),
I have tried various permutations with substitute without success. 
e.g.
  do.call("substitute", list(fun, list(a = as.name("x"), b = as.name("y"))))

Regards,

John.

John Gavin <john.gavin at ubs.com>,
Quantitative Risk Models and Statistics,
UBS Investment Bank, 6th floor, 
100 Liverpool St., London EC2M 2RH, UK.
Phone +44 (0) 207 567 4289
Fax   +44 (0) 207 568 5352

Visit our website at http://www.ubs.com

This message contains confidential information and is intend...{{dropped}}

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

From r-help-bounces@stat.math.ethz.ch Thu Sep 30 23:08:31 2004
Content-Type: text/plain;
  charset="iso-8859-1"
From: Jim Lemon <bitwrit@ozemail.com.au>
To: ferri.leberl@gmx.at
Subject: Re: [R] Warning: number of items to replace is not a multiple of
	replacement length
Date: Thu, 30 Sep 2004 21:11:45 +1000
Content-Transfer-Encoding: 8bit
Received-SPF: none (hypatia: domain of r-help-bounces@stat.math.ethz.ch does not designate permitted sender hosts)
Received-SPF: none (hypatia: domain of bitwrit@ozemail.com.au does not
	designate permitted sender hosts)
X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on hypatia.math.ethz.ch
X-Spam-Level: 
X-Spam-Status: No, hits=-0.3 required=5.0 tests=AWL, BAYES_50,
	RCVD_IN_SORBS autolearn=no version=2.63
Cc: r-help@stat.math.ethz.ch
X-BeenThere: r-help@stat.math.ethz.ch
X-Mailman-Version: 2.1.5
List-Id: "Main R Mailing List: Primary help" <r-help.stat.math.ethz.ch>
List-Unsubscribe: <https://stat.ethz.ch/mailman/listinfo/r-help>,
	<mailto:r-help-request@stat.math.ethz.ch?subject=unsubscribe>
List-Archive: <https://stat.ethz.ch/pipermail/r-help>
List-Post: <mailto:r-help@stat.math.ethz.ch>
List-Help: <mailto:r-help-request@stat.math.ethz.ch?subject=help>
List-Subscribe: <https://stat.ethz.ch/mailman/listinfo/r-help>,
	<mailto:r-help-request@stat.math.ethz.ch?subject=subscribe>
Content-Length: 1105

Mag. Ferri Leberl wrote:
> What does this warning mean precisely?
> Is there any reason to care about it?
> Can I Avoid it by another way of programming?

As you have already gotten most of your questions answered, here is a 
possible answer to the last. You may want to care about it, but not 
necessarily. I have had to use the recycling capability of R without knowing 
whether the length of the result would be a multiple of that of the source 
vector. Say I want to label a vector of daily observations, but I do not know 
which day the observations start or how many there are:

label.weekdays<-function(ndays,start=1) {
 daynames<-rep(c("Sun","Mon","Tue","Wed","Thu","Fri","Sat"),ndays/7+1)
 return(daynames[start:(start+ndays-1)])
}

By creating a vector that is intentionally too long, then truncating it on 
one or both ends, I can recycle the source vector and avoid the warning.

Jim

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

