Re: [R] different results from nls in 2.10.1 and 2.11.1

2011-06-20 Thread Prof. John C Nash
Interesting!
I get nice convergence in both 32 and 64 bit systems on 2.13.0. I agree the 
older versions
are a bit of a distraction. The inconsistent behaviour on current R is a 
concern.

Maybe Philip, Uwe, and I (and others who might be interested) should take this 
off line
and see what is going on. I'll offer to act as tabulator of results and have 
set up a
temporary wiki on

http://macnash.telfer.uottawa.ca/PBettProb

to allow tries to be saved for comparison. Needs a login to "write". Please use
username=Ruser
password=statistics

Hopefully there won't be wikispam, or I'll have to close it off.

JN


On 06/20/2011 06:00 AM, r-help-requ...@r-project.org wrote:
> Date: Mon, 20 Jun 2011 11:25:54 +0200
> From: Uwe Ligges 
> To: p.e.b...@dunelm.org.uk
> Cc: r-help@r-project.org, Philip Bett 
> Subject: Re: [R] different results from nls in 2.10.1 and 2.11.1
> Message-ID: <4dff1222.7040...@statistik.tu-dortmund.de>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Since one is a 32-bit and the other one a 64-bit, and therefore the 
> compiler is also different, you can get different numerical results 
> easily, even with identical versions of R (and most of us do not have 
> outdated R installations around).
> 
> I just tried your example on 3 different systems with R-2.13.0 and all 
> told me "singular convergence"...
> 
> Uwe Ligges
> 
>

__
R-help@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.


Re: [R] Using MLE Method to Estimate Regression Coefficients

2011-06-15 Thread Prof. John C Nash
The error msg puts it quite clearly -- the initial parameters 1,1,1,1 are 
inadmissible for
your function. You need to have valid initial parameters for the variable 
metric method
(option BFGS).

This is one of the main problems users have with any optimization method. It is 
ALWAYS a
good idea to actually evaluate your function outside of the optimizer i.e., 
simply put in
the initial parameters and find out what function value you get.

It should also be noted (as the package optimx does) that the VM and CG based 
methods
really don't do very well without analytic gradients.

JN


On 06/15/2011 06:00 AM, r-help-requ...@r-project.org wrote:
> Message: 46
> Date: Tue, 14 Jun 2011 13:04:55 -0400 (GMT-04:00)
> From: boyla...@earthlink.net
> To: r-help@r-project.org
> Subject: [R] Using MLE Method to Estimate Regression Coefficients
> Message-ID:
>   
> <11895593.1308071096125.javamail.r...@mswamui-andean.atl.sa.earthlink.net>
>   
> Content-Type: text/plain; charset="utf-8"
> 
> Good Afternoon,
> 
>   I am relatively new to R and have been trying to figure out how to estimate 
> regression coefficients using the MLE method.  Some background: I am trying 
> to examine scenarios in which certain estimators might be preferred to 
> others, starting with MLE.  I understand that MLE will (should) produce the 
> same results as Ordinary Least Squares if the assumption of normality holds. 
> That said, in the following code (my apologies up front for any lack of 
> elegance) I use the data from the printing press study (commonly used in the 
> QE and stats literature) to develop first and second order models using OLS.  
> Then, using some code I found online, I tried to use MLE to do the same 
> thing. However, I cannot get it to work, as I get an error in my attempt to 
> use the optim function.  I have been studying the optim function in R; I have 
> also explored the use of MLE in the R documentation via the stats4, MASS, and 
> a few other packages but to little avail.  My questions are as follows:
> 
> 1) Is there a particular error in the MLE code below that I am just not 
> seeing?
> 2) Is there a simpler, more direct, or otherwise better way to approach it?
> 3) Which package should I use for MLE regression?
> 
> Sorry for the length and thanks in advance for any assistance someone might 
> have; I know your time is valuable.  I have pasted my code below but have 
> also attached as a .txt file.
> 
> v/r,
> Greg
> Doctoral Student, 
> Dept. of Industrial Eng, Clemson University

[snip]
> 
> # Now let's use the above function to estimate the model. 
> model <- optim(c(1,1,1,1), llik.regress, method="BFGS", 
> control=list(fnscale=-1),
>  hessian=TRUE)
> Error in optim(c(1, 1, 1, 1), llik.regress, method = "BFGS", control = 
> list(fnscale = -1),  : 
>   initial value in 'vmmin' is not finite
>  
> 
> --

__
R-help@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.


Re: [R] R Crashes when using "large" matrices (Ubuntu 11.04)

2011-06-04 Thread Prof. John C Nash
On Ubuntu 10.04 it ran fine, albeit in a machine with lots of memory, it seems 
to work
fine. Here's the output:
> rm(list=ls())
> gc()
 used (Mb) gc trigger (Mb) max used (Mb)
Ncells 131881  7.1 35 18.7   35 18.7
Vcells 128838  1.0 786432  6.0   559631  4.3
> p <- 500
> n <- 300
> set.seed(1234)
> x <- matrix(rnorm(n*p), n, p)
> sih <- var(x)
> b <- svd(sih)
>
> gc()
  used (Mb) gc trigger (Mb) max used (Mb)
Ncells  133536  7.2 35 18.7   35 18.7
Vcells 1030006  7.92644909 20.2  2536523 19.4
>

> sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.utf8   LC_NUMERIC=C
 [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8
 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8
 [7] LC_PAPER=en_US.utf8   LC_NAME=C
 [9] LC_ADDRESS=C  LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
>


Maybe another 11.04 glitch.

JN


On 06/04/2011 06:00 AM, r-help-requ...@r-project.org wrote:
> Message: 93
> Date: Fri, 3 Jun 2011 18:55:06 -0700 (PDT)
> From: Matias Salibian-Barrera 
> To: "R-help@r-project.org" 
> Subject: [R] R Crashes when using "large" matrices (Ubuntu 11.04)
> Message-ID: <75655.88533...@web161614.mail.bf1.yahoo.com>
> Content-Type: text/plain; charset=iso-8859-1
> 
> 
> This simple SVD calculation (commands are copied 
> immediately below) crashes on my Ubuntu machine (R 2.13.0). However it 
> works fine on my Windows 7 machine, so I suspect there's a problem with 
> (my?) Ubuntu and / or R. Can anybody else reproduce it (with Ubuntu 
> 11.04)? Thanks in advance.
> 
> p <- 500
> n <- 300
> set.seed(1234)
> x <- matrix(rnorm(n*p), n, p)
> sih <- var(x)
> b <- svd(sih)
>

__
R-help@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.


Re: [R] Problem with constrained optimization with maxBFGS

2011-05-12 Thread Prof. John C Nash
Is this a homework problem in finding the largest eigensolution of W?

If not, I'd be trying to maximize (D' W D)/ (D' D)

using (n-1) values of D and setting one value to 1 -- hopefully a value that is 
not going
to be zero.

JN


> 
> Date: Wed, 11 May 2011 17:28:54 -0300
> From: Leonardo Monasterio 
> To: r-help@r-project.org
> Subject: [R] Problem with constrained optimization with maxBFGS
> Message-ID: 
> Content-Type: text/plain
> 
> Dear all,
> 
> I need to maximize the v:
> 
>  v= D' W D
> 
> 
> D is a column vector ( n , 1)
> W is a given matrix (n, n)
> 
> subject to:
>  sum D= 1
> 
> (BTW, n is less than 300)
> I´ve tried to use maxBFGS, as follows:
> 
> #
> objectiveFunction<-function(x)
> {
>   return(t(D)%*%W%*%D)
> }
> 
> Amat<-diag(nrow(D))
> Amat<-rbind((rep(-1, nrow(D))), Amat)
> bvec<-matrix( c(0), nrow(D)+1, 1)
> bvec[1,1]<-c(1)
> startValues=rep(1/nrow(D),nrow(D)) #Istart value is homogeneous distribution
> res <<- maxBFGS(objectiveFunction, start=startValues,
> constraints=list(ineqA=Amat, ineqB=bvec))
> 
> The outcome is equal to the startValues. I´ve tried several initial values
> and nothing changes.
> Please, what am I doing wrong? Any suggestion?
> 
> Thanks a lot!
> 
> Leo.
> 
>   [[alternative HTML version deleted]]
> 
> 
> 
> -

__
R-help@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.


Re: [R] Problems with predict in fGarch

2011-03-24 Thread Prof. John C Nash
It's likely that the loss function has a log() or 1/x and the finite difference
approximations to gradients have added / subtracted a small number and caused a
singularity. Unfortunately, you'll need to dig into the fGarch code or write 
your own
(ouch!). Or perhaps the fGarch package maintainer will be willing to look at 
the package
if you provide him/her your problem.

This sort of thing  is common enough that some of us have been looking into 
better tools
for generating gradients. However, don't hold your breath. It's not easy work.

JN


On 03/24/2011 07:00 AM, r-help-requ...@r-project.org wrote:
> Message: 85
> Date: Thu, 24 Mar 2011 17:03:41 +0800
> From: Luis Felipe Parra 
> To: r-help 
> Subject: [R] Problems with predict in fGarch
> Message-ID:
>   
> Content-Type: text/plain
> 
> Hello.  I am using fGarch to estimate the following model:
> 
> 
> Call:
>  garchFit(formula = fmla, data = X[, i], trace = F)
> Mean and Variance Equation:
>  data ~ arma(1, 1) + garch(1, 1)
> 
> Conditional Distribution:
>  norm
> Coefficient(s):
>   mu   ar1   ma1 omegaalpha1 beta1
> -0.94934   1.0  -0.23211  54.06402   0.45709   0.61738
> Std. Errors:
>  based on Hessian
> Error Analysis:
> Estimate  Std. Error  t value Pr(>|t|)
> mu -0.949336   11.600072   -0.082  0.93477
> ar1 1.000.005947  168.139  < 2e-16 ***
> ma1-0.2321110.068638   -3.382  0.00072 ***
> omega  54.064022   16.5787353.261  0.00111 **
> alpha1  0.4570870.0931254.908 9.19e-07 ***
> beta1   0.6173780.044561   13.855  < 2e-16 ***
> ---
> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
> 
> 
> when I use predict I am getting the following error:
> 
> Error en optim(init[mask], armafn, method = optim.method, hessian = TRUE,  :
>   non-finite finite-difference value [1]
> 
> 
> does anybody know what might be going on?
> 
> Thank you
> 
> Felipe Parra
> 
>   [[alternative HTML version deleted]]
> 
>

__
R-help@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.


[R] R part of Google Summer of Code 2011

2011-03-21 Thread Prof. John C Nash
Last Friday we learned that R is accepted again for the Google Summer of Code.

R's "ideas" are at 
http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2011

On that page is a link to our google groups list for mentors and prospective 
students.
See http://www.google-melange.com/ for the official Google site. Note that 
successful
student applicants are paid a stipend that is generally considered to be quite 
attractive.

Students interested should
1) look at the ideas and get in touch with mentors of projects of interest.
2) join the google group for gsoc-r http://groups.google.com/group/gsoc-r which 
we use to
administer the program for R

Right now Melange (the system Google uses to run the program) is being reset. 
Should be
back real soon.

We hope for a number of strong applications. Last year we did not take all the 
slots
offered by Google as we did not feel all the student proposals were strong 
enough.

John Nash (co-admin with Claudia Beleites of GSoC-R)

__
R-help@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.


Re: [R] BFGS versus L-BFGS-B

2011-02-26 Thread Prof. John C Nash
Bert has put a finger on one of the key questions: Are we there yet?

Global optima are very difficult to find in many, possibly most problems.
We can check for local optima. In package optimx (currently resetting it on 
CRAN due to a
variable naming glitch with Rvmmin -- should be there in a couple of days) we 
carry out
the Kuhn Karush Tucker tests, but even these have scale dependencies. On 
R-forge there's a
new package under our optimization and solving packages project called kktc 
that separates
off the tests. However, that's only a start.

Constraints require us to do more work, too.

A couple of very large scale problems have been noted. The minimization of 
energy for
collections of atoms or molecules was suggested, but my experience with that 
type of
problem is that it has a huge number of local minima and is not amenable to the 
techniques
that the original poster had in mind, and certainly optim(BFGS) nor Rcgmin nor
optim(L-BFGS-B) are appropriate as they stand, though they may be helpful in 
some sort of
polyalgorithm.

ALso I did not post, but mentioned in private emails, that L-BFGS-B and Rcgmin 
should
offer much lower memory demands for problems in large numbers of parameters than
optim(BFGS) which has an explicit inverse Hessian approximation i.e., n*n 
doubles to
store. BFGS and L-BFGS-B have very different internals.

JN


On 02/25/2011 08:46 PM, Bert Gunter wrote:
> Thanks to all for clarifications. So I'm off base, but whether waaay
> off base depends on whether there is a reasonably well defined optimum
> to converge to. Which begs the question, I suppose: How does one know
> whether one has converged to such an optimum?  This is always an
> issue, of course, even for a few parameters; but maybe more so with so
> many.
> 
> -- Bert
> 
> On Fri, Feb 25, 2011 at 3:35 PM, Ravi Varadhan  wrote:
>> I have worked on a 2D image reconstruction problem in PET (positron emission
>> tomography) using a Poisson model.  Here, each pixel intensity is an unknown
>> parameter.  I have solved problems of size 128 x 128 using an accelerated EM
>> algorithm.  Ken Lange has shown that you can achieve term by term separation
>> using a minorization inequality, and hence the problem simplifies greatly.
>>
>> Ravi.
>>
>> ---
>> Ravi Varadhan, Ph.D.
>> Assistant Professor,
>> Division of Geriatric Medicine and Gerontology School of Medicine Johns
>> Hopkins University
>>
>> Ph. (410) 502-2619
>> email: rvarad...@jhmi.edu
>>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
>> Behalf Of Prof. John C Nash
>> Sent: Friday, February 25, 2011 5:55 PM
>> To: Bert Gunter
>> Cc: r-help@r-project.org
>> Subject: Re: [R] BFGS versus L-BFGS-B
>>
>> For functions that have a reasonable structure i.e., 1 or at most a few
>> optima, it is
>> certainly a sensible task. Separable functions are certainly nicer (10K 1D
>> minimizations),
>> but it is pretty easy to devise functions e.g., generalizations of
>> Rosenbrock, Chebyquad
>> and other functions that are high dimension but not separable.
>>
>> Admittedly, there are not a lot of real-world examples that are publicly
>> available. More
>> would be useful.
>>
>> JN
>>
>>
>> On 02/25/2011 05:06 PM, Bert Gunter wrote:
>>> On Fri, Feb 25, 2011 at 12:00 PM, Brian Tsai  wrote:
>>>> Hi John,
>>>>
>>>> Thanks so much for the informative reply!  I'm currently trying to
>> optimize
>>>> ~10,000 parameters simultaneously - for some reason,
>>>
>>> -- Some expert (Ravi, John ?) please correct me, but: Is the above not
>>> complete nonsense? I can't imagine poking around usefully  in 10K
>>> dimensional space for an extremum unless maybe one can find the
>>> extremum by 10K separate 1-dim optimizations. And maybe not then
>>> either.
>>>
>>> Am I way offbase here, or has Brian merely described just another
>>> inefficient way to produce random numbers?
>>>
>>> -- Bert
>>
>> __
>> R-help@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.

__
R-help@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.


Re: [R] BFGS versus L-BFGS-B

2011-02-25 Thread Prof. John C Nash
For functions that have a reasonable structure i.e., 1 or at most a few optima, 
it is
certainly a sensible task. Separable functions are certainly nicer (10K 1D 
minimizations),
but it is pretty easy to devise functions e.g., generalizations of Rosenbrock, 
Chebyquad
and other functions that are high dimension but not separable.

Admittedly, there are not a lot of real-world examples that are publicly 
available. More
would be useful.

JN


On 02/25/2011 05:06 PM, Bert Gunter wrote:
> On Fri, Feb 25, 2011 at 12:00 PM, Brian Tsai  wrote:
>> Hi John,
>>
>> Thanks so much for the informative reply!  I'm currently trying to optimize
>> ~10,000 parameters simultaneously - for some reason,
> 
> -- Some expert (Ravi, John ?) please correct me, but: Is the above not
> complete nonsense? I can't imagine poking around usefully  in 10K
> dimensional space for an extremum unless maybe one can find the
> extremum by 10K separate 1-dim optimizations. And maybe not then
> either.
> 
> Am I way offbase here, or has Brian merely described just another
> inefficient way to produce random numbers?
> 
> -- Bert

__
R-help@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.


[R] BFGS versus L-BFGS-B

2011-02-25 Thread Prof. John C Nash
There are considerable differences between the algorithms. And BFGS is an 
unfortunate
nomenclature, since there are so many variants that are VERY different. It was 
called
"variable metric" in my book from which the code was derived, and that code was 
from Roger
Fletcher's Fortran VM code based on his 1970 paper. L-BFGS-B is a later and more
complicated algorithm with some pretty nice properties. The code is much larger.

Re: "less memory" -- this will depend on the number of parameters, but to my 
knowledge
there are no good benchmark studies of memory and performance. Perhaps someone 
wants to
propose one for Google Summer of Code (see
http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2011
).

The optimx package can call Rvmmin which has box constraints (also Rcgmin that 
is intended
for very low memory). Also several other methods with box constraints, 
including L-BFGS-B.
Worth a try if you are seeking a method for multiple "production" runs. 
Unfortunately, we
seem to have some CRAN check errors on Solaris and some old releases -- 
platforms I do not
have -- so it may be a few days or more until we sort out the issues, which 
seem to be
related to alignment of the underlying packages for which optimx is a wrapper.

Use of transformation can be very effective. But again, I don't think there are 
good
studies on whether use of box constraints or transformations is "better" and 
when. Another
project, which I have made some tentative beginings to carry out. 
Collaborations welcome.

Best,

JN


On 02/25/2011 06:00 AM, r-help-requ...@r-project.org wrote:
> Message: 86
> Date: Fri, 25 Feb 2011 00:11:59 -0500
> From: Brian Tsai 
> To: r-help@r-project.org
> Subject: [R] BFGS versus L-BFGS-B
> Message-ID:
>   
> Content-Type: text/plain
> 
> Hi all,
> 
> I'm trying to figure out the effective differences between BFGS and L-BFGS-B
> are, besides the obvious that L-BFGS-B should be using a lot less memory,
> and the user can provide box constraints.
> 
> 1) Why would you ever want to use BFGS, if L-BFGS-B does the same thing but
> use less memory?
> 
> 2) If i'm optimizing with respect to a variable x that must be non-negative,
> a common approach is to do a change of variables x = exp(y), and optimize
> unconstrained with respect to y.  Is optimization using box constraints on
> x, likely to produce as good a result as unconstrained optimization on y?
> 
> - Brian.
> 
>   [[alternative HTML version deleted]]
> 
> 
>

