Re: [R] FastICA

2008-08-11 Thread Hans W. Borchers
Maura E Monville  gmail.com> writes:

> 
> Is the FastICA R implementation as good as the MatLab Implementation ?
> I would appreciate talking to someone who has used FastICA for R.

The fastICA packages for Matlab and R (and there is even a version for Python)
have a common origin at the Helsinki University of Technology. I regularly use
Matlab and R, not seeing much of a difference in packages like these.

//  Hans Werner Borchers

> 
> Thank you 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.


Re: [R] re cursive root finding

2008-08-08 Thread Hans W. Borchers

As your curve is defined by its points, I don't see any reason to 
artificially apply functions such as 'uniroot' or 'optim' (being a 
real overkill in this situation).

First smooth the curve with splines, Savitsky-Golay, or Whittacker 
smoothing, etc., then loop through the sequence of points and compute 
the gradient by hand, single-sided, two-sided, or both.

At the same time, mark those indices where the gradient is zero or 
changes its sign; these will be the solutions you looked for.

With your example, I immediate got as maxima or minima:

x1 = 1.626126
x2 = 4.743243
x3 = 7.851351

//  Hans Werner Borchers


Any comments? Maybe the problem was not clear or looked too specific.  
I'll add a more "bare bones" example, if only to simulate discussion:

> x <- seq(1,10,length=1000)
> set.seed(11) # so that you get the same randomness
> y <- jitter(sin(x),a = 0.2)
> values <- data.frame(x= x,  y = y)
>
> findZero <- function (guess, neighbors, values)
> {
>   
> smooth <- smooth.spline(values$x, values$y)
>
> obj <- function(x) {
> (predict(smooth, x)$y) ^2
> }
> minimum <- which.min(abs(values$x - guess))
> optimize(obj, interval = c(values$x[minimum - neighbors],
>  values$x[minimum + 
> neighbors]))  # uniroot could be used  
> instead i suppose
>
> }
>
> test <- findZero(guess = 6 ,  neigh = 50, values = values)
> plot(x,y)
> abline(h=0)
> abline(v=test$minimum, col="red")

Now, I would like to find all (N=)3 roots, without a priori knowledge  
of their location in the interval. I considered several approaches:

1) find all the numerical values of the initial data that are close to  
zero with a given threshold. Group these values in N sets using cut()  
and hist() maybe? I could never get this to work, the factors given by  
cut confuse me (i couldn't extract their value). Then, apply the  
function given above with the guess given by the center of mass of the  
different groups of zeros.

2) apply findZero once, store the result, then add something big  
(1e10) to the neighboring points and look for a zero again and repeat  
the procedure until N are found. This did not work, I assume because  
it does not perturb the minimization problem in the way I want.

3) once a zero is found, look for zeros on both sides, etc... this  
quickly makes a complicated decision tree when the number of zeros  
grows and I could not find a clean way to implement it.

Any thoughts welcome! I feel like I've overlooked an obvious trick.

Many thanks,

baptiste


On 7 Aug 2008, at 11:49, baptiste auguie wrote:

> Dear list,
>
>
> I've had this problem for a while and I'm looking for a more general  
> and robust technique than I've been able to imagine myself. I need  
> to find N (typically N= 3 to 5) zeros in a function that is not a  
> polynomial in a specified interval.
>
> The code below illustrates this, by creating a noisy curve with  
> three peaks of different position, magnitude, width and asymmetry:
>
>> x <- seq(1, 10, length=500)
>> exampleFunction <- function(x){ # create some data with peaks of  
>> different scaling and widths + noise
>>  fano <- function (p, x)
>>  {
>>  y0 <- p[1]
>>  A1 <- abs(p[2])
>>  w1 <- abs(p[3])
>>  x01 <- p[4]
>>  q <- p[5]
>>  B1 <- (2 * A1/pi) * ((q * w1 + x - x01)^2/(4 * (x - x01)^2 +
>>  w1^2))
>>  y0 + B1
>>  }
>>  p1 <- c(0.1, 1, 1, 5, 1)
>>  p2 <- c(0.5, 0.7, 0.2, 4, 1)
>>  p3 <- c(0, 0.5, 3, 1.2, 1)
>>  y <- fano(p1, x) + fano(p2, x) + fano(p3, x)
>>  jitter(y, a=0.005*max(y))
>> }
>>
>> y <- exampleFunction(x)
>>
>> sample.df <- data.frame(x = x, y = y)
>>
>> with(sample.df, plot(x, y, t="l")) # there are three peaks, located  
>> around x=2, 4 ,5
>> y.spl <- smooth.spline(x, y) # smooth the noise
>> lines(y.spl, col="red")
>>
>
> I wish to obtain the zeros of the first and second derivatives of  
> the smoothed spline y.spl. I can use uniroot() or optim() to find  
> one root, but I cannot find a reliable way to iterate and find the  
> desired number of solutions (3 peaks and 2 inflexion points on each  
> side of them). I've used locator() or a guesstimate of the disjoints  
> intervals to look for solutions, but I would like to get rid off  
> this unnecessary user input and have a robust way of finding a  
> predefined number of solutions in the total interval. Something  
> along the lines of:
>
> findZeros <- function( f , numberOfZeros = 3, exclusionInterval =  
> c(0.1 , 0.2, 0.1)
> {
> #
> # while (number of solutions found is less than numberOfZeros)
> # search for a root of f in the union of intervals excluding a  
> neighborhood of the solutions already found (exclusionInterval)
> #
> }
>
> I could then apply this procedure to the first and second  
> derivatives of y.spl, but it could also be useful for any other  
> function.
>
> Many thanks for any remar

Re: [R] Constrained Optimization

2008-08-04 Thread Hans W. Borchers
  gmx.net> writes:

> 
> Hello,
> 
> I am trying to run a constrained optimization in R. "constrOptim" is really 
> useful and has helped me a lot, but unfortunately, it doesn't provide the 
> hessian.  Is there a solution to this problem?

You didn't provide an example to understand why 'optim' doesn't solve your
problem. Perhaps you can find an optimal point with 'constrOptim' and then
compute the hessian at that point with some other R function, for instance
'numDeriv::hessian'.

//  Hans Werner Borchers
 
> I've tried "optim" with penalty-functions and "L-BFGS-B", but it doesn't help.
> 
> Alan.

__
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] Are there any guis out there, which will allow editing of the graph?

2008-08-04 Thread Hans W. Borchers
Duncan Murdoch  stats.uwo.ca> writes:
> 
> On 04/08/2008 12:50 PM, Arthur Roberts wrote:
> > Hi, all,
> > 
> > I would like to know if there is any gui interface out there  
> > (academic or commercial) that allows one to edit R-language generated  
> > graphs (e.g positioning x axis labels.)  It would be nice to have  
> > something like the user interface of Igor or Origin.  I have already  
> > used JGR and R-gui.  These are good, but they don't allow one to  
> > easily edit graphs.  I have also tried locator() and the package  
> > iplots.  Your input is greatly appreciated.
> 
> I imagine there are a number of commercial packages available that would 
> allow you to edit PDF or PS files, but I haven't used any of them, so I 
> can't recommend one.

There is this fantastic open source editor for vector graphics, *Inkscape*
(http://www.inkscape.org/). Inkscape can read PDF files generated by R as
PDFs. By 'ungrouping' graphs, Inkscape is able to modify any single piece
of the diagram. Inkscape will save modified diagrams in PDF, EPS, SVG or
any other reasonable graphics format.

Regards,

Hans Werner Borchers
ABB Corporate Research

> 
> Duncan Murdoch
>

__
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] Long Range Dependence: Hurst exponent estimation

2008-08-04 Thread Hans W. Borchers
> 

There is the 'fdim' package that computes the fractal dimension D.
Between D and the Hurst exponent H there should be a relation

D = 2 - H

I wonder if this is true when computing D and H with different
approaches

Regards,

Hans Werner Borchers
ABB Corporate Research

 jpmorgan.com> writes:
> Thanks Gary. 
> 
> That package is a bit weird. When one installs and loads it up, you don't 
> actually get any of those functions. [...]
>  
>  It appears to be the case that the fSeries package currently does not 
> really have that functionality. Perhaps they meant to put it in there but 
> decided to exclude it in the current release for some reason.
> 
> I have also cc'd the RMetrics group here to see if they can cast a light 
> on this issue.
> 
> Thanks,
> Tolga
>

__
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] convert for loop into apply()

2008-08-03 Thread Hans W. Borchers

Also, your request can easily be formulated as an SQL statement,
for example utilizing the 'sqldf' package:


library(sqldf)

a1 <- data.frame(id = 1:6,
 cat = paste('cat', rep(1:3, c(2,3,1))),
 st = c(1, 7, 30, 40, 59, 91),
 en = c(5, 25, 39, 55, 70, 120))

a2 <- data.frame(id = paste('probe', 1:8),
 cat = paste('cat', rep(1:3, c(2,3,3))),
 st = c(1, 9, 20, 38, 53, 70, 80, 95),
 en = c(6, 15, 36, 43, 58, 75, 85, 98))

