Daisy Englert Duursma | 1 Aug 2011 01:20
Picon

Re: Legend for 2 plots on same screen

You could make three plots. The first two you plot in and the third
one you place the legend in.

nf<-layout(matrix(c(1,2,3), 1, 3, byrow = TRUE), c(6,6,3), c(6))
layout.show(nf)

plot(sin, -pi, 2*pi, col = "blue2")
plot(sin, -pi, 2*pi, col = "darkorange3")

plot(1, xlim=c(1,2), ylim=c(1,2), type="n",axes=F, ann=F)
	legend("topleft", c("A","B"), lty=c(1,3),col= c("blue2","darkorange3"))

On Mon, Aug 1, 2011 at 4:52 AM, Cheryl Johnson
<johnson.cheryl625 <at> gmail.com> wrote:
> Hello,
>
> I have two plots on the same screen. I use the command par(mfrow=c(1,2)) in
> order to do this. When I try to make a legend for both plots, it only puts
> the legend in the plot on the right side. If I would like a legend that is
> outside of both of the plots, how would I do this?
>
> Thanks
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help <at> 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.
(Continue reading)

David Winsemius | 1 Aug 2011 01:25
Picon

Re: example package for devel newcomers


On Jul 31, 2011, at 5:11 PM, Joshua Wiley wrote:

> On Sun, Jul 31, 2011 at 2:05 PM, Alexandre Aguiar
> <asaguiar <at> spsconsultoria.com> wrote:
>> Hi,
>>
>> I'd like to know whether there is a package (or more, of course)  
>> regarded
>> as a good example that could be used also as an instructional tool  
>> for
>> newcomers to R extensions development.
>
> I used/use SoDA, but then I also used Dr. Chambers' book.

My memory is that this question gets asked every few months and one of  
the stock answers is to use the function 'package.skeleton' in the  
utils package as a starting point.

>
> Josh
>
>>
>> Thanks.
>>
>> --

David Winsemius, MD
West Hartford, CT

(Continue reading)

Duncan Murdoch | 1 Aug 2011 01:36
Picon

Re: Display/show the evaluation result of R commands automatically

On 11-07-31 7:15 AM, Anthony Ching Ho Ng wrote:
> Hello R-help,
>
> I wonder if it is possible to configure R, so that it will
> display/show the evaluation result of the R commands automatically
> (similar to the behavior of Matlab)

It's open source so in theory anything is possible, but there's no 
built-in support for that.

> i.e. If I type x<- 8
>
> it will print 8 in the command prompt, instead of having type x
> explicitly to show the result and perhaps put an ";" at the end to
> suppress the output.
>
> i.e. x<- 8;

If you wrap the assignment in parens the result is made visible, e.g.

(x <- 8)

will print if you enter it in the console.  (It won't print if it's a 
line in a function; there you need an explicit call to print().  Only 
the value returned at the top level is eligible for auto-printing.)

Duncan Murdoch

Paul Menzel | 1 Aug 2011 01:36
Picon

Re: Is R the right choice for simulating first passage times of random walks?

Am Mittwoch, den 27.07.2011, 19:59 -0400 schrieb R. Michael Weylandt :
> Some more skilled folks can help with the curve fitting, but the general
> answer is yes -- R will handle this quite ably.

Great to read that.

> Consider the following code:
> 
> <<-------------------------------------->>
> n = 1e5
> length = 1e5
> 
> R = matrix(sample(c(-1,1),length*n,replace=T),nrow=n)
> R = apply(R,1,cumsum) ## this applies cumsum `row-wise' to R and will make
> your life INFINITELY better
> R = cbind(rep(0,n),R) ## Now each row is a random walk as you desired.
> 
> <<---------------------------------------->>
> 
> There are actually even faster ways to do what you are asking for, but this
> introduces you to some useful R architecture, above all the apply function.

Thank you very much. I realized the the 0 column is not need when
summing this up. Additionally I posted the wrong example code and I
actually am only interested how long it stays negative from the
beginning.

> To see how long the longest stretch of negatives in each row is, the
> following is a little sneaky but works pretty well:
> 
(Continue reading)

Gabor Grothendieck | 1 Aug 2011 01:39
Picon

Re: Display/show the evaluation result of R commands automatically

On Sun, Jul 31, 2011 at 7:15 AM, Anthony Ching Ho Ng
<anthony.ch.ng <at> gmail.com> wrote:
> Hello R-help,
>
> I wonder if it is possible to configure R, so that it will
> display/show the evaluation result of the R commands automatically
> (similar to the behavior of Matlab)
>
> i.e. If I type x <- 8
>
> it will print 8 in the command prompt, instead of having type x
> explicitly to show the result and perhaps put an ";" at the end to
> suppress the output.
>
> i.e. x <- 8;
>

Not quite the same but perhaps good enough is that at the console this
will give you the last value:

.Last.value

--

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

Dennis Murphy | 1 Aug 2011 02:31
Picon

Re: Is R the right choice for simulating first passage times of random walks?

