[Rd] discrepancy between lm and MASS:rlm

2011-03-14 Thread Vadim Ogranovich
Dear R-devel,

There seems to be a discrepancy in the order in which lm and rlm evaluate their 
arguments. This causes rlm to sometimes produce an error where lm is just fine.

Here is a little script that illustrate the issue:

 library(MASS)
 ## create data
 n - 100
 dat - data.frame(x=rep(c(-1,0,1), n), y=rnorm(3*n))

 ## call lm, works fine
 summary(lm(y ~ as.factor(x), data=dat, subset=x!=0))

Call:
lm(formula = y ~ as.factor(x), data = dat, subset = x != 0)

Residuals:
 Min   1Q   Median   3Q  Max
-2.60619 -0.82160  0.06307  0.65501  2.56677

Coefficients:
  Estimate Std. Error t value Pr(|t|)
(Intercept)   0.061010   0.100027   0.6100.543
as.factor(x)1 0.001332   0.141459   0.0090.992

Residual standard error: 1 on 198 degrees of freedom
Multiple R-squared: 4.479e-07,  Adjusted R-squared: -0.00505
F-statistic: 8.868e-05 on 1 and 198 DF,  p-value: 0.9925

 ## call rlm, error
 summary(rlm(y ~ as.factor(x), data=dat, subset=x!=0))
