[Rd] Wishlist: axis( ) could take vector of colors (PR#7930)

2005-06-10 Thread epurdom
Hi,
This is not a bug, but a simple enhancement suggestion: that axis( ) also 
allow option "col" to take a vector of colors equal to the length of 
"labels". Currently it allows it, in the sense that there is no error 
message, but the function will use just the first element of the vector.

Example
 > plot(1:5,exp(1:5),axes=F,type="o")
 > axis(1,col=c(rep("red",2),rep("blue",3)))
gives all red axis notation.

Thanks,
Elizabeth Purdom
(Windows XP, R 2.1.0)

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Wishlist: strwidth allow for rotation of text (PR#7931)

2005-06-10 Thread epurdom
Hi,

This is not a bug, but an enhancement suggestion. "strwidth" only gives the 
width of the text according to the x-axis user coordinates, and similarly 
for "strheight". Even if the par setting "srt" is changed to rotate the 
text, the resulting width (resp. height) is in terms of the non-rotated 
text. Currently, if I want to know how much space to leave for vertical 
text in the user coordinates, I manually invert the user coordinates, and 
then change them back.

Even if arbitrary "srt" is too much, just having the option for 90 degree 
rotation would be helpful. If it were implemented for arbitrary srt, then I 
personally think it's x-axis and y-axis dimensions are of interest, and not 
the actual length of the rotated text.

I'm using R 2.1.0, Windows XP

Thanks,
Elizabeth Purdom

Example:
plot(1:100,seq(2,5,length=100), type="n")
par("usr")
# [1]  -2.96 103.96   1.88   5.12
strwidth("hello","user")
# [1] 7.613353
par(srt=90) #rotate 90 degrees
strwidth("hello","user") #still gives same width of text
# [1] 7.613353
par(usr=par("usr")[c(3,4,1,2)])
strwidth("hello","user")
# [1] 0.2307077

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Error handling in solve.default (PR#8494)

2006-01-16 Thread epurdom
Hi, this is a minor problem in solve.default but I didn't see anyone 
mention it. The function does not give "correct" error-handling if given 
non-square matrix, LINPACK=F, and matrix has names attributes (either 
row or column names).

Demo:
##"correct" error handling of non-square matrix
 > temp<-diag(1,5)[,1:4]
 > solve(temp,LINPACK=F)
Error in solve.default(diag(1, 5)[, 1:4], LINPACK = F) :
'A' (5 x 4) must be square

#indeciferable error handling when same matrix is given names attributes
 > temp<-diag(1,5)[,1:4]
 > rownames(temp)<-as.character(1:5)
 > colnames(temp)<-as.character(1:4)
 > solve(temp,LINPACK=F)
Error in "rownames<-"(`*tmp*`, value = c("1", "2", "3", "4")) :
length of 'dimnames' [1] not equal to array extent

I think the problem is that if LINPACK=F, then the error handling of the 
argument "a" is not done until after creating a matrix "b", when none 
was given. Then, the function creates a square identity matrix for "b", 
to which it tries to assign row and column names of "a". Of course, 
since "a" is not square, they are not of the correct length.

Best,
Elizabeth

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] bug in '...' of constrOptim (PR#14071)

2009-11-18 Thread epurdom
Dear all,

There appears to be a bug in how constrOptim handles ... arguments that 
are suppose to be passed to optim, according to the documentation. This 
means you can't get the hessian to be returned, for example (so this is 
a real problem, and not just a question of mistaken documentation).

Looking at the code, it appears that a call to the user-defined f 
includes the ..., when the ... should only be passed to the optim call. 
  I get around it by putting a dummy 'hessian=TRUE' argument in my f 
function, but this is not how the function should work.

I show the relevant problem in the code, give an example, and also give 
my sessionInfo() call below.

Thanks,
Elizabeth

##Copy of the relevant segment of the code of constrOptim and where I 
think the problem might be:
for (i in 1L:outer.iterations) {
 obj.old <- obj
 r.old <- r
 theta.old <- theta
 fun <- function(theta, ...) { ##this one's okay
 R(theta, theta.old, ...)##this one's okay
 }
 gradient <- function(theta, ...) {##this one's okay
 dR(theta, theta.old, ...)##this one's okay
 }
 a <- optim(theta.old, fun, gradient, control = control,
 method = method, ...)##this one's okay
 r <- a$value
 if (is.finite(r) && is.finite(r.old) && abs(r - 
r.old)/(outer.eps +
 abs(r - r.old)) < outer.eps)
 break
 theta <- a$par
 obj <- f(theta, ...)##this one's NOT okay
 if (obj > obj.old)
 break
 }

###Here is an example modified from the examples of the help page of 
constrOptim:
 > fr <- function(x) {   ## Rosenbrock Banana function
+ x1 <- x[1]
+ x2 <- x[2]
+ 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
+ }
 > grr <- function(x) { ## Gradient of 'fr'
+ x1 <- x[1]
+ x2 <- x[2]
+ c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1),
+200 *  (x2 - x1 * x1))
+ }
 > constrOptim(c(-1.2,0.9), fr, grr, ui=rbind(c(-1,0),c(0,-1)), ci=c(-1,-1))
$par
[1] 0.761 0.522

$value
[1] 5.708626e-10

$counts
function gradient
61

$convergence
[1] 0

$message
NULL

$outer.iterations
[1] 14

$barrier.value
[1] -0.0001999198

 > constrOptim(c(-1.2,0.9), fr, grr, ui=rbind(c(-1,0),c(0,-1)), 
ci=c(-1,-1),hessian=TRUE)
Error in f(theta, ...) : unused argument(s) (hessian = TRUE)
#add in a dummy argument to my f function
 > fr <- function(x,hessian=TRUE) {   ## Rosenbrock Banana function
+ x1 <- x[1]
+ x2 <- x[2]
+ 100 * (x2 - x1 * x1)^2 + (1 - x1)^2
+ }
 > constrOptim(c(-1.2,0.9), fr, grr, ui=rbind(c(-1,0),c(0,-1)), 
ci=c(-1,-1),hessian=TRUE)
$par
[1] 0.761 0.522

$value
[1] 5.708626e-10

$counts
function gradient
61

$convergence
[1] 0

$message
NULL

$hessian
   [,1]  [,2]
[1,]  801.9599 -399.9905
[2,] -399.9905  199.9952

$outer.iterations
[1] 14

$barrier.value
[1] -0.0001999198
###My Session info
 > sessionInfo()
R version 2.10.0 (2009-10-26)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] GEOquery_2.10.0RCurl_1.2-1bitops_1.0-4.1 
Biobase_2.5.8  biomaRt_2.1.0  projectManager_1.0 lattice_0.17-26 
RColorBrewer_1.0-2
[9] XML_2.6-0

loaded via a namespace (and not attached):
[1] grid_2.10.0  tools_2.10.0
-- 
Elizabeth Purdom
Assistant Professor
Department of Statistics
UC, Berkeley
Evans Hall, Rm 433
epur...@stat.berkeley.edu
(510) 642-6154 (office)
(510) 642-7892 (fax)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel