Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread Duncan Murdoch
On 21/09/2010 1:29 PM, baptiste auguie wrote: I see, thank you. I'm still worried by the very dramatic error I obtained just from shifting so slightly the support of the integrand, it took me a while to figure what happened even with this basic example (I knew the integral couldn't be so small!

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread baptiste auguie
I see, thank you. I'm still worried by the very dramatic error I obtained just from shifting so slightly the support of the integrand, it took me a while to figure what happened even with this basic example (I knew the integral couldn't be so small!). For a general integration in [0, infty), ther

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread Thomas Lumley
On Tue, 21 Sep 2010, baptiste Auguié wrote: Thanks, I'll do that too from now on. It strikes me that in a case such as this one it may be safer to use a truncated, finite interval around the region where the integrand is non-zero, rather than following the advice of ?integrate to use Inf as in

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread baptiste Auguié
> of 1.e-08 (roughly, sqrt(machine epsilon)) in my computations, and I also > increase subdivisions to 500. > > Ravi. > > From: baptiste Auguié [mailto:baptiste.aug...@googlemail.com] > Sent: Tuesday, September 21, 2010 9:58 AM > To: Ravi Varadhan > Cc: 'bap

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread Ravi Varadhan
rel.tol of 1.e-08 (roughly, sqrt(machine epsilon)) in my computations, and I also increase subdivisions to 500. Ravi. From: baptiste Auguié [mailto:baptiste.aug...@googlemail.com] Sent: Tuesday, September 21, 2010 9:58 AM To: Ravi Varadhan Cc: 'baptiste auguie'; 'r-help' Sub

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread Matt Shotwell
ilto:r-help-boun...@r-project.org] On > Behalf Of baptiste auguie > Sent: Tuesday, September 21, 2010 8:38 AM > To: r-help > Subject: [R] puzzle with integrate over infinite range > > Dear list, > > I'm calculating the integral of a Gaussian function from 0 to >

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread baptiste Auguié
ct.org] On > Behalf Of baptiste auguie > Sent: Tuesday, September 21, 2010 8:38 AM > To: r-help > Subject: [R] puzzle with integrate over infinite range > > Dear list, > > I'm calculating the integral of a Gaussian function from 0 to > infinity. I understand from

Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread Ravi Varadhan
-07)$value } shift <- seq(500, 800, by=10) plot(shift, sapply(shift, shiftedGauss)) Hope this helps, Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of baptiste auguie Sent: Tuesday, September 21, 2010 8:38 AM To: r-help Subje

[R] puzzle with integrate over infinite range

2010-09-21 Thread baptiste auguie
Dear list, I'm calculating the integral of a Gaussian function from 0 to infinity. I understand from ?integrate that it's usually better to specify Inf explicitly as a limit rather than an arbitrary large number, as in this case integrate() performs a trick to do the integration better. However,

Re: [R] Puzzle

2010-08-26 Thread Jeff Newmiller
Look for a vectorized solution such as ?table or ?aggregate to obtain a list of combination counts, followed by logical indexing or ?subset to get a set of valid combinations, and then use ?sample to get your random selections of locations/surveyors and then process only those combinations from

Re: [R] Puzzle

2010-08-26 Thread Hans W Borchers
Ben Holt bio.ku.dk> writes: > I have data similar to this: > > Location Surveyor Result > A1 83 > A2 76 > A3 45 > B1 71 > B4 67 > C2 23 > C5 12 > D3 34 > E4

[R] Puzzle

2010-08-26 Thread Ben Holt
I have data similar to this: Location Surveyor Result A1 83 A2 76 A3 45 B1 71 B4 67 C2 23 C5 12 D3 34 E4 75 F4 46 G5 90 et

Re: [R] in continuation with the earlier R puzzle

2010-07-13 Thread Raghu
Many many thanks to all of you. The beer cleared the air of doubts! Pls look at the following lines of code. This is taken from the example of tradesys documentation. When I run the given example using the data.frame spx it works just very fine but while I use some other data.frame (here nifty) it

Re: [R] in continuation with the earlier R puzzle

2010-07-13 Thread Petr PIKAL
Hi I do not use any of mentioned libraries so I can not directly answer it. I would try to use debug(expr.frame) to see at what time the error is thrown. I have no idea why did you obtain error. Try to evaluate code in peaces e.g. what is result of list(MAf=quote(SMA(Last, 20)), MAs=quote(SMA

[R] Odp: in continuation with the earlier R puzzle

2010-07-13 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 12.07.2010 16:09:30: > When I just run a for loop it works. But if I am going to run a for loop > every time for large vectors I might as well use C or any other language. > The reason R is powerful is becasue it can handle large vectors without each >

Re: [R] in continuation with the earlier R puzzle

2010-07-12 Thread Joshua Wiley
I wanted to point out one thing that Ted said, about initializing the vectors ('s' in your example). This can make a dramatic speed difference if you are using a for loop (the difference is neglible with vectorized computations). Also, a lot of benchmarks have been flying around, each from a diff

Re: [R] in continuation with the earlier R puzzle

2010-07-12 Thread Raghu
tate University > Corvallis, OR 97331 > ph: 541-737-6232 > fx: 541-737-1393 > > > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Ted Harding > Sent: Monday, July 12, 2010 9:36 AM > To: r-help@r-p

Re: [R] in continuation with the earlier R puzzle

2010-07-12 Thread Huso, Manuela
iety Oregon State University Corvallis, OR   97331 ph: 541-737-6232 fx: 541-737-1393 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ted Harding Sent: Monday, July 12, 2010 9:36 AM To: r-help@r-project.org Cc: Raghu Subject: Re: [R] in

Re: [R] in continuation with the earlier R puzzle

2010-07-12 Thread Ted Harding
On 12-Jul-10 14:09:30, Raghu wrote: > When I just run a for loop it works. But if I am going to > run a for loop every time for large vectors I might as well > use C or any other language. > The reason R is powerful is becasue it can handle large vectors > without each element being manipulated? Pl

Re: [R] in continuation with the earlier R puzzle

2010-07-12 Thread David Winsemius
On Jul 12, 2010, at 10:09 AM, Raghu wrote: When I just run a for loop it works. But if I am going to run a for loop every time for large vectors I might as well use C or any other language. The reason R is powerful is becasue it can handle large vectors without each element being manipula

Re: [R] in continuation with the earlier R puzzle

2010-07-12 Thread Seeliger . Curt
> The reason R is powerful is becasue it can handle large vectors without each > element being manipulated? Please let me know where I am wrong. > > for(i in 1:length(news1o)){ > + if(news1o[i]>s2o[i]) > + s[i]<-1 > + else > + s[i]<--1 > + } You might give ifelse() a shot here. s <- ifelse(news

Re: [R] in continuation with the earlier R puzzle

2010-07-12 Thread Alain Guillet
I don't know what is wrong with your code but I believe you should use ifelse instead of a for loop: s <- ifelse(news1o > s2o, 1 , -1 ) Alain On 12-Jul-10 16:09, Raghu wrote: When I just run a for loop it works. But if I am going to run a for loop every time for large vectors I might as wel

[R] in continuation with the earlier R puzzle

2010-07-12 Thread Raghu
When I just run a for loop it works. But if I am going to run a for loop every time for large vectors I might as well use C or any other language. The reason R is powerful is becasue it can handle large vectors without each element being manipulated? Please let me know where I am wrong. for(i in 1

Re: [R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Duncan Murdoch
On 10/14/2009 2:29 PM, Adrian Dragulescu wrote: Thank you. If I use gsub(" \xad", "-", x) [1] "NEW YORK-NEW ENGLAND" I get what I want. Right, that's simpler than what I suggested. Duncan Murdoch Adrian sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=En

Re: [R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Adrian Dragulescu
Thank you. If I use gsub(" \xad", "-", x) [1] "NEW YORK-NEW ENGLAND" I get what I want. Adrian sessionInfo() R version 2.9.2 (2009-08-24) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=

Re: [R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Duncan Murdoch
On 10/14/2009 2:16 PM, Adrian Dragulescu wrote: I get the same results (not working) using R 2.9.2 and R.10.0 beta. But it is working: the dash is an "ad" in x, not a "2d". You need to ask to substitute for the "ad" character, e.g. by spacelongdash <- rawToChar(as.raw(c(0x20, 0xad))) gsub(

Re: [R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Adrian Dragulescu
I get the same results (not working) using R 2.9.2 and R.10.0 beta. Thank you for looking at this. On Wed, 14 Oct 2009, Duncan Murdoch wrote: On 10/14/2009 1:41 PM, Adrian Dragulescu wrote: charToRaw(x) [1] 4e 45 57 20 59 4f 52 4b 20 ad 4e 45 57 20 45 4e 47 4c 41 4e 44 charToRaw(y)

Re: [R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Prof Brian Ripley
On Wed, 14 Oct 2009, Adrian Dragulescu wrote: charToRaw(x) [1] 4e 45 57 20 59 4f 52 4b 20 ad 4e 45 57 20 45 4e 47 4c 41 4e 44 charToRaw(y) [1] 4e 45 57 20 59 4f 52 4b 20 2d 4e 45 57 20 45 4e 47 4c 41 4e 44 So they are different. We really do need the 'at a minimum' information we asked

Re: [R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Duncan Murdoch
On 10/14/2009 1:41 PM, Adrian Dragulescu wrote: charToRaw(x) [1] 4e 45 57 20 59 4f 52 4b 20 ad 4e 45 57 20 45 4e 47 4c 41 4e 44 charToRaw(y) [1] 4e 45 57 20 59 4f 52 4b 20 2d 4e 45 57 20 45 4e 47 4c 41 4e 44 So they are different. Adrian I use R 2.8.1 on WinXP But that's ancient.

Re: [R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Adrian Dragulescu
charToRaw(x) [1] 4e 45 57 20 59 4f 52 4b 20 ad 4e 45 57 20 45 4e 47 4c 41 4e 44 charToRaw(y) [1] 4e 45 57 20 59 4f 52 4b 20 2d 4e 45 57 20 45 4e 47 4c 41 4e 44 So they are different. Adrian I use R 2.8.1 on WinXP On Wed, 14 Oct 2009, Duncan Murdoch wrote: On 10/14/2009 1:30 PM, A

Re: [R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Duncan Murdoch
On 10/14/2009 1:30 PM, Adrian Dragulescu wrote: Hello, Below is some output that shows my issue. I have a variable x that I read from a file (more on this below) x [1] "NEW YORK NEW ENGLAND" gsub(" -", "-", x)# this does not work! [1] "NEW YORK NEW ENGLAND" It looks as though

[R] puzzle using gsub (and encodings maybe)

2009-10-14 Thread Adrian Dragulescu
Hello, Below is some output that shows my issue. I have a variable x that I read from a file (more on this below) x [1] "NEW YORK NEW ENGLAND" gsub(" -", "-", x)# this does not work! [1] "NEW YORK NEW ENGLAND" Encoding(x) # is x in a special encoding? no [1]

Re: [R] puzzle about contrasts

2008-09-09 Thread Peter Dalgaard
Peter Dalgaard skrev: > Prof Brian Ripley skrev: > >> -0.5*(A+B) is not a contrast, which is the seat of your puzzlement. >> >> All you can get from y ~ x is an intercept (a column of ones) and a >> single 'contrast' column for 'x'. >> >> If you use y ~ 0+x you can get two columns for 'x', but R

Re: [R] puzzle about contrasts

2008-09-09 Thread Peter Dalgaard
Prof Brian Ripley skrev: > -0.5*(A+B) is not a contrast, which is the seat of your puzzlement. > > All you can get from y ~ x is an intercept (a column of ones) and a > single 'contrast' column for 'x'. > > If you use y ~ 0+x you can get two columns for 'x', but R does not > give you an option of w

Re: [R] puzzle about contrasts

2008-09-09 Thread Prof Brian Ripley
-0.5*(A+B) is not a contrast, which is the seat of your puzzlement. All you can get from y ~ x is an intercept (a column of ones) and a single 'contrast' column for 'x'. If you use y ~ 0+x you can get two columns for 'x', but R does not give you an option of what columns in the case: see the

[R] puzzle about contrasts

2008-09-09 Thread Kenneth Knoblauch
Hi, I'm trying to redefine the contrasts for a linear model. With a 2 level factor, x, with levels A and B, a two level factor outputs A and B - A from an lm fit, say lm(y ~ x). I would like to set the contrasts so that the coefficients output are -0.5 (A + B) and B - A, but I can't get the sign