[R] integer
Patrick Burns
pburns at pburns.seanet.com
Tue Nov 2 18:12:55 CET 2004
Yes, it is possible -- there are two steps:
1) Create a suitable function. This is likely to look something like:
f.wrapper <- function(pars)
{
ipars <- round(pars)
f(ipars[1], ipars[2], ipars[3])
}
2) Find a suitable optimizer.
A genetic algorithm, as you alluded to earlier, is a likely choice.
Choices include "genopt" from S Poetry (you can extract "genopt"
and "genopt.control" from the shar file).
Another possibility is simulated annealing which is available via
the "optim" function.
Patrick Burns
Burns Statistics
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
Ludovic Tambour wrote:
>Sorry, the formulation of my question is bad. I hope that you have not lost
>your time. The problem is not a problem of integer identification.
>
>The problem is :
>" I have a numerical function y = f(x1,x2,x3) where x1...x3 are integers. I
>would like to determine x1,x2,x3 so that "y" has a minimal value. I know
>that
>R can determine a minimal value when x1,x2,x3 are real. Is-it possible to do
>this when x1, x2, x3 are restricted to be integers ? "
>
>Ludo
>
>
>
>
>----- Original Message -----
>From: "Uwe Ligges" <ligges at statistik.uni-dortmund.de>
>To: "GÃ¶ran BrostrÃ¶m" <gb at stat.umu.se>
>Cc: <r-help at stat.math.ethz.ch>
>Sent: Tuesday, November 02, 2004 3:44 PM
>Subject: Re: [R] integer
>
>
>
>
>>GÃ¶ran BrostrÃ¶m wrote:
>>
>>
>>
>>>On Tue, Nov 02, 2004 at 11:36:27AM +0100, Uwe Ligges wrote:
>>>
>>>
>>>
>>>>Ludovic Tambour wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>Hello,
>>>>>
>>>>>I need to use "R" to determine parameters which are integers. How I can
>>>>>
>>>>>
>do
>
>
>>>>>this, please ?
>>>>>
>>>>>
>>>>What so you mean with "parameters"? In which context?
>>>>
>>>>To check whether a numeric vector "x" contains only integers, you can
>>>>
>>>>
>try
>
>
>>>>all.equal(as.integer(x), x)
>>>>
>>>>
>>>I don't think so:
>>>
>>>
>>>
>>>
>>>>x <- as.double(c(1, 2))
>>>>y <- as.integer(c(1, 2))
>>>>all.equal(x, y)
>>>>
>>>>
>>>[1] TRUE
>>>
>>>But,
>>>
>>>
>>>
>>>
>>>>identical(x, y)
>>>>
>>>>
>>>[1] FALSE
>>>
>>>
>>[The story was completely different from the stuff I guessed, so all
>>further communication related to this thread is "academic".]
>>
>>GÃ¶ran,
>>
>>yes, as expected.
>>
>>
>>
>>
>>>On the other hand, why not use
>>>
>>>
>>>
>>>
>>>>is.integer(x)
>>>>
>>>>
>>>[1] FALSE
>>>
>>>
>>>
>>>>is.integer(y)
>>>>
>>>>
>>>[1] TRUE
>>>
>>>because I think that a numeric vector can't have a mix of integer and
>>>non-integer elements. With a list it's a different story.
>>>
>>>
>>Yes.
>>
>>My guees was that the asker tried to identify integers such as 2, 3 in
>>contrast to 2.1, 3.1, ...and you won't know it by looking at R's storage
>>mode (my guess was that the asker was not interested in the storage
>>mode, but in the nature of the numbers!).
>>Note that is.integer(1) is FALSE!!!
>>
>>The given usage of all.equal() helps to identify 1 as an integer, but
>>not 1.1...
>>
>>Uwe
>>
>>
>>
>>>GÃ¶ran
>>>
>>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide!
>>
>>
>http://www.R-project.org/posting-guide.html
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
>
>
More information about the R-help
mailing list