sqldf("select a1.id as id, count(*) from a1, a2 where a1.cat = a2.cat
  and a2.st <= a1.en
  and a2.en >= a1.st
  group by a1.id")

#   id count(*)
#11
#21
#32
#42
#61


Of course, it needs some overhead in generating the SQLite tables.
Therefore I would very much like to hear whether there is some
significant improvement -- or the contrary.

//  Hans Werner Borchers



Anh Tran-2 wrote:
> 
> Hi all,I know this topic has came up multiple times, but I've never fully
> understand the apply() function.
> 
> Anyway, I'm here asking for your help again to convert this loop to
> apply().
> 
> I have 2 data frames with the following information: a1 is the fragment
> that
> is need to be covered, a2 is the probes that cover the specific fragment.
> 
> I need to count the number of probes cover every given fragment (they need
> to have the same cat ID to be on the same fragment)
> 
> a1<-data.frame(id=c(1:6), cat=c('cat 1','cat 1','cat 2','cat 2','cat
> 2','cat
> 3'), st=c(1,7,30,40,59,91), en=c(5,25,39,55,70,120));
> a2<-data.frame(id=paste('probe',c(1:8)), cat=c('cat 1','cat 1','cat
> 2','cat
> 2','cat 2','cat 3','cat 3','cat 3'), st=c(1,9,20,38,53,70,80,95),
> en=c(6,15,36,43,58,75,85,98));
> a1$coverage<-NULL;
> 
> I came up with this for loop (basically, if a probe starts before the
> fragment end, and end after a fragment start, it cover that fragment)
> 
> for (i in 1:length(a1$id))
> {
> a1$coverage[i]<-length(a2[a2$st<=a1$en[i]&a2$en>=a1$st[i]&a2$cat==a1$cat[i],]$id);
> }
> 
>> a1$coverage
> [1] 1 1 2 2 0 1
> 
> 
> This loop runs awefully slow when I have 200,000 probes and 30,000
> fragments. Is there anyway I can speed this up with apply()?
> 
> This is the time for my for loop to scan through the first 20 record of my
> dataset:
>user  system elapsed
>   2.264   0.501   2.770
> 
> I think there is room for improvement here. Any idea?
> 
> Thanks
> -- 
> Regards,
> Anh Tran
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/convert-for-loop-into-apply%28%29-tp18786483p18796799.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] Solving Yis[i] = a*cos((2*pi/T)*(times[i] - Tau)) + ...

2008-08-01 Thread Hans W. Borchers

Treat it as an over-determined linear system, that is:

A <- cbind(cos((2*pi/T)*(Times - Tau)), sin((2*pi/T)*(Times - Tau)))
qr.solve(A, Yis)

because 'solve' will only handle square matrices.


Hans W. Borchers


Josué Polanco wrote:
> 
> Hi everybody,
> 
> I am reading the Lomb paper (Lomb, 1976) and I found an interesting
> equation, and I wish to resolve it using R. I am wondering if anybody has
> a
> hint. The equation is:
> 
> Yis[i] = a*cos((2*pi/T)*(Times[i] - Tau))  + b*sin((2*pi/T)*(Times[i] -
> Tau)) ... (1)
> 
> Where T and Tau are constants.  I know the "Times" and "Tis" values (in
> fact
> these values come from a Time Series), and I need found the values of a
> and
> b. I can resolve the eq. (1) using a pencil and paper (expanding this as a
> linear system of equation), it is not a difficult problem, although I am
> not
> able to resolve it using R.
> 
> Any hint or advice would be very appreciated,
> 
> Thank you so much
> 
> --
> Josue  Polanco
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Solving-Yis-i--%3D-a*cos%28%282*pi-T%29*%28times-iTau%29%29-%2B-...-tp18771850p18774613.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] Fit a 3-Dimensional Line to Data Points

2008-07-25 Thread Hans W. Borchers
S. M. Niaz Arifin  yahoo.com> writes:
> 
> Hi Experts,
> I am new to R, and was wondering how to do 3D linear
> regression in R. In other words, I need to Fit a
> 3-Dimensional Line to Data Points (input).
> 
> I googled before posting this, and found that it is
> possible in Matlab and other commercial packages. For
> example, see the Matlab link:
>
http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/orthoregdemo.html#10
> 
> Is there a way to achieve this in R?

As a short self-test I translated the Matlab code into R where we take
as "best fit" the first principal component -- as in the Matlab example.

# I copied the Matlab matrix see below; load it from there first.
# X <- matrix(scan(stdin()), ncol=3, byrow=TRUE)
#   -0.4326   -1.0767   -0.9895
#   ...
#

  N <- nrow(X)

  meanX <- apply(X, 2, mean)
  Xpca   <- princomp(X)
  dirVector <- Xpca$loadings[, 1]

  Xfit1 <- matrix(rep(meanX, each=N), ncol=3) + 
 Xpca$score[, 1] %*% t(dirVector)
  t <- c(min(Xpca$score[, 1])-.2, max(Xpca$score[, 1])+.2)
  endpts <- rbind(meanX + t[1]*dirVector, meanX + t[2]*dirVector)

  library(scatterplot3d)
  s3d <- scatterplot3d(X[, 1], X[, 2], X[, 3], color="blue")
  s3d$points3d(endpts[, 1], endpts[, 2], endpts[, 3], type="l",
   col="red", lwd=2)

I leave it as an exercise to add the straight perpendicular segment from
the points to the line.

You can look at it interactively applying the RGL package !

Hans Werner Borchers


P.S.:   Definition of X copied from the Matlab example

X <- matrix(scan(stdin()), ncol=3, byrow=TRUE)
   -0.4326   -1.0767   -0.9895
   -1.66560.2689   -2.7947
0.12530.52250.7053
0.28771.7158   -0.4033
   -1.14650.3500   -0.6580
1.1909   -0.39241.0894
1.18920.61050.7931
   -0.0376   -0.9963   -0.5846
0.32730.0463   -0.4308
0.1746   -0.0123   -0.1329
   -0.1867   -0.0373   -0.9605
0.7258   -0.1663   -0.1853
   -0.58830.95520.4620
2.1832   -1.39951.8350
   -0.13640.3923   -1.0084
0.11390.9003   -0.0771
1.06680.9295   -0.1472
0.05930.5780   -0.9852
   -0.09560.0204   -0.2554
   -0.83230.4969   -0.0122
0.29440.61630.2148
   -1.3362   -0.5177   -0.4395
0.7143   -0.2270   -0.2632
1.62360.03480.8565
   -0.6918   -1.5837   -0.4571
0.8580   -0.0577   -0.2148
1.25400.3669   -0.0623
   -1.5937   -0.0103   -0.5090
   -1.44101.1262   -1.2071
0.5711   -0.2297   -0.0015
   -0.39990.53070.1948
0.69000.92090.5309
0.81561.0850   -0.2560
0.7119   -0.82971.5774
1.29020.46581.0754
0.66860.36681.4688
1.1908   -0.74921.7739
   -1.2025   -0.9675   -1.2144
   -0.01981.0565   -1.0725
   -0.1567   -0.1602   -0.1419
   -1.60410.0612   -1.4099
0.25730.1377   -0.4227
   -1.0565   -0.8339   -0.3004
1.4151   -0.26522.1121
   -0.80510.2737   -1.0093
0.5287   -0.8250   -0.0866
0.21930.8093   -0.1305
   -0.92190.3731   -0.2627
   -2.1707   -1.2392   -1.9997
   -0.0592   -0.2721   -0.8440

#EOF

__
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] Coconut benchmark for R?

2008-07-24 Thread Hans W. Borchers

I wonder what such a benchmark test would be good for.

Relevant and speaking tests in Global Optimization are formulated as models
in AMPL, GAMS, GMPK, MPS, etc. Rewriting a model in matrix form can be a
tedious manual task and I have not yet seen it.

Very few optimization packages in R accept such higher models as input, as
for instance linprog, lpSolve, Rglpk, or Rsymphony.

And those that do are in reality free implementations that have been
integrated into R. Benchmarking these functions will not show significant
differences to benchmarks done with their original versions.

Did I misunderstand your intentions?

Hans Werner Borchers
ABB Corporate Research



Imanpreet Arora wrote:
> 
> Hello All,
> 
> Could anybody point me out any port of "Global Optimization
> Test
> Problems" OR "Constraint Satisfaction Test Problems" part of Coconut[%]
> benchmark or other such similar benchmarks for R.
> 
> 
> [%] Coconut benchmark:
> http://www.mat.univie.ac.at/users/neum/public_html/glopt/coconut/Benchmark/Benchmark.html
> 
> 
> Cheers!
> 
> Isa
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Coconut-benchmark-for-R--tp18628700p18638008.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] How to get rule number in arules

2008-07-24 Thread Hans W. Borchers

As always, 'str(rules)' will provide you with a view on the internal
structure of 'rules'. By the way, 'rules' is of class 'rules', see the
"rules-class" entry in the ARULES help pages, with more explanations on the
meaning of attributes.

For example, '[EMAIL PROTECTED]' will show support, confidence, and lift of all
generated rules in sequence. 

Hans Werner Borchers
ABB Corporate Research



Daniel Wagner-7 wrote:
> 
> Dear R experts
> 
> I generated rules using apriori method in arules package. Though I can
> access rules using %in% function but I am unable to access a specific rule
> by its unique identifier number. I want to use rule number for further
> analysis..
> 
> Thanking you in advance.
> 
> Daniel
> Amsterdam
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-get-rule-number-in-arules-tp18629019p18637087.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] randomForest Tutorial

2008-07-22 Thread Hans W. Borchers

The help pages for 'randomForest' are quite clear in stating how to use the
'randomForest()' function. Input is a data frame (not a csv-file) and a
formula involving attribute names.

There is a kind of tutorial for classification and clustering with Random
Forests on Leo Breiman's web page
.  It
describes the older code on which the R package is built, not the
implementation of RandomForest from Salford systems, so more or less what
you want.

And there is another implementation of random forests in the 'party'
package, see the 'cforest()' function. (The package varSelRF has already
been mentioned in a previous post.)

Hans Werner Borchers
ABB Corporate Research

Dirk Nemitz wrote:
> 
> I am new to R  and I'd like to use the randomForest package for my thesis
> (identifying important variables for more detailed analysis with other
> software). I have found extremely well written and helpful information on
>  the usage of R.
> 
> Unfortunately it seems to be very difficult to find similarly detailed
> tutorials for randomForest, and I just can't get it work with the
> information on
> http://rss.acs.unt.edu/Rdoc/library/randomForest/html/randomForest.html
> 
> Can anybody give me a hint where to find a more detailed tutorial? I am
> especially interested in preparation of data to use with randomForest (how
> to structure the csv-file) and which information is mandatory for the
> package to work. Maybe someone has a simple copy-paste example to share
> and
> experiment?
> 
> Thank you for your attention,
> 
> Dirk
> 
> ---
> Dirk Nemitz
> Zeppelinstr. 11a
> 37083 Göttingen
> Germany
> 
> Tel: +49 (0)551 492 32 51
> Mobil: +49 (0)175 709 31 92
> ---
> 
> 

-- 
View this message in context: 
http://www.nabble.com/randomForest-Tutorial-tp18588688p18594872.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] Editor fpr Mac OS

2008-07-21 Thread Hans W. Borchers
Angelo Scozzarella  tiscali.it> writes:

> 
> Hi,
> is there a good editor for Mac Os?

We had the same discussion in December 2007 and again in June 2008. Please
consider the recommendations given in these threads.

My personal favorite: TextMate , though commercial, is
excellent -- except you are an experienced Emacs user, in that case take also
Aquamacs  into account.
 
> Thank
> 
> Angelo Scozzarella
> 
> __
> 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.
> 

Hans Werner Borchers
ABB Corporate Research

__
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] Non-linearly constrained optimisation

2008-07-20 Thread Hans W. Borchers

Please have a look at the 'Rdonlp2' package at <http://arumat.net/Rdonlp2/>. 
It provides non-linear optinization with nonlinear constraints, so it may be
exactly what you are looking for. 

Whether this algorithm is powerful enough for your task has to be seen. 
There are examples on the Web page that will enable a quick start.

You did not give information about the complexity of your task, nor whether
you are seeking local or global solutions.

Hans Werner Borchers
ABB Corporate Research



Dear R Users,
I am looking for some guidance on setting up an optimisation in R with
non-linear constraints.

Here is my simple problem:
- I have a function h(inputs) whose value I would like to maximise
- the 'inputs' are subject to lower and upper bounds
- however, I have some further constraints: I would like to constrain the
values for two other separate function f(inputs) and g(inputs) to be within
certain bounds

This means the 'inputs' must not only lie within the bounds specified by
the 'upper' and 'lower' bounds, but they must also not take on values such
that f(inputs) and g(inputs) take on values outside defined values. h, f
and g are all non-linear.

I believe constroptim would work if f and g were linear. Alas, they are
not. Is there any other way I can achieve this in R ?

Thanks in advance,
Tolga


-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context: 
http://www.nabble.com/Non-linearly-constrained-optimisation-tp18549310p18558334.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] principal factor analysis

2008-07-20 Thread Hans W. Borchers
Jinsong Zhao  mail.hzau.edu.cn> writes:

> 
> Hi,
> 
> Is there a function to do principal factor analysis in R?

Do a 'RSiteSearch("factor analysis")' and you will find several packages for
Factor Analysis, such as:

FAiRFactor Analysis in R
FactoMineR  Factor Analysis and Data Mining with R

or  factor.pa(), "Principal Axis Factor Analysis", in package 'psych'.

It seems, 'common factors' is a more colloquial term used in PCA books, or did
you mean to compare 'principal components' with 'principal factors'?
 
> I am reading through ``A user's guide to principal components'' by J. E.
> Jackson. In Table 17.1, a comparison between principal components and
> common factors, and there is obvious difference between them. However, I
> don't know how to get the common factors.
> 
> Any suggestions? Thanks!
> 
> Jinsong
>

__
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] Histogram with colors according to factor

2008-07-08 Thread Hans W. Borchers

No; thanks for your try, but this is not what I want.

Here each bar has one single color. I would like to render each bar with
several colors according to the distribution of a factor.

I now learned that this is called "stacked histogram" (damned Excel).  In
the following entry

https://stat.ethz.ch/pipermail/r-help/2007-April/129645.html

Deepayan Sarkar has provided a solution though he doubts its value. Still, I
find "stacked histograms" a vuable tool during exploratory data analysis. 

Hans Werner


Is this what you want?

dataset <- data.frame(x = c(rnorm(100), runif(100), rchisq(100, 1)), y =
gl(3, 100, labels = LETTERS[1:3]))
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram()
ggplot(dataset, aes(x = x, fill = y)) + geom_histogram(position =
"dodge")

HTH,

Thierry 


-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context: 
http://www.nabble.com/Histogram-with-colors-according-to-factor-tp18336930p18337935.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] Histogram with colors according to factor

2008-07-08 Thread Hans W. Borchers

Given a data frame with a continuous variable and a factor. I would like to
generate a histogram of the continuous variable, where each bar is filled
with different colors according to the percentage of factor values falling
into this region of the continuous variable.

I looked into packages like 'lattice' and 'ggplot2'. Searching R-help
revealed that 'histogram' is spelled 'histogramm' in almost 2% of the
time.  I now know how to color whole bars, but did not find a solution
for this specific kind of visualization.

Many thanks in advance,  Hans Werner Borchers


Hans W. Borchers
ABB Corporate Research