Hi:

See if this works for you:

f4 <- function()
  {
     x <- sample(c(-1L,1L), 1)

      if (x >= 0 ) {return(1)} else {
           csum <- x
           len <- 1
               while(csum < 0) {
                   csum <- csum + sample(c(-1, 1), 1)
                   len <- len + 1
                                          }     }
      len
  }

# In one batch of repetitions of this function,
system.time(out <- replicate(1000, f4()))
   user  system elapsed
   0.51    0.00    0.52
> range(out)
[1]     1 17372

but in another (untimed), this took a significantly longer amount of
time to run [for obvious reasons]:
> range(out)
[1]      1 987752

(Continue reading)

Alexandre Aguiar | 1 Aug 2011 03:24
X-Face
Favicon

Re: example package for devel newcomers

Em Domingo 31 Julho 2011, você escreveu:
> My memory is that this question gets asked every few months and one of
> the stock answers is to use the function 'package.skeleton' in the
> utils package as a starting point.

Got that from docs. And actually I already have most of the code written. 
My question addresses known tricks and impressions by experienced R 
interface programmers. This kind of stuff can be really useful. For 
instance, tricks are much better than docs when embedding php.

Thanx.

--

-- 

Alexandre

--
Alexandre Santos Aguiar, MD, SCT
Em Domingo 31 Julho 2011, você escreveu:
> My memory is that this question gets asked every few months and one of
> the stock answers is to use the function 'package.skeleton' in the
> utils package as a starting point.

Got that from docs. And actually I already have most of the code written. 
My question addresses known tricks and impressions by experienced R 
interface programmers. This kind of stuff can be really useful. For 
instance, tricks are much better than docs when embedding php.

(Continue reading)

Ben Bolker | 1 Aug 2011 04:12
Picon

Re: Simulating from the Null

Jim Silverton <jim.silverton <at> gmail.com> writes:

> 
> Hello all,
> I am doing  glm with a negative binomial link.
> I have two treatments and 3 replicates in each treatment. My question is
> this, how can I simulate data for the the columns  from the null and

[alternative?]

> distribution.
> 

Simulate from the null:
fit the null model and use the simulate method:

nullmodel <- glm.nb(response~1,data=yourdata)
simulate(nullmodel)

Simulate from the fitted distribution: as above, but
fit the full model.

jim holtman | 1 Aug 2011 04:32
Picon

Re: memory problem; Error: cannot allocate vector of size 915.5 Mb

My advice to you is to get a 64-bit version of R.  Here is what it
does on my 64-bit Windows 7 version:

> N<-250
> x<-matrix(c(rnorm(N,-1.5,1), rnorm(N,1,1), rbinom(N,1,0.5)), ncol=3)
> my.stats(1)
1 (1) - Rgui : 22:30:20 <0.7 78.6> 78.6 : 20.5MB
> start<-(-1)
> end<-3
> step<-10^(-2)
> n.steps<-(end-start)/step
> steps2  <-n.steps^2
> grids<-seq(from=start+step, to=end, by=step)
> xMax    <-matrix(0,N*steps2,3)
> my.stats(2)
2 (1) - Rgui : 22:30:23 <4.1 82.1> 82.1 : 935.5MB
> xMax[,1]<-rep(x[,1],steps2)
> xMax[,2]<-rep(x[,2],steps2)
> xMax[,3]<-rep(x[,3],steps2)
> my.stats(3)
3 (1) - Rgui : 22:30:35 <16.0 94.3> 94.3 : 1998.9MB
> G.search1<-as.matrix(rep(grids, n.steps, each=N))
> G.search2<-as.matrix(rep(grids, N, each=n.steps))
> G.search<-cbind(1,G.search1, G.search2)
> my.stats(3)
3 (1) - Rgui : 22:30:45 <25.2 103.7> 103.7 : 2456.6MB
>
> gc()
            used   (Mb) gc trigger   (Mb)  max used   (Mb)
Ncells    143726    7.7     350000   18.7    350000   18.7
(Continue reading)

Steve Lianoglou | 1 Aug 2011 05:32
Picon

Re: Is R the right choice for simulating first passage times of random walks?

Hi,

I haven't been following this thread very closely, but I'm getting the
impression that the "inner loop" that's killing you folks here looks
quite simple (assuming it is the one provided below).

How about trying to write the of this `f4` function below using the
rcpp/inline combo. The C/C++ you will need to write looks to be quite
trivial, let's change f4 to accept an x argument as a vector:

I've defined f4 in the same way as Dennis did:

> f4 <- function()
>  {
>     x <- sample(c(-1L,1L), 1)
>
>      if (x >= 0 ) {return(1)} else {
>           csum <- x
>           len <- 1
>               while(csum < 0) {
>                   csum <- csum + sample(c(-1, 1), 1)
>                   len <- len + 1
>                                          }     }
>      len
>  }

Now, let's do some inline/c++ mojo:

library(inline)
inc <- "
(Continue reading)


Gmane