__
R-help@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.


[R] odfWeave graphics glitch

2011-02-22 Thread Prof. John C Nash
Using R2.12.1 on Ubuntu 10.04.1 I've tried to run the following code chunk in 
odfWeave

<>=
x<-seq(1:100)/10
y<-sin(cos(x/pi))
imageDefs <- getImageDefs()
imageDefs$dispWidth <- 4.5
imageDefs$dispHeight<- 4.5
setImageDefs(imageDefs)
X11(type="cairo")
plot(x,y)
title(main="sin(cos(x/pi))")
savePlot("sincosx.png")
@

This is embedded in file example02in.odt, which has very little else.

In R I run

library(odfWeave)
infile<-"example02in.odt"
outfile<-"ex2.odt"
odfWeave(infile,outfile)

I get the png file created, but the ex2.odt is "corrupted" according to 
OpenOffice.
On automatic fixup, it does have a frame for a graph, but this is labelled 
"Read Error".

Note that the vignette for odfWeave has a blank graph too. I've emailed the 
package
maintainer, but so far no response.

Wondering if it's just my inexperience with this (I manage Sweave OK, but a 
client is
interested in non-TEX solution). Or perhaps some issue has developed recently 
that blocks
graphics in odfWeave. Note that some of the stuff in the example (the cairo 
line for
example) are part of several tries to find a solution.

JN

__
R-help@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.


[R] pre-announcement Google Summer of Code 2011 -- R projects

2011-02-20 Thread Prof. John C Nash
In a little over a month (Mar 28), students will have just over a week (until 
April 8) to
apply to work on Google Summer of Code projects. In the past few years, R has 
had several
such projects funded. Developers and mentors are currently preparing project 
outlines on
the R wiki at http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2011

This is just a pre-announcement, as the application time will be very short.

Please let Claudia Beleites or I know if there are any errors or other problems 
on that page.

JN

__
R-help@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.


Re: [R] nlminb doesn't converge and produce a warning

2011-01-22 Thread Prof. John C Nash
Kamel,

You have already had several comments suggesting some ideas for improvement, 
namely,

1) correct name for iteration limit (Karl Ove Hufthammer)
2) concern about number of parameters and also possibilities of multiple minima 
(Doug Bates)
3) use of optimx to allow several optimizers to be tried (Ravi Varadhan).

Here is another. Within optimx() we call can call Rcgmin, which possibly might 
help with
box-constrained minimization of a function of a lot of parameters like yours. 
There is a
"but", and it is that analytic gradients are almost mandatory. Moreover, our 
experience
base is mainly on unconstrained functions of many parameters. However, if you 
can debug
the function/gradient so that the number of parameters is correct and there is 
a known
correct value for f(x) for a given x, I'll be willing to give the problem a 
try. Send it
to me off-list, preferably as a zip file of R code and data (or alternatively a 
tarball).
We need to gain more experience with such functions and methods, as well as 
learn how to
formulate the problems for a good chance of success.

Best,

JN

__
R-help@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.


Re: [R] R-help Digest, Vol 95, Issue 17

2011-01-17 Thread Prof. John C Nash
For those issues with optimization methods (optim, optimx, and others) I see, a 
good
percentage are because the objective function (or gradient if user-supplied) is 
mis-coded.
However, an almost equal number are due to functions getting into overflow or 
underflow
territory and yielding quantities that the optimization tools cannot handle (NA 
or Inf etc.)

Two general approaches I find helpful:
1) even if there are no actual bounds on parameters, put in "reasonable" 
limits. They
don't need to be too tight, just enough to keep the parameters from giving a 
silly
objective function
2) do some evaluations of the objective to make sure it is really being properly
calculated. Never hurts to have some "known" outcomes.

Beyond this, we get into reparametrizations. Great idea, but far too much work 
for most of
us, even if we work in the field.

Best,

JN


On 01/17/2011 06:00 AM, r-help-requ...@r-project.org wrote:
> From: Uwe Ligges 
> To: Jinrui Xu 
> Cc: r-help@r-project.org
> Subject: Re: [R] fgev_error_matrix_singular

__
R-help@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.


[R] Minor warning about seq

2010-11-30 Thread Prof. John C Nash
I spent more time than I should have debugging a script because I wanted
   x<-seq(0,100)*0.1

but typed
   x<-seq(O:100)*0.1

seq(0:100) yields 1 to 101,
Clearly my own brain to fingers fumble, but possibly one others may want to 
avoid it.

JN

__
R-help@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.


[R] DBLEPR?

2010-11-16 Thread Prof. John C Nash
Ravi Varadhan and I have been looking at UCMINF to try to identify why it gives 
occasional
(but not reproducible) errors, seemingly on Windows only. There is some 
suspicion that its
use of DBLEPR for finessing the Fortran WRITE() statements may be to blame. 
While I can
find DBLEPR in Venables and Ripley, it doesn't get much mention after about 
2000 in the
archives, though it is in the R FAQ and Brian R. mentions they are in libR in a 
2009 post.
Are the xxxPR routines now deprecated (particularly for 64 bit systems) or 
still OK to
use?  If OK, can anyone point to documentation and examples?

JN

__
R-help@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.


Re: [R] Fitting GLM with BFGS algorithm

2010-10-27 Thread Prof. John C Nash
In the sort of problem mentioned below, the suggestion to put in gradients (I 
believe this
is what is meant by "minus score vector") is very important. Using analytic 
gradients is
almost always a good idea in optimization of smooth functions for both 
efficiency of
computation and quality of results.

Also users may want to use either updated codes (Rvmmin is BFGS algorithm with 
box
constraints; ucminf does it unconstrained) or different approaches, depending 
on the
function. Package optimx lets users discover relative properties of different 
optimizers
on their class of problems.

John Nash



> From: Dimitris Rizopoulos 
> To: justin bem 
> Cc: R Maillist 
> Subject: Re: [R] Fitting GLM with BFGS algorithm
> Message-ID: <4cc6c0db.9070...@erasmusmc.nl>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> for instance, for logistic regression you can do something like this:
> 
> # simulate some data
> x <- cbind(1, runif(100, -3, 3), rbinom(100, 1, 0.5))
> y <- rbinom(100, 1, plogis(c( x%*% c(-2, 1, 0.3
> 
> # BFGS from optim()
> fn <- function (betas, y, x) {
>-sum(dbinom(y, 1, plogis(c(x %*% betas)), log = TRUE))
> }
> optim(rep(0, ncol(x)), fn, x = x, y = y, method = "BFGS")
> 
> # IWLS from glm()
> glm(y ~ x[, -1], family = "binomial")
> 
> You can also improve it by providing the minus score vector as a third 
> argument to optim().
> 
> 
> I hope it helps.
> 
> Best,
> Dimitris

__
R-help@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.


Re: [R] maximum likelihood problem

2010-10-02 Thread Prof. John C Nash
Ravi has already responded about the possibility of using nls(). He and I also have put up 
the optimx package which allows a control 'maximize=TRUE' because of the awkwardness of 
using fnscale in optim. (optimx still lets you use optim()'s tools too, but wrapped with 
this facility.) There are a number of optimizers available through optimx. If you can 
compute gradients analytically, you will find methods that can use these much more 
efficient, and your subsequent Hessian estimates better too.


You should be aware that optimise() is for 1D problems i.e., 1 parameter to 
optimize.

John Nash



Message: 81
Date: Fri, 1 Oct 2010 16:39:58 -0400 (EDT)
From: mlar...@rsmas.miami.edu
To: r-help@r-project.org
Subject: [R] maximum likelihood problem
Message-ID:
<3675.129.171.104.122.1285965598.squir...@webmail.rsmas.miami.edu>
Content-Type: text/plain;charset=iso-8859-1

I am trying to figure out how to run maximum likelihood in R.  Here is my
situation:

I have the following equation:
equation<-(1/LR-(exp(-k*T)*LM)*(1-exp(-k)))

LR, T, and LM are vectors of data.  I want to R to change the value of k
to maximize the value of equation.

My attempts at optim and optimize have been unsuccessful.  Are these the
recommended functions that I should use to maximize my equation?

With optim I wanted the function to be maximized so I had to make the
fnscale negative.  Here is what I put:

L<-optim(k,equation,control=(fnscale=-1))

My result:   Error: could not find function "fn"


Here is what I put for optimize:

L<-optimise(equation,k,maximum=TRUE)

My result:   Error: 'xmin' not less than 'xmax'

Any advise would be greatly appreciated.
Mike



--



__
R-help@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.


Re: [R] Which language is faster for numerical computation?

2010-09-10 Thread Prof. John C Nash
Dirk E. has properly focussed the discussion on measurement rather than opinion. I'll add 
the issue of the human time taken to convert, and more importantly debug, interfaced code. 
That too could be measured, but we rarely see human hours to code/debug/test reported.


Moreover, I'll mention the cat among the pigeons of Rcgmin, which I wrote to allow me to 
play with an optimization code more easily to discover where the algorithm might be 
improved. The resulting package on some problems outperforms C equivalents. Now the code 
is quite vectorized, but this has still been a very nice surprise. In fact, I've decided 
to avoid playing around with the interfaces if I can run things well-enough entirely in R.


JN

__
R-help@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.


[R] Converting expressions to functions

2010-07-31 Thread Prof. John C Nash

Dear R colleagues,

I'm looking for some examples or vignettes or similar to suggest good ways to convert an 
expression to a function. In particular, I'd like to (semi-) automate the conversion of 
nls() expressions to residual functions. Example


Given variables y, T and parameters b1, b2, b3 in

exprtext<-"y~b1/(1+b2*exp(-b3*T))"

I'd like to generate a function

resids<-function(b, y, T){
b1<-b[1]
b2<-b[2]
b3<-b[3] # Pedestrian but hopefully clear
res<-b1/(1+b2*exp(-b3*T))-y
return(res)
}

Preferably, I want to use only R facilities rather than call Perl or Python etc. And as 
much as possible, I'd like to automate the process. There are likely several ways to proceed.


Please contact me off list. I will report my success or lack thereof to the list in the 
near future.


Thanks,

John Nash

__
R-help@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.


Re: [R] newton.method

2010-07-30 Thread Prof. John C Nash

Sometimes it is easier to just write it. See below.

On 10-07-30 06:00 AM, r-help-requ...@r-project.org wrote:

Date: Thu, 29 Jul 2010 11:15:05 -0700 (PDT)
From: sammyny
To:r-help@r-project.org
Subject: Re: [R] newton.method
Message-ID:<1280427305687-2306895.p...@n4.nabble.com>
Content-Type: text/plain; charset=us-ascii


newton.method is in package 'animation'.

Thanks Ravi.
BBSolve/BBOptim seems to work very well although I am not familiar with the
optimization methods being used there. Is there a way to specify a tolerance
in the function to get the required precision.

I did something like this to use newton method.
require(animation)
newton.method(f, init=2, tol=10*exp(-8))
But it gives bogus results.

If someone could point me a correct working version of newton method for
finding roots and its usage, that would be helpful.

cheers,

Sam




tfn<-function(x) {
 f = 2.5*exp(-0.5*(2*0.045 - x)) + 2.5*exp(-0.045) + 2.5*exp(-1.5*x) - 100
 return(f)
}
tgr<-function(x) {
 g = 0.5*2.5*exp(-0.5*(2*0.045 - x))  -1.5*2.5*exp(-1.5*x)
 return(g)
}
newt<-function(start, fun, grad) {
x<-start
newx<-x+100 # to avoid stopping
while( 1 != 0) {
   f<-fun(x)
   g<-grad(x)
   newx<-x-f/g
   cat("x, newx, f, g:",x,' ',newx,' ',f,' ',g,"\n")
   if ((100+x) == (100+newx)) return(newx)
   tmp<-readline("continue?")
   x<-newx
}
}

You can try

   newt(7,tfn, tgr)

   newt(-7,tfn,tgr)

and get both roots quite quickly.

However, I'd probably used uniroot by preference as a general tool. The scripts above are 
meant for learning purposes.


Best,

John Nash

PS. I did check tgr with numDeriv -- always worth doing.

__
R-help@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.


[R] Not nice behaviour of nlminb (windows 32 bit, version, 2.11.1)

2010-07-10 Thread Prof. John C Nash
I won't add to the quite long discussion about the vagaries of nlminb, but will note that 
over a long period of software work in this optimization area I've found a number of 
programs and packages that do strange things when the objective is a function of a single 
parameter. Some methods quite explicitly throw an error when n<2. It seems nlminb does 
not, but that does not mean that the authors ever thought anyone would use their large 
package to solve a small 1D problem, or if they did, whether they seriously tested for the 
awkward things that happen when one only has one parameter. I've seen similar things go 
wrong with matrix packages e.g., eigensolutions of 1 by 1 matrices.


So this msg is to watch carefully when problems are n=1 and put in some checks that 
answers make sense.


JN

__
R-help@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.


Re: [R] selection of optim parameters

2010-07-06 Thread Prof. John C Nash

Without the data and objective function, it is fairly difficult to tell what is 
going on.

However, we can note:

- no method is specified, but it would have to be L-BFGS-B as this is 
the only
one that can handle box constraints

- the fourth parameter is at a different scale, and you are right to think about 
this, especially as you don't seem to be providing analytic gradients.


Options:
- I would definitely rescale your function i.e., in the code, so your rawpar[4] 
is
1*par[4]. That gets all the scales approx. the same, assuming your start reflects the 
eventual answer

- try bobyqa from minqa package once scaled -- it really doesn't like scale 
differences.

If you have data and a script nicely packaged that can be emailed, I'll take a look at it. 
If analytic gradients can be provided, there are more possibilities too, e.g., Rvmmin. spg 
from BB package also does constraints.


It may, of course, turn out that the solution really is on the boundary.

JN




Message: 47
Date: Mon, 05 Jul 2010 21:53:18 +0200
From: Fabian Gehring 
To: r-help@r-project.org
Subject: [R] selection of optim parameters
Message-ID: <4c32382e.3050...@bluewin.ch>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed

Hi all,

I am trying to rebuild the results of a study using a different data
set. I'm using about 450 observations. The code I've written seems to
work well, but I have some troubles minimizing the negative of the
LogLikelyhood function using 5 free parameters.

As starting values I am using the result of the paper I am rebuiling.
The system.time of the calculation of the function is about 0.65 sec.
Since the free parameters should be within some boundaries I am using
the following command:

optim(fn=calculateLogLikelyhood, c(0.4, 2, 0.4, 8, 0.8),
lower=c(0,0,0,0,0), upper=c(1, 5, Inf, Inf, 1), control=list(trace=1,
maxit=1000))

Unfortunately the result doesn't seem to be reasonable. 3 of the
optimized parameters are on the boundaries.

Unfortunately I don't have much experience using optimizatzion methods.
That's why I am asking you.
Do you have any hints for me what should be taken into account when
doing such an optimization.

Is there a good way to implement the boundaries into the code (instead
of doing it while optimizing)? I've read about parscale in the
help-section. Unfortunately I don't really know how to use it. And
anyways, could this help? What other points/controls should be taken
into account?

I know that this might be a bit little information about my current
code. But I don't know what you need to give me some advise. Just let me
know what you need to know.

Thankds




__
R-help@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.


Re: [R] Optimizing given two vectors of data (confusedSoul)

2010-06-25 Thread Prof. John C Nash

I am trying to estimate an Arrhenius-exponential model in R.  I have one
vector of data containing failure times, and another containing
corresponding temperatures.  I am trying to optimize a maximum likelihood
function given BOTH these vectors.  However, the optim command takes only
one such vector parameter.

How can I pass both vectors into the function?


You need to combine your vectors

  params<-c(vecone, vectwo)

Inside your objective function, you will need to split them out again.

However, I have some suspicions that you are referring to the DATA for the function rather 
than the parameters that are being optimized. The data goes into the '...' arguments to 
optim and other optimization tools.


JN

__
R-help@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.


[R] Subject: Re ZINB by Newton Raphson??

2010-06-22 Thread Prof. John C Nash
I have not included the previous postings because they came out very strangely on my mail 
reader. However, the question concerned the choice of minimizer for the zeroinfl() 
function, which apparently allows any of the current 6 methods of optim() for this 
purpose. The original poster wanted to use Newton-Raphson.


Newton-Raphson (or just Newton for simplicity) is commonly thought to be the "best" way to 
approach optimization problems. I've had several people ask me why the optimx() package 
(see OptimizeR project on r-forge -- probably soon on CRAN, we're just tidying up) does 
not have such a choice. Since the question comes up fairly frequently, here is a response. 
I caution that it is based on my experience and others may get different mileage.


My reasons for being cautious about Newton are as follows:
1) Newton's method needs a number of safeguards to avoid singular or indefinite Hessian 
issues. These can be tricky to implement well and to do so in a way that does not hinder 
the progress of the optimization.
2) One needs both gradient and Hessian information, and it needs to be accurate. Numerical 
approximations are slow and often inadequate for tough problems.
3) Far from a solution, Newton is often not very good, likely because the Hessian is not 
like a nice quadratic over the whole space.


Newton does VERY well at converging when it has a "close enough" start. If you can find an 
operationally useful way to generate such starts, you deserve awards like the Fields.


We have in our optimx work (Ravi Varadhan and I) developed a prototype safeguarded Newton. 
As yet we have not included it in optimx(), but probably will do so in a later version 
after we figure out what advice to give on where it is appropriate to apply it.


In the meantime, I would suggest that BFGS or L-BFGS-B are the closest options in optim() 
and generally perform quite well. There are updates to BFGS and CG on CRAN in the form of 
Rvmmin and Rcgmin which are all-R implementations with box constraints too. UCMINF is a 
very similar implementation of the unconstrained algorithm that seems to have the details 
done rather well -- though BFGS in optim() is based on my work, I actually find UCMINF 
often does better. There's also nlm and nlminb.


Via optimx() one can call these, and also some other minimizers, or even "all.methods", 
though that is meant for learning about methods rather than solving individual problems.


JN

__
R-help@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.


[R] R licensing query

2010-06-19 Thread Prof. John C Nash
I think that Marc S. has provided some of the better refs. for R and its usage 
in
commercial and organizational settings.

However, the kinds of bloody-minded "We're going to insist you use 
inappropriate software
because we are idiots" messages are not news to many of us. Duncan points out 
that R has
"Absolutely no warranty", but unlike Excel, you are allowed to comment on it. 
It is very
clear to some of us that the IT folk who like to use Microsoft software in a 
mindless way
have never read the EULA or asked their legal advisors about its lack of 
warranty AND the
fact you are not permitted to warn your friends in reviews or opinions, at 
least if you
keep to the EULA.. Fortunately, there are people who do try to provide 
warnings. I
recommend The European Spreadsheet Risks Interest Group http://eusprig.org/ 
especially
their horror stories -- were talking big money here. They've been going a 
while. I
participated in the 2003, 2004 and 2005 conferences, but finally decided I'd 
have more
success convincing people to use R than to use spreadsheets responsibly. Eric 
Neuwirth and
Thomas Baier have some R-Excel interfaces that take a different approach that 
is interesting.

As a tangential approach, are your IT folk willing to offer virtual machines? 
In our
Telfer School setup, the orthodoxy is strongly Win-obsessed, but it turns out 
there were
some applications powerful folk needed that use Linux etc.  VMWare was the 
chosen
solution, and it allowed me to have my own Ubuntu setup. I'm happy not to be 
bothered with
all the virus checking and install controls of the central system, and the IT 
folk aren't
worried I'll cause trouble for them either. My machine cannot send email 
outside the local
domain (to control spam forwarding), but that is a pretty minor issue.

JN

__
R-help@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.


Re: [R] an alternative to R for nonlinear stat models

2010-06-16 Thread Prof. John C Nash
I'd echo Paul's sentiments that we need to know where and when and how R goes 
slowly. I've
been working on optimization in many environments for many years (try ?optim 
and you'll
find me mentioned!). So has Dave Fournier. AD Model Builder has some real 
strengths and we
need Automatic Differentiation in R -- hence the Google Summer of Code project 
in which
I'm mentoring Chillu (see the R Wiki for some info on this). But it will be a 
while before
we really have really good interfaces to such capability. There is already some 
capability
for ADMB. Dave F. may even agree with me when I suggest that most users find 
ADMB and
indeed most optimization tools quite an effort to use.

Moreover, there's a general feeling that to "go fast" you need to "go C". Yet 
my package
Rcgmin is all in R, and does large-n optimization via a more modern CG method 
than optim's
CG (I've primary rights to complain as the latter is based on my own code.) Yet 
on some
fairly common test problems it often goes extremely fast. We're talking 3 
seconds to
minimize a function of 5000 parameters on an Asus netbook (with analytic 
derivatives). BUT
... sometimes I can slow it down by just changing the starting vector.

We're statisticians -- so let's make sure the sample is large enough and 
representative
enough. But my main messages here:

  - we need to know about the problems and have them available to use as tests
  - we should aim for easy-to-use and consistent interfaces to the R tools so 
we are
not having to constantly write "glue" code to get things to work and 
additionally put
ourselves at risk of introducing errors.

JN




> Message: 119 Date: Wed, 16 Jun 2010 09:36:24 +0200 
>  From: Paul Hiemstra  
>  To: benedikt.g...@ieu.uzh.ch Cc: r-help@r-project.org, da...@otter-rsch.com 
> Subject: 
>  Re: [R] an alternative to R for nonlinear stat models 
>  Message-ID: <4c187ef8.1050...@geo.uu.nl> Content-Type: text/plain; 
> charset=ISO-8859-1; format=flowed 
>  On 06/16/2010 07:35 AM, benedikt.g...@ieu.uzh.ch wrote:
>> > Hi
>> > I implemented the age-structure model in Gove et al (2002) in R, which 
>> > is a
>> > nonlinear statistical model. However running the model in R was very 
>> > slow.
>> > So Dave Fournier suggested to use the AD Model Builder Software 
>> > package and
>> > helped me implement the model there.
>> > ADMB was incredibly fast in running the model:
>> > While running the model in R took 5-10 minutes, depending on the 
>> > settings,
>> > in ADMB it took 1-2 seconds!
>> > I'm reporting this so that people who have performance issues with 
>> > nonlinear
>> > statistical models in R will know that there is a good free 
>> > alternative for
>> > more difficult problems.
>> > There  is also a help platfrom equivalent to the one for R, and people
>> > running it are extremley helpful.
>> > I hope this might help someone
>> > cheers
>> > Beni
>> > __
>> > R-help@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.
>> >
> Hi Beni,
> 
> Thanks for posting information that might be useful for people on the 
> list. The only thing is that without a little more detail on how exactly 
> you implemented things in R, we are left to guess if the performance 
> issues are a problem of R, or that your particular implementation was 
> the problem. There are was of implementing R code in two ways, where the 
> first takes minutes and the second 1-2 seconds. Furthermore, you are 
> giving us no option to defend R  ;) .
> 
> cheers,
> Paul
> 
> -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences 
> University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: 
> +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri 
> http://intamap.geo.uu.nl/~paul 
> http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 
> --

__
R-help@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.


Re: [R] Wait for keystroke or timeout

2010-05-28 Thread Prof. John C Nash
Matt's suggestion works in Linux (I use Ubuntu and Debian variants), but I 
haven't yet
been able to get it to work in Windows. In a DOS terminal, I can run Cygwin's 
blas.exe via

   blas -c "read -t 1 -n 1"

and get the right functioning, but when embedded in R in various ways, I get 
several error
messages that imply R is not finding or interpreting the command correctly.

As the details are arcane, please contact me off-line, and I'll report back to 
the list
when we have a solution.

However, if someone could try Matt's suggestion on a Mac and let me know 
outcome, that
would be helpful. Since .Platform allows me to determine OS type, I should be 
able to work
out a more or less platform-independent function.

JN

biostatmatt wrote:
> On Thu, 2010-05-27 at 19:08 -0400, Prof. John C Nash wrote:
>> I would like to have a function that would wait either until a specified 
>> timeout (in
>> seconds preferably) or until a key is pressed. 
>  If you are using Linux
> you can use try this
> 
>> system("read -t 1 -n 1")
> 
> where -n indicates the number of characters to read and -t specifies the
> timeout in seconds.

__
R-help@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.


[R] Wait for keystroke or timeout

2010-05-27 Thread Prof. John C Nash
I would like to have a function that would wait either until a specified 
timeout (in
seconds preferably) or until a key is pressed. I've found such a function quite 
useful in
other programming environments in setting up dialogs with users or displaying 
results,
rather like a timed slideshow that can be speeded up by hitting a key.

Searching R-seek has led to wait() in the package 'audio', but when I try, for 
example,

joe<-wait(readline("hit a key to continue"), timeout=6)

I am forced to wait the full timeout.

Probably someone has done this before and I'm just not using the right search 
terms.
Suggestions welcome.

Thanks in advance.

JN

__
R-help@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.


Re: [R] R CMD REMOVE etc. query

2010-04-15 Thread Prof. John C Nash
Brian Ripley pointed out that the library() documentation (third screen, however) says 
that library() and require() check current environment to see if a package is loaded and 
only load if it is not present. I may have oversimplified, and clarifications welcome. But 
this is clearly NOT what I want, since I need the latest package version to test.


Tentative solution is outlined, but suggestions welcome on string cleanup issue 
mentioned.

As I need to remove a package and its dependencies before reloading, I can use 
tool::pkgDepends to get a list.


I found that a character string extracted from the dependency vector gives 'invalid name' 
error in detach(). That is, I can create a variable myfoo="package:foo", but detach(myfoo) 
gives the error while typing detach("package:foo") works fine.  Workaround seems to be


   slist<-search()
   idx<-which(slist==myfoo)
   detach(idx)

There's still a nuisance issue of how to strip off  the (>=0.7.11) descriptors in the 
dependency list. strsplit() will work, but I seem to need to loop through the list to use 
it when only some of the packages are restricted by qualifiers.


If someone has already dealt with this type of issue, I'd be happy to know. For example, 
if there is a forceLoad() somewhere, it would save the effort above and could be useful 
for developers to ensure they are using the right version of a package.


JN




From: Prof. John C Nash 
Date: Thu, 15 Apr 2010 10:17:46 -0400

I've been working on a fairly complex package that is a wrapper for several 
optimization routines. In this work, I've attempted to do the following:

* edit the package code foo.R
* in a root terminal at the right directory location 


R CMD REMOVE foo 


R CMD INSTALL foo 


However, I don't get the right code. In fact, if I just do the remove,

 library(foo)

does not throw an error. If I stop my R session and restart it, I do.

Is this expected behaviour?

For information, I run scripted tests that start with

rm(list=ls())
library(foo)

to ensure I'm getting "new" code each time.

If desired I can provide a minimal package to show this, but I expect that it 
is a known issue for which I've missed the documentation. Perhaps there is a 
command to reset the session. I did a brief search, but appropriate keywords 
pick up a lot of irrelevant material.

JN


__
R-help@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.


Re: [R] R CMD REMOVE etc. query

2010-04-15 Thread Prof. John C Nash
I've been working on a fairly complex package that is a wrapper for several optimization 
routines. In this work, I've attempted to do the following:


- edit the package code   foo.R
- in a root terminal at the right directory location
R CMD REMOVE foo
R CMD INSTALL foo

However, I don't get the right code. In fact, if I just do the remove,

library(foo)

does not throw an error. If I stop my R session and restart it, I do.

Is this expected behaviour?

For information, I run scripted tests that start with
   rm(list=ls())
   library(foo)

to ensure I'm getting "new" code each time.

If desired I can provide a minimal package to show this, but I expect that it is a known 
issue for which I've missed the documentation. Perhaps there is a command to reset the

session. I did a brief search, but appropriate keywords pick up a lot of 
irrelevant material.

JN

__
R-help@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.


Re: [R] Restricting optimisation algorithm's parameter space

2010-04-03 Thread Prof. John C Nash
I have a problem. I am  using the NLME library to fit a non-linear model. There is a linear  component to the model that has a couple parameter values that can only  be positive (the coefficients are embedded in a sqrt). When I try and  fit the model to data the search algorithm tries to see if a negative  value for one of these parameter values will produce an optimal fit. When  it does so, it crashes because the equation can not have a negative  value because its in a sqrt function. 


QUESTION: How do I  restrict the optimisation algorithm's  parameter space so 
it does not  search negative values when using GNLM? Are there other Libraries 
that Fit Non-linear models and allow for one to control the parameter space the 
search algorithm is restricted by?


There are two issues here:

1) Rendering optimization codes resistant to inadmissible parameter vectors (sqrt of 
negatives etc.)


2) Providing constraints, particularly parameter bounds, on parameter inputs to 
optimization.

There is quite a lot of activity going on right now with optimization in R. With Ravi 
Varadhan, Kate Mullen and Paul Gilbert, I've been putting some codes on R-forge in the 
OptimizeR project. Doug Bates has done some important kibbitzing. Stefan Theussl and 
others have the R Optimization Infrastructure. There are some differences of focus in 
these projects.


For the present poster, I cannot unfortunately help much on GNLM details, but I can say 
that there are trial versions of methods that will handle bounds (packages minqa, Rcgmin 
and Rvmmin) that accept bounds, along with existing L-BFGS-B in optim(). Rcgmin and Rvmmin 
also accept "masks", that is fixed parameters. These routines are about to go into CRAN.


It appears GNLM is not a CRAN package. Does it permit substitution of optimizer? That is 
something those of us working in optimization strongly recommend to package writers i.e., 
make the optimization a black box so any of a number of tools can be slotted in easily. 
That way, advances or even minor fixups to routines can be included in tools quickly.


However, the "bad parameters" issue, such as trying to take square root of negatives, 
requires the user or the writer of a package that the user calls to code the objective 
function to return a flag -- we are looking at an Inf or an NA, we are not yet fully 
decided on the rules -- AND the optimization package writer to then make it act 
appropriately. Mary Walker-Smith and I had this in BASIC codes in the 1980s, but we were 
maybe a bit ahead of folk and it didn't catch on generally.


If R users have some nice examples of things crashing because of such issues, I would 
really like to hear of them off-list. For us, "nice" means pretty small and easy to build 
into tests. Without such tests -- and users always provide better ones than we can think 
of -- the code is never as robust.


JN

__
R-help@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.


[R] Error "singular gradient matrix at initial parameter estimates" in nls

2010-03-31 Thread Prof. John C Nash

If you have a perfect fit, you have zero residuals. But in the nls manual page 
we have:


Warning:

 *Do not use ‘nls’ on artificial "zero-residual" data.*


So this is a case of complaining that your diesel car is broken because you ignored the 
"Diesel fuel only" sign on the filler cap and put in gasoline.


However I've not been happy with this choice in the code of nls -- it's been there a long 
time -- and my own codes from 1974 onwards have always handled zero residual cases. I do 
believe that the code could at least give a better diagnostic message. Zero residuals -- 
perfect fits -- arise when one is interested more or less in an interpolating function 
rather than doing statistics, and I can understand the reluctance of statisticians to 
countenance such a use of nls.


And Bert's comment on overparametrization is almost certainly valid also.

JN

__
R-help@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.


Re: [R] What does "Odp" mean?

2010-03-05 Thread Prof. John C Nash
Though I've been on the list for quite a while, I've not yet figured out what the "Odp:" 
entry in subject lines means. Is it important information?


JN

__
R-help@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.


[R] Simulation conference -- possible R opportunity

2010-03-01 Thread Prof. John C Nash
I have been talking with Gabriel Wainer about the possibility of some community building 
with R and simulation workers. The conference announced below is just before UseR (but in 
that capital to the north of Washington).