-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context: 
http://www.nabble.com/Histogram-with-colors-according-to-factor-tp18336930p18336930.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] Question about Constraint Optimization

2008-06-27 Thread Hans W. Borchers

Have a look at the following R-help entry in March:

https://stat.ethz.ch/pipermail/r-help/2008-March/157249.html

with an example of how to use 'optim' with equality constraints. This will
also work with no gradient and 'method="SANN" '.

In my experience, solutions received with "SANN" were not too convincing. If
you look for 'evolutionary computing' approaches, Differential Evolution as
in 'DEoptim' -- though slower -- will give more accurate results in general. 

Hans Werner Borchers


HNie wrote:
> 
> Dear All,
> 
> I am having trouble in using R function "constrOptim" to do constraint 
> optimization. It seems that "constrOptim" calls function "optim" when it 
> does the optimization, and "optim" allows us to set "method" to be "SANN" 
> if we want to use simulated annealing. In "optim", the function allows us 
> to set gradient to be NULL when we treat "method" as "SANN". But in 
> "constrOptim", the function does not allow us to set gradient as "SANN" if 
> we set "method" to be "SANN". I am just curious about it.
> 
> I just wonder whether I am able to apply simulated annealing in to 
> constraint optimization function "constrOptim". Could someone help?
> 
> Thanks very much!
> 
> Sincerely,
> Hui 
> 
>   [[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.
> 
> 


-

Hans W. Borchers
ABB Corporate Research Germany
-- 
View this message in context: 
http://www.nabble.com/Question-about-Constraint-Optimization-tp18144556p18150237.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] constrOptim with method = "L-BFGS-B"

2008-06-18 Thread Hans W. Borchers

Dear Georges,

if you are interested in optimization methods in R, there is the
Optimization Task View that has been set up only a few weeks ago.  Most
likely it covers all the optimization algorithms available in R packages.

For constraint handling there have been some postings in April and May about
how to do this with 'optim' or 'constrOptim'.

If the error message says there are infinite values then this is probably
true: So maybe you should check your function that is to be optimized (or
the gradient function).

Consider that 'optim' is a _local_ optimizer, so the solution will heavily
depend on your starting values. There have been some discussions on local
and global optimizers in the postings as well.  The Optimization Task View
is quite careful about this difference.

Best regards,  Hans Werner


lhaba wrote:
> 
> Thank you for your answer. 
> 
> I posted this problem as it is because I am benchmarking multiple solvers
> over this particular problem. 
> 
> I will enquire LowRankQP, kernlab and quadprog packages as you suggested.
> 
> Thank you
> 
> Georges
> 

-- 
View this message in context: 
http://www.nabble.com/constrOptim-with-method-%3D-%22L-BFGS-B%22-tp17916460p17965067.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] Solving 100th order equation

2008-05-25 Thread Hans W. Borchers
Rolf Turner  auckland.ac.nz> writes:

>
>   [...]
> 
>   However uniroot(p,c(1.995,2.005)) gives
> 
>   $root
>   [1] 1.93
> 
>   $f.root
>   [1] -4.570875e+24
> 
>   $iter
>   [1] 4
> 
>   $estim.prec
>   [1] 6.103516e-05
> 
>   What a difference 7.214144e-06 makes!  When you're dealing with  
> polynomials of degree 100.
> 

I don't think R is the right tool to solve this kind of questions that belong to
the realm of Computer Algebra Systems. Yacas is much to weak for such high-order
polybomials, but we can apply more powerful CASystems, for instance the free
Maxima system. Applying

(%i)nroots(x^100 - 2*x^99 + 10*x^50 + 6*x - 4000, minf, inf)

immediately shows that there are only *two* real solutions, and then

(%i)a: realroots(x^100 - 2*x^99 + 10*x^50 + 6*x - 4000, 1e-15);
(%i)float(a)

(%o)[x=-1.074126672042147,x=1.982]

will provide real solutions with 15 decimals (does not change when more decimals
are used). So the difference that counts is actually much smaller.

The complex roots -- if needed -- will require special treatment.

I believe it would be fair to point such questions to Computer Algebra mailing
lists and not try to give the appearance they could be solved satisfyingly with
R. The same as a complicated statistics question in a Matlab or Mathematica
mailing list should be pointed to R-help.

Hans Werner

>   Bozhemoi!
> 
>   cheers,
> 
>   Rolf Turner

__
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] is.category

2008-05-12 Thread Hans W Borchers
Applejus  gmail.com> writes:

> 
> 
> Hello,
> 
> Could someone tell me what the SPLUS "is.category" function do and what is
> its equivalent in R?
> Thank you, I couldn't find any help elsewhere...
> 
>  

If you Web search for "splus help" or similar, you will find, among others,

  http://www.uni-muenster.de/ZIV/Mitarbeiter/BennoSueselbeck/s-html/shelp.html

and there under "is.category"

  "Creates or tests for categorical objects (vectors with a "levels" attribute).
   This function is deprecated; factor or ordered are now preferred."

Hans Werner

__
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] Hashes as S4 Classes, or: How to separate environments

2008-05-10 Thread Hans W Borchers
For learning purposes mainly I attempted to implement hashes/maps/dictionaries
(Python lingua) as S4 classes, see the coding below. I came across some rough S4
edges, but in the end it worked (for one dictionary).

When testing ones sees that the dictionaries D1 and D2 share their environments
[EMAIL PROTECTED] and [EMAIL PROTECTED], though I thought a new and empty 
environment would be
generated each time 'new("Dict")' is called.

QUESTION: How can I separate the environments [EMAIL PROTECTED] and [EMAIL 
PROTECTED] ?

Reading the articles mentioned in "Tipps and Tricks" didn't help me really.
Of course, I will welcome other corrections and improvements as well.
Working in R 2.7.0 under Windows.

Hans Werner


#-- Class and method definition for dictionaries ---

setClass("Dict",
representation (hash = "environment"),
prototype (hash = new.env(hash=T, parent = emptyenv()))
)

setMethod("show", signature(object="Dict"),
definition = function(object) ls([EMAIL PROTECTED])
)

setGeneric("hclear", function(object) standardGeneric("hclear"))
setMethod("hclear", signature(object="Dict"),
function(object) rm(list=ls([EMAIL PROTECTED]), [EMAIL PROTECTED])
)

setGeneric("hput", function(object, key, value) standardGeneric("hput"))
setMethod("hput", signature(object="Dict", key="character", value="ANY"),
function(object, key, value) assign(key, value, [EMAIL PROTECTED])
)

setGeneric("hget", function(object, key, ...) standardGeneric("hget"))
setMethod("hget", signature(object="Dict", key="character"),
function(object, key) {
if (exists(key, [EMAIL PROTECTED], inherits = FALSE)) {
get(key, [EMAIL PROTECTED])
} else {
return(NULL)
}
}
)

#  Some tests 
D1 <- new("Dict")
hput(D1, "a", 1)   # Same as: [EMAIL PROTECTED] <- 1
hput(D1, "b", 2)
hget(D1, "a")
hget(D1, "b")
show(D1)

D2 <- new("Dict")
hput(D2, "c", 3)
hput(D2, "d", 4)
hget(D2, "a")  # Wrong: was defined only for D1
hget(D2, "b")
show(D2)

hclear(D2) # Wrong: clears D1 too
show(D1)
#-

__
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] quasi-random sequences

2008-04-26 Thread Hans W. Borchers
baptiste Auguié  exeter.ac.uk> writes:
> 
> Dear list useRs,

You might be interested to apply the Hammersley or Halton point sets that 
are often used in numerical integration or Differential Evolution. These 
pseudo-random distributions are both uniform and irregular, but have a 
kind of minimum resolution

There is an implementation of Halton Sequences in the often overlooked 
'sfsmisc' package, see the 'QUnif()' function there.  The help includes a 
visualization example dispaying the behavior I think you were looking for.

Hans Werner


> I have to generate a random set of coordinates (x,y) in [-1 ; 1]^2  
> for say, N points. At each of these points is drawn a circle (later  
> on, an ellipse) of random size, [...]
> 
> My problem is to avoid collisions (overlap, really) between the  
> points. I would like some random pattern, but with a minimum  
> exclusion distance. In looking up "Numerical recipes in C", I found  
> out about some Sobol quasi-random sequences, which one can call from  
> the gsl package,
> [...]
> but this does not look very random: I clearly see some pattern  
> (diagonals, etc...), and even the non-overlapping condition is not  
> impressive.
> 
> One (painful) way I can foresee is to check the distance between each  
> symbol and the others, and move the overlapping ones in a recursive  
> manner. Before delving into this, I wanted to check I'm not  
> overlooking something in the rgl quasi-random sequences, or missing a  
> more obvious way to generate such patterns. Perhaps solving an  
> electrostatic problem with a potential both attractive at long  
> distances and repulsive at short distances is a better way? I have a  
> vague recollection of hearing that somewhere to position points  
> evenly on a sphere.
> 
> Thanks for any comment / suggestion,
> 
> Baptiste
>

__
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] How to pack my stuff into a package (library, collection)?

2008-04-07 Thread Hans W. Borchers
Tribo Laboy  gmail.com> writes:
> [...]
> These seem to include among others Perl and compiler. But R is an
> interpreted and cross-platform language, I don't understand the need
> for additional platform specific tools just to call a user collection
> of R-files. Anyone knows of a smooth introduction to these topics?

There is a small 15-pages tutorial:

"Making R Packages Under Windows: A Simple Guide" by P. Rossi
http://faculty.chicagogsb.edu/peter.rossi/research/bayes%20book/bayesm/
   Making%20R%20Packages%20Under%20Windows.pdf

that might be helpful as a step-by-step instruction.

Hans Werner

__
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] How to improve the "OPTIM" results

2008-04-06 Thread Hans W Borchers
> MORE GENERAL OPTIM ISSUES
> 
>   I'm considering creating a package 'optimMLE' that would automate 
> some of this and package it with common 'methods' that would assume that 
> sum(fn(...)) was either a log(likelihood) or the negative of a 
> log(likelihood), etc.  However, before I do, I need to make more 
> progress on some of my other commitments, review RSiteSearch("optim", 
> "fun") to make sure I'm not duplicating something that already exists, 
> etc.  If anyone is interested in collaborating on this, please contact 
> me off-line. 
> 
>   Hope this helps. 
>   Spencer

Thanks for your tips on using `optim()'. I believe `optim' is a reasonable good
implementation of numerical optimization techniques such as quasi-Newton BFGS or
conjugate gradients. Maybe methods using modern line searches or trust regions
can follow someday.

Everybody applying `optim' should be aware that it is a *Local Optimization*
(LO) approach. What you describe appears to be a step towards *Global
Optimization* (GO) in R. And indeed more and more requests in to the R-help list
are about `optim' as a tool for global optimization, not always being fully
aware of the differences.

I am wondering whether it would be more useful to provide one or two global
optimization approaches to the R community. And as this is an active research
area, there are many and with different advantages and drawbacks.

I would like to propose IPOPT as one of he newer and more advanced methods for
global optimization. This powerful software package is open source and available
through the COIN-OR initiative and its Web pages:

http://www.coin-or.org/Ipopt/documentation/

``Ipopt (Interior Point OPTimizer, pronounced I-P-Opt) is a software 
package 
for large-scale nonlinear optimization. Ipopt is written in C++ and is 
released as open source code under the Common Public License (CPL). It is
available from the COIN-OR initiative. The code has been written by Carl
Laird (Carnegie Mellon University) and Andreas Wachter (IBM's T.J. Watson 
Research Center), who is the COIN project leader for Ipopt.''

PERHAPS the COIN project would agree for IPOPT to be integrated into the open
source project R as a package. For testing it right now there is an AMPL-based
interface to IPOPT at the NEOS solver:

http://neos.mcs.anl.gov/neos/solvers/nco:Ipopt/AMPL.html