Error in rlm.default(x, y, weights, method = method, wt.method = wt.method,  :
  'x' is singular: singular fits are not implemented in rlm



My guess is that rlm first converts x to a factor, which becomes a three-level 
factor, then subsets on x!=0, which effectively eliminates a level, and then 
creates a regression matrix, which becomes singular due to the absence of 
data for a level.

Is there a simple way to work around it. The simplest I could think of is
with(subset(dat, x!=0), rlm(y ~ as.factor(x))
which is ok, but most of my scripts make use of data arg to regressions and I'd 
like to stay consistent as much as practical.

Thanks,
Vadim


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

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


Re: [Rd] discrepancy between lm and MASS:rlm

2011-03-14 Thread Vadim Ogranovich
Indeed! I added the drop.unused.levels argument and it now works. Thank you 
Bill!

Here is a patch which one should use at one's own risk as it redefines 
rlm.formula as global object, i.e. rlm.formula is no longer in the MASS 
namespace and this is certainly not a good idea:

rlm.formula - function (formula, data, weights, ..., subset, na.action, method 
= c(M,
MM, model.frame), wt.method = c(inv.var, case), model = TRUE,
x.ret = TRUE, y.ret = FALSE, contrasts = NULL)
{
mf - match.call(expand.dots = FALSE)
mf$method - mf$wt.method - mf$model - mf$x.ret - mf$y.ret - 
mf$contrasts - mf$... - NULL
mf$drop.unused.levels - TRUE
mf[[1L]] - as.name(model.frame)
mf - eval.parent(mf)
method - match.arg(method)
wt.method - match.arg(wt.method)
if (method == model.frame)
return(mf)
mt - attr(mf, terms)
y - model.response(mf)
offset - model.offset(mf)
if (!is.null(offset))
y - y - offset
x - model.matrix(mt, mf, contrasts)
xvars - as.character(attr(mt, variables))[-1L]
if ((yvar - attr(mt, response))  0L)
xvars - xvars[-yvar]
xlev - if (length(xvars)  0L) {
xlev - lapply(mf[xvars], levels)
xlev[!sapply(xlev, is.null)]
}
weights - model.weights(mf)
if (!length(weights))
weights - rep(1, nrow(x))
fit - MASS:::rlm.default(x, y, weights, method = method, wt.method = 
wt.method,
...)
fit$terms - mt
cl - match.call()
cl[[1L]] - as.name(rlm)
fit$call - cl
fit$contrasts - attr(x, contrasts)
fit$xlevels - .getXlevels(mt, mf)
fit$na.action - attr(mf, na.action)
if (model)
fit$model - mf
if (!x.ret)
fit$x - NULL
if (y.ret)
fit$y - y
fit
}

-Original Message-
From: William Dunlap [mailto:wdun...@tibco.com]
Sent: Monday, March 14, 2011 1:39 PM
To: Vadim Ogranovich; r-devel@r-project.org
Subject: RE: [Rd] discrepancy between lm and MASS:rlm


 -Original Message-
 From: r-devel-boun...@r-project.org
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Vadim Ogranovich
 Sent: Monday, March 14, 2011 10:37 AM
 To: 'r-devel@r-project.org'
 Subject: [Rd] discrepancy between lm and MASS:rlm

 Dear R-devel,

 There seems to be a discrepancy in the order in which lm and
 rlm evaluate their arguments. This causes rlm to sometimes
 produce an error where lm is just fine.

It may not be a problem with the order of evaluation.  rlm()
might not be calling model.frame() with drop.unused.levels=TRUE.
I've made that mistake before with similar symptoms.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 Here is a little script that illustrate the issue:

  library(MASS)
  ## create data
  n - 100
  dat - data.frame(x=rep(c(-1,0,1), n), y=rnorm(3*n))
 
  ## call lm, works fine
  summary(lm(y ~ as.factor(x), data=dat, subset=x!=0))

 Call:
 lm(formula = y ~ as.factor(x), data = dat, subset = x != 0)

 Residuals:
  Min   1Q   Median   3Q  Max
 -2.60619 -0.82160  0.06307  0.65501  2.56677

 Coefficients:
   Estimate Std. Error t value Pr(|t|)
 (Intercept)   0.061010   0.100027   0.6100.543
 as.factor(x)1 0.001332   0.141459   0.0090.992

 Residual standard error: 1 on 198 degrees of freedom
 Multiple R-squared: 4.479e-07,  Adjusted R-squared: -0.00505
 F-statistic: 8.868e-05 on 1 and 198 DF,  p-value: 0.9925

  ## call rlm, error
  summary(rlm(y ~ as.factor(x), data=dat, subset=x!=0))
 Error in rlm.default(x, y, weights, method = method,
 wt.method = wt.method,  :
   'x' is singular: singular fits are not implemented in rlm
 


 My guess is that rlm first converts x to a factor, which
 becomes a three-level factor, then subsets on x!=0, which
 effectively eliminates a level, and then creates a
 regression matrix, which becomes singular due to the
 absence of data for a level.

 Is there a simple way to work around it. The simplest I could
 think of is
 with(subset(dat, x!=0), rlm(y ~ as.factor(x))
 which is ok, but most of my scripts make use of data arg to
 regressions and I'd like to stay consistent as much as practical.

 Thanks,
 Vadim


 Note: This email is for the confidential use of the named
 addressee(s) only and may contain proprietary, confidential
 or privileged information. If you are not the intended
 recipient, you are hereby notified that any review,
 dissemination or copying of this email is strictly
 prohibited, and to please notify the sender immediately and
 destroy this email and any attachments.  Email transmission
 cannot be guaranteed to be secure or error-free.  Jump
 Trading, therefore, does not make any guarantees as to the
 completeness or accuracy of this email or any attachments.
 This email is for informational purposes only and does not
 constitute a recommendation, offer, request or solicitation
 of any kind to buy, sell, subscribe, redeem or perform any
 type of transaction of a financial product.

 __
 R

[Rd] calling browser on error

2010-10-15 Thread Vadim Ogranovich
Dear R-developers,

I am trying to figure out a way to call browser() when an error occur, and 
naturally I want the browser() to be called in the environment of the error.

I tried something simple in vain:

 f - function() { x - 1; stop('ok') }
 tryCatch(f(), error=browser())
Called from: tryCatch(f(), error = browser())
## if browser() was called in the local environment of f then 'x' would be set, 
but it's not
Browse[1] x
Error: object 'x' not found
Browse[1] Q

Is there a way to make it work? What do people do to 'set an on-error 
breakpoint'?

Thanks,
Vadim


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

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


Re: [Rd] calling browser on error

2010-10-15 Thread Vadim Ogranovich
Joshua,

I didn't know about 'recover', thank you!

Anyway it doesn't work for me:
 tryCatch((function() { x - 1; stop('ok') })(), error=recover())

Enter a frame number, or 0 to exit

1: tryCatch((function() {

Selection: 1
Called from: eval(expr, envir, enclos)
Browse[1] x
Error: object 'x' not found
Browse[1] Q

Though it does work if I set options(error = recover):
 options(error = recover)
 (function() { x - 1; stop('ok') })()
Error in (function() { : ok

Enter a frame number, or 0 to exit

1: (function() {

Selection: 1
Called from: eval(expr, envir, enclos)
Browse[1] x
[1] 1
Browse[1] Q

I do not run the latest R so it might be the reason:
 version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  9.1
year   2009
month  06
day26
svn rev48839
language   R
version.string R version 2.9.1 (2009-06-26)


-Original Message-
From: Joshua Ulrich [mailto:josh.m.ulr...@gmail.com]
Sent: Friday, October 15, 2010 1:31 PM
To: Vadim Ogranovich
Cc: r-devel@r-project.org
Subject: Re: [Rd] calling browser on error

I believe options(error=recover) will do what you want.

--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



On Fri, Oct 15, 2010 at 1:27 PM, Vadim Ogranovich
vogranov...@jumptrading.com wrote:
 Dear R-developers,

 I am trying to figure out a way to call browser() when an error occur, and 
 naturally I want the browser() to be called in the environment of the error.

 I tried something simple in vain:

 f - function() { x - 1; stop('ok') }
 tryCatch(f(), error=browser())
 Called from: tryCatch(f(), error = browser())
 ## if browser() was called in the local environment of f then 'x' would be 
 set, but it's not
 Browse[1] x
 Error: object 'x' not found
 Browse[1] Q

 Is there a way to make it work? What do people do to 'set an on-error 
 breakpoint'?

 Thanks,
 Vadim


 Note: This email is for the confidential use of the named addressee(s) only 
 and may contain proprietary, confidential or privileged information. If you 
 are not the intended recipient, you are hereby notified that any review, 
 dissemination or copying of this email is strictly prohibited, and to please 
 notify the sender immediately and destroy this email and any attachments.  
 Email transmission cannot be guaranteed to be secure or error-free.  Jump 
 Trading, therefore, does not make any guarantees as to the completeness or 
 accuracy of this email or any attachments.  This email is for informational 
 purposes only and does not constitute a recommendation, offer, request or 
 solicitation of any kind to buy, sell, subscribe, redeem or perform any type 
 of transaction of a financial product.

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


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

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


Re: [Rd] [R] converting result of substitute to 'ordidnary' expression

2010-06-26 Thread Vadim Ogranovich
I switched the thread to r-devel because here I am proposing a patch for 
subset.data.frame().


Thank you Chuck, it was inspiring. It turns out that a simple modification to 
subset.data.frame makes my example work:

subset.data.frame -
  function (x, subset, select, drop = FALSE, ...)
{
  if (missing(subset))
r - TRUE
  else {
r - eval(substitute(subset), x, parent.frame())

if (!is.logical(r)) {
  ## try w/o substitute
  r - eval(subset, x, parent.frame())
}

if (!is.logical(r))
  stop('subset' must evaluate to logical)

r - r  !is.na(r)
  }
  if (missing(select))
vars - TRUE
  else {
nl - as.list(1L:ncol(x))
names(nl) - names(x)
vars - eval(substitute(select), nl, parent.frame())
  }
  x[r, vars, drop = drop]
}


And now:
 dat - data.frame(x=1:10, y=1:10)

 subset(dat, 5x)
x  y
6   6  6
7   7  7
8   8  8
9   9  9
10 10 10

 subsetexp - expression(5x)

 subset(dat, subsetexp)
x  y
6   6  6
7   7  7
8   8  8
9   9  9
10 10 10


 do.call(subset, list(dat, subsetexp))
x  y
6   6  6
7   7  7
8   8  8
9   9  9
10 10 10

 version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  9.1
year   2009
month  06
day26
svn rev48839
language   R
version.string R version 2.9.1 (2009-06-26)


Thank you,
Vadim



-Original Message-
From: Charles C. Berry [mailto:cbe...@tajo.ucsd.edu]
Sent: Friday, June 25, 2010 9:16 PM
To: Vadim Ogranovich
Cc: 'r-h...@r-project.org'
Subject: Re: [R] converting result of substitute to 'ordidnary' expression

On Fri, 25 Jun 2010, Vadim Ogranovich wrote:

 Dear R users,


 As substitute() help page points out:
 Substituting and quoting often causes confusion when the argument
 is 'expression(...)'. The result is a call to the 'expression'
 constructor function and needs to be evaluated with 'eval' to give
 the actual expression object.

 And indeed I am confused. Consider:

 dat - data.frame(x=1:10, y=1:10)

 subsetexp - substitute(ax, list(a=5))

 ## this doesn't work
 subset(dat, subsetexp)
 Error in subset.data.frame(dat, subsetexp) :
  'subset' must evaluate to logical

 ## this does work (thanks to the help page), but one needs to remember to 
 call eval
 subset(dat, eval(subsetexp))


 Is there a way to create subsetexp that needs no eval inside the call to 
 subset()?

I do not think so. See

page(subset.data.frame,'print')

Then think about this:

 eval(substitute(subsetexp))
5  x
 eval(substitute(subsetexp),list(x=2))
5  x
 eval(substitute(eval(subsetexp)),list(x=2))
[1] FALSE


The added layer of substitution is making things a bit tricky.

One alternative is to build up your own call like this:

 sss - expression(subset(dat,sbst))
 sss[[1]][[3]] - subsetexp
 sss
expression(subset(dat, 5  x))
 eval(sss)
 x  y
6   6  6
7   7  7
8   8  8
9   9  9
10 10 10


HTH,

Chuck



 I experimented with the following, but it didn't work:
 subsetexp - eval(substitute(ax, list(a=5)))
 Error in eval(expr, envir, enclos) : object 'x' not found

 Thank you very much for your help,
 Vadim

 Note: This email is for the confidential use of the named addressee(s) only 
 and may contain proprietary, confidential or privileged information. If you 
 are not the intended recipient, you are hereby notified that any review, 
 dissemination or copying of this email is strictly prohibited, and to please 
 notify the sender immediately and destroy this email and any attachments.  
 Email transmission cannot be guaranteed to be secure or error-free.  Jump 
 Trading, therefore, does not make any guarantees as to the completeness or 
 accuracy of this email or any attachments.  This email is for informational 
 purposes only and does not constitute a recommendation, offer, request or 
 solicitation of any kind to buy, sell, subscribe, redeem or perform any type 
 of transaction of a financial product.

 __
 r-h...@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.


Charles C. Berry(858) 534-2098
 Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu   UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure

[Rd] Save all objects in all environment stack

2009-09-14 Thread Vadim Ogranovich
Dear R Developers,

I am writing a function that would save all objects in all environments 
'visible' from the point where the function is called (very much like 
save.image, but kind of saving the entire stack).

I figured that the call
lapply (seq(0, sys.nframe()), function(i) ls(sys.frame(i), all.names=T))
will list all such objects.

However not all of them seem to be visible, see a session transcript below

## create a simple function with a 'breakpoint'
 f - function(x) { browser() }
## call f in lapply inside an anonymous function defined on the fly
 (function(d) lapply('a', f))('d')
Called from: FUN(a[[1L]], ...)
## Examine all frames
Browse[1] lapply(seq(0, sys.nframe()), function(i) ls(sys.frame(i), 
all.names=T))
[[1]]
[1] f

[[2]]
[1] d

[[3]]
[1] ... FUN X

[[4]]
[1] x

## try to get d, which is in the second entry on the list
Browse[1] d
Error: object 'd' not found

Why 'd' is not found?

Did anyone try to write a function that, loosely speaking, saves the entire 
stack?

Thanks,
Vadim

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

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


Re: [Rd] bug in approx crashes R

2009-07-28 Thread Vadim Ogranovich
Thank you Martin! The new 'rule'-s is exactly what I wanted. It's intuitive and 
consistent with the scalar use.

Thanks,
Vadim

-Original Message-
From: Martin Maechler [mailto:maech...@stat.math.ethz.ch]
Sent: Tuesday, July 28, 2009 5:00 AM
To: Vadim Ogranovich
Cc: 'William Dunlap'; r-devel@r-project.org
Subject: Re: [Rd] bug in approx crashes R

 Vadim Ogranovich vogranov...@jumptrading.com
 on Mon, 27 Jul 2009 12:47:47 -0500 writes:

 Thank you Bill.

Indeed, thank you, Bill Dunlap!

 The original motivation for my
 experiments with setting yleft to NULL was to see if I
 could get more flexibility that that allowed by the
 'rule' argument. To recall:

 rule: an integer describing how interpolation is to
 take place outside the interval ['min(x)', 'max(x)']. If
 'rule' is '1' then 'NA's are returned for such points
 and if it is '2', the value at the closest data extreme
 is used.

 What I wanted is to interpolate at the left end, but not
 at the right end. Still don't know how to do that.

Really?
If you quickly browse the code, you see that's it's simply a
matter of correctly setting  yleft  and  yright.

But in order to help future users, and since it's so trivial,
I will change approxfun() {my favorite} and approx() to also
accept
rule = c(1,2)
or  rule = c(2,1)


 I agree that having a clear error message when yleft,
 yright, and f are set to non-scalars is better than
 silently returning NA.

yes, I agree too.

---
Martin Maechler, ETH Zurich


 Thanks,
 Vadim


 -Original Message-
 From: William Dunlap [mailto:wdun...@tibco.com]
 Sent: Monday, July 27, 2009 12:14 PM
 To: Vadim Ogranovich; r-devel@r-project.org
 Subject: RE: [Rd] bug in approx crashes R

 The C code called by approx (via .C, not .Call), following the help
 file,
 assumes that yleft and yright are scalars but NULL is not scalar.
 The following change would let your example work (returning NA)

 --- R/approx.R  (revision 48911)
 +++ R/approx.R  (working copy)
 @@ -61,8 +61,8 @@
 }
 y - .C(R_approx, as.double(x), as.double(y), as.integer(nx),
 xout = as.double(xout), as.integer(length(xout)),
 -   as.integer(method), as.double(yleft), as.double(yright),
 -   as.double(f), NAOK = TRUE, PACKAGE = stats)$xout
 +   as.integer(method), as.double(yleft)[1],
 as.double(yright)[1],
 +   as.double(f)[1], NAOK = TRUE, PACKAGE = stats)$xout
 list(x = xout, y = y)
 }

 but I think it would be better to get an error message that yleft,
 yright, and f are expected to be scalar:

 --- R/approx.R  (revision 48911)
 +++ R/approx.R  (working copy)
 @@ -59,6 +59,7 @@
 stop('approx' requires n = 1)
 xout - seq.int(x[1L], x[nx], length.out = n)
 }
 +stopifnot(length(yleft)==1, length(yright)==1, length(f)==1)
 y - .C(R_approx, as.double(x), as.double(y), as.integer(nx),
 xout = as.double(xout), as.integer(length(xout)),
 as.integer(method), as.double(yleft), as.double(yright),


 Bill Dunlap
 TIBCO Software Inc - Spotfire Division
 wdunlap tibco.com

 -Original Message-
 From: r-devel-boun...@r-project.org
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Vadim Ogranovich
 Sent: Tuesday, July 21, 2009 12:24 PM
 To: 'r-devel@r-project.org'
 Subject: [Rd] bug in approx crashes R

 Dear R-devel,

 The following line crashes R
  approx(1, 1, 0, method='const', rule=2, f=0, yleft=NULL,
 ties='ordered')$y

 Process R:2 exited abnormally with code 5 at Tue Jul 21 14:18:09 2009


  version
 _
 platform   i386-pc-mingw32
 arch   i386
 os mingw32
 system i386, mingw32
 status
 major  2
 minor  9.1
 year   2009
 month  06
 day26
 svn rev48839
 language   R
 version.string R version 2.9.1 (2009-06-26)

 Thanks,
 Vadim

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


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation

Re: [Rd] bug in approx crashes R

2009-07-27 Thread Vadim Ogranovich
Thank you Bill.

The original motivation for my experiments with setting yleft to NULL was to 
see if I could get more flexibility that that allowed by the 'rule' argument. 
To recall:

rule: an integer describing how interpolation is to take place
  outside the interval ['min(x)', 'max(x)']. If 'rule' is '1'
  then 'NA's are returned for such points and if it is '2', the
  value at the closest data extreme is used.

What I wanted is to interpolate at the left end, but not at the right end. 
Still don't know how to do that.

I agree that having a clear error message when yleft, yright, and f are set to 
non-scalars is better than silently returning NA.

Thanks,
Vadim


-Original Message-
From: William Dunlap [mailto:wdun...@tibco.com]
Sent: Monday, July 27, 2009 12:14 PM
To: Vadim Ogranovich; r-devel@r-project.org
Subject: RE: [Rd] bug in approx crashes R

The C code called by approx (via .C, not .Call), following the help
file,
assumes that yleft and yright are scalars but NULL is not scalar.
The following change would let your example work (returning NA)

--- R/approx.R  (revision 48911)
+++ R/approx.R  (working copy)
@@ -61,8 +61,8 @@
 }
 y - .C(R_approx, as.double(x), as.double(y), as.integer(nx),
xout = as.double(xout), as.integer(length(xout)),
-   as.integer(method), as.double(yleft), as.double(yright),
-   as.double(f), NAOK = TRUE, PACKAGE = stats)$xout
+   as.integer(method), as.double(yleft)[1],
as.double(yright)[1],
+   as.double(f)[1], NAOK = TRUE, PACKAGE = stats)$xout
 list(x = xout, y = y)
 }

but I think it would be better to get an error message that yleft,
yright, and f are expected to be scalar:

--- R/approx.R  (revision 48911)
+++ R/approx.R  (working copy)
@@ -59,6 +59,7 @@
stop('approx' requires n = 1)
xout - seq.int(x[1L], x[nx], length.out = n)
 }
+stopifnot(length(yleft)==1, length(yright)==1, length(f)==1)
 y - .C(R_approx, as.double(x), as.double(y), as.integer(nx),
xout = as.double(xout), as.integer(length(xout)),
as.integer(method), as.double(yleft), as.double(yright),


Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com

 -Original Message-
 From: r-devel-boun...@r-project.org
 [mailto:r-devel-boun...@r-project.org] On Behalf Of Vadim Ogranovich
 Sent: Tuesday, July 21, 2009 12:24 PM
 To: 'r-devel@r-project.org'
 Subject: [Rd] bug in approx crashes R

 Dear R-devel,

 The following line crashes R
  approx(1, 1, 0, method='const', rule=2, f=0, yleft=NULL,
 ties='ordered')$y

 Process R:2 exited abnormally with code 5 at Tue Jul 21 14:18:09 2009


  version
_
 platform   i386-pc-mingw32
 arch   i386
 os mingw32
 system i386, mingw32
 status
 major  2
 minor  9.1
 year   2009
 month  06
 day26
 svn rev48839
 language   R
 version.string R version 2.9.1 (2009-06-26)

 Thanks,
 Vadim

 Note: This email is for the confidential use of the named
 addressee(s) only and may contain proprietary, confidential
 or privileged information. If you are not the intended
 recipient, you are hereby notified that any review,
 dissemination or copying of this email is strictly
 prohibited, and to please notify the sender immediately and
 destroy this email and any attachments.  Email transmission
 cannot be guaranteed to be secure or error-free.  Jump
 Trading, therefore, does not make any guarantees as to the
 completeness or accuracy of this email or any attachments.
 This email is for informational purposes only and does not
 constitute a recommendation, offer, request or solicitation
 of any kind to buy, sell, subscribe, redeem or perform any
 type of transaction of a financial product.

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


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

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


[Rd] bug in approx crashes R

2009-07-21 Thread Vadim Ogranovich
Dear R-devel,

The following line crashes R
 approx(1, 1, 0, method='const', rule=2, f=0, yleft=NULL, ties='ordered')$y

Process R:2 exited abnormally with code 5 at Tue Jul 21 14:18:09 2009


 version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  9.1
year   2009
month  06
day26
svn rev48839
language   R
version.string R version 2.9.1 (2009-06-26)

Thanks,
Vadim

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

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


Re: [Rd] lsfit w/ rank-deficient x

2009-03-17 Thread Vadim Ogranovich
Actually, the correct permutation is given by the inverse of qr$pivot:

foo$coefficients[foo$qr$pivot] - foo$coefficients

Here foo is an object returned by lsfit, see below.



-Original Message-
From: Vadim Ogranovich
Sent: Friday, March 13, 2009 5:25 PM
To: 'r-devel@r-project.org'
Subject: lsfit w/ rank-deficient x

Dear R-devel,

It seems that lsfit incorrectly reports coefficients when the input matrix 'x' 
is rank-deficient, see the example below:

## here values of 'b' and 'c' are incorrectly swapped
 x - cbind(a=rnorm(100), b=0, c=rnorm(100)); y - rnorm(100); lsfit(x, y)$coef
 Intercept  a  b  c
-0.0227787  0.1042860 -0.1729261  0.000
Warning message:
In lsfit(x, y) : 'X' matrix was collinear

## correct values
 lsfit(x[,-2], y)$coef
 Intercept  a  c
-0.0227787  0.1042860 -0.1729261


I looked inside the lsfit code and it appears that even though rank-deficiency 
is detected there is no attempt to patch the coefficients. Why is that?

Taking clues from the code it appears that the following trick might do the 
work:

 foo - lsfit(x, y)
Warning message:
In lsfit(x, y) : 'X' matrix was collinear
 structure(foo$coefficients[foo$qr$pivot], names=names(foo$coefficients))
  Intercept   a   b   c
 0.14857345 -0.07473099  0.  0.12835155


Is this reliable or there are cases when it may fail?

Thanks,
Vadim

P.S.

 version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  7.1
year   2008
month  06
day23
svn rev45970
language   R
version.string R version 2.7.1 (2008-06-23)


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

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


[Rd] lsfit w/ rank-deficient x

2009-03-13 Thread Vadim Ogranovich
Dear R-devel,

It seems that lsfit incorrectly reports coefficients when the input matrix 'x' 
is rank-deficient, see the example below:

## here values of 'b' and 'c' are incorrectly swapped
 x - cbind(a=rnorm(100), b=0, c=rnorm(100)); y - rnorm(100); lsfit(x, y)$coef
 Intercept  a  b  c
-0.0227787  0.1042860 -0.1729261  0.000
Warning message:
In lsfit(x, y) : 'X' matrix was collinear

## correct values
 lsfit(x[,-2], y)$coef
 Intercept  a  c
-0.0227787  0.1042860 -0.1729261


I looked inside the lsfit code and it appears that even though rank-deficiency 
is detected there is no attempt to patch the coefficients. Why is that?

Taking clues from the code it appears that the following trick might do the 
work:

 foo - lsfit(x, y)
Warning message:
In lsfit(x, y) : 'X' matrix was collinear
 structure(foo$coefficients[foo$qr$pivot], names=names(foo$coefficients))
  Intercept   a   b   c
 0.14857345 -0.07473099  0.  0.12835155


Is this reliable or there are cases when it may fail?

Thanks,
Vadim

P.S.

 version
   _
platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  7.1
year   2008
month  06
day23
svn rev45970
language   R
version.string R version 2.7.1 (2008-06-23)


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

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


[Rd] weekly update 20081208

2008-12-08 Thread Vadim Ogranovich
In Progress:
* EURO DOLLAR data for trading Z* and vice versa
* scripts for computing asset correlations w/ application to ED
* improving R code for collecting stats accross dates and groups of data.

Completed:
* New signals for US Equity (based on PK alpha). Brandon will simulate and 
deploy if promising.


Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments. Email 
transmission cannot be guaranteed to be secure or error-free. Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments. This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

[[alternative HTML version deleted]]

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


[Rd] Rscript thank you

2007-12-19 Thread Vadim Ogranovich
Hi, 

I'd like to say thank you to the developers of Rscript. It is a nice tool that 
allows integration of R into multi-tool work flow and, in my experience so far, 
it does exactly what is expected of a utility program. 

Thank you very much! 
Vadim 


[[alternative HTML version deleted]]

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