If anyone on this list is participating or thinking of participating, perhaps they could 
let me know off-list. Ottawa-Gatineau R User Group would likely try to set up some 
informal meet-and-greet if there are folk who can help convey what R is to simulation 
researchers. (Simulation not a big part of my own activities, I'm afraid.)



John Nash



2010 Summer Computer Simulation Conference (SCSC'10)

 11-14 July 2010 - Ottawa, ON, Canada

  CALL FOR PAPERS
(DEADLINE EXTENDED - MARCH 22,2010)

 http://www.dacya.ucm.es/jlrisco/SCSC10/

http://simulation.ning.com


  Organized by the Society for Modeling and Simulation International
   Co-Sponsored by ACM SIGSIM and ICST (pending)


Come to Ottawa, Canada for SCSC 2010 to witness the 42nd edition of this
leading conference in the field of Modeling and Simulation. SCSC’10 is
focused on basic and applied research in modeling and simulation.

SCSC 2010 features varied tutorials, tracks and workshops. The conference
focuses on modeling and simulation, tools, theory, methodologies and
applications, providing a forum the latest R&D results in academia and
industry.

All submissions will be reviewed based on the draft full paper and/or
extended abstract. The best contributed paper will be given an award. A
selected group of full papers will be selected for possible publication in a
special issue of the Simulation Journal (SCS). All papers will be published
in the ACM and the EU Digital Libraries (pending).


Important Dates:

Submission of full papers (and tutorials proposals): March 22nd, 2010
Notification of acceptance:  April 30th, 2010
Final manuscript and Early Registration: May 28th, 2010


General Chair:
Gabriel Wainer, SCE, Carleton University, Canada

Program Chairs:
Mhamed Itmi, INSA Rouen, France
Peter Kropf, Université de Neuchâtel, Switzerland3
Andreas Tolk, VMASC, USA


Current Tracks & Workshops:
Agent-Directed Simulation
Applications in Business, Management, Planning & Logistics
C3 - Complexity, Chaos and Combinatorics
Computer Graphics for Simulation
Emergency Simulation
Engineering and Management in the M&S Discipline
Executable Architecture (EA)
M&S for Defense & Security
Microarchitecture and circuits simulation (MCS)
Model-based Design and Simulation
Modeling and Simulation of Dynamic Structure Systems
Modeling and simulation languages
Modeling and Simulation of Ultra-Large-Scale Systems (MSULSS)
Simulation in Healthcare and Bioinformatics
Simulation for Transportation
Simulation of Complex Social Systems (SiCoSSys)
Simulation Education
Simulation for Transportation
Vivid representing, artificial to human

__
R-help@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.


[R] how to install rattle for data mining

2010-02-26 Thread Prof. John C Nash
Besides the suggestions made by others, you may want to look at the R-wiki, where there is 
a section on installing rattle and its dependencies, but mostly for Linux distros. Rattle 
involves lots of other tools, which makes it challenging to install.  You could do the 
community a service by adding a section on Windows installs. And someone with Mac 
experience might do likewise. The wiki offers a chance -- but not a guarantee -- that 
information that appears over several posts here can be consolidated.


JN






Message: 1
Date: Thu, 25 Feb 2010 03:06:40 -0800 (PST)
From: chinna 
To: r-help@r-project.org
Subject: [R] how to install rattle for data mining
Message-ID: <1267096000783-1568841.p...@n4.nabble.com>
Content-Type: text/plain; charset=us-ascii


 library(rattle)
Loading required package: pmml
Loading required package: XML
Error: package 'XML' could not be loaded
In addition: Warning message:
In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc =
lib.loc) :
  there is no package called 'XML'



i have installed glade package 


>install.packages("RGtk2")
> install.packages("rattle")


__
R-help@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.


[R] non-linear contrained optimization

2010-02-18 Thread Prof. John C Nash
If the data is fairly small, send it and the objective function to me off-list and I'll 
give it a quick try.


However, this looks very much like the kind of distance-constrained type of problem like 
the "largest small polygon" i.e., what is the maximum area hexagon where no vertex is more 
than 1 unit from another. (It is NOT a regular hexagon! More like a dented pentagon.)

Such problems are often better posed using polar coordinates, but the setup 
takes work.

If you are going to have to do a lot of these problems, it will be worthwhile looking into 
ways to get very good starts, in which case a very crude method using penalty or barrier 
functions could be effective.


John Nash




From: Brandon Zicha 
Subject: [R] non-linear contrained optimization
Message-ID: <33c13a02-f603-410a-871d-e78dde272...@ua.ac.be>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

I have searched the previous help boards and discovered the problem  
with Rdonlp2 - Specifically, its non-availability. I thought that this  
was my solution, but perhaps there is a better way that you all could  
help me with.  I imagine that this problem is trivial to people such  
as the experts on this mailing list.


I am trying to solve this problem over and over again in a simulation:

I want to find the values of x and y which minimize
f(x,y) = sqrt((z-x)2+(w-y)2

subject to the constraints:
0=< sqrt((z2-x)2+(w2-y)2) - d2
0=< sqrt((z3-x)2+(w3-y)2) - d3
.
0=< sqrt((zk-x)2+(wk-y)2) - dk

where zi, wi, di are known scalars.

I would appreciate any help with how to implement this in R.

Many thanks,

Brandon Z.

University of Antwerp


__
R-help@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.


[R] Trouble with optim function

2010-02-18 Thread Prof. John C Nash
optim really isn't intended for [1D] functions. And if you have a constrained search area, 
it pays to use it. The result you are getting is like the second root of a quadratic that 
you are not interested in.


You may want to be rather careful about the problem to make sure you have the function you 
intend.



I'm trying to make a little script to determine an "unknown" rate for a 
number of known exponential trials.




My Code:
#Set Trials and generate number
trials=100
rand<-runif(1,0,1)
vector=0

#Generate vector of 100 random exponentials and sum them
for (i in 1:100) {
vector<-rexp(trials,rate=rand)
}
sumvect=sum(vector)

#Create the log likelihood function
LL<-function(x) {(trials*log(x))-(x*sumvect)}

optim(1,LL,method="BFGS")



The "rand" variable should be between 0 and 1 and is what I am trying to 
approximate. However, as it is I generally get a value in the tens of 
thousands. I'm sure it's something simple but I can't find my error.


How about?

> ans2<-optimize(f=LL,interval=c(0,1))
> ans2
$minimum
[1] 6.610696e-05

$objective
[1] -962.4322

>

J Nash

__
R-help@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.


Re: [R] Does the R "statistical language includes, > modules/packages to carry out nonlinear optimization similar to the, > SAS NLIN and NLP procedures?

2010-02-17 Thread Prof. John C Nash
There is also the OptimizeR project on R-forge 
http://r-forge.r-project.org/R/?group_id=395. Other related projects are there also, but 
I'll let their authors speak for themselves. Stefan Theussl did a good job in the Task 
View, but it is from last June, and it would be a monumental effort to keep up to date 
with all the work going on.


We're "almost" ready to put some of our updated functions on CRAN, mainly for smooth 
functions with at most box constraints. Within that caveat, the codes are working, but 
they may not be fully bullet-proof or documented. We plan more material as we can get 
round to it.


For discussion, with rather up and down traffic that takes various directions, I also run 
a wiki called optimx at http://macnash.telfer.uottawa.ca/optimx/doku.php but only the 
first page is publicly visible as we use it to discuss ideas that may be half (or less!) 
baked. However, I'm happy to give logins on request to genuine R folk and there have been 
some quite useful ideas exchanged. Unfortunately, one of my colleagues' wikis had a 
pornographer "contributing", so do provide real name and affiliation when asking for access.


JN



Date: Tue, 16 Feb 2010 11:09:35 -0500
From: "Powers, Randall - BLS" 
To: 
Subject: [R] Does the R "statistical language includes
modules/packages to carry out nonlinear optimization similar to the
SAS NLIN andNLP procedures?
Message-ID:

Content-Type: text/plain

Hello R folks,

I'm hoping the answer to the question in the subject line.

I have in the past used SAS PROC NLIN and PROC NLP to carry out
nonlinear optimizations. I'm wondering if there is analogous ways for
doing this using R. If so, could someone please point me to some
literature that would help me examine this further?

Thanks very much.


__
R-help@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.


[R] R Group on LinkedIn has new book discounts

2010-02-11 Thread Prof. John C Nash
Has anyone else experienced frustration with the LinkedIn site. It's been spamming me 
since I tried to join, and I seem to see R postings, but I've never been able to "confirm" 
my email address i.e., it never sent me THAT email. So I can never get past the login 
screen to see more than the subject headings.


There's been several postings there I might like to respond to and help folk, but  And 
I might want to enjoy a book discount.


JN

__
R-help@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.


[R] R wiki link ?

2010-02-08 Thread Prof. John C Nash
Is this a transient problem, or has the link to the R wiki on the R home page 
(www.r-project.org) to http://wiki.r-project.org/ been corrupted? I can find

http://rwiki.sciviews.org that works.

JN

__
R-help@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.


Re: [R] iterative regressions, adding a new line of data each, time

2010-02-02 Thread Prof. John C Nash
Possibly of limited use to the original poster, but of interest more generally, there are 
a number of tools developed in the 70s for updating the matrix decompositions. There's at 
least one in my 1979 book "Compact numerical methods for computers" (still in print 
apparently) -- we didn't have enough space to keep all the data in the HP9830A machine. If 
there's sufficient interest, I can probably come up with some suitable references.


Beyond the historical interest, however, it may be that the updating of the decompositions 
is useful in improving efficiency of computation and revealing structure of the problems. 
The cost, of course, is in writing the R interface code, so unless one needs to solve a 
lot of problems, I'd use R's resources, though possibly via svd.


JN

__
R-help@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.


[R] obtain intermediate estimate using optim

2009-12-11 Thread Prof. John C Nash


Doing a hessian estimate at each Nelder-Mead iteration is rather like going 
from den Haag
to Delft as a pedestrian walking and swimming via San Francisco. The structure of the 
algorithm means the Hessian estimate is done in addition to the NM work.


While my NM code was used for optim(), I didn't do the interfacing. The 
reporting choices
are reasonably good, but don't necessarily suit your current needs. I'd 
recommend going to
r-forge and installing my updated BFGS code. See
http://r-forge.r-project.org/R/?group_id=395 for a list of the codes -- Rvmmin 
is the one
you want) which is all in R so you can put in output where you choose. It also 
has bounds
constraints, which are quite useful to avoid roaming into unsuitable areas of 
the
parameter space. While Rvmmin works best with analytic gradients, it does OK 
most of the
time with numeric approximations. It keeps an approximate inverse hessian, but 
I would not
assume that bears too much resemblance to the real hessian. Package ucminf uses
essentially the same algorithm (unconstrained only), and the detailed tactics 
seem to be
well-thought out.  However, I don't know how well reporting can be controlled 
(it is R
interfaced to Fortran).

A derivative free method that may be worth a try is bobyqa in the minqa package 
at the
same site as above. This is Mike Powell's code. The output can be set quite 
detailed by
pushing the reporting control (iprint) higher. Again R -> Fortran interface 
(thanks to
Kate Mullen).

Ravi Varadhan has several NM versions in R also, but I don't think they are yet 
on r-forge.

If you try any of these, you can help us improve them by reporting 
success/failure off
list. We believe that they are in pretty good shape, but there are always 
interfacing and
tuning issues.

Cheers, JN




Message: 1
Date: Thu, 10 Dec 2009 12:40:17 +0100
From: Lisanne Sanders 
Subject: [R] obtain intermediate estimate using optim
To: 
Message-ID: 
Content-Type: text/plain


Hi,

Currently I am trying to solve a minimization problem using optim as method Nelder-Mead. However, Neldel-Mead needs many iterations until it finally converges. I have set $control.trace and $control.report such that I can see the value of the function at each iteration. I do see that I set the convergence criteria to strict in the sense that the function value does not change much. However, before loosening my convergence criteria, I was wondering how to progamm that I can see the estimates of the true parameters and of the hessian such that I can see whether they do not change much either. Than I can adjust my convergence criteria such that he ends at that point. I do know how to adjust the convergence parameters but I do not know how to obtain intermediate estimates of the parameters. I was wondering whether someone can help me with this. 


Kind regards,

Lisanne Sanders


__
R-help@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.


[R] R CMD check glitch (resolved)

2009-12-10 Thread Prof. John C Nash

Today I wanted to update one of my r-forge packages (optimx) and when I ran the 
usual

R CMD check optimx

I got all sorts of odd errors with Latex (and a very slow R CMD check). I thought I had 
managed to damage the Rd file, which indeed I had changed. Since I recently started using 
Ubuntu 9.04 (Jaunty) but had kept an alternative boot on a separate disk to 8.04 (Hardy). 
On reboot, the R CMD check worked fine. I thought that maybe I needed to reinstall 
pdflatex, which turns out to be part of some of the tetex packages. Since fonts seemed to 
be at the heart of my problem, I installed tetex-bin, and problems went away.


I'm not sure how this sort of glitch should be documented, but thought at least a mention 
here might help some others.


JN

__
R-help@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.


Re: [R] optim with constraints

2009-12-07 Thread Prof. John C Nash


Without the data / script, I'm guessing that it is likely an attempt to evaluate the loss 
function at an inadmissible point e.g., at the constraint where there is a log(0). 
Different optimization tools handle things differently, and there are a couple of us 
working (very slowly due to other things) on trying to provide a nice wrapper to catch 
these exceptions so that they can be handled better.


JN



Message: 56
Date: Sun, 6 Dec 2009 17:32:54 -0800 (PST)
From: Steven 
Subject: Re: [R] optim with constraints
To: r-help@r-project.org
Message-ID:
<88d5c01d-c30c-4e91-900c-2b825d5e3...@z4g2000prh.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi, Prof Nash

Thanks for your comment!

I modified my code to be (added an extra parametr):

optim(c(1.14,0.25,0.06), weibull.like, mydata=mydata, method="L-BFGS-
B", hessian = TRUE, lower = c(0, 0, 0), upper = c(Inf, Inf, 1))

But I had the following error:

Error in optim(c(1.14, 0.25, 0.06), weibull.like, mydata = mydata,
method = "L-BFGS-B",  :
  non-finite finite-difference value [2]

What does that mean? Much appreciate your help!

Steven



__
R-help@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.


Re: [R] optim with constraints

2009-12-06 Thread Prof. John C Nash

As per  ?optim


Usage:

 optim(par, fn, gr = NULL, ...,
   method = c("Nelder-Mead", "BFGS", "CG", "L-BFGS-B", "SANN"),
   lower = -Inf, upper = Inf,
   control = list(), hessian = FALSE)


Note that the optimx() function on R-forge
http://r-forge.r-project.org/R/?group_id=395
is a wrapper that allows some other methods too.

JN





Message: 72
Date: Sun, 6 Dec 2009 02:53:55 -0800 (PST)
From: Steven 
Subject: [R] optim with constraints
To: r-help@r-project.org
Message-ID:
<5e293933-91f2-48f7-98e5-bc87905c5...@x25g2000prf.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi, dear R users

I am a newbie in R and I wantto use the method of meximum likelihood
to fit a Weibull distribution to my survival data. I use "optim" as
follows:


optim(c(1, 0.25),weibull.like,mydata=mydata,method="L-BFGS-B",hessian
= TRUE)

My question is: how do I setup the constraints so that the two
parametrs of Weibull to be pisotive? Or should I use other function
like"nlm"?

Many thanks! Any comments are greatly appreciated!

Steven


__
R-help@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.


Re: [R] Starting estimates for nls Exponential Fit

2009-12-02 Thread Prof. John C Nash
Kate is correct. The parameter scaling helps quite a bit, but not enough
to render the problem "nice" so that many "reasonable" starting points
will give useful results. Indeed, a run using "all.methods=TRUE" in our
optimx package (on r-forge at
http://r-forge.r-project.org/R/?group_id=395) gives

  par  fvalues  method   fns grs itns conv
4   2.194931, 1.01, 1.27 566407.6 nlmNA  NA   30
1 2.1949335, -9.0413113, 0.7516435 566407.6   BFGS37   6 NULL0
2  2.1950009, 0.2548318, 1.1163498 566404.6 Nelder82  NA NULL0
3 1.974226, 1.829957, 1.681338 2409.771   SANN 1  NA NULL0
6  1.9904045, 0.6151421, 1.7559401 1696.497  ucminf51  51 NULL0
5  1.9906488, 0.6012996, 1.7575365 1696.248  nlminb80 166   510
   KKT1  KKT2
4 FALSE FALSE
1  TRUE FALSE
2 FALSE FALSE
3 FALSE  TRUE
6 FALSE  TRUE
5 FALSE  TRUE
>

A bit of a dog's dinner.

On the positive side, this is a simple but nasty problem to illustrate
lots of the issues with nonlinear parameter estimation.

JN



Katharine Mullen wrote:
> You used starting values:
>pa <- c(1,2,3)
> 
> but both algorithms (port and Gauss-Newton) fail if you use the slightly
> different values:
>pa <- c(1,2,3.5)
> 
> Scaling does not fix the underlying sensitivity to starting values.
> pa[3] in particular cannot be above ~3.15 for GN and ~3.3 for port; both
> alg. also fail if there is insufficient spread (e.g., both fail for
> pa <- c(1,1.25,1.5) ).
> 
> For the record, DE uses (by default at least) a random start and for bad
> starts will sometimes fail to give good results; decrease the probability
> this happens by increasing itermax from the default itermax=200, as in:
> 
> ss <- DEoptim(fun, lower=rep(0,3), upper=c(10e7, 10, 10),
>   control=list(trace=FALSE, itermax=1000))
> 
> On Wed, 2 Dec 2009, Prof. John C Nash wrote:
> 
>> Kate Mullen showed one approach to this problem by using DEOptim to get
>> some good starting values.
>>
>> However, I believe that the real issue is scaling (Warning: well-ridden
>> hobby-horse!).
>>
>> With appropriate scaling, as below, nls does fine. This isn't saying nls
>> is perfect -- I've been trying to figure out how to do a nice job of
>> helping folk to scale their problems. Ultimately, it would be nice to
>> has an nls version that will do the scaling and also watch for some
>> other situations that give trouble.
>>
>> Cheers, JN
>>
>>
>> ## JN test
>> rm(list=ls())
>>
>> ExponValues <- c(2018.34,2012.54,2018.85,2023.52,2054.58,2132.61,2247.17,
>>  2468.32,2778.47)
>>
>> ExponCycles <- c(17,18,19,20,21,22,23,24,25)
>>
>> mod <- function(x) x[1] + x[2]*x[3]^ExponCycles
>>
>> modj <- function(x) (1000*x[1] + 0.001*x[2]*x[3]^ExponCycles)
>>
>> fun <- function(x) sum((ExponValues-mod(x))^2)
>>
>>
>>
>> pa<-c(1,2,3)
>> lo<-c(0,0,0)
>> up<-c(20,20,20)
>> names(pa) <- c("Y0", "a", "E")
>>
>> ## fit w/port and GN
>> Emodjn<- nls(ExponValues ~ (1000*Y0 + 0.001*a*(E^ExponCycles)),
>>  start=pa, algorithm='port', lower=lo, upper=up,
>>  control=list(maxiter=1000, trace=TRUE, warnOnly=TRUE))
>>
>> Emodjn1 <- nls(ExponValues ~ (1000*Y0 + 0.001*a*(E^ExponCycles)), start=pa,
>>  control=list(maxiter=1000, trace=TRUE, warnOnly=TRUE))
>>
>> ## fit
>> matplot(cbind(ExponValues, fitted(Emodjn), fitted(Emodjn1)),type="l")
>>
>> __
>> R-help@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.
>>

__
R-help@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.


Re: [R] Starting estimates for nls Exponential Fit

2009-12-02 Thread Prof. John C Nash
Kate Mullen showed one approach to this problem by using DEOptim to get
some good starting values.

However, I believe that the real issue is scaling (Warning: well-ridden
hobby-horse!).

With appropriate scaling, as below, nls does fine. This isn't saying nls
is perfect -- I've been trying to figure out how to do a nice job of
helping folk to scale their problems. Ultimately, it would be nice to
has an nls version that will do the scaling and also watch for some
other situations that give trouble.

Cheers, JN


## JN test
rm(list=ls())

ExponValues <- c(2018.34,2012.54,2018.85,2023.52,2054.58,2132.61,2247.17,
 2468.32,2778.47)

ExponCycles <- c(17,18,19,20,21,22,23,24,25)

mod <- function(x) x[1] + x[2]*x[3]^ExponCycles

modj <- function(x) (1000*x[1] + 0.001*x[2]*x[3]^ExponCycles)

fun <- function(x) sum((ExponValues-mod(x))^2)



pa<-c(1,2,3)
lo<-c(0,0,0)
up<-c(20,20,20)
names(pa) <- c("Y0", "a", "E")

## fit w/port and GN
Emodjn<- nls(ExponValues ~ (1000*Y0 + 0.001*a*(E^ExponCycles)),
 start=pa, algorithm='port', lower=lo, upper=up,
 control=list(maxiter=1000, trace=TRUE, warnOnly=TRUE))

Emodjn1 <- nls(ExponValues ~ (1000*Y0 + 0.001*a*(E^ExponCycles)), start=pa,
 control=list(maxiter=1000, trace=TRUE, warnOnly=TRUE))

## fit
matplot(cbind(ExponValues, fitted(Emodjn), fitted(Emodjn1)),type="l")

__
R-help@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.


Re: [R] Question about output from optim

2009-11-30 Thread Prof. John C Nash
As Ben Bolker has indicated, I am working on various improvements to the 
functionality of optim() along with others, esp. Ravi Varadhan and Kate 
Mullen.


With relevance to the posts by Sebastien Bihorel and Ben Bolker about 
output of point/function value information on each evaluation, I am 
working (rather slowly due to other commitments) on a wrapper for the 
user's function that will do this. It allows nice progress graphs and 
performance profiles to be created. The tricky bit it getting a file 
opened to store the information and to close it again when done, and to 
do this fairly cleanly. Collaborations welcome.


Also I want the wrapper to allow for flagging when the function cannot 
be evaluated. At the moment as far as I can tell, some methods -- not 
just in optim but other functions too --  die, some keep going with 
garbage, and some can handle a function that returns Inf or similar flag 
properly i.e., back off a line search or similar recovery which would be 
useful to protect users from unhappy results.


I suggest off-list responses and we can see how quickly a good 
resolution can be achieved.


JN

__
R-help@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.


[R] Maximum Likelihood Estimation

2009-11-04 Thread Prof. John C Nash
What do you mean by the "estimates were very bad"? In nearly 40 years of
working with optimization, I've seen badly set-up  functions cause
troubles, I've seen multiple minima situations, I've seen comparisons of
results from one data set to the estimates for another, and I've seen
optimization produce the proper results when published ones were just
plain wrong.

So there are many possibilities.

And for Cobb-Douglas functions, I've seen least squares estimates based
on the log of the production function give estimates with different
signs from those using a nonlinear least squares objective on the
original exponential form.

You are not the first to step in the cow pie of Cobb Douglas.

We need some numbers please. If you send a file or files (I don't think
you can attach files to Rhelp, but can do so off-list) with a runnable
script and the data, I'll be willing to try it out.

JN





> Message: 84
> Date: Tue, 3 Nov 2009 19:49:17 +
> From: Andre Barbosa Oliveira 
> Subject: [R] Maximum Likelihood Estimation
> To: 
> Message-ID: 
> Content-Type: text/plain
> 
> 
> Hi,
> 
> I would like estimate a model for function of production's Coob-Douglas using 
> maximum likelihood. The model is log(Y)= 
> beta[1]+beta[2]*log(L)+beta[3]*log(K). I tried estimate this model using the 
> tools nlm ( ) and optim ( ) using the log-likelihood function below:
>
> > mloglik <- function (beta, Y, L, K) {
> + n <- length(Y)
> + sum ( (log(Y)- beta[1]-beta[2]*log(L)-beta[3]*log(K))2)/2*beta[4]2 + 
> n/2*log(2*pi)+ n*log(beta[4])
> + }
> Then I did estimates the parameters using nlm ( ) and optim ( ), but the 
> estimates were very bad. I used these codes:
>
>> > mlem <- nlm (mloglik, c(1,1,1,1), Y=Y, L=L, K=K)
> 
>> > mlem2 <- optim(c(1,1,1,1), mloglik, Y=Y, L=L, K=K, method="BFGS")
> 
> How I improve the estimates What's the best and more simple form for 
> estimate a modelo using the  maximum likelihood's method???
> 
> Best regards,
> 
> Andre' Barbosa Oliveira
> 
> Student of Master in Economics at University Federal of Rio Grande do Sul - 
> Brazil 
> 
> _
> Novo windowslive.com.br. Descubra como juntar a galera com os produtos 
> Windows Live.
> 
> 
>   [[alternative HTML version deleted]]
> 
>

__
R-help@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.


[R] 1 dimensional optimization with local minima

2009-11-03 Thread Prof. John C Nash
Most methods for optimization in R seek local minima, though there are
some -- mainly for >1 dimensions, that attempt to find the global
minimum stochastically (optim method SANN, DEoptim). SANN does, I
believe, handle 1 dimension, but does not have a convergence test, but
runs a fixed number of function evaluations (I got bitten by this
unusual behaviour, as it returns a "converged" flag after the specified
number of evaluations).

While there are some techniques that can generate global minima given
conditions on the function, I would anticipate you will do better
graphing your function(s) to learn if they have just a few (++) or very
many (-- = very bad for you) optima. You should apply bounds to your
domain -- a lot of computational time is wasted when routines take a
wild excursion away from a region of interest. That may be enough. Or
you may need to segment the domain to isolate the minima then select the
best. That is, find a local minimum, choose a new interval that does not
include this and apply optimize() again. Messy, but unless you have lots
of local minima, should work OK. If you do have lots, it is likely you
need to re-pose your problem.

JN





> Message: 114
> Date: Mon, 2 Nov 2009 23:00:40 -0800 (PST)
> From: Jeroen Ooms 
> Subject: [R]  1 dimensional optimization with local minima
> To: r-help@r-project.org
> Message-ID: <26160001.p...@talk.nabble.com>
> Content-Type: text/plain; charset=us-ascii
> 
> 
> I am using numerical optimization to fit a 1 parameter model, in which the
> input parameter is bounded. I am currently using optimize(), however, the
> problem turns out to have local minima, and optimize does not always seem to
> find the global minimum. I could to write a wrapping function that tries
> multiple intervals or starting values, but I would prefer a package that has
> built-in methods to make it more robust against local minima.
> 
> I checked the CRAN Task View for Optimization, however there seem to be a
> lot of alternatives, and not being an optimization expert, I could use some
> advice. What could be an appropriate package or function for one-dimensional
> bounded optimization, that includes some protection against local minima? 
> 
> 
> 
> -
> Jeroen Ooms * Dept. of Methodology and Statistics * Utrecht University 
> 
> Visit  http://www.jeroenooms.com www.jeroenooms.com  to explore some of my
> current projects.
> 
> 
> 
> 
> 
>  
> -- View this message in context: 
> http://old.nabble.com/1-dimensional-optimization-with-local-minima-tp26160001p26160001.html
>  Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] environment or other technique to isolate some private working information

2009-10-30 Thread Prof. John C Nash
In order to instrument functions for optimization or DE solving etc., I
want to set up a private ensemble of working data somewhere in my
workspace that won't collide with the problem-data. I can do this
already with named objects within .GlobalEnv, but I'd like to have
functions like

fnmon.setup<-function( etc. ) {

...
 # create an environment
monenv<-new.env(baseenv())

# then create some names in the monenv for a file of data to be written,
#  some counters, timers etc.

}

and within my function call a function
  fnmon.next<- ...

that gets the appropriate infomation from the special area writes lines
to the monitoring file

and finally

  fnmon.stop<-

to close things out.

I've got it working with objects in .GlobalEnv as indicated, but
attempts to do it as above cause failure to find the environment in the
fnmon.next.

Likely I'm misreading the documentation on 'environment' somehow (it may
be clear to folks who are deep into Lisp/Scheme, but not mere mortals).
Or perhaps there is a better way to isolate the private collection of
objects that will do the monitoring.

I can provide the files to anyone wanting a tryout, but they are a bit
long, and I suspect there is an "easy" approach that is eluding me.

JN

__
R-help@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.


Re: [R] fast optimizer

2009-10-30 Thread Prof. John C Nash
> Date: Fri, 30 Oct 2009 09:29:06 +0100
> From: Christophe Dutang 
> Subject: Re: [R] [R-SIG-Finance]  Fast optimizer
> To: R_help Help 
> Cc: r-help@r-project.org
>> > Ok. I have the following likelihood function.
>> >
>> > L <- p*dpois(x,a)*dpois(y,b+c)+(1-p)*dpois(x,a+c)*dpois(y,b)
>> >
>> > where I have 100 points of (x,y) and parameters c(a,b,c,p) to
>> > estimate. Constraints are:
>> >
>> > 0 < p < 1
>> > a,b,c > 0
>> > c < a
>> > c < b
>> >
>> > I construct a loglikelihood function out of this. First ignoring the
>> > last two constraints, it takes optim with box constraint about 1-2 min
>> > to estimate this. I have to estimate the MLE on about 200 rolling
>> > windows. This will take very long. Is there any faster implementation?
> Take a look at the CRAN task view on optimisation, you may find faster  
> algorithms.
> 

There are several new or revised methods in development as well as a new
wrapper optimx() in the r-forge OptimizeR project
http://r-forge.r-project.org/R/?group_id=395

In particular Rvmmin is an all-R implementation of the algorithm at the
heart of optim's BFGS but with bounds and mask (fixed parameter)
constraints. I'm looking into how it can be made more convenient to
hot-start with suspected "good" parameters, which would be likely be
important here.

JN

__
R-help@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.


[R] (no subject) -- rename to optim() crash due to NA returned

2009-10-20 Thread Prof. John C Nash
While developing updates to optimization tools for R (I was behind 3 of 
the 5 codes in optim(), but Brian Ripley did the implementation), I've 
been seeing this kind of error when the objective function cannot be 
computed so returns NA. Examples: attempts to divide by 0 or sqrt(-ve) 
or log(0). A crude work-around is to detect bad situations when 
evaluating the function and return a very large number e.g., something 
using .Machine$double.xmax  (I used this divided by 4 or so to avoid 
troubles if algorithms try to do some arithmetic, as in gradient based 
routines).


Most routines will "bounce off" such a value, but the scaling of the 
surface is messed up so it is not always efficient. A better way is if 
optimization codes can handle a "failed evaluation" flag and simply back 
off from a step or whatever is needed, but in R non tools do this as yet 
-- I'm hoping to put this in some of my codes using returned values 
larger than some threshhold as the "flag". My 1980s BASIC codes had this 
(and bounds and masks). However, it takes time and 


For information, I'd like to know if this turns out to be the problem, 
as it would raise the priority for working on such issues.


JN




Message: 57
Date: Mon, 19 Oct 2009 17:48:12 +0200
From: "Reynaerts, Jo" 
Subject: [R] (no subject)
To: "r-help@r-project.org" 
Message-ID:

<603d249cbe0b304490d0f774142b8e0f01cdcb9a4...@econsrvex6.econ.kuleuven.ac.be>

Content-Type: text/plain

Dear R users

I have the following problem when calling optim() to minimize a function "f.obj" (= outer 
loop) that calls another function "f.con" (a contraction mapping, = inner loop).  It 
seems to me that it is a numerical problem that I currently fail to take into account when coding.

Calling optim(), for the first few iterations of the outer loop, everything 
seems fine; the contraction mapping is calculated in each run.  However, after 
a number of outer loop iterations, an error occurs and the following message is 
displayed:

Error in while (max.dev >= tol.in) { :
missing value where TRUE/FALSE needed

The previous conditional statement ensures that the iteration in the inner loop 
should run as long as max.dev <- max(abs(x - x.in)) is greater than the inner loop 
tolerance level (tol.in <- 1E-9), where x is computed by the contraction mapping 
using x.in.  I used different stopping rules and tolerance levels, but this gives the 
same result.

As I said, I think it's a numerical problem.  Has anyone had similar 
experiences using optim() and could you give some coding advice?

Thanks in advance,

Jo Reynaerts


__
R-help@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.


[R] How to get slope estimates from a four parameter logistic with SSfpl?

2009-10-20 Thread Prof. John C Nash

Is the following helpful?

 pdd<-deriv(~a+(b-a)/(1+exp((c-t)/d)),"d")
> pdd
expression({
.expr1 <- b - a
.expr2 <- c - t
.expr4 <- exp(.expr2/d)
.expr5 <- 1 + .expr4
.value <- a + .expr1/.expr5
.grad <- array(0, c(length(.value), 1L), list(NULL, c("d")))
.grad[, "d"] <- .expr1 * (.expr4 * (.expr2/d^2))/.expr5^2
attr(.value, "gradient") <- .grad
.value
})

Or perhaps you want it with respect to "t"?

JN



Message: 46
Date: Mon, 19 Oct 2009 14:50:15 +0100
From: "Weber, Sam" 
Subject: [R] How to get slope estimates from a four parameter logistic
with SSfpl?
To: "r-help@R-project.org" 
Message-ID:

<5bb78285b60f9b4db2c6a4da8f3e788c12c64b3...@exchmbs04.isad.isadroot.ex.ac.uk>

Content-Type: text/plain

Hi,

I was hoping to get some advice on how to derive estimates of slopes from four 
parameter logistic models fit with SSfpl.

I fit the model using:

model<-nls(temp~SSfpl(time,a,b,c,d))
summary(model)

I am interested in the values of the lower and upper asymptotes (parameters a 
and b), but also in the gradient of the line at the inflection point (c) which 
I assume tells me my rate of increase when it is steepest (?).

However, I cannot work out how to derive a slope estimate. I'm guessing it has 
something to do with the scaling parameter d but having searched the internet 
for hours I have not made any progress, and it is probably quite simple. Any 
help would be hugely appreciated!

All the best

Sam


__
R-help@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.


Re: [R] R-help Digest, Vol 80, Issue 18

2009-10-18 Thread Prof. John C Nash
As a first try, use a bounds constrained method (L-BFGS-B or one from 
the r-forge Optimizer project 
http://r-forge.r-project.org/R/?group_id=395) and then add a penalty or 
barrier function to your objective function to take care of the

x1+x2 < 1  (the other end is implicit in the lower bounds on x1 and x2).

e.g.,   - const * log(1-x1-x2)

You should provide a feasible starting point. const scales the penalty.

Cheers, JN




Message: 27
Date: Sat, 17 Oct 2009 13:50:10 -0700 (PDT)
From: kathie 
Subject: [R]  optimization problem with constraints...
To: r-help@r-project.org
Message-ID: <25941686.p...@talk.nabble.com>
Content-Type: text/plain; charset=us-ascii


Dear R users, 


I need some advises on how to use R to optimize a nonlinear function with
the following constraints.

f(x1,x2,x3,x4,x5,x6) 

s.t 


0 < x1 < 1
0 < x2 < 1
0 < x1+x2 < 1
-inf < x3 < inf
-inf < x4 < inf
0 < x5 < inf
0 < x6 < inf

Is there any built-in function or something for these constraint??

Any suggestion will be greatly appreciated.

Regards,

Kathryn Lord 
-- View this message in context: http://www.nabble.com/optimization-problem-with-constraints...-tp25941686p25941686.html Sent from the R help mailing list archive at Nabble.com.


__
R-help@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.


[R] optimization problem with constraints..

2009-10-18 Thread Prof. John C Nash
Apologies if this shows up a second time with uninformative header 
(apparently it got filtered, but ...), as I forgot to replace the 
subject line.


As a first try, use a bounds constrained method (L-BFGS-B or one from 
the r-forge Optimizer project 
http://r-forge.r-project.org/R/?group_id=395) and then add a penalty or 
barrier function to your objective function to take care of the

x1+x2 < 1  (the other end is implicit in the lower bounds on x1 and x2).

e.g.,   - const * log(1-x1-x2)

You should provide a feasible starting point. const scales the penalty.

Cheers, JN



> Message: 27
> Date: Sat, 17 Oct 2009 13:50:10 -0700 (PDT)
> From: kathie 
> Subject: [R]  optimization problem with constraints...
> To: r-help@r-project.org
> Message-ID: <25941686.p...@talk.nabble.com>
> Content-Type: text/plain; charset=us-ascii
>
>
> Dear R users,
> I need some advises on how to use R to optimize a nonlinear function with
> the following constraints.
>
> f(x1,x2,x3,x4,x5,x6)
> s.t
> 0 < x1 < 1
> 0 < x2 < 1
> 0 < x1+x2 < 1
> -inf < x3 < inf
> -inf < x4 < inf
> 0 < x5 < inf
> 0 < x6 < inf
>
> Is there any built-in function or something for these constraint??
>
> Any suggestion will be greatly appreciated.
>
> Regards,
>
> Kathryn Lord -- View this message in context: 
http://www.nabble.com/optimization-problem-with-constraints...-tp25941686p25941686.html 
Sent from the R help mailing list archive at Nabble.com.


__
R-help@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.


Re: [R] Escaping . in regular expression

2009-09-14 Thread Prof. John C Nash

Thanks. That fixes things.

I saw mention of \\. in ?Quotes, but the usage was not clear. I took it 
to mean the \ was to be printed. Maybe my little example would help, as 
?Quotes doesn't have any.


JN

Henrique Dallazuanna wrote:

You need double backslashes:

grep('\\.f', cvec, value = TRUE)

On Mon, Sep 14, 2009 at 4:25 PM, Prof. John C Nash <mailto:nas...@uottawa.ca>> wrote:


If I run


cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f")
print(cvec)
indx<-grep('\.f',cvec,perl=TRUE)
fset<-cvec[indx]
print(fset)

I get

 > cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f")
 > print(cvec)
[1] "test.f"  "test.sf" "try.g"   "try.res" "try.f"
 > indx<-grep("\.f",cvec,perl=TRUE)
Warning messages:
1: '\.' is an unrecognized escape in a character string
2: unrecognized escape removed from "\.f"
 > fset<-cvec[indx]
 > print(fset)
[1] "test.f"  "test.sf" "try.f"
 >

This ignores the . for which I want to test.

In perl, the function

#!/usr/bin/perl
use strict;
my @cvec=("test.f", "test.sf", "try.g","try.res", "try.f");
foreach my $elem (@cvec) {
  print "$elem : ";
  if ( $elem =~ '\.f' ) {
  print "matches \n";
  } else {
  print "does not match \n";
  }
}


gives

$ perl perlmatch.pl
test.f : matches
test.sf : does not match
try.g : does not match
try.res : does not match
try.f : matches
$

which does what I want. It looks like a bug (or at least a nasty
documentation failure) of "perl=TRUE".

Anyone have suggestions of how to get appropriate filtering? I need
this to automate optimization tests on large sets of test problems.

Cheers, JN

__
R-help@r-project.org <mailto:R-help@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.




--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O


__
R-help@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.


[R] Escaping . in regular expression

2009-09-14 Thread Prof. John C Nash

If I run


cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f")
print(cvec)
indx<-grep('\.f',cvec,perl=TRUE)
fset<-cvec[indx]
print(fset)

I get

> cvec<-c("test.f", "test.sf", "try.g","try.res", "try.f")
> print(cvec)
[1] "test.f"  "test.sf" "try.g"   "try.res" "try.f"
> indx<-grep("\.f",cvec,perl=TRUE)
Warning messages:
1: '\.' is an unrecognized escape in a character string
2: unrecognized escape removed from "\.f"
> fset<-cvec[indx]
> print(fset)
[1] "test.f"  "test.sf" "try.f"
>

This ignores the . for which I want to test.

In perl, the function

#!/usr/bin/perl
use strict;
my @cvec=("test.f", "test.sf", "try.g","try.res", "try.f");
foreach my $elem (@cvec) {
   print "$elem : ";
   if ( $elem =~ '\.f' ) {
   print "matches \n";
   } else {
   print "does not match \n";
   }
}


gives

$ perl perlmatch.pl
test.f : matches
test.sf : does not match
try.g : does not match
try.res : does not match
try.f : matches
$

which does what I want. It looks like a bug (or at least a nasty 
documentation failure) of "perl=TRUE".


Anyone have suggestions of how to get appropriate filtering? I need this 
to automate optimization tests on large sets of test problems.


Cheers, JN

__
R-help@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.


[R] Principle components analysis on a large dataset

2009-08-21 Thread Prof. John C Nash
The essential issue is that the matrix you need to manipulate is very 
large. This is not a new problem, and about a year ago I exchanged ideas 
with the Rff package developers (things have been on the back burner 
since due to recession woes and illness issues). These ideas were based 
on some very small codes from my 1979 book "Compact numerical methods 
for computers". This contains a code that takes a matrix row-wise from a 
file and builds a triangular decomposition as well as a list of 
orthogonal transformations, then does an svd of the result. Your problem 
would work on the transpose. This is a whole lot different from how R 
users generally  work, so there are lots of interfacing and similar 
issues. Also there are likely more efficient computational methods than 
the one I used -- but I was working in 1974 on an HP9830 desk calculator 
with the matrix on punched cards to develop this. And it has a short 
code that can be written in a fairly vectorized way in R only, which may 
make the human/computer trade-off favourable, depending on how many 
times you need to run such problems.


However, the main point is that you need to use some sort of "out of 
core" (how dated that sounds!) method, which is and will remain an issue 
for systems like R that work on objects in memory.


I'm willing to kibbitz on such work, but it would go best if there are 
3-4 folk involved to bring different skills to the table.


John Nash




Message: 128
Date: Thu, 20 Aug 2009 17:45:00 -0700 (PDT)
From: misha680 
Subject: [R]  Principle components analysis on a large dataset
To: r-help@r-project.org
Message-ID: <25072510.p...@talk.nabble.com>
Content-Type: text/plain; charset=us-ascii


Dear Sirs:

Please pardon me I am very new to R. I have been using MATLAB.

I was wondering if R would allow me to do principal components analysis on a
very large
dataset.

Specifically, our dataset has 68800 variables and around 6000 observations.
Matlab gives "out of memory" errors. I have tried also doing princomp in
pieces, but this does not seem to quite work for our approach.

Anything that might help much appreciated. If anyone has had experience
doing this in R much appreciated.

Thank you
Misha
-- View this message in context: 
http://www.nabble.com/Principle-components-analysis-on-a-large-dataset-tp25072510p25072510.html 
Sent from the R help mailing list archive at Nabble.com.


__
R-help@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.


[R] optimization free software

2009-08-21 Thread Prof. John C Nash
There are also several projects on r-forge.r-project.org that deal with 
optimization, including one I'm involved with that has been putting up a 
number of new or reworked methods so that they can be tested, evaluated 
and improved. These all deal with unconstrained or box-constrained 
minimization problems (minimize -f(x) to maximize). In particular, we 
have an implementation of Mike Powell's BOBYQA (derivative-free 
box-constrained method using quadratic approximation) that seems quite 
interesting. See package minqa in the project 
http://r-forge.r-project.org/R/?group_id=395.


There is also a reworking of conjugate gradients with a rather better 
automated choice of generation formula (using Dai and Yuan, 2001 ideas) 
with box-constraints. It handles very large problems, often amazingly 
quickly e.g., an n=5000 generalized Rosenbrock problem, with analytic 
gradients, in <3 secs on an Asus Eee 900 netbook. And that is an all-R 
implementation.


Caveat: all these are developmental codes. We believe they "work", but 
we are trying to torture test them and are finding some situations where 
they have glitches. We welcome use and comments to improve them. I 
expect the same applies to other codes on r-forge.


John Nash




Message: 98
Date: Thu, 20 Aug 2009 11:08:29 -0700
From: Gaspar N??ez 
Subject: [R] optimization free software
To: r-help@r-project.org
Message-ID:
<9cd4bb290908201108x554ad8a3h520417208a330...@mail.gmail.com>
Content-Type: text/plain

Hi

i´m starting to work with free software
(with free as in freedom)

i've been working with GAMS
(General Algebraic Modeling System)
to solve static and dynamic optimization problems
and non-linear large systems of equations

i'm wondering if there is any free software
and documentation on the subject,
wether in R, Maxima, or something else

i will appreciate any help
and any references about this issue

thanks in advance

gaspar

__
R-help@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.


Re: [R] R User Group listings

2009-08-01 Thread Prof. John C Nash
Better ideas should prevail. There is now a wiki page at 
http://wiki.r-project.org/rwiki/doku.php?id=rugs:r_user_groups.


It is not yet fully populated. (David Smith's blog at REvolution 
Computing mentions more groups.)


JN

__
R-help@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.


Re: [R] R User Group listings

2009-08-01 Thread Prof. John C Nash
Why not! Looks like there were several conversations going on 
independently at UseR about this.


I'll put up a page and then ask Martin to adjust the link.

JN


Friedrich Leisch wrote:

On Fri, 31 Jul 2009 06:45:38 -0400,
Prof John C Nash (PJCN) wrote:


  > Further to my posting about R UG mailing lists etc., and David Smith's 
  > post about the list he is maintaining (I was aware of his blog, but not 
  > that he was updating -- good show), I'm in communication with him to try 
  > to ensure we get appropriate information out to useRs.


  > Already there has been a posting asking if there is any group in 
  > Germany, and asking is the first step to getting a group going. I 
  > suspect we need to expand from just a listing to also include 
  > "Desperately seeking R users..." entries. Will see what we can do.


I shortly talked with Jip Porzak about it at useR (because he
previously approached me with the question about having such a list on
the "official" R web pages). My personal opinion is that such a
listing really belongs into the R Wiki, such that user groups can add
themselves. Of course it would be great if somebody could act as an
editor and have an eye on the page, and we could have a prominent link
to it from the R homepage.

Just my 2c,
Fritz





__
R-help@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.


Re: [R] constrained input for optimization algorithm

2009-07-31 Thread Prof. John C Nash
As someone very involved with optim and its evolution I can say it is 
not at all suited to this sort of combinatoric optimization. I don't 
know if there are packages in R to help out -- it would be nice.


If (this may be a big IF) your set of possible combinations is not too 
large, combn() generates the C(n,r) combinations and, assuming the 
function is not too expensive to compute, one can use enumeration and be 
certain of having the optimum.


choose(60,5) shows about 5.5 million sets. A bit tedious, but likely 
doable over lunchtime. But choose(600,5) is >600 billion, and probably 
too heavy.


John Nash

>From: Zhi Xie 

>It seems that optimization algorithm, optim, tries to find optimized
>parameters within defined lower and upper bounds. In my problem, all
>the parameters are integers. My question is that if there is any means
>that I can let "optim" only tries mutual exclusive integers. To be
>specific, I am giving an example here.

>I tried to find a set parameters with five elements with the lowest
>value for the cost function. The parameter set that "optim" returned
>is "5, 5, 49, 51, 51". However, I only wanted to search unique
>parameter values, such as "5, 6, 49, 50, 51".

__
R-help@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.


Re: [R] R User Group listings

2009-07-31 Thread Prof. John C Nash


Further to my posting about R UG mailing lists etc., and David Smith's 
post about the list he is maintaining (I was aware of his blog, but not 
that he was updating -- good show), I'm in communication with him to try 
to ensure we get appropriate information out to useRs.


Already there has been a posting asking if there is any group in 
Germany, and asking is the first step to getting a group going. I 
suspect we need to expand from just a listing to also include 
"Desperately seeking R users..." entries. Will see what we can do.


JN

__
R-help@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.


Re: [R] R User Group listings

2009-07-30 Thread Prof. John C Nash
There are now several R geographic user groups, and a few have mailing 
lists on the R mailing list system. Thanks to Martin M, there's also a 
pointer to a page I'm maintaining to list/describe the groups. The page 
is at


http://macnash.telfer.uottawa.ca/RUG.html


Contact me if you have a listing. I'm prepared to wikify it if there is 
sufficient interest.


John Nash

__
R-help@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.


Re: [R] Automatic differentiation in R

2009-07-23 Thread Prof. John C Nash

>> Gabor G. wrote
>>  "R does not currently have AD (except for the Ryacas package
>>  which can do true AD for certain simple one line functions, i..e.
>>  input the function and output a function representing its
>>  derivative); however, for specific problems one can get close
>>  using deriv and associated functions or the approach explained
>>  below using rSymPy:
>> ...

As the instigator of Finlay's participation in this work, I probably 
didn't express clearly enough the contribution Gabor has made to get as 
far as he has with Ryacas and rSympy, which may show another pathway for 
AD/Symbolic diff. development. At UseR all conversations seemed more 
rushed than I'd like.


Gabor showed Ravi Varadhan and I a way to get some derivatives via his 
tools that "worked". We need to play with this a bit more to see how 
general it could be -- Gabor is very fair in his post that some work is 
needed for each instance. On the other hand, if analytic gradients were 
straightforward, we wouldn't be exchanging posts about them.


The clear issue in my mind is that users who need gradients/Jacobians 
for R want to be able to send a function X to some process that will 
return another function gradX or JacX that computes analytic 
derivatives. This has to be "easy", which implies a very simple command 
or GUI interface. I am pretty certain the users have almost no interest 
in the mechanism, as long as it works. Currently, most use numerical 
derivatives, not realizing the very large time penalty and quite large 
loss in accuracy that can compromise some optimization and differential 
equation codes. I'll try to prepare a few examples to illustrate this 
and post them somewhere in the next few weeks. Time, as always, ...


However, the topic does appear to be on the table.

JN

__
R-help@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.


[R] Determining if swap memory is turned off

2009-06-26 Thread Prof. John C Nash
In order to run some performance tests on optimization tools, I want to 
be able
to avoid the use of swap memory. In *nix systems, at least Linux ones, I 
can issue
a 'sudo swapoff -a' command and use just the RAM available.  If I don't 
do this, at
some point swap will be used, the disk goes ballistic and the machine is 
unresponsive
because it is thrashing data to the swap.  I suspect others have 
encountered this
too. Clearly I'd rather fail out than get into the thrashing situation. 
Generally I
prefer no swap -- memory is cheap enough that it is easier not to worry 
about these
sorts of woes. However, I'd like to make packages I'm developing 
bullet-proof.


What I need to know is if there are similar facilities on other 
platforms and how to
use them. I see memory.size and memory.limit for Windows -- making R 
less platform
independent -- and they seem to work on a WinXP virtual machine I have 
available.
However, I suspect that the memory.limit includes the swap. When I was 
running
Windoze, I tried valiantly to get the PageFile.sys killed and found it 
kept being set
up again despite following all the recommended steps. (I needed to avoid 
the
plaintext of an encrypted file being "saved" for me!)  I know nothing 
about Mac

swap and how to control it.

Advice welcome.  Below is a crude but self-contained example.

John Nash

## memcrash.R -- try to hit the wall with memory

cat("memcrash.R -- try to hit the wall\n")
cat("You should have swap turned off\n")
temp<-readline("Do you?")
if (temp != "y") stop("Fix swap")

for (j in 1:10) {
  n <- 5^j
  cat("building matrix of order ",n,"\n")
  A<-matrix(nrow=n, ncol=n)
} # end loop

__
R-help@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.