There may be other rewarding projects in the COIN-OR initiative, such as
`SYMPHONY' for solving mixed-integer linear programs (MILP, stronger than `glpk'
and `lp-solve'), or the BONMIN open source *non-linear* mixed integer
programming (MINLP) solver. I could imagine R to be a good platform for
integrating some of these algorithms.


Hans W. Borchers
Control and Optimization Group
ABB Corporate Research Germany
[EMAIL PROTECTED]

__
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] Applying rbind() to a sequence of data frame names

2008-04-01 Thread Hans W. Borchers
I have a set of data frames ds1, ds2, ... each having the same columns
and column names:

  ds1 <- data.frame(x=c(1,2,3,4), y=c(5,6,7,8))
  ds1 <- data.frame(x=c(9,10,11,12), y=c(13,14,15,16))
  ...

and I would like to combine them into just one data frame like

  ds <- rbind(ds1, ds2, ...)

Because there are so many of them, I will have to use a character array

  nms <- c("ds1", "ds2", ...)

How can I use this character array to generate a command using rbind()
on all of these data frames at once.

I tried to apply eval() somehow, but did not come up with the right idea.

Thanks

__
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] DE optimization with equality constraint

2008-03-31 Thread Hans W. Borchers
Paul Smith  gmail.com> writes:
> The problem with DEoptim approach is that is not guaranteed that it
> converges to the solution. Moreover, from my experience, it seems to
> be quite slow when the optimization problem is high-dimensional (i.e.,
> with many variables).
> 
> Paul

There is a difference between local and global optimization:

'optim' realizes *local* optimization using a gradient-based approach.
This is fast, but will get stuck in local optima (except method SANN). 
'DEoptim' is one of many approaches to *global* optimization, of which
each has its advantages and drawbacks.

> ...not guaranteed that it converges to the solution.

  As a local optimization routine, also 'optim' does not guarantee to
  reach a (global) optimum.

> [DEoptim] seems to be quite slow...

  This is normal for routines in global optimization as they have to
  search a quite large space.

Hans Werner

__
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] DE optimization with equality constraint

2008-03-29 Thread Hans W. Borchers
> Reply to "Optimization with constraint" on March 14, 2008

One can get an accurate solutons applying the "Differential Evolution" algorithm
as implemented in the DEoptim package:

f2 <- function(x){
if (x[1] + x[2] < 1 || x[1] + x[2] > 1) {
r <- Inf
} else {
r <- x[1]^2 + x[2]^2
}
return(r)
}

lower <- c(0, 0)
upper <- c(1, 1)

DEoptim(f2, lower, upper, control=list(refresh=200))$bestmem

iteration:  200 best member:  0.5 0.5 best value:  0.5

This approach assumes nothing about the gradient, hessian or whatever. And the
equality is split into two inequalities assuming no relaxation or penalty.


Andreas Klein  yahoo.de> wrote:
> 
> Hello.
> 
> I have some problems, when I try to model an
> optimization problem with some constraints.
> 
> The original problem cannot be solved analytically, so
> I have to use routines like "Simulated Annealing" or
> "Sequential Quadric Programming".
> 
> But to see how all this works in R, I would like to
> start with some simple problem to get to know the
> basics:
> 
> The Problem:
> min f(x1,x2)= (x1)^2 + (x2)^2
> s.t. x1 + x2 = 1
> 
> The analytical solution:
> x1 = 0.5
> x2 = 0.5
> 
> Does someone have some suggestions how to model it in
> R with the given functions optim or constrOptim with
> respect to the routines "SANN" or "SQP" to obtain the
> analytical solutions numerically?
> 
> Again, the simple example should only show me the
> basic working of the complex functions in R.
> 
> Hope you can help me.
> 
> With regards
> Andreas.

__
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 Code and the Pygments Python SyntaxHighlighter

2008-03-27 Thread Hans W. Borchers
Dear R Help,

is someone going to write a R/S language lexer for the Pygments Python syntax
highlighter ? As it is used now by Trac, Django, or the
Python documentation tool Sphinx, the R community can apply it in Python-based
Wikis like Moinmoin and others.

Hans Werner

__
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] Optimization with constraint.

2008-03-14 Thread Hans W Borchers
Andreas Klein  yahoo.de> writes:
> 
> Hello.
> 
> I have some problems, when I try to model an
> optimization problem with some constraints.
> 
> The original problem cannot be solved analytically, so
> I have to use routines like "Simulated Annealing" or
> "Sequential Quadric Programming".
> 
> But to see how all this works in R, I would like to
> start with some simple problem to get to know the
> basics:
> 
> The Problem:
> min f(x1,x2)= (x1)^2 + (x2)^2
> s.t. x1 + x2 = 1
> 
> The analytical solution:
> x1 = 0.5
> x2 = 0.5
> 
> Does someone have some suggestions how to model it in
> R with the given functions optim or constrOptim with
> respect to the routines "SANN" or "SQP" to obtain the
> analytical solutions numerically?
> 

In optimization problems, very often you have to replace an equality by two
inequalities, that is you replace  x1 + x2 = 1  with

min f(x1,x2)= (x1)^2 + (x2)^2
s.t.  x1 + x2 >= 1
  x1 + x2 <= 1

The problem with your example is that there is no 'interior' starting point for
this formulation while the documentation for constrOptim requests:

The starting value must be in the interior of the feasible region,
but the minimum may be on the boundary.

You can 'relax', e.g., the second inequality with  x1 + x2 <= 1.0001 and use
(1.5, 0.0) as starting point, and you will get a solution:

>>> A <- matrix(c(1, 1, -1, -1), 2)
>>> b <- c(1, -1.0001)

>>> fr <- function (x) { x1 <- x[1]; x2 <- x[2]; x1^2 + x2^2 }

>>> constrOptim(c(1.5, 0.0), fr, NULL, ui=t(A), ci=b)

$par
[1] 0.5000232 0.4999768
$value
[1] 0.5
[...]
$barrier.value
[1] 9.21047e-08

where the accuracy of the solution is certainly not excellent, but the solution
is correctly fulfilling  x1 + x2 = 1.

__
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] Package for Multiple Additive Regression Trees

2008-02-14 Thread Hans W. Borchers
Christopher Schwalm  umn.edu> writes:

> 
> Hello List,
> 
> I've been unsuccessful in tracking down a package that does MART. J 
> Friedman's website has a page that mentions an R implementation but the 
> links lead nowhere. There is also a nice walkthru/vignette pdf on his site. 
> But I can not find this package anywhere. Perhaps it's commercial? Does 
> anyone know of where it might be available or of any other R package (or 
> Matlab toolbox) that can do MART?
> 
> Many thanks,
> Christopher
> 

There has been a rough R-code implementation of MART some years ago on
Friedman's home page. Since then, MART is only available from Salford
Systems as part of their TreeNet software.

I asked Jerome Friedman about the R/MART interface, but he only guided
me to the Salford System Web page. Salford replied, but I never received
any R interface for their software from them.

TreeNet is a very interesting Data Mining applicatione. To try it out
you can easily receive a demo license from Salford -- without the R
interface, of course.

Hans W. Borchers

__
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] Expert systems

2008-01-29 Thread Hans W. Borchers
Ralf Finne  syh.fi> writes:
> 
> Hi R-users
> Is there any functions in R that can implement "expert systems"?
> The aim of an expert system is to produce a probable diagnosis
> for a patient with certain symptoms.
> In the classical expert system a mumber of "experts" are asked to make
> "statements" on the probabilities for different diseases when a
> combination of systems would appear.   One typical "expert system"
> uses Fuzzy Logic to suggest the diagnosis.
> 
> In more modern systems one tends to make the system self learning
> to improve the system.
> 

What you are describing here is just one of several ways to realize an "expert
systems". And the question is also what kind of technique you would like to
implement such a system in, e.g., rule-based, fuzzy sets, (Bayesian) networks,
constraints, case bases, etc.

The closest R may come to expert system techniques is through Weka in the RWeka
package (I should also mention 'deal' for graphical networks). R as statistical
software focuses more on the learning aspect, not on explicitly representing
'knowledge' in whatever form.

There are commercial and free "expert system shells" one could utilize. CLIPS
 is a bit old-fashioned, but could easily be
integrated with R; JESS  being another one.

Also Prolog systems (especially if they include CSP solvers) such as BProlog or
SWI Prolog are free and could be combined (at least through file or pipe
transfer) with R to generate complete applications.

Regards,  Hans Werner Borchers


> Hoping for comments
> Ralf Finne
> Swenska yrkeshögskolan
> Vasa Finland
> 
> __
> 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.


[R] Plotting error bars in xy-direction

2007-12-05 Thread Hans W. Borchers
Dear R-help,

I am looking for a function that will plot error bars in x- or y-direction (or 
both), the same as the Gnuplot function 'plot' can achieve with:

plot "file.dat" with xyerrorbars,...

Rsite-searching led me to the functions 'errbar' and 'plotCI' in the Hmisc, 
gregmisc, and plotrix packages. As I understand the descriptions and examples, 
none of these functions provides horizontal error bars.

Looking into 'errbar' and using segments, I wrote a small function for myself 
adding these kinds of error bars to existing plots. I would still be interested 
to know what the standard R solution is.

Regards,  Hans Werner

__
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] Questions on RWeka classifiers?

2007-11-28 Thread Hans W. Borchers
Li Li  gmail.com> writes:

> 
> Hi,
> 
> I am using some classifiers in RWeka packages and met a couple problems.
> 
> (1) J48 implements C45 classifier, the C45 should be able to handle missing
>  values in both training set and test set. But I found the J48
> classifier can
>  not be evaluated on test set with missing values--it just ignore them.

Why don't you ask this question on the WEKA mailing list at, for instance,
http://news.gmane.org/gmane.comp.ai.weka !

If I remember correctly, C4.5 is smart enough to simply drop examples with
missing values, while C5.0 will handle them more intelligently. It will also
address numerical attributes more sensible than C4.5 or CART.

Unfortunately, C5.0 is commercial software, but you can get a 2-weeks demo from
Quinlan's site.

> (2) The ensemble classifiers in RWeka such as bagging and boosting: there
>  is a control argument as "W" to describe which base classifier should
> be used.
>  I use "W=J48" to boost C45 tree, but I am not sure how to down size the
> tree
> to be a "weak" learner. Based on what I observed, the default boosted
> J48 tree
> gets worse performance.

This is difficult to answer without any concrete data. From my own experince I
can say that in many cases results have distinctively improved when applying
Adaboost.

> 
> Thanks for any discussion and help,
> 
> Li
> 

Regards,  Hans Werner Borchers

__
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 and reading matlab compressed files

2007-11-19 Thread Hans W Borchers
Prof Leslie Smith  cs.stir.ac.uk> writes:

> 
> Is there any way to read these files (standard .mat files, created by
> matlab version 7 onwards are compressed)? I know that R.matlab doesn't
> read them (it even says in the file MatlabServer.m "Matlab v7 saves
> compressed files, which is not recognized by R.matlab's readMat()" (lines
> 47-8)).
> 
> I know I should be able to make R call Matlab and transfer data (not that
> I managed to make it work yet!), but I'd rather not run Matlab & R
> together: I'd like to use R to read matlab files on machines not licensed
> for matlab!
> 
> Are there any ways to make this work?
> 
> --Leslie Smith
> 

You can save data in Matlab with the '-ASCII' option (see 'help save') which 
makes them easily readable by R or any other numerical software. By also zipping
the file it will be comparable in size to the binary '.mat' format.

Hans Werner

__
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] convex optimization package for R, specifically semidefinite programming

2007-11-15 Thread Hans W Borchers
>
Hi there,

I do assume you are talking about the CVXOPT (and CVXMOD) Python package(s). 
Please note that CVXOPT only contains _interfaces_ to the solvers in MOSEK, 
because these are commercial products (as Roger Koenker already has mentioned).

There appear to be some Python/Scipy-based solvers available in CVXOPT, but for 
larger applications one would still have to utilize the original CVX modules. 
CVX itself is a free "Matlab software for disciplined convex optimization". As 
you can read on their Web page , future 
plans are to port it to other frameworks such as *R*, Octave, or Mathematica.

Perhaps the R community could accelerate such an R port by contacting the 
developers and by offering support and provision (I can't, I'm no programmer, 
I am only modeling and trying to solve optimization problems).

--  Hans Werner


Galkowski, Jan  akamai.com> writes:
> 
> Recently, a package for convex optimization was announced for Python,
> based upon the LP solver GLPK, the SDP solver
> in DSDP5, and the LP and QP solvers in MOSEK.  I'm aware GLPK is
> available for R, but wondered if anyone had good
> packages for convex optimization along these lines for R.
> 
> TIA.
> 
> __
> 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.


<    1   2   3