Re: [R] conditional probability

2010-11-08 Thread Michael Bedward
Hello Jumlong,

For Normal distribution see the help page for pnorm.

For dealing with unknown (empirical) distributions, look at ecdf.

Hope this helps
Michael

On 8 November 2010 16:29, Jumlong Vongprasert jumlong.u...@gmail.com wrote:
 Dear all
          I have problem with calculate probability, I have data x1,...,x10,
 I want to calculate probability x11 given x1,...,x10 with two conditions.
          1. x is normal
           2. unknow distribution
         How I can do this.
 Many Thanks.
 Jumlong

 --
 Jumlong Vongprasert Assist, Prof.
 Institute of Research and Development
 Ubon Ratchathani Rajabhat University
 Ubon Ratchathani
 THAILAND
 34000

        [[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.


__
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] How to eliminate this for loop ?

2010-11-08 Thread PLucas

Hi, I would like to create a list recursively and eliminate my for loop :

a-c()
a[1] - 1; # initial value
for(i in 2:N) {
a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector
}


Is it possible ?

Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-eliminate-this-for-loop-tp3031667p3031667.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 eliminate this for loop ?

2010-11-08 Thread Nick Sabbe
Whenever you use a recursion (that cannot be expressed otherwise), you
always need a (for) loop.
Apply and the like do not allow to use the intermediary results (i.e. a[i-1]
to calculate a[i]).

So: no, it cannot be avoided in your case, I guess.


Nick Sabbe
--
ping: nick.sa...@ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36

-- Do Not Disapprove



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of PLucas
Sent: maandag 8 november 2010 10:26
To: r-help@r-project.org
Subject: [R] How to eliminate this for loop ?


Hi, I would like to create a list recursively and eliminate my for loop :

a-c()
a[1] - 1; # initial value
for(i in 2:N) {
a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector
}


Is it possible ?

Thanks
-- 
View this message in context:
http://r.789695.n4.nabble.com/How-to-eliminate-this-for-loop-tp3031667p30316
67.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-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] About 5.1 Arrays

2010-11-08 Thread Stephen Liu
Hi Joshua,

 .You can think of a 3d array
 kind of like a journal (I don't know if this is helpful, but I kind of
 like the analogy so...).  Each page holds a two dimensional table, so
 I could tell you to look at row 4, column 3 on page 16.  Nevertheless,
 at any given point, it is just a flat page.

A good example.  It can be regarded as a book with multiple pages.  Each page 
holds a table of 2 dimensions.

 No, it is correct.  You cannot assume that you may use the same
 indices to access an array when you have created it with different
 dimensions.  Consider:

 array(1:24, dim = c(3, 4, 2))[1, 2, 1]
 [1] 4
 array(1:24, dim = c(1, 2, 1))[1, 2, 1]
 [1] 2

I understand now, e.g.

 array(1:24, dim = c(3, 4, 2))[2,3,2]
[1] 20


Not
 array(1:24, dim = c(2, 3, 2))[2,3,2]
[1] 12


Lot of thanks for your advice and effort.


B.R.
Stephen L







- Original Message 
From: Joshua Wiley jwiley.ps...@gmail.com
To: Stephen Liu sati...@yahoo.com
Cc: r-help@r-project.org
Sent: Mon, November 8, 2010 8:33:50 AM
Subject: Re: [R] About 5.1 Arrays

On Sat, Nov 6, 2010 at 7:38 AM, Stephen Liu sati...@yahoo.com wrote:
 Hi Joshua,

 Thanks for your advice.

 1)
 Re your advice:-[quote]
 a3d
 , , 1 --- this is the first position of the third dimension ***THIS IS THE 
THIRD DIMENSION***

 [,1] [,2] [,3] [,4]  --- positions 1, 2, 3, 4 of the second dimension
 [1,]147   10
 [2,]258   11
 [3,]369   12
 ^  the first dimension

 , , 2 --- the second position of the third dimension ***THIS IS THE THIRD 
DIMENSION***
 ...
 [/quote]

 Where is the third dimension?

I pointed to the third dimension above.  You can think of a 3d array
kind of like a journal (I don't know if this is helpful, but I kind of
like the analogy so...).  Each page holds a two dimensional table, so
I could tell you to look at row 4, column 3 on page 16.  Nevertheless,
at any given point, it is just a flat page.


 2)
 Re your advice:-[quote]
 so you can think that in the original vector a:
 1 maps to a[1, 1, 1] in the 3d array
 2 maps to a[2, 1, 1].
 3 maps to a[3, 1, 1]
 4 maps to a[1, 2, 1]
 12 maps to a[3, 4, 1]
 20 maps to a[2, 3, 2]
 24 maps to a[3, 4, 2]
 [/quote]

 My finding;

 # 1 maps to a[1, 1, 1] in the 3d array
 a3d - array(a, dim = c(1, 1, 1))
 a3d
 , , 1

 [,1]
 [1,]1

 Correct

 # 2 maps to a[2, 1, 1].
 a3d - array(a, dim = c(2, 1, 1))
 a3d
 , , 1

 [,1]
 [1,]1
 [2,]2

 Correct

 # 3 maps to a[3, 1, 1]
 a3d - array(a, dim = c(3, 1, 1))
 a3d
 , , 1

 [,1]
 [1,]1
 [2,]2
 [3,]3

 Correct

 # 4 maps to a[1, 2, 1]
 a3d - array(a, dim = c(1, 2, 1))
 a3d
 , , 1

 [,1] [,2]
 [1,]12

 Incorrect.  It is 2

No, it is correct.  You cannot assume that you may use the same
indices to access an array when you have created it with different
dimensions.  Consider:

 array(1:24, dim = c(3, 4, 2))[1, 2, 1]
[1] 4
 array(1:24, dim = c(1, 2, 1))[1, 2, 1]
[1] 2



 # 12 maps to a[3, 4, 1]
 a3d - array(a, dim = c(3, 4, 1))
 a3d
 , , 1

 [,1] [,2] [,3] [,4]
 [1,]147   10
 [2,]258   11
 [3,]369   12

 Correct

 # 20 maps to a[2, 3, 2]
 a3d - array(a, dim = c(2, 3, 2))
 a3d
 , , 1

 [,1] [,2] [,3]
 [1,]135
 [2,]246

 , , 2

 [,1] [,2] [,3]
 [1,]79   11
 [2,]8   10   12

 Incorrect.  It is 12

See my above comment about not expecting things in the same location
when you change the space they live in.

Sorry this was so slow in coming, I missed the email somehow.

Cheers,

Josh

[snip]




__
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] unknown dimensions for loglm

2010-11-08 Thread P Ehlers

Jason Hwa wrote:

Dear R-help community,

I am working with multidimensional contingency tables and I am having 
trouble getting loglm to run on all dimensions without typing out each 
dimension.


I have generated random data and provided output for the results I want 
below:


d1.c1 - rnorm(20, .10, .02)
d1.c2 - rnorm(20, .10, .02)
d2.c1 - rnorm(20, .09, .02)
d2.c2 - rnorm(20, .09, .02)
d3.c1 - rnorm(20, .11, .02)
d3.c2 - rnorm(20, .11, .02)

group1 - cbind(1, d1.c1, d2.c1, d3.c1)
group2 - cbind(2, d1.c2, d2.c2, d3.c2)

colnames(group1) - colnames(group2) - c(group, dim1, dim2, dim3)
combined - rbind(group1, group2)
combined[,2:4] - combined[,2:4]  .1

ctables - xtabs(~., data = combined)
loglm(~group+dim1+dim2+dim3, data=ctables)

Call:
loglm(formula = ~group + dim1 + dim2 + dim3, data = ctables)

Statistics:
   X^2 df  P( X^2)
Likelihood Ratio 12.29856 11 0.3416253
Pearson  10.28058 11 0.5053391

However, the number and the names of the dimensions change for each 
dataset. What I want is to be able to run the following line at the end 
of the code: loglm(~., data=ctables), but it always prints the 
following error:


Error in terms.formula(formula - denumerate(formula)) :
   '.' in formula and no 'data' argument

Can anyone help me out?

Thank you,
Jason


Presumably you're using loglm from package MASS (which you
should indicate).

To use the dot notation, you need to put your data in
dataframe form. This works:

 d - data.frame(ftable(ctables))
 loglm(Freq ~ ., data = d)

Or you could use the integer notation for the formula:

 loglm( ~ 1 + 2 + 3 + 4, data = ctables)

You could generate the formula in your code:

 form - as.formula(paste(~, paste(1:4, collapse=+)))

and then use

 loglm(form, data = ctables)


   -Peter Ehlers

__
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] how to remove border while saving R plots ?

2010-11-08 Thread vikrant

I am saving R graph as a jpeg image and the border is plotted defaultly when
you open the image.How can I avoid the border?
small R code is as follows :- 

volume- seq(100,10,-10)

   jpeg(filename = mygraph.jpg,width=366,height=284,units=px)
{
pie(volume,main=title,radius=radius ,bty=n,clockwise = 
TRUE,col=color,
font.main = 2,cex.main = 1.8,cex.lab=1.5,border = FALSE)

}
dev.off()
 when I open this image  automaticaly border is  plotted around the graph.
How to avoid this?

-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-to-remove-border-while-saving-R-plots-tp3031713p3031713.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] [R-pkgs] RGtk2 2.20.x

2010-11-08 Thread Michael Lawrence
This is to announce the release of the RGtk2 2.20.x series. RGtk2 is an
interface between R and the GTK+ GUI toolkit and friends. The new release
updates the bindings to support up to GTK+ 2.20 (and remains backwards
compatible to 2.8). Previously, the interface supported only up to GTK+
2.12, which is several years old.

New features in GTK 2.20 (relative to 2.12) include:

* GtkInfoBar widget: Displays transient popup notifications, generally at
the bottom of the window (near the status bar).
* Off-screen rendering of widgets, e.g., automatically save a widget or
visualization to disk.
* GtkSpinner: Animated widget for indicating activity
* GtkToolPalette: Essentially a multi-row toolbar with drag and drop of
toolbar items between the palette and other tool item containers.

The bindings to Pango and Cairo were also updated to the latest stable
versions.

RGtk2 also adds a new library to its interface: GIO (2.22), a low-level
library supporting asynchronous streaming I/O, mounting of volumes,
networking, etc. Might be useful.

There is also a new mode of error handling available, that is disabled by
default. By setting the option RGtk2::newErrorHandling to TRUE, errors in
the libraries will result in errors in R (instead of warnings), and the
error object is no longer returned, which often simplifies return values by
no longer requiring a list to hold both the error and the original return
value. This is probably a more sensible strategy.

Windows users: The new binaries for Windows are being built against 2.20, so
you'll need to get GTK+ 2.20 (or higher, 2.22 is released but does not
really add any new features) for Windows at:
http://gtk-win.sourceforge.net/home/index.php/en/Downloads.

Thanks,
Michael

[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] Create Matrix of 2 Dim from two vectors

2010-11-08 Thread abotaha

Hello, 

I have two data. 

x-c(1, 2, 3) 
y-c(4,5,6) 

How do i create matrix of 3 by 3 from this two, such that  

 (1,4)  (1,5)  (1,6)
 (2,4)  (2,5)  (2,6)
 (3,4)  (3,5)  (3,6)

I tried some thing like this:

xy - as.data.frame(c(0,0,0), dim=c(3,3))
for(i in 1:3)
for(j in 1:3)
xy[i][j]-c(x[i],y[j])

but i got errors..
any help would appreciate




-- 
View this message in context: 
http://r.789695.n4.nabble.com/Create-Matrix-of-2-Dim-from-two-vectors-tp3031718p3031718.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] Create Matrix of 2 Dim from two vectors

2010-11-08 Thread Vaiva P
Try
 x1-matrix(1,3,1)%x%x
 y1-y%x%matrix(1,3,1)

Z-cbind(x1,y1)
And later you need to move towards list and matrix


On Mon, Nov 8, 2010 at 11:15 AM, abotaha yaseen0...@gmail.com wrote:

 Hello,

 I have two data.

 x-c(1, 2, 3)
 y-c(4,5,6)

 How do i create matrix of 3 by 3 from this two, such that

  (1,4)  (1,5)  (1,6)
  (2,4)  (2,5)  (2,6)
  (3,4)  (3,5)  (3,6)

 I tried some thing like this:

 xy - as.data.frame(c(0,0,0), dim=c(3,3))
 for(i in 1:3)
 for(j in 1:3)
 xy[i][j]-c(x[i],y[j])

 but i got errors..
 any help would appreciate




 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Create-Matrix-of-2-Dim-from-two-vectors-tp3031718p3031718.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-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 eliminate this for loop ?

2010-11-08 Thread Dennis Murphy
Hi:

?Recall

HTH,
Dennis

On Mon, Nov 8, 2010 at 1:25 AM, PLucas plucasplucasplu...@yopmail.comwrote:


 Hi, I would like to create a list recursively and eliminate my for loop :

 a-c()
 a[1] - 1; # initial value
 for(i in 2:N) {
a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector
 }


 Is it possible ?

 Thanks
 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-eliminate-this-for-loop-tp3031667p3031667.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.


[[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.


Re: [R] Create Matrix of 2 Dim from two vectors

2010-11-08 Thread Ivan Calandra

Hi,

First, create a MATRIX of the correct size:
xy - matrix(nrow=3, ncol=3)

Then, in your for loop, you need to index each cell correctly, like this:
xy[i,j]

Finally, if you want to assign 1,4 to each cell, you need to paste 
x[i] and y[j] together, like this:

xy[i,j]-paste(x[i],y[j], sep=,)

With the brackets if you want:
xy[i,j]-paste((, x[i], ,, y[j], ), sep=)

Or easier like this:
xy - matrix(rep(x,3),nrow=3, ncol=3)
apply(xy, 1, FUN=paste, y, sep=,)

HTH,
Ivan

Le 11/8/2010 11:15, abotaha a écrit :

Hello,

I have two data.

x-c(1, 2, 3)
y-c(4,5,6)

How do i create matrix of 3 by 3 from this two, such that

  (1,4)  (1,5)  (1,6)
  (2,4)  (2,5)  (2,6)
  (3,4)  (3,5)  (3,6)

I tried some thing like this:

xy- as.data.frame(c(0,0,0), dim=c(3,3))
for(i in 1:3)
for(j in 1:3)
xy[i][j]-c(x[i],y[j])

but i got errors..
any help would appreciate






--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php

__
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] Create Matrix of 2 Dim from two vectors

2010-11-08 Thread Dennis Murphy
Hi:

If you want the literal character strings, this works:

 x-c(1, 2, 3)
 y-c(4,5,6)
 outer(x, y, function(x, y) paste('(', x, ',', y, ')', sep = '') )
 [,1][,2][,3]
[1,] (1,4) (1,5) (1,6)
[2,] (2,4) (2,5) (2,6)
[3,] (3,4) (3,5) (3,6)

However, I have the sense you want to use the values of x and y as
coordinates in a function. This is also a job for outer(); e.g.,

f - function(x, y) x + 0.5 * y
outer(x, y, f)
 [,1] [,2] [,3]
[1,]3  3.54
[2,]4  4.55
[3,]5  5.56

If you want to apply a two-dimensional function to a pair of vectors,
outer() may be what you're after.

HTH,
Dennis


On Mon, Nov 8, 2010 at 2:15 AM, abotaha yaseen0...@gmail.com wrote:


 Hello,

 I have two data.

 x-c(1, 2, 3)
 y-c(4,5,6)

 How do i create matrix of 3 by 3 from this two, such that

  (1,4)  (1,5)  (1,6)
  (2,4)  (2,5)  (2,6)
  (3,4)  (3,5)  (3,6)

 I tried some thing like this:

 xy - as.data.frame(c(0,0,0), dim=c(3,3))
 for(i in 1:3)
 for(j in 1:3)
 xy[i][j]-c(x[i],y[j])

 but i got errors..
 any help would appreciate




 --
 View this message in context:
 http://r.789695.n4.nabble.com/Create-Matrix-of-2-Dim-from-two-vectors-tp3031718p3031718.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.


[[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.


[R] nonparametric multiple comparisons

2010-11-08 Thread ellen pape
Hello everyone,

I apologize if this question is out of the scope of this forum

I have a small dataset with a dependent continuous variable which I want to
compare amongst 3 levels of a factor, which I analyzed using a
Kruskall-Wallis test. I am wondering which posthoc multiple comparison I
should use?

Pairwise wilcoxon test or the Steel test within the package npmc?

Thanks!
Ellen

[[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.


[R] Computing ergodic mean with CODA

2010-11-08 Thread Raquel Rangel de Meireles Guimarães

Hi all,

I would like to compute ergodic mean using MCMC output from WinBUGS. I
tried using CODA package, but it seems that it is not implemented yet.

Could anyone help me to compute this?

Kind regards,

Raquel

--
Raquel Rangel de Meireles Guimarães
Doutoranda em Demografia
raq...@cedeplar.ufmg.br
http://ufmg.academia.edu/RaquelGuimaraes
Cedeplar - Centro de Desenvolvimento e Planejamento Regional
Avenida Antônio Carlos, 6627, Sala 2090, Pampulha, BH-MG
Telefones: (31) 3409-7144 - (31) 9732-2132
Faculdade de Ciências Econômicas, UFMG (http://www.cedeplar.ufmg.br)

__
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] Rserve alternative?

2010-11-08 Thread Ralf B
The Rserve documentation at

http://rosuda.org/Rserve/doc.shtml#start

states that even when making multiple connections to the Rserve,
Windows won't separate workspaces physically and share environments,
which will obviously cause problems and should therefore not be used.
Are there any alternatives for the windows platform?

Ralf

__
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] Create Matrix of 2 Dim from two vectors

2010-11-08 Thread abotaha

Thanks a lot guys...all of your solution are useful, and good.
once again thanks.


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Create-Matrix-of-2-Dim-from-two-vectors-tp3031718p3031797.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] finding the last day of the month

2010-11-08 Thread Benjamin Williams
Dear R Help,

I am trying to get fields showing the last day of each month for a monthly
closing project.  In order to find the last day of the previous month, I
subtract the number of days from the current month. For all months my code
works; however, for October, my code doesn't work...it returns
2010-09-*29* instead
of 2010-09-*30*.

format(strptime(2010-10-31,
%Y-%m-%d)-(as.numeric(format(as.Date(2010-10-31),%d))*24*3600),%Y-%m-%d)

I appreciate any suggestions or tips.

Thank you.
Ben

[[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.


Re: [R] finding the last day of the month

2010-11-08 Thread Ben Bolker
Benjamin Williams ben at bwmcct.com writes:

 I am trying to get fields showing the last day of each month for a monthly
 closing project.  In order to find the last day of the previous month, I
 subtract the number of days from the current month. For all months my code
 works; however, for October, my code doesn't work...it returns
 2010-09-*29* instead
 of 2010-09-*30*.
 
 format(strptime(2010-10-31,
 %Y-%m-%d)-(as.numeric(format(as.Date(2010-10-31),%d))*24*3600),
   %Y-%m-%d)

  Very timely question.
  This is a daylight savings time issue; subtracting 24 hours
gives a different answer when there are only 23 hours in a particular
day (spring forward, fall back).  Search the R-help
archives for the last week or so for a similar issue.
(Hint: try subtracting days from dates rather than converting
to seconds first.)

  Ben Bolker

__
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] Using changing names in loop in R

2010-11-08 Thread Tuatara

Josh, 

thanks so much for your detailed reply. This is exactly what I was looking
for. 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Using-changing-names-in-loop-in-R-tp3030132p3031899.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] Visualization of histograms

2010-11-08 Thread Etienne Stockhausen
Dear r-user,

 

I've wrote a small function to visualize the creation of a histogram.
Therefore I create a vector with random values and let them plot in
histograms. I better give a small example in R-Code:

 

i=0

funVec=rnorm(1000)

temp=hist(funVec,plot=FALSE)

plot(1,xlim=c(max(temp$breaks),min(temp$breaks)),

 ylim=c(0,max(temp$counts)+0.1*max(temp$counts)),col=white)

for(i in 1:1000)

 {

 hist(funVec[1:i],add=TRUE,col=white)

 Sys.sleep(1/25)

 }

 

I don't find any mistake in the example above and nevertheless there
something strange about the result. R should plot 1000 histograms with time
breaks of 1/25 seconds between the single plots. But the program visualize
not even 100 steps. I don't understand that circumstance. If I don't use the
add parameter, R visualize all 1000 steps. 

I hope somebody could help me or explain me what ist happening there. I m
looking forward to any hints or clues.

 

Greetings and thanks in advance

 

Etienne

 


[[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.


Re: [R] finding the last day of the month

2010-11-08 Thread Gabor Grothendieck
On Mon, Nov 8, 2010 at 7:06 AM, Benjamin Williams b...@bwmcct.com wrote:
 Dear R Help,

 I am trying to get fields showing the last day of each month for a monthly
 closing project.  In order to find the last day of the previous month, I
 subtract the number of days from the current month. For all months my code
 works; however, for October, my code doesn't work...it returns
 2010-09-*29* instead
 of 2010-09-*30*.

 format(strptime(2010-10-31,
 %Y-%m-%d)-(as.numeric(format(as.Date(2010-10-31),%d))*24*3600),%Y-%m-%d)


There are many ways to do this but here is one using as.yearmon in
zoo.  This converts the Date variable, today, to yearmon class which
is a year and a fraction representing a month.  Then it converts it
back to Date class using frac = 1 which means all the way to the end
of the month (frac = 0, the default, means 1st of month, etc.):

 library(zoo)
 today - Sys.Date()
 as.Date(as.yearmon(today), frac = 1)
[1] 2010-11-30

If you are trying to show monthly data another option might be just to
not show the day at all:

 format(as.yearmon(today))
[1] Nov 2010

 # or without yearmon
 format(today, %b %Y)
[1] Nov 2010




-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] help to sum up data frame

2010-11-08 Thread jim holtman
Nice thing about R is there is more than one way of doing something:

 x
   name ip Bsent Breceived
1 a  1  0.00  0.00
2 a  2  1.43 19.83
3 a  1  0.00  0.00
4 a  2  1.00  1.00
5 b  1  0.00  2.00
6 b  3  0.00  2.00
7 b  2  2.00  0.00
8 b  2  2.00  0.00
9 b  1 24.40 22.72
10c  1  1.00  1.00
11c  1  2.00  1.00
12c  1  2.00  1.00
13c  1 90.97 15.70
14d  0  0.00  0.00
15d  1 30.00 17.14
 require(sqldf)
 sqldf('select name, sum(ip) as ip, sum(Bsent) as Bsent,
+ sum(Breceived) as Breceived
+ from x
+ group by name')
  name ip Bsent Breceived
1a  6  2.43 20.83
2b  9 28.40 26.72
3c  4 95.97 18.70
4d  1 30.00 17.14



On Sun, Nov 7, 2010 at 8:59 AM, Mohan L l.mohanphys...@gmail.com wrote:
 Dear All,

 I have a data frame like this:

 name      ip      Bsent     Breceived
 a           1        0.00      0.00
 a           2       1.43       19.83
 a           1       0.00      0.00
 a          2        1.00      1.00
 b          1        0.00      2.00
 b          3       0.00      2.00
 b          2       2.00      0.00
 b         2       2.00      0.00
 b         1       24.40     22.72
 c         1       1.00      1.00
 c         1       2.00      1.00
 c         1       2.00      1.00
 c         1      90.97      15.70
 d         0       0.00      0.00
 d         1     30.00       17.14

 I want to sum up the similar name into one row, like :

 name      ip      Bsent     Breceived
 a            6        2.43      20.83
 b            9       28.40     26.72
 c
 d

 I need help to sum up. Thanks for your time.


 Thanks  Rg
 Mohan L

 __
 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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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] Rserve causes Perl error

2010-11-08 Thread jim holtman
Could be both.  Do you have perl installed and is it on a path that R can find.

On Mon, Nov 8, 2010 at 1:32 AM, Ralf B ralf.bie...@gmail.com wrote:
 Hi all,

 I tried to run Rserve: I installed it from CRAN using

 install.packages(Rserve)

 and tried to run it from the command line using:

 R CMD Rserve

 I am getting an error telling me that the command perl cannot be
 found. What is wrong and what can I do to fix this? Do I need to
 install any other packages or is it just a path problem?

 Ralf

 __
 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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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] Rserve alternative?

2010-11-08 Thread Erich Neuwirth
You might want to look at statconnWS (available from rcom.univie.ac.at).
Warning: This project is not open source.


On 11/8/2010 12:40 PM, Ralf B wrote:
 The Rserve documentation at
 
 http://rosuda.org/Rserve/doc.shtml#start
 
 states that even when making multiple connections to the Rserve,
 Windows won't separate workspaces physically and share environments,
 which will obviously cause problems and should therefore not be used.
 Are there any alternatives for the windows platform?
 
 Ralf
 
 __
 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.


Re: [R] irregular grid

2010-11-08 Thread Ben Bolker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 10-11-08 08:05 AM, wolfgang.pola...@gmail.com wrote:
 Thanks, what if a I want to add to the plot a second column of observations, 
 like a type h line from the x,y plane?
 Wolfgang

  see segments3d.
  rgl is somewhat more do-it-yourself/construct-your-own-geometrical
objects than the various 2D graphic systems (a bit more than base
graphics, certainly more than lattice or ggplot)

  [forwarding back to r-help]

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzX+lsACgkQc5UpGjwzenNy2QCfbA6YKcbr8uqXZI0EdYtnxMd0
DaAAni7Lo1ml+xu1BlThktyajvcmP7TE
=z0h8
-END PGP SIGNATURE-

__
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] Rserve alternative?

2010-11-08 Thread Ajay Ohri
Alternatives to Windows platform are Linux. Try Ubuntu download from
http://www.ubuntu.com/getubuntu/downloadmirrors if you are a Linux newbie to
use Rserve

Also see Rapache at http://rapache.net/ for using Apache Web Server and R
together.

The third R interface on web is Rweb see
http://www.jstatsoft.org/v04/i01/paper or http://www.math.montana.edu/Rweb/

Regards

Ajay

Websites-
http://decisionstats.com
http://dudeofdata.com
http://kushohri.com



Linkedin- www.linkedin.com/in/ajayohri




On Mon, Nov 8, 2010 at 5:10 PM, Ralf B ralf.bie...@gmail.com wrote:

 The Rserve documentation at

 http://rosuda.org/Rserve/doc.shtml#start

 states that even when making multiple connections to the Rserve,
 Windows won't separate workspaces physically and share environments,
 which will obviously cause problems and should therefore not be used.
 Are there any alternatives for the windows platform?

 Ralf

 __
 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.


[[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.


[R] Visualization of histograms

2010-11-08 Thread Etienne Stockhausen
Dear r-user,

 

I've wrote a small function to visualize the creation of a histogram.
Therefore I create a vector with random values and let them plot in
histograms. I better give a small example in R-Code:

 

i=0

funVec=rnorm(1000)

temp=hist(funVec,plot=FALSE)

plot(1,xlim=c(max(temp$breaks),min(temp$breaks)),

 ylim=c(0,max(temp$counts)+0.1*max(temp$counts)),col=white)

for(i in 1:1000)

 {

 hist(funVec[1:i],add=TRUE,col=white)

 Sys.sleep(1/25)

 }

 

I don't find any mistake in the example above and nevertheless there
something strange about the result. R should plot 1000 histograms with time
breaks of 1/25 seconds between the single plots. But the program visualize
not even 100 steps. I don't understand that circumstance. If I don't use the
add parameter, R visualize all 1000 steps. 

I hope somebody could help me or explain me what ist happening there. I m
looking forward to any hints or clues.

 

Greetings and thanks in advance

 

Etienne

 

 


[[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.


Re: [R] Visualization of histograms

2010-11-08 Thread Ted Harding
On 08-Nov-10 12:56:26, Etienne Stockhausen wrote:
 Dear r-user,
 I've wrote a small function to visualize the creation of a histogram.
 Therefore I create a vector with random values and let them plot in
 histograms. I better give a small example in R-Code:
 
 i=0
 funVec=rnorm(1000)
 temp=hist(funVec,plot=FALSE)
 
 plot(1,xlim=c(max(temp$breaks),min(temp$breaks)),
  ylim=c(0,max(temp$counts)+0.1*max(temp$counts)),col=white)
 for(i in 1:1000)
  {
  hist(funVec[1:i],add=TRUE,col=white,)
  Sys.sleep(1/25)
  }
 
 I don't find any mistake in the example above and nevertheless there
 something strange about the result. R should plot 1000 histograms
 with time breaks of 1/25 seconds between the single plots. But the
 program visualize not even 100 steps. I don't understand that
 circumstance. If I don't use the add parameter, R visualize all 1000
 steps. 
 
 I hope somebody could help me or explain me what ist happening there.
 I m looking forward to any hints or clues.
 
 Greetings and thanks in advance
 Etienne

I tried your code, and observed what you expected to see (not what
you say you saw). It may be a problem with your system. As a check,
I added a couple of lines to your code, as follows:

  i=0
  funVec=rnorm(1000)
  temp=hist(funVec,plot=FALSE)

  plot(1,xlim=c(max(temp$breaks),min(temp$breaks)),
   ylim=c(0,max(temp$counts)+0.1*max(temp$counts)),col=white)
  maxx-max(temp$breaks) ; maxy-max(temp$counts) ## upper x  y lims
  for(i in 1:1000)
   {
   hist(funVec[1:i],add=TRUE,col=white,)
   points(i*maxx/1000,i*maxy/1000,pch=+)  ## plot a tracker point
   Sys.sleep(1/25)
   }

and saw the tracker move steadily from start to finish, with
clearly far more than a mere 100 steps, and at each new tracker
point there is also a change in the histogram. So in my case the
results were plotted as you wanted.

My system:

sessionInfo()
R version 2.11.0 (2010-04-22) 
i486-pc-linux-gnu 

locale:
 [1] LC_CTYPE=en_GB.UTF-8   LC_NUMERIC=C  
 [3] LC_TIME=en_GB.UTF-8LC_COLLATE=en_GB.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8   LC_NAME=C 
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C   

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

loaded via a namespace (and not attached):
[1] tools_2.11.0




E-Mail: (Ted Harding) ted.hard...@wlandres.net
Fax-to-email: +44 (0)870 094 0861
Date: 08-Nov-10   Time: 13:34:10
-- XFMail --

__
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 remove border while saving R plots ?

2010-11-08 Thread David Winsemius


On Nov 8, 2010, at 5:13 AM, vikrant wrote:



I am saving R graph as a jpeg image and the border is plotted  
defaultly when

you open the image.How can I avoid the border?
small R code is as follows :-

volume- seq(100,10,-10)

  jpeg(filename =  
mygraph.jpg,width=366,height=284,units=px)

{
		pie(volume,main=title,radius=radius ,bty=n,clockwise =  
TRUE,col=color,

font.main = 2,cex.main = 1.8,cex.lab=1.5,border = FALSE)

}
dev.off()
when I open this image  automaticaly border is  plotted around the  
graph.

How to avoid this?


Read the help pages? The pie help page Argument definition for border  
refers you to the polygon help page... see that handy little link?


border
the color to draw the border. The default, NULL, means to use  
par(fg). Use border = NA to omit borders.


I get an error complaining about missing a color vector when I try  
to test border=NA  with your code, but presumably a more complete  
example would have demonstrated success. (  I did try putting in  
something for col= but then radius was also missing so back to you,  
booby.)


--

David Winsemius, MD
West Hartford, CT

__
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] Working with semantic data triplets

2010-11-08 Thread Leonard Mada
Dear R Help List,

I have the following data set:
id date factor
eg.
1, date11, f1
1, date12, f2
1, date13, f3
[...]
2, date21, fi
2, date22, fj
[…]

f1 – fn are various levels of a factor variable.

Each ID may contain 1 to many entries. These represent basically semantic data 
(triplets).

I want to construct the corresponding contingency table, detailing all direct 
transitions:
factor_i = factor_j; in other words:
__ f1 f2 f3 f4 … fn
f1
f2
f3
…
fn

Beyond the simple count, I would also want to compute various statistics on the 
time intervals between the (fi, fj) transition, including mean, sd, median and 
various quantiles.

(fi, fi) transitions are only possible if only one entry is available for that 
ID, and consequently this represents the number of unique IDs with only one 
triplet (and that triplet having associated fi) – but the solution is not 
required to compute this (I am not very interested in this data; it is more for 
pedantic reasons).

However, the solution should also compute:
all (fi, fj) direct transitions
all (fi, fj) direct transitions, where fi is the baseline value (baseline = 
smallest date); it may be easy to create such a data subset, once the first 
problem is solved, and the true issue is only solving for the general problem

What would be the best way to do this?
I am invariably ending up with solutions based on loops, but I feel this is 
entirely wrong. Also, the dataset contains over 600,000 triplets and is growing 
fast, so loops would be pretty unusable on my home computer (my senses are 
telling me that loops are very slow).

I can sort the data externally (by ID, DATE) to ease computations.

Thank you very much for your help.

Sincerely,

Leonard

-- 
GRATIS! Movie-FLAT mit über 300 Videos.

__
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] Computing ergodic mean with CODA

2010-11-08 Thread Giovanni Petris
Hola Raquel,

As Ben already told you, ergodic means are pretty easy to compute from
scratch. If you are lazy, or you want something more, like estimated
standard errors, you can check out the functions ergMean and mcmcMean in
package dlm.

Best,
Giovanni Petris

On Sun, 2010-11-07 at 14:34 -0200, Raquel Rangel de Meireles Guimarães
wrote:
 Hi all,
 
 I would like to compute ergodic mean using MCMC output from WinBUGS. I 
 tried using CODA package, but it seems that it is not implemented yet.
 
 Could anyone help me to compute this? Attached to this email are my 
 output and index files.
 
 Kind regards,
 
 Raquel
 
 --
 Raquel Rangel de Meireles Guimarães
 Doutoranda em Demografia
 raq...@cedeplar.ufmg.br
 http://ufmg.academia.edu/RaquelGuimaraes
 Cedeplar - Centro de Desenvolvimento e Planejamento Regional
 Avenida Antônio Carlos, 6627, Sala 2090, Pampulha, BH-MG
 Telefones: (31) 3409-7144 - (31) 9732-2132
 Faculdade de Ciências Econômicas, UFMG (http://www.cedeplar.ufmg.br)
 
 __
 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.


Re: [R] conditional probability

2010-11-08 Thread Giovanni Petris

If you want a conditional distribution of x11 given x1,..x10, you need
to make some assumptions about the joint distribution. It seems from the
original post that items 1. and 2. refer to the marginal distribution of
each observation.

In general, it would help to specify the question a little more
carefully.

Giovanni Petris

On Mon, 2010-11-08 at 19:31 +1100, Michael Bedward wrote:
 Hello Jumlong,
 
 For Normal distribution see the help page for pnorm.
 
 For dealing with unknown (empirical) distributions, look at ecdf.
 
 Hope this helps
 Michael
 
 On 8 November 2010 16:29, Jumlong Vongprasert jumlong.u...@gmail.com wrote:
  Dear all
   I have problem with calculate probability, I have data x1,...,x10,
  I want to calculate probability x11 given x1,...,x10 with two conditions.
   1. x is normal
2. unknow distribution
  How I can do this.
  Many Thanks.
  Jumlong
 
  --
  Jumlong Vongprasert Assist, Prof.
  Institute of Research and Development
  Ubon Ratchathani Rajabhat University
  Ubon Ratchathani
  THAILAND
  34000
 
 [[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.
 
 
 __
 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.


Re: [R] How to eliminate this for loop ?

2010-11-08 Thread David Winsemius


On Nov 8, 2010, at 4:30 AM, Nick Sabbe wrote:


Whenever you use a recursion (that cannot be expressed otherwise), you
always need a (for) loop.


Not necessarily true ... assuming a is of length n:

a[2:n] - a[1:(n-1))]*b + cc[1:(n-1)]
# might work if b and n were numeric vectors of length 1 and cc had  
length = n. (Never use c as a vector name.)
# it won't work if there are no values for the nth element at the  
beginning and you are building up a element by element.


And you always need to use operations that appropriate to the object  
type. So if a really is a list, this will always fail since  
arithmetic does not work on list elements. If on the other hand, the  
OP were incorrect in calling this a list and a were a numeric  
vector, there might be a chance of success if the rules of indexing  
were adhered to. The devil is in the details and the OP has not  
supplied enough code to tell what might happen.


--
David.

Apply and the like do not allow to use the intermediary results  
(i.e. a[i-1]

to calculate a[i]).

So: no, it cannot be avoided in your case, I guess.


Nick Sabbe
--
ping: nick.sa...@ugent.be
link: http://biomath.ugent.be
wink: A1.056, Coupure Links 653, 9000 Gent
ring: 09/264.59.36

-- Do Not Disapprove



-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org 
] On

Behalf Of PLucas
Sent: maandag 8 november 2010 10:26
To: r-help@r-project.org
Subject: [R] How to eliminate this for loop ?


Hi, I would like to create a list recursively and eliminate my for  
loop :


a-c()
a[1] - 1; # initial value
for(i in 2:N) {
a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector
}


Is it possible ?

Thanks
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-eliminate-this-for-loop-tp3031667p30316
67.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-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.


David Winsemius, MD
West Hartford, CT

__
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] RMark error: only 0's may be mixed with negative subscripts

2010-11-08 Thread Jeff Laake
Umesh-

You should contact the package maintainer or a SIG with a question about 
a package.  RMark isn't posted on CRAN so it is unlikely most folks will 
even know about it.  There is a support forum for MARK and RMark on the 
phidot site where you got them.  I'll look at your data and problem and 
will get back to you.  I suggest that you subscribe to the phidot forum.

Jeff Laake (RMark maintainer)

On 11/7/2010 11:03 PM, Umesh Srinivasan wrote:
 Hi all,

 I have just started using RMark to analyse capture-recapture data. I am
 trying to analyse a simulated data set using the Robust Design (two primary
 periods with three secondary sessions in each) to estimate apparent
 survival. On specifying the time intervals (that tell R about the primary
 and secondary sampling sessions), this is the error I get:


 time.int- c(0,0,1,0,0)
 model- mark(dat, model = Robust, time.intervals = time.int)
  
 Error in time.intervals[1:(i - 1)] :
only 0's may be mixed with negative subscripts

 This is what I tried to do overall:

 ###

 library(RMark)

 dat- import.chdata(/home/umesh/Desktop/capture history.txt)
 head(dat)

 time.int- c(0,0,1,0,0)
 model- mark(dat, model = Robust, time.intervals = time.int)

 ###

 I am attaching the simulated capture histories in the file 'capture
 history.txt' as well if that will help.

 Thanks in advance,

 Umesh Srinivasan
 National Centre for Biological Sciences
 Bangalore, India



 __
 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.


[[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.


[R] try (nls stops unexpectedly because of chol2inv error

2010-11-08 Thread Monte Shaffer
Hi,

I am running simulations that does multiple comparisons to control.

For each simulation, I need to model 7 nls functions.  I loop over 7 to do
the nls using try

if try fails, I break out of that loop, and go to next simulation.

I get warnings on nls failures, but the simulation continues to run, except
when the internal call (internal to nls) of the chol2inv fails.


Error in chol2inv(object$m$Rmat()) :
  element (2, 2) is zero, so the inverse cannot be computed
In addition: Warning messages:
1: In nls(myModel.nlm, fData, start = initialValues, control =
nls.control(warnOnly = TRUE),  :
  number of iterations exceeded maximum of 50
2: In nls(myModel.nlm, fData, start = initialValues, control =
nls.control(warnOnly = TRUE),  :
  singular gradient
===

Any suggestions on how to prevent chol2inv from breaking my simulation...
The point of the simulation is to address power.  As our data goes down to
N, of the 100 simulations, only 53 are good simulations because we don't
have enough data for nls or chol2inv to work correctly.


monte

{x:

###


## case I  ## EQUAL SAMPLE SIZES and design points
nsim = 100;
N_i = M_i = 10; ## also try (10, 30, 50, 100, 200)
r = M_i / N_i;

X.start = 170; # 6 design points, at 170,180,190, etc. where each point has
N_i elements
X.increment = 10;
X.points = 6;
X.end = 260;
Xval = seq(X.start,length.out=X.points,by=X.increment );
Xval = seq(X.start,X.end,length.out=X.points);

L = 7;  ## 6 + control
k = 3;
varY = 0.15;

### for each simulation, we need to record all of this information, write to
a table or file.

### Under the null of simulation, we assign all locations to have same model
## we assume these are the true parameters
b = 2.87; d = 0.0345; t = 173;


B = seq(2.5,4.5,length.out=21);
#B = seq(2.75,3.25,length.out=21);
#B = seq(2.85,2.95,length.out=21);
#B = seq(2.8,3.0,length.out=21);
B = seq(2.5,3.2,length.out=21);
D = seq(0.02,0.04,length.out=21);
T = seq(165,185,length.out=21);

alpha = .05;
nu = k; ## number of parameters
tr = L-1; ## number of treatments (including control)
rho = 1/(1+r); ## dependency parameter
myCritical = qmvchi(alpha,nu,tr,rho);
## we change one parameter at a time until the results fail most of the
time.


## do independent for now, but let's store the parameters and quantiles???
INFO for one location
# beta delta tau  nsim %Reject(V.pooled) %Reject(V.total) [Simulation level]
 resultS
# beta delta tau i of nsim max(V.pooled) max(V.total) [Individual level]
 resultI

resultS = resultI = NULL;
for(p1 in 1:length(D))
{
print(paste(p1,  [D] of ,length(D))); flush.console();
print(D[p1]);
myReject.pooled = myReject.pooled.1 = MAX.pooled = rep(-1,nsim);
gsim = 0; ## good simulations
for(i in 1:nsim)
{
doubleBreak = F;
print(paste(i,  of ,nsim)); flush.console();
tData = NULL;
pooledNum = matrix(0,nrow=k,ncol=k);  ##numerator as weighted sum AS
(n_k-1)cov.scaled
pooledDen = 0;  ##denominator as correction AS N-k
#Sigma_pooled = ((omit.1-1)*summary.nls.1$cov.scaled +
(omit.2-1)*summary.nls.2$cov.scaled +
(omit.L-1)*summary.nls.L$cov.scaled)/(sum(omit.1,omit.2,omit.L)-L);


for(j in 1:L)
{
Y = numeric(N_i);
X = createDomain(Xval,N_i); noise = rnorm(N_i, mean=0,sd=sqrt(varY) );

if(j==1)
{
## location #1 is different
 Y = noise + evaluateModel(X,b,D[p1],t);
beta = b;
delta = D[p1];
tau = t;
} else {
Y = noise + evaluateModel(X,b,d,t);
}
print(paste(j,  location NLS of ,L)); flush.console();

fData = as.data.frame(cbind(Y,X)); colnames(fData)=c(Y,X); unique =
doUnique(fData);
initialValues = list(b=3,d=0.04,t=180);
 #plot(X,Y,main=j);

# http://stackoverflow.com/questions/2963729/r-catching-errors-in-nls
try.fit = try(
 nls(
myModel.nlm ,
fData,
start = initialValues,
control = nls.control(warnOnly = TRUE),
trace=T
)
  );

if(class(try.fit) == try-error)
{
doubleBreak = T;
print(doubleBreak);
break;  ## skip to next simulation?
} else {
fit.nls = try.fit;
summary.nls = summary(fit.nls);
summary.nls$cov.scaled = scaledCOV(summary.nls);
pooledDen = pooledDen + dim(fData)[1];
pooledNum = pooledNum + (dim(fData)[1]-1)*summary.nls$cov.scaled;
results = list(data=fData,fit.nls=fit.nls,summary.nls=summary.nls);
tData = rbind(tData,fData); ## total data
}
 if(j==L)
{
myStr = nls.L;
} else {
myStr = paste(nls.,j,sep=);
}
assign(myStr,results);
 }
if(doubleBreak==T)
{
# break from outer loop if fit didn't work [SKIP simulation]
print(doubleBreak);
doubleBreak = F;
next;
}
gsim = gsim + 1;
# http://www.maths.bris.ac.uk/~mazjcr/SGP.R

COV.pooled = pooledNum/pooledDen;

## loop back through, use COV.t and COV.pooled to do tests and record reject
or not
CONTROL = nls.L$summary.nls$parameters[,1];
Vp = numeric(L-1);
for(j in 1:(L-1))
{
myStr = paste(nls.,j,sep=);
myData = get(myStr);

Diff =  myData$summary.nls$parameters[,1]-nls.L$summary.nls$parameters[,1];


Re: [R] help! kennard-stone algorithm in soil.spec packages does not work for my dataset!!!

2010-11-08 Thread bbslover

http://r.789695.n4.nabble.com/file/n3032045/rsv1.txt rsv1.txt 


I am very grateful to David's suggestion, here , I upload my dataset
rsv1.txt, also the question, 

ks-ken.sto(rsv1,per=TRUE,per.n=0.3,va=FALSE,sav=FALSE)

it does not work, all results are NULL, i do not known why it is ?

hope, friends can give me a hand!

thanks 

kevin

-- 
View this message in context: 
http://r.789695.n4.nabble.com/help-kennard-stone-algorithm-in-soil-spec-packages-does-not-work-for-my-dataset-tp3031344p3032045.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] Maria Teresa Torres Muñoz/Gestion de Intangi bles/LineaDirecta está ausente de la oficina.

2010-11-08 Thread Maria Teresa Torres Muñoz


Estaré ausente de la oficina desde el  08/11/2010 y no volveré hasta el
16/11/2010.

Responderé a su mensaje cuando regrese, si es urgente enviar mail a
INNOVACION
Visítenos en:  www.lineadirecta.com  

Este mensaje y los documentos que, en su caso, lleve anexos, pueden contener 
información confidencial. Por ello, se informa a quien lo reciba por error que 
la información contenida en el mismo es reservada y su uso no autorizado está 
prohibido legalmente, por lo que en tal caso le rogamos se abstenga de realizar 
copias del mensaje, leerlo, remitirlo o difundirlo y proceda a borrarlo 
inmediatamente. 

This message is intended only for the use of the individual to whom it is 
addressed and may contain information that is confidential. If you have 
received this communication, by error, you are hereby notified that any 
distribution or copying of this communication is prohibited.   
[[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.


[R] Add text to a stacked barplot

2010-11-08 Thread Ashraf Yassen
Hi All,

I need some help in putting text in a stacked barplot. The barplot is filled
with 5 levels and now I would like to put text to each level in the stacked
barplot. However, it seems that the code that I am using is not placing the
text at the correct hight (centered at each fill) in the barplot. Any
suggestions to improve the code to make it work?

barchart(FREQ ~ VISIT |which*as.factor(TRTN), data = stuffa,par.strip.text =
list(cex = 0.35),
groups = RES, xlab=Visit,ylab=Frequency,
layout = c(4,2),
par.settings=list(superpose.polygon=list(col=colors()[c(636,96,256,92,27,376)])),
stack = T,
auto.key = list(points = FALSE, rectangles = TRUE,
space = top),
scales = list(x = list(alternating=c(1,1),tck=c(1,0),abbreviate = TRUE,
minlength
= 5, rot = 0),y=list(alternating=c(1,1),tck=c(1,0))),
panel = function(y,x,...){
panel.grid(h = -1, v = 0, col = gray, lty = 3,lwd=1)
panel.barchart(x,y,...)
panel.text(x,y,label = round(y,1),cex=0.48)
}
)



Kind regards,
Ashraf Yassen

[[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.


Re: [R] Add text to a stacked barplot

2010-11-08 Thread RICHARD M. HEIBERGER
Please post some data (fake data is fine) for stuffa.  The example doesn't
execute as is.

Rich



On Mon, Nov 8, 2010 at 10:27 AM, Ashraf Yassen ashraf.yas...@gmail.comwrote:

 Hi All,

 I need some help in putting text in a stacked barplot. The barplot is
 filled
 with 5 levels and now I would like to put text to each level in the stacked
 barplot. However, it seems that the code that I am using is not placing the
 text at the correct hight (centered at each fill) in the barplot. Any
 suggestions to improve the code to make it work?

 barchart(FREQ ~ VISIT |which*as.factor(TRTN), data = stuffa,par.strip.text
 =
 list(cex = 0.35),
 groups = RES, xlab=Visit,ylab=Frequency,
 layout = c(4,2),

 par.settings=list(superpose.polygon=list(col=colors()[c(636,96,256,92,27,376)])),
 stack = T,
 auto.key = list(points = FALSE, rectangles = TRUE,
 space = top),
 scales = list(x = list(alternating=c(1,1),tck=c(1,0),abbreviate = TRUE,
 minlength
 = 5, rot = 0),y=list(alternating=c(1,1),tck=c(1,0))),
 panel = function(y,x,...){
 panel.grid(h = -1, v = 0, col = gray, lty = 3,lwd=1)
 panel.barchart(x,y,...)
 panel.text(x,y,label = round(y,1),cex=0.48)
 }
 )



 Kind regards,
 Ashraf Yassen

[[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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[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.


[R] Sample size calculation for differences between two very small proportions (Fisher's exact test or others)?

2010-11-08 Thread Giulio Di Giovanni


Hi, 
I'm try to compute the minimum sample size needed to have at least an 80% of 
power, with alpha=0.05. The problem is that empirical proportions are really 
small: 0.00154 in one case and 0.00234. These are the estimated failure 
proportion of two medical treatments.
Thomas and Conlon (1992) suggested Fisher's exact test and proposed a 
computational method, which according to their table gives a sample size of 
roughly 2. Unfortunately I cannot find any software applying their method.
-Does anyone know how to estimate sample size on Fisher's exact test by using R?
-Even better, does anybody know other, maybe optimal, methods for such a 
situation (small p1 and p2) and the corresponding R software? 

Thanks in advance,
Giulio


  
[[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.


[R] Add values of rlm coefficients to xyplot

2010-11-08 Thread PtitBleu

Hello,

I have a simple xyplot with rlm lines.
I would like to add the a and b coefficients (y=ax+b) of the rlm calculation
in each panel.
I know I can do it 'outside' the xyplot command but I would like to do all
at the same time. 

I found some posts with the same question, but no answer.

Is it impossible ?

Thanks in advance for your help.
Ptit Bleu.

x11(15,12)
xyplot(df1$col2 ~ df1$col3 | df1$Name,
panel = function(x, y,...) {
panel.abline(h=seq(20,40,5), col=gray)
panel.abline(v=seq(-10,60,5), col=gray)
panel.xyplot(x, y, type=p, col=red, pch=20,...)
panel.abline(rlm(y ~ x), col=blue)
}, scales=list(cex=1.2),
 xlab=list(X, cex=1.4), ylab=list(Y, cex=1.4),
xlim=c(-10,60), ylim=c(20,40))

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Add-values-of-rlm-coefficients-to-xyplot-tp3032166p3032166.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] Error: could not find function extract in package raster

2010-11-08 Thread Monica Pisica

Hi,
 
I would like to use the function extract from package raster and i get the 
following error:
 m01e - extract(marsh01, p)
Error: could not find function extract
 
marsh01 is a raster object and p is an intersectExtent object that is not null.

The package is installed and loaded, i use a Windows machine 64 bit and R x64 
2.11.0. Do i really need to update my R to use this function?
 
Thanks, Monica
[[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.


Re: [R] Error: could not find function extract in package raster

2010-11-08 Thread Joshua Wiley
Hi Monica,

Evidently, there is not an extract function in your search path
(base R, loaded packages, etc.).  Given that you are talking about a
function from a package (rather than base R), it would probably help
us more if you mentioned what version of raster you have installed.
You can get this easily by loading it and reporting the results of
sessionInfo() (per the posting guide).  On my current system (see
specs below), there is an extract function and it seems to work.,

Cheers,

Josh



 sessionInfo()
R version 2.12.0 (2010-10-15)
Platform: i486-pc-linux-gnu (32-bit)

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

other attached packages:
[1] raster_1.6-10 sp_0.9-72

loaded via a namespace (and not attached):
[1] grid_2.12.0 lattice_0.19-13 tools_2.12.0

On Mon, Nov 8, 2010 at 8:08 AM, Monica Pisica pisican...@hotmail.com wrote:

 Hi,

 I would like to use the function extract from package raster and i get the 
 following error:
  m01e - extract(marsh01, p)
 Error: could not find function extract

 marsh01 is a raster object and p is an intersectExtent object that is not 
 null.

 The package is installed and loaded, i use a Windows machine 64 bit and R x64 
 2.11.0. Do i really need to update my R to use this function?

 Thanks, Monica
        [[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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] Sample size calculation for differences between two very small proportions (Fisher's exact test or others)?

2010-11-08 Thread Mitchell Maltenfort
Not with R, but look for G*Power3, a free tool for power calc,
includes FIsher's test.

http://www.psycho.uni-duesseldorf.de/abteilungen/aap/gpower3

On Mon, Nov 8, 2010 at 10:52 AM, Giulio Di Giovanni
perimessagg...@hotmail.com wrote:


 Hi,
 I'm try to compute the minimum sample size needed to have at least an 80% of 
 power, with alpha=0.05. The problem is that empirical proportions are really 
 small: 0.00154 in one case and 0.00234. These are the estimated failure 
 proportion of two medical treatments.
 Thomas and Conlon (1992) suggested Fisher's exact test and proposed a 
 computational method, which according to their table gives a sample size of 
 roughly 2. Unfortunately I cannot find any software applying their method.
 -Does anyone know how to estimate sample size on Fisher's exact test by using 
 R?
 -Even better, does anybody know other, maybe optimal, methods for such a 
 situation (small p1 and p2) and the corresponding R software?

 Thanks in advance,
 Giulio



        [[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.


__
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] How to plot a normal distribution curve and a shaded tail with alpha?

2010-11-08 Thread Wu Gong

I want to create a graph to express the idea of the area under a pdf curve,
like

http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg 

Thank you for any help.

-
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.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] varclus in Hmisc vs SAS PROC VARCLUS

2010-11-08 Thread Darin A. England
My impression is that varclus from the Hmisc library is very
convenient to use when you want to get an idea of the correlation
among predictor variables in a regression setting, but if you want
to perform cluster analysis in general, you may be better off using
a different function in R, such as hclust or kmeans. 
Darin


On Sun, Nov 07, 2010 at 11:00:00AM -0500, Lars Bishop wrote:
 Hi,
 
 
 
 I'll apreciate your guidance on how can I re-create the output from SAS PROC
 VARCLUS in R. I've found the varclus function in Hmisc. However, is it
 possible to use that function to compute for each variable the 1-R**2 ratio
 (this is the ratio of 1 minus the R-squared with Own Cluster to one minus
 the R-squared in the Next Closest cluster)?
 
 
 
 Thanks in advance for any help,
 
 
 
 Lars.
 
   [[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.

__
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] Sample size calculation for differences between two very small proportions (Fisher's exact test or others)?

2010-11-08 Thread David Winsemius


On Nov 8, 2010, at 11:16 AM, Mitchell Maltenfort wrote:


Not with R,


Really?

require(sos)
findFn(power exact test)
found 54 matches;  retrieving 3 pages
2 3

These look on point:
http://finzi.psych.upenn.edu/R/library/statmod/html/power.html

http://finzi.psych.upenn.edu/R/library/binom/html/cloglog.sample.size.html


Would also think that methods based on a poisson model of rare events  
could be informative:


http://finzi.psych.upenn.edu/R/library/asypow/html/asypow.n.html

--
David.


but look for G*Power3, a free tool for power calc,
includes FIsher's test.

http://www.psycho.uni-duesseldorf.de/abteilungen/aap/gpower3

On Mon, Nov 8, 2010 at 10:52 AM, Giulio Di Giovanni
perimessagg...@hotmail.com wrote:



Hi,
I'm try to compute the minimum sample size needed to have at least  
an 80% of power, with alpha=0.05. The problem is that empirical  
proportions are really small: 0.00154 in one case and 0.00234.  
These are the estimated failure proportion of two medical treatments.
Thomas and Conlon (1992) suggested Fisher's exact test and proposed  
a computational method, which according to their table gives a  
sample size of roughly 2. Unfortunately I cannot find any  
software applying their method.
-Does anyone know how to estimate sample size on Fisher's exact  
test by using R?
-Even better, does anybody know other, maybe optimal, methods for  
such a situation (small p1 and p2) and the corresponding R software?


Thanks in advance,
Giulio






David Winsemius, MD
West Hartford, CT

__
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 plot a normal distribution curve and a shaded tail with alpha?

2010-11-08 Thread David Winsemius


On Nov 8, 2010, at 11:18 AM, Wu Gong wrote:



I want to create a graph to express the idea of the area under a pdf  
curve,

like

http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg


I think you could have titled this request:
Yet Another Request to Do My Searching For Me:

http://search.r-project.org/cgi-bin/namazu.cgi?query=plot+normal+curve+with+shadingmax=100result=normalsort=scoreidxname=functionsidxname=Rhelp08idxname=Rhelp10idxname=Rhelp02

The R search space is littered with examples and that search string  
is not likely to uncover them all, but is rather  just one example.


--
David



Thank you for any help.

-
A R learner.
--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.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.


David Winsemius, MD
West Hartford, CT

__
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] Centre of gravity of a mountain

2010-11-08 Thread Ab Hu

Hi all,
I have a matrix of a mountain of form 21x21 and values in them are height
(Z). Using the persp function I can view this mountain in 3D. 
Now, I am trying to find a measure to find the centre of gravity (maybe
centroid?) of this mountain. Any idea what would be the best way to go?
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Centre-of-gravity-of-a-mountain-tp3032319p3032319.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] Sample size calculation for differences between two very small proportions (Fisher's exact test or others)?

2010-11-08 Thread Marc Schwartz
Hi,

I don't have access to the article, but must presume that they are doing 
something radically different if you are only getting a total sample size 
of 20,000. Or is that 20,000 per arm?

Using the G*Power app that Mitchell references below (which I have used 
previously, since they have a Mac app):

Exact - Proportions: Inequality, two independent groups (Fisher's exact test) 

Options:Exact distribution

Analysis:   A priori: Compute required sample size 
Input:  Tail(s) =   Two
Proportion p1   =   0.00154
Proportion p2   =   0.00234
α err prob  =   0.05
Power (1-β err prob)=   0.8
Allocation ratio N2/N1  =   1
Output: Sample size group 1 =   49851
Sample size group 2 =   49851
Total sample size   =   99702
Actual power=   0.8168040
Actual α=   0.0462658




Using the base R power.prop.test() function:

 power.prop.test(p1 = 0.00154, p2 = 0.00234, power = 0.8)

 Two-sample comparison of proportions power calculation 

  n = 47490.34
 p1 = 0.00154
 p2 = 0.00234
  sig.level = 0.05
  power = 0.8
alternative = two.sided

 NOTE: n is number in *each* group 



Using Frank's bsamsize() function in Hmisc:

 bsamsize(p1 = 0.00154, p2 = 0.00234, fraction = .5, alpha = .05, power = .8)
  n1   n2 
47490.34 47490.34 



Finally, throwing together a quick Monte Carlo simulation using the FET, I get:

TwoSampleFET - function(n, p1, p2, power = 0.85,
 R = 5000, correct = FALSE)
{  
  MCSim - function(n, p1, p2)
  {
Control - rbinom(n, 1, p1)
Treat - rbinom(n, 1, p2)
fisher.test(cbind(table(Control), table(Treat)))$p.value
  }

  # Run MC Replicates
  MC.res - replicate(R, MCSim(n, p1, p2))

  # Get p value at power quantile
  quantile(MC.res, power)
}


# 50,000 per arm
 TwoSampleFET(5, p1 = 0.00154, p2 = 0.00234, power = 0.8, R = 500)
   80% 
0.04628263 



So all four of these are coming back with numbers in the 48,000 to 50,000 
***per arm***.


HTH,

Marc Schwartz


On Nov 8, 2010, at 10:16 AM, Mitchell Maltenfort wrote:

 Not with R, but look for G*Power3, a free tool for power calc,
 includes FIsher's test.
 
 http://www.psycho.uni-duesseldorf.de/abteilungen/aap/gpower3
 
 On Mon, Nov 8, 2010 at 10:52 AM, Giulio Di Giovanni
 perimessagg...@hotmail.com wrote:
 
 
 Hi,
 I'm try to compute the minimum sample size needed to have at least an 80% of 
 power, with alpha=0.05. The problem is that empirical proportions are really 
 small: 0.00154 in one case and 0.00234. These are the estimated failure 
 proportion of two medical treatments.
 Thomas and Conlon (1992) suggested Fisher's exact test and proposed a 
 computational method, which according to their table gives a sample size of 
 roughly 2. Unfortunately I cannot find any software applying their 
 method.
 -Does anyone know how to estimate sample size on Fisher's exact test by 
 using R?
 -Even better, does anybody know other, maybe optimal, methods for such a 
 situation (small p1 and p2) and the corresponding R software?
 
 Thanks in advance,
 Giulio

__
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] Centre of gravity of a mountain

2010-11-08 Thread Peter Langfelder
Weighted mean of x and y coordinates (sorry for the pun :)), that is
something like

n = 21
y = matrix( c(1:n), n, n)
x = matrix( c(1:n), n, n, byrow = TRUE)

# These are the Center of mass coordinates:
xCenter = sum(x * Z)/sum(Z);
yCenter = sum(y * Z)/sum(Z);

If you also need the z coordinate, it simply the mean of the matrix Z.

zCenter = mean(Z)

Peter




On Mon, Nov 8, 2010 at 9:07 AM, Ab Hu master.rs...@yahoo.com wrote:

 Hi all,
 I have a matrix of a mountain of form 21x21 and values in them are height
 (Z). Using the persp function I can view this mountain in 3D.
 Now, I am trying to find a measure to find the centre of gravity (maybe
 centroid?) of this mountain. Any idea what would be the best way to go?
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Centre-of-gravity-of-a-mountain-tp3032319p3032319.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-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] Error: could not find function extract in package raster

2010-11-08 Thread Monica Pisica

Hi Joshua,

OK, my session info is this:

R version 2.11.0 (2010-04-22) 
x86_64-pc-mingw32 

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C  
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] raster_1.5-16 sp_0.9-64

loaded via a namespace (and not attached):
[1] grid_2.11.0lattice_0.18-8

I also have installed the 32 bit version of R under windows 64 bit and there 
the raster package has the function extract and session info is:

R version 2.11.0 (2010-04-22) 
i386-pc-mingw32 

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C  
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] raster_1.6-10 sp_0.9-62

loaded via a namespace (and not attached):
[1] grid_2.11.0lattice_0.18-5

Obviously i would like to work with the R64 bit because i have more memory 
available. It is not clear to me why the function extract exists in the package 
raster for 32 bit but not for 64 bit. Is there any reason?

Thanks,

Monica

 Date: Mon, 8 Nov 2010 08:17:48 -0800
 Subject: Re: [R] Error: could not find function extract in package raster
 From: jwiley.ps...@gmail.com
 To: pisican...@hotmail.com
 CC: r-help@r-project.org
 
 Hi Monica,
 
 Evidently, there is not an extract function in your search path
 (base R, loaded packages, etc.).  Given that you are talking about a
 function from a package (rather than base R), it would probably help
 us more if you mentioned what version of raster you have installed.
 You can get this easily by loading it and reporting the results of
 sessionInfo() (per the posting guide).  On my current system (see
 specs below), there is an extract function and it seems to work.,
 
 Cheers,
 
 Josh
 
 
 
  sessionInfo()
 R version 2.12.0 (2010-10-15)
 Platform: i486-pc-linux-gnu (32-bit)
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base
 
 other attached packages:
 [1] raster_1.6-10 sp_0.9-72
 
 loaded via a namespace (and not attached):
 [1] grid_2.12.0 lattice_0.19-13 tools_2.12.0
 
 On Mon, Nov 8, 2010 at 8:08 AM, Monica Pisica pisican...@hotmail.com wrote:
 
  Hi,
 
  I would like to use the function extract from package raster and i get 
  the following error:
   m01e - extract(marsh01, p)
  Error: could not find function extract
 
  marsh01 is a raster object and p is an intersectExtent object that is not 
  null.
 
  The package is installed and loaded, i use a Windows machine 64 bit and R 
  x64 2.11.0. Do i really need to update my R to use this function?
 
  Thanks, Monica
 [[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.
 
 
 
 
 -- 
 Joshua Wiley
 Ph.D. Student, Health Psychology
 University of California, Los Angeles
 http://www.joshuawiley.com/
  
[[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.


Re: [R] How to eliminate this for loop ?

2010-11-08 Thread Bert Gunter
1. The for loop is probably as or more efficient than recursion,
especially for large n (comments/corrections on this claim  from
cogniscenti are welcome);

2. One can **Always** express a for loop recursively -- that is the
nature of computer languages (comments/corrections again welcome).

3. Here is code that does it: Note that I have changed argument name
c to const to avoid confusion with the c() function

f - function(n,b,const)
{
if(length(const) n-1)stop(const is too short)
g - function(i){
if(i==1) 1
else b*g(i-1)+ const[i-1]
}
g(n)
}

As David intimated, this produces a vector, not a list. Cast with
as.list if that's what you want.

Cheers,
Bert


On Mon, Nov 8, 2010 at 6:03 AM, David Winsemius dwinsem...@comcast.net wrote:

 On Nov 8, 2010, at 4:30 AM, Nick Sabbe wrote:

 Whenever you use a recursion (that cannot be expressed otherwise), you
 always need a (for) loop.

 Not necessarily true ... assuming a is of length n:

 a[2:n] - a[1:(n-1))]*b + cc[1:(n-1)]
 # might work if b and n were numeric vectors of length 1 and cc had length
= n. (Never use c as a vector name.)
 # it won't work if there are no values for the nth element at the beginning
 and you are building up a element by element.

 And you always need to use operations that appropriate to the object type.
 So if a really is a list, this will always fail since arithmetic does not
 work on list elements. If on the other hand, the OP were incorrect in
 calling this a list and a were a numeric vector, there might be a chance
 of success if the rules of indexing were adhered to. The devil is in the
 details and the OP has not supplied enough code to tell what might happen.

 --
 David.

 Apply and the like do not allow to use the intermediary results (i.e.
 a[i-1]
 to calculate a[i]).

 So: no, it cannot be avoided in your case, I guess.


 Nick Sabbe
 --
 ping: nick.sa...@ugent.be
 link: http://biomath.ugent.be
 wink: A1.056, Coupure Links 653, 9000 Gent
 ring: 09/264.59.36

 -- Do Not Disapprove



 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On
 Behalf Of PLucas
 Sent: maandag 8 november 2010 10:26
 To: r-help@r-project.org
 Subject: [R] How to eliminate this for loop ?


 Hi, I would like to create a list recursively and eliminate my for loop :

 a-c()
 a[1] - 1; # initial value
 for(i in 2:N) {
        a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector
 }


 Is it possible ?

 Thanks
 --
 View this message in context:

 http://r.789695.n4.nabble.com/How-to-eliminate-this-for-loop-tp3031667p30316
 67.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-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.

 David Winsemius, MD
 West Hartford, CT

 __
 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.




-- 
Bert Gunter
Genentech Nonclinical Biostatistics
467-7374
http://devo.gene.com/groups/devo/depts/ncb/home.shtml

__
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] Sample size calculation for differences between two very small proportions (Fisher's exact test or others)?

2010-11-08 Thread Giulio Di Giovanni







Yep, it is 20.000 per arm, sorry. The reference it's about an application of 
the method, and I cannot download the paper with the main algorithm, so I don't 
know exactly how they did. 
Thanks everybody for the rich and interesting suggestions. Through free web 
software (PS, others)  I found also an N around 47.000 per arm. I guess these 
are the values (also seen Marc's Monte Carlo).
Maybe the Poisson models approach suggested by David can be an alternative, 
even if I guess at this point I won't get big differences in numbers. Would I?

Thanks a lot everybody again for your suggestions,  
if anybody has other comments, they are always welcome.

Best,

Giulio


 Subject: Re: [R] Sample size calculation for differences between two very 
 small proportions (Fisher's exact test or others)?
 From: marc_schwa...@me.com
 Date: Mon, 8 Nov 2010 11:13:12 -0600
 CC: perimessagg...@hotmail.com; r-h...@stat.math.ethz.ch
 To: mmal...@gmail.com
 
 Hi,
 
 I don't have access to the article, but must presume that they are doing 
 something radically different if you are only getting a total sample size 
 of 20,000. Or is that 20,000 per arm?
 
 Using the G*Power app that Mitchell references below (which I have used 
 previously, since they have a Mac app):
 
 Exact - Proportions: Inequality, two independent groups (Fisher's exact test) 
 
 Options:  Exact distribution
 
 Analysis: A priori: Compute required sample size 
 Input:Tail(s) =   Two
   Proportion p1   =   0.00154
   Proportion p2   =   0.00234
   á err prob  =   0.05
   Power (1-â err prob)=   0.8
   Allocation ratio N2/N1  =   1
 Output:   Sample size group 1 =   49851
   Sample size group 2 =   49851
   Total sample size   =   99702
   Actual power=   0.8168040
   Actual á=   0.0462658
 
 
 
 
 Using the base R power.prop.test() function:
 
  power.prop.test(p1 = 0.00154, p2 = 0.00234, power = 0.8)
 
  Two-sample comparison of proportions power calculation 
 
   n = 47490.34
  p1 = 0.00154
  p2 = 0.00234
   sig.level = 0.05
   power = 0.8
 alternative = two.sided
 
  NOTE: n is number in *each* group 
 
 
 
 Using Frank's bsamsize() function in Hmisc:
 
  bsamsize(p1 = 0.00154, p2 = 0.00234, fraction = .5, alpha = .05, power = .8)
   n1   n2 
 47490.34 47490.34 
 
 
 
 Finally, throwing together a quick Monte Carlo simulation using the FET, I 
 get:
 
 TwoSampleFET - function(n, p1, p2, power = 0.85,
  R = 5000, correct = FALSE)
 {  
   MCSim - function(n, p1, p2)
   {
 Control - rbinom(n, 1, p1)
 Treat - rbinom(n, 1, p2)
 fisher.test(cbind(table(Control), table(Treat)))$p.value
   }
 
   # Run MC Replicates
   MC.res - replicate(R, MCSim(n, p1, p2))
 
   # Get p value at power quantile
   quantile(MC.res, power)
 }
 
 
 # 50,000 per arm
  TwoSampleFET(5, p1 = 0.00154, p2 = 0.00234, power = 0.8, R = 500)
80% 
 0.04628263 
 
 
 
 So all four of these are coming back with numbers in the 48,000 to 50,000 
 ***per arm***.
 
 
 HTH,
 
 Marc Schwartz
 
 
 On Nov 8, 2010, at 10:16 AM, Mitchell Maltenfort wrote:
 
  Not with R, but look for G*Power3, a free tool for power calc,
  includes FIsher's test.
  
  http://www.psycho.uni-duesseldorf.de/abteilungen/aap/gpower3
  
  On Mon, Nov 8, 2010 at 10:52 AM, Giulio Di Giovanni
  perimessagg...@hotmail.com wrote:
  
  
  Hi,
  I'm try to compute the minimum sample size needed to have at least an 80% 
  of power, with alpha=0.05. The problem is that empirical proportions are 
  really small: 0.00154 in one case and 0.00234. These are the estimated 
  failure proportion of two medical treatments.
  Thomas and Conlon (1992) suggested Fisher's exact test and proposed a 
  computational method, which according to their table gives a sample size 
  of roughly 2. Unfortunately I cannot find any software applying their 
  method.
  -Does anyone know how to estimate sample size on Fisher's exact test by 
  using R?
  -Even better, does anybody know other, maybe optimal, methods for such a 
  situation (small p1 and p2) and the corresponding R software?
  
  Thanks in advance,
  Giulio
 
  
[[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.


[R] Several lattice plots on one page

2010-11-08 Thread Marcus Drescher
Dear all,

I am trying (!!!) to generate pdfs that have 8 plots on one page:


df = data.frame(
day = c(1,2,3,4),
var1 = c(1,2,3,4),
var2 = c(100,200,300,4000),
var3 = c(10,20,300,4),
var4 = c(10,2,3,4000),
var5 = c(10,20,30,40),
var6 = c(0.001,0.002,0.003,0.004),
var7 = c(123,223,123,412),
var8 = c(213,123,234,435),
all = as.factor(c(1,1,1,1)))

pdf(test1.pdf, width=20, heigh=27, paper=a4) 
print(plot(groupedData(var1 ~ day | all, data = df), main = var1, 
xlab=, ylab=), split=c(1,1,2,4), more=TRUE)
print(plot(groupedData(var2 ~ day | all, data = df), main = var2, 
xlab=, ylab=), split=c(1,2,2,4), more=TRUE)
print(plot(groupedData(var3 ~ day | all, data = df), main = var3, 
xlab=, ylab=), split=c(1,3,2,4), more=TRUE)
print(plot(groupedData(var4 ~ day | all, data = df), main = var4, 
xlab=, ylab=), split=c(1,4,2,4), more=TRUE)
print(plot(groupedData(var5 ~ day | all, data = df), main = var5, 
xlab=, ylab=), split=c(2,1,2,4), more=TRUE)
print(plot(groupedData(var6 ~ day | all, data = df), main = var6, 
xlab=, ylab=), split=c(2,2,2,4), more=TRUE)
print(plot(groupedData(var7 ~ day | all, data = df), main = var7, 
xlab=, ylab=), split=c(2,3,2,4), more=TRUE)
print(plot(groupedData(var8 ~ day | all, data = df), main = var8, 
xlab=, ylab=), split=c(2,4,2,4))
dev.off()


My problem is that the separate plots all have different sizes. (Some are tall, 
but very small, or the other way around. The target is to have equally tall and 
wide graphs. (The variables have different scales. Grouping does not work.)

Optimally, the plots would use the complete pdf page.

Any ideas how to adjust height and width?

Best 
Marcus

__
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] Error: could not find function extract in package raster

2010-11-08 Thread Prof Brian Ripley
Users of R 2.11.1 (let alone 2.11.0) x64 Windows were asked to update 
in August, and we switched off the last remnants of support when 
2.12.0 was released.


Please do as the posting guide asked you to do before posting: update 
to R 2.12.0 (or 2.12.0 patched), and update all your packages.


lattics is 0.19-13
raster is 1.6-15
sp is 0.9-72

On Mon, 8 Nov 2010, Monica Pisica wrote:



Hi Joshua,

OK, my session info is this:

R version 2.11.0 (2010-04-22)
x86_64-pc-mingw32

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] raster_1.5-16 sp_0.9-64


These are not the same versions as below.



loaded via a namespace (and not attached):
[1] grid_2.11.0lattice_0.18-8

I also have installed the 32 bit version of R under windows 64 bit 
and there the raster package has the function extract and session 
info is:


R version 2.11.0 (2010-04-22)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] raster_1.6-10 sp_0.9-62

loaded via a namespace (and not attached):
[1] grid_2.11.0lattice_0.18-5

Obviously i would like to work with the R64 bit because i have more 
memory available. It is not clear to me why the function extract 
exists in the package raster for 32 bit but not for 64 bit. Is there 
any reason?


Thanks,

Monica


Date: Mon, 8 Nov 2010 08:17:48 -0800
Subject: Re: [R] Error: could not find function extract in package raster
From: jwiley.ps...@gmail.com
To: pisican...@hotmail.com
CC: r-help@r-project.org

Hi Monica,

Evidently, there is not an extract function in your search path
(base R, loaded packages, etc.).  Given that you are talking about a
function from a package (rather than base R), it would probably help
us more if you mentioned what version of raster you have installed.
You can get this easily by loading it and reporting the results of
sessionInfo() (per the posting guide).  On my current system (see
specs below), there is an extract function and it seems to work.,

Cheers,

Josh




sessionInfo()

R version 2.12.0 (2010-10-15)
Platform: i486-pc-linux-gnu (32-bit)

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

other attached packages:
[1] raster_1.6-10 sp_0.9-72

loaded via a namespace (and not attached):
[1] grid_2.12.0 lattice_0.19-13 tools_2.12.0

On Mon, Nov 8, 2010 at 8:08 AM, Monica Pisica pisican...@hotmail.com wrote:


Hi,

I would like to use the function extract from package raster and i get the 
following error:
 m01e - extract(marsh01, p)
Error: could not find function extract

marsh01 is a raster object and p is an intersectExtent object that is not null.

The package is installed and loaded, i use a Windows machine 64 bit and R x64 
2.11.0. Do i really need to update my R to use this function?

Thanks, Monica
   [[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.





--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/


[[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.



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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 plot a normal distribution curve and a shaded tail with alpha?

2010-11-08 Thread Greg Snow
Look at power.examp in the TeachingDemos package.  If that plot is not good 
enough, you can steal the code and modify to your specifications.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Wu Gong
 Sent: Monday, November 08, 2010 9:18 AM
 To: r-help@r-project.org
 Subject: [R] How to plot a normal distribution curve and a shaded tail
 with alpha?
 
 
 I want to create a graph to express the idea of the area under a pdf
 curve,
 like
 
 http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg
 
 Thank you for any help.
 
 -
 A R learner.
 --
 View this message in context: http://r.789695.n4.nabble.com/How-to-
 plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-
 tp3032194p3032194.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-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] Difference scores

2010-11-08 Thread statscurious

Hi all,
I have a couple of questions that are general statistics questions rather
than being R-specific.

I'm interested in figuring out how to compute something like standard error
for difference scores (in particular, differences scores of reaction times). 
Does anyone know if there is a standard way to do this? Any references would
be very much appreciate.

Secondly, I'm interested in figure out something like standard error for
data points contributing to a correlation.  I am looking at the correlation
between the means of reaction times in two tasks by individual participants,
and for some participants, the scores are going to have more or less error
associated with them (and it is also possible that task A might have more
error associated with it than task B, etc.). It seems logical to weight each
set of points by this error when computing the correlation somehow, but I'm
not sure if there might be a standardized way of doing this. Does anyone
have any ideas or know of a method that is typically used?

Any pointers are greatly appreciate, thanks very much!

M
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Difference-scores-tp3032484p3032484.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] How to rbind list of vectors with unequal vector lengths?

2010-11-08 Thread johannes rara
Hi,

How to rbind these vectors from a list?:

 l - list(a = c(1, 2), b = c(1, 2, 3))
 l
$a
[1] 1 2

$b
[1] 1 2 3

 do.call(rbind, l)
  [,1] [,2] [,3]
a121
b123
Warning message:
In function (..., deparse.level = 1)  :
  number of columns of result is not a multiple of vector length (arg 1)


-J

__
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 rbind list of vectors with unequal vector lengths?

2010-11-08 Thread Henrique Dallazuanna
Try this:

t(sapply(l, '[', 1:max(sapply(l, length

On Mon, Nov 8, 2010 at 5:05 PM, johannes rara johannesr...@gmail.comwrote:

 Hi,

 How to rbind these vectors from a list?:

  l - list(a = c(1, 2), b = c(1, 2, 3))
  l
 $a
 [1] 1 2

 $b
 [1] 1 2 3

  do.call(rbind, l)
  [,1] [,2] [,3]
 a121
 b123
 Warning message:
 In function (..., deparse.level = 1)  :
  number of columns of result is not a multiple of vector length (arg 1)
 

 -J

 __
 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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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.


Re: [R] How to rbind list of vectors with unequal vector lengths?

2010-11-08 Thread Erik Iverson

What class of object / structure do you exactly want
in the end?  A matrix, a data.frame, a vector?

johannes rara wrote:

Hi,

How to rbind these vectors from a list?:


l - list(a = c(1, 2), b = c(1, 2, 3))
l

$a
[1] 1 2

$b
[1] 1 2 3


do.call(rbind, l)

  [,1] [,2] [,3]
a121
b123
Warning message:
In function (..., deparse.level = 1)  :
  number of columns of result is not a multiple of vector length (arg 1)

-J

__
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.


Re: [R] How to rbind list of vectors with unequal vector lengths?

2010-11-08 Thread johannes rara
Thanks, data.frame or matrix.

-J

2010/11/8 Erik Iverson er...@ccbr.umn.edu:
 What class of object / structure do you exactly want
 in the end?  A matrix, a data.frame, a vector?

 johannes rara wrote:

 Hi,

 How to rbind these vectors from a list?:

 l - list(a = c(1, 2), b = c(1, 2, 3))
 l

 $a
 [1] 1 2

 $b
 [1] 1 2 3

 do.call(rbind, l)

  [,1] [,2] [,3]
 a    1    2    1
 b    1    2    3
 Warning message:
 In function (..., deparse.level = 1)  :
  number of columns of result is not a multiple of vector length (arg 1)

 -J

 __
 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.


Re: [R] How to rbind list of vectors with unequal vector lengths?

2010-11-08 Thread Erik Iverson

So what do you want the matrix to
look like, since the number of columns
will be different between the two rows?



johannes rara wrote:

Thanks, data.frame or matrix.

-J

2010/11/8 Erik Iverson er...@ccbr.umn.edu:

What class of object / structure do you exactly want
in the end?  A matrix, a data.frame, a vector?

johannes rara wrote:

Hi,

How to rbind these vectors from a list?:


l - list(a = c(1, 2), b = c(1, 2, 3))
l

$a
[1] 1 2

$b
[1] 1 2 3


do.call(rbind, l)

 [,1] [,2] [,3]
a121
b123
Warning message:
In function (..., deparse.level = 1)  :
 number of columns of result is not a multiple of vector length (arg 1)

-J

__
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.


Re: [R] Several lattice plots on one page

2010-11-08 Thread Dennis Murphy
Hi:

Is this what you had in mind?

library(reshape2)
df - df[, -10]   # last variable is superfluous
dm - melt(df, id = 'day')
head(dm)
  day variable value
1   1 var1 1
2   2 var1 2
3   3 var1 3
4   4 var1 4
5   1 var2   100
6   2 var2   200
xyplot(value ~ day | variable, data = dm,
  scales = list(y = list(relation = 'free')))

melt() is useful in this problem because it stacks the data in 'long' form
and creates a factor 'variable' whose levels are the variable names. The
variable 'value' contains the responses. Conditioning on 'variable' in dm
then gets you individual plots of value ~ day by variable. You can use
layout = to specify the arrangement of plots per page, and perhaps as.table
= TRUE if you want the plots rendered from top left rather than bottom left.

HTH,
Dennis

On Mon, Nov 8, 2010 at 10:19 AM, Marcus Drescher dresc...@tum.de wrote:

 Dear all,

 I am trying (!!!) to generate pdfs that have 8 plots on one page:


 df = data.frame(
day = c(1,2,3,4),
var1 = c(1,2,3,4),
var2 = c(100,200,300,4000),
var3 = c(10,20,300,4),
var4 = c(10,2,3,4000),
var5 = c(10,20,30,40),
var6 = c(0.001,0.002,0.003,0.004),
var7 = c(123,223,123,412),
var8 = c(213,123,234,435),
all = as.factor(c(1,1,1,1)))

 pdf(test1.pdf, width=20, heigh=27, paper=a4)
print(plot(groupedData(var1 ~ day | all, data = df), main = var1,
 xlab=, ylab=), split=c(1,1,2,4), more=TRUE)
print(plot(groupedData(var2 ~ day | all, data = df), main = var2,
 xlab=, ylab=), split=c(1,2,2,4), more=TRUE)
print(plot(groupedData(var3 ~ day | all, data = df), main = var3,
 xlab=, ylab=), split=c(1,3,2,4), more=TRUE)
print(plot(groupedData(var4 ~ day | all, data = df), main = var4,
 xlab=, ylab=), split=c(1,4,2,4), more=TRUE)
print(plot(groupedData(var5 ~ day | all, data = df), main = var5,
 xlab=, ylab=), split=c(2,1,2,4), more=TRUE)
print(plot(groupedData(var6 ~ day | all, data = df), main = var6,
 xlab=, ylab=), split=c(2,2,2,4), more=TRUE)
print(plot(groupedData(var7 ~ day | all, data = df), main = var7,
 xlab=, ylab=), split=c(2,3,2,4), more=TRUE)
print(plot(groupedData(var8 ~ day | all, data = df), main = var8,
 xlab=, ylab=), split=c(2,4,2,4))
 dev.off()


 My problem is that the separate plots all have different sizes. (Some are
 tall, but very small, or the other way around. The target is to have equally
 tall and wide graphs. (The variables have different scales. Grouping does
 not work.)

 Optimally, the plots would use the complete pdf page.

 Any ideas how to adjust height and width?

 Best
 Marcus

 __
 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.


[[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.


Re: [R] How to rbind list of vectors with unequal vector lengths?

2010-11-08 Thread johannes rara
This is the ideal result (data.frame):

 result
  names X1 X2 X3
1 a  1  2 NA
2 b  1  2  3


2010/11/8 Erik Iverson er...@ccbr.umn.edu:
 So what do you want the matrix to
 look like, since the number of columns
 will be different between the two rows?



 johannes rara wrote:

 Thanks, data.frame or matrix.

 -J

 2010/11/8 Erik Iverson er...@ccbr.umn.edu:

 What class of object / structure do you exactly want
 in the end?  A matrix, a data.frame, a vector?

 johannes rara wrote:

 Hi,

 How to rbind these vectors from a list?:

 l - list(a = c(1, 2), b = c(1, 2, 3))
 l

 $a
 [1] 1 2

 $b
 [1] 1 2 3

 do.call(rbind, l)

  [,1] [,2] [,3]
 a    1    2    1
 b    1    2    3
 Warning message:
 In function (..., deparse.level = 1)  :
  number of columns of result is not a multiple of vector length (arg 1)

 -J

 __
 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.


Re: [R] Sample size calculation for differences between two very small proportions (Fisher's exact test or others)?

2010-11-08 Thread David Winsemius

On Nov 8, 2010, at 1:00 PM, Giulio Di Giovanni wrote:

 Yep, it is 20.000 per arm, sorry. The reference it's about an  
 application of the method, and I cannot download the paper with the  
 main algorithm, so I don't know exactly how they did.
 Thanks everybody for the rich and interesting suggestions. Through  
 free web software (PS, others)  I found also an N around 47.000 per  
 arm. I guess these are the values (also seen Marc's Monte Carlo).
 Maybe the Poisson models approach suggested by David can be an  
 alternative, even if I guess at this point I won't get big  
 differences in numbers. Would I?

I certainly would not expect remarkable differences.  With 50,000/arm  
you would be expecting:
  c(p1 = 0.00154, p2 = 0.00234)*5
  p1  p2
  77 117
# with a rate ratio of:
  0.00234/0.00154
[1] 1.519481

A difference of 30 in expected counts would seem to give fairly  
significant power. It seems that a Poisson structured test might give  
you smaller numbers but probably not as small as 20,000
  c(p1 = 0.00154, p2 = 0.00234)*2
   p1   p2
30.8 46.8

(The sd() of a Poisson variable is sqrt(mean()) so that 31 is well  
within any sensibly constructed CI around 47.)

If you look up Table 7.5 in Breslow and Day (vol2, page 283) with a  
relative risk of 1.5,  the necessary expected value in the control  
group using and equal sized  control group ( for 80% power at 5%  
significance) is 64.9. So that a bit lower than the 77 above but  
implies that 42,207 would be needed.

-- 
David.



 Thanks a lot everybody again for your suggestions,
 if anybody has other comments, they are always welcome.

 Best,

 Giulio


  Subject: Re: [R] Sample size calculation for differences between  
 two very small proportions (Fisher's exact test or others)?
  From: marc_schwa...@me.com
  Date: Mon, 8 Nov 2010 11:13:12 -0600
  CC: perimessagg...@hotmail.com; r-h...@stat.math.ethz.ch
  To: mmal...@gmail.com
 
  Hi,
 
  I don't have access to the article, but must presume that they are  
 doing something radically different if you are only getting a  
 total sample size of 20,000. Or is that 20,000 per arm?
 
  Using the G*Power app that Mitchell references below (which I have  
 used previously, since they have a Mac app):
 
  Exact - Proportions: Inequality, two independent groups (Fisher's  
 exact test)
 
  Options:Exact distribution
 
  Analysis:   A priori: Compute required sample size
  Input:   Tail(s) =  Two
  Proportion p1 = 0.00154
  Proportion p2 = 0.00234
  α err prob =   0.05
  Power (1-β err prob) = 0.8
  Allocation ratio N2/N1 =1
  Output:  Sample size group 1 =  49851
  Sample size group 2 =   49851
  Total sample size = 99702
  Actual power =  0.8168040
  Actual α = 0.0462658
 
 
 
 
  Using the base R power.prop.test() function:
 
   power.prop.test(p1 = 0.00154, p2 = 0.00234, power = 0.8)
 
  Two-sample comparison of proportions power calculation
 
  n = 47490.34
  p1 = 0.00154
  p2 = 0.00234
  sig.level = 0.05
  power = 0.8
  alternative = two.sided
 
  NOTE: n is number in *each* group
 
 
 
  Using Frank's bsamsize() function in Hmisc:
 
   bsamsize(p1 = 0.00154, p2 = 0.00234, fraction = .5, alpha = .05,  
 power = .8)
  n1 n2
  47490.34 47490.34
 
 
 
  Finally, throwing together a quick Monte Carlo simulation using  
 the FET, I get:
 
  TwoSampleFET - function(n, p1, p2, power = 0.85,
  R = 5000, correct = FALSE)
  {
  MCSim - function(n, p1, p2)
  {
  Control - rbinom(n, 1, p1)
  Treat - rbinom(n, 1, p2)
  fisher.test(cbind(table(Control), table(Treat)))$p.value
  }
 
  # Run MC Replicates
  MC.res - replicate(R, MCSim(n, p1, p2))
 
  # Get p value at power quantile
  quantile(MC.res, power)
  }
 
 
  # 50,000 per arm
   TwoSampleFET(5, p1 = 0.00154, p2 = 0.00234, power = 0.8, R =  
 500)
  80%
  0.04628263
 
 
 
  So all four of these are coming back with numbers in the 48,000 to  
 50,000 ***per arm***.
 
 
  HTH,
 
  Marc Schwartz
 
 
  On Nov 8, 2010, at 10:16 AM, Mitchell Maltenfort wrote:
 
   Not with R, but look for G*Power3, a free tool for power calc,
   includes FIsher's test.
  
   http://www.psycho.uni-duesseldorf.de/abteilungen/aap/gpower3
  
   On Mon, Nov 8, 2010 at 10:52 AM, Giulio Di Giovanni
   perimessagg...@hotmail.com wrote:
  
  
   Hi,
   I'm try to compute the minimum sample size needed to have at  
 least an 80% of power, with alpha=0.05. The problem is that  
 empirical proportions are really small: 0.00154 in one case and  
 0.00234. These are the estimated failure proportion of two medical  
 treatments.
   Thomas and Conlon (1992) suggested Fisher's exact test and  
 proposed a computational method, which according to their table  
 gives a sample size of roughly 2. Unfortunately I cannot find  
 any software applying their method.
   -Does anyone know how to estimate sample size on Fisher's exact  
 test by using R?
   -Even better, does anybody know other, maybe optimal, methods  
 for such a situation 

Re: [R] How to rbind list of vectors with unequal vector lengths?

2010-11-08 Thread Erik Iverson

Then one solution is to use
rbind.fill from the plyr package.

johannes rara wrote:

This is the ideal result (data.frame):


result

  names X1 X2 X3
1 a  1  2 NA
2 b  1  2  3

2010/11/8 Erik Iverson er...@ccbr.umn.edu:

So what do you want the matrix to
look like, since the number of columns
will be different between the two rows?



johannes rara wrote:

Thanks, data.frame or matrix.

-J

2010/11/8 Erik Iverson er...@ccbr.umn.edu:

What class of object / structure do you exactly want
in the end?  A matrix, a data.frame, a vector?

johannes rara wrote:

Hi,

How to rbind these vectors from a list?:


l - list(a = c(1, 2), b = c(1, 2, 3))
l

$a
[1] 1 2

$b
[1] 1 2 3


do.call(rbind, l)

 [,1] [,2] [,3]
a121
b123
Warning message:
In function (..., deparse.level = 1)  :
 number of columns of result is not a multiple of vector length (arg 1)

-J

__
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.


Re: [R] How to rbind list of vectors with unequal vector lengths?

2010-11-08 Thread johannes rara
I have tried it, but it does not seem to work with vectors, only data.frames

 do.call(rbind.fill, l)
NULL


-J

2010/11/8 Erik Iverson er...@ccbr.umn.edu:
 Then one solution is to use
 rbind.fill from the plyr package.

 johannes rara wrote:

 This is the ideal result (data.frame):

 result

  names X1 X2 X3
 1     a  1  2 NA
 2     b  1  2  3

 2010/11/8 Erik Iverson er...@ccbr.umn.edu:

 So what do you want the matrix to
 look like, since the number of columns
 will be different between the two rows?



 johannes rara wrote:

 Thanks, data.frame or matrix.

 -J

 2010/11/8 Erik Iverson er...@ccbr.umn.edu:

 What class of object / structure do you exactly want
 in the end?  A matrix, a data.frame, a vector?

 johannes rara wrote:

 Hi,

 How to rbind these vectors from a list?:

 l - list(a = c(1, 2), b = c(1, 2, 3))
 l

 $a
 [1] 1 2

 $b
 [1] 1 2 3

 do.call(rbind, l)

  [,1] [,2] [,3]
 a    1    2    1
 b    1    2    3
 Warning message:
 In function (..., deparse.level = 1)  :
  number of columns of result is not a multiple of vector length (arg
 1)

 -J

 __
 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] lookup in R - possible to avoid loops?

2010-11-08 Thread Dimitri Liakhovitski
Hello!
Hope there is a nifty way to speed up my code by avoiding loops.
My task is simple - analogous to the vlookup formula in Excel. Here is
how I programmed it:

# My example data frame:
set.seed(1245)
my.df-data.frame(names=rep(letters[1:3],3),value=round(rnorm(9,mean=20,sd=5),0))
my.df-my.df[order(my.df$names),]
my.df$names-as.character(my.df$names)
(my.df)

# My example lookup table:
my.lookup-data.frame(names=letters[1:3],category=c(AAA,BBB,CCC))
my.lookup$names-as.character(my.lookup$names)
my.lookup$category-as.character(my.lookup$category)
(my.lookup)

# Just adding an extra column to my.df that contains the categories of
the names in the column names:
my.df2-my.df
my.df2$category-NA
for(i in unique(my.df$names)){
my.df2$category[my.df2$names %in%
i]-my.lookup$category[my.lookup$names %in% i]
}
(my.df2)

It does what I need, but it's way too slow - I need to run it for
hundreds and hundreds of names in 100 of huge files (tens of
thousands of rows in each).
Any way to speed it up?


Thanks a lot!

-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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] lookup in R - possible to avoid loops?

2010-11-08 Thread Henrique Dallazuanna
Try this:

 merge(my.df, my.lookup)

On Mon, Nov 8, 2010 at 5:43 PM, Dimitri Liakhovitski 
dimitri.liakhovit...@gmail.com wrote:

 Hello!
 Hope there is a nifty way to speed up my code by avoiding loops.
 My task is simple - analogous to the vlookup formula in Excel. Here is
 how I programmed it:

 # My example data frame:
 set.seed(1245)

 my.df-data.frame(names=rep(letters[1:3],3),value=round(rnorm(9,mean=20,sd=5),0))
 my.df-my.df[order(my.df$names),]
 my.df$names-as.character(my.df$names)
 (my.df)

 # My example lookup table:
 my.lookup-data.frame(names=letters[1:3],category=c(AAA,BBB,CCC))
 my.lookup$names-as.character(my.lookup$names)
 my.lookup$category-as.character(my.lookup$category)
 (my.lookup)

 # Just adding an extra column to my.df that contains the categories of
 the names in the column names:
 my.df2-my.df
 my.df2$category-NA
 for(i in unique(my.df$names)){
my.df2$category[my.df2$names %in%
 i]-my.lookup$category[my.lookup$names %in% i]
 }
 (my.df2)

 It does what I need, but it's way too slow - I need to run it for
 hundreds and hundreds of names in 100 of huge files (tens of
 thousands of rows in each).
 Any way to speed it up?


 Thanks a lot!

 --
 Dimitri Liakhovitski
 Ninah Consulting
 www.ninah.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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

[[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.


Re: [R] lookup in R - possible to avoid loops?

2010-11-08 Thread Phil Spector

Dimitri -
   While merge is most likely the fastest way to solve
your problem, I just want to point out that you can use
a named vector as a lookup table.  For your example:

categories = my.lookup$category
names(categories) = my.lookup$names

creates the lookup table, and

my.df$category = categories[my.df$names]

creates the category column.
   - Phil



On Mon, 8 Nov 2010, Dimitri Liakhovitski wrote:


Hello!
Hope there is a nifty way to speed up my code by avoiding loops.
My task is simple - analogous to the vlookup formula in Excel. Here is
how I programmed it:

# My example data frame:
set.seed(1245)
my.df-data.frame(names=rep(letters[1:3],3),value=round(rnorm(9,mean=20,sd=5),0))
my.df-my.df[order(my.df$names),]
my.df$names-as.character(my.df$names)
(my.df)

# My example lookup table:
my.lookup-data.frame(names=letters[1:3],category=c(AAA,BBB,CCC))
my.lookup$names-as.character(my.lookup$names)
my.lookup$category-as.character(my.lookup$category)
(my.lookup)

# Just adding an extra column to my.df that contains the categories of
the names in the column names:
my.df2-my.df
my.df2$category-NA
for(i in unique(my.df$names)){
my.df2$category[my.df2$names %in%
i]-my.lookup$category[my.lookup$names %in% i]
}
(my.df2)

It does what I need, but it's way too slow - I need to run it for
hundreds and hundreds of names in 100 of huge files (tens of
thousands of rows in each).
Any way to speed it up?


Thanks a lot!

--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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-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] A more efficient way to roll values in an irregular time series dataset?

2010-11-08 Thread Richard Vlasimsky
Does anyone recommend a more efficient way to roll values in a time series 
dataset?  

I merged a bunch of different time series datasets (10's of thousands of them) 
whose observation dates and sampling interval differ.  Some time series 
observations are reported at the beginning of the month, some at the end, some 
on Mondays, some on Wednesday, some annually, etc.  

In the process of merging all of the irregular time series (by date observed), 
a significant number of NA's appear in the dataset where I really want the last 
reported value 'rolled'  forward.  

To use a concrete example, a time series that has reported values at the 
beginning of every month shows NA's for every day except the date it was 
reported (in this case, the first of the month).  I want the value to roll 
forward so that NA's after the first of the month are replaced with a last 
reported value.

I wrote the following for loop to accomplish the task on the object 'dataset', 
however it is far to slow too process 10's of thousands of different time 
series with 15,000 observations each.  At this rate it is going, it would take 
weeks to complete.  

for(j in 1:length(names(dataset)))
{
last-NA;
for(i in 1:length(row.names(dataset)))
ifelse(is.na(dataset[i,j]), test[i,j] - last, 
last-dataset[i,j]);

}

One would think a rather simple operation as this could perform much faster.  
My sense is using the apply function is the way to go, however I just can't 
get my head around a function that would reference the last reported value.

Any guidance is appreciated.

-Richard
[[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.


Re: [R] How to eliminate this for loop ?

2010-11-08 Thread Greg Snow
If you are willing to shift the c vector by 1 and have 1 (the initial value) as 
the start of c, then you can just do:

cumsum( cc * b^( (n-1):0 ) ) / b^( (n-1):0 )

to compare:

cc - c(1, rnorm(999) )
b - 0.5
n - length(cc)

a1 - numeric(100)
a1[1] - 1

system.time(for(i in 2:n ) {
a1[i] - b*a1[i-1] + cc[i]
})

system.time(a2 - cumsum( cc * b^( (n-1):0 ) ) / b^( (n-1):0 ))

all.equal(a1,a2)

Though you could have problems with the b^ part if the length gets too long.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of PLucas
 Sent: Monday, November 08, 2010 2:26 AM
 To: r-help@r-project.org
 Subject: [R] How to eliminate this for loop ?
 
 
 Hi, I would like to create a list recursively and eliminate my for loop
 :
 
 a-c()
 a[1] - 1; # initial value
 for(i in 2:N) {
   a[i]-a[i-1]*b - c[i-1] # b is a value, c is another vector
 }
 
 
 Is it possible ?
 
 Thanks
 --
 View this message in context: http://r.789695.n4.nabble.com/How-to-
 eliminate-this-for-loop-tp3031667p3031667.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-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] A more efficient way to roll values in an irregular time series dataset?

2010-11-08 Thread Dennis Murphy
Hi:

Look into the zoo package and its rollapply() function. The package is
designed to handle irregular and multiple series.

HTH,
Dennis

On Mon, Nov 8, 2010 at 12:16 PM, Richard Vlasimsky 
richard.vlasim...@imidex.com wrote:

 Does anyone recommend a more efficient way to roll values in a time
 series dataset?

 I merged a bunch of different time series datasets (10's of thousands of
 them) whose observation dates and sampling interval differ.  Some time
 series observations are reported at the beginning of the month, some at the
 end, some on Mondays, some on Wednesday, some annually, etc.

 In the process of merging all of the irregular time series (by date
 observed), a significant number of NA's appear in the dataset where I really
 want the last reported value 'rolled'  forward.

 To use a concrete example, a time series that has reported values at the
 beginning of every month shows NA's for every day except the date it was
 reported (in this case, the first of the month).  I want the value to roll
 forward so that NA's after the first of the month are replaced with a last
 reported value.

 I wrote the following for loop to accomplish the task on the object
 'dataset', however it is far to slow too process 10's of thousands of
 different time series with 15,000 observations each.  At this rate it is
 going, it would take weeks to complete.

 for(j in 1:length(names(dataset)))
 {
last-NA;
for(i in 1:length(row.names(dataset)))
ifelse(is.na(dataset[i,j]), test[i,j] - last,
 last-dataset[i,j]);

 }

 One would think a rather simple operation as this could perform much
 faster.  My sense is using the apply function is the way to go, however I
 just can't get my head around a function that would reference the last
 reported value.

 Any guidance is appreciated.

 -Richard
[[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.


[[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.


Re: [R] A more efficient way to roll values in an irregular time series dataset?

2010-11-08 Thread Gabor Grothendieck
On Mon, Nov 8, 2010 at 3:16 PM, Richard Vlasimsky
richard.vlasim...@imidex.com wrote:
 Does anyone recommend a more efficient way to roll values in a time series 
 dataset?

 I merged a bunch of different time series datasets (10's of thousands of 
 them) whose observation dates and sampling interval differ.  Some time series 
 observations are reported at the beginning of the month, some at the end, 
 some on Mondays, some on Wednesday, some annually, etc.

 In the process of merging all of the irregular time series (by date 
 observed), a significant number of NA's appear in the dataset where I really 
 want the last reported value 'rolled'  forward.

 To use a concrete example, a time series that has reported values at the 
 beginning of every month shows NA's for every day except the date it was 
 reported (in this case, the first of the month).  I want the value to roll 
 forward so that NA's after the first of the month are replaced with a last 
 reported value.

 I wrote the following for loop to accomplish the task on the object 
 'dataset', however it is far to slow too process 10's of thousands of 
 different time series with 15,000 observations each.  At this rate it is 
 going, it would take weeks to complete.

 for(j in 1:length(names(dataset)))
 {
        last-NA;
        for(i in 1:length(row.names(dataset)))
                        ifelse(is.na(dataset[i,j]), test[i,j] - last, 
 last-dataset[i,j]);

 }

 One would think a rather simple operation as this could perform much faster.  
 My sense is using the apply function is the way to go, however I just can't 
 get my head around a function that would reference the last reported value.

 Any guidance is appreciated.


Don't know if its fast enough for you but in zoo you can merge and
carry the last occurrence forward like this:

# suppose z1, z2, z3 are zoo series

na.locf(merge(z1, z2, z3)) # as many as you like

or

L - list(z1, z2, z3)
na.locf(do.call(merge, L))

which produces a multivariate series, one per column with NAs filled in.

-- 
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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 plot a normal distribution curve and a shaded tail with alpha?

2010-11-08 Thread James Long
Here's an example of a PDF with the tails shaded:

http://stackoverflow.com/q/3494593/37751

-JD


On Mon, Nov 8, 2010 at 10:18 AM, Wu Gong w...@mtmail.mtsu.edu wrote:

 I want to create a graph to express the idea of the area under a pdf curve,
 like

 http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg

 Thank you for any help.

 -
 A R learner.
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.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-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 plot a normal distribution curve and a shaded tail with alpha?

2010-11-08 Thread Joshua Wiley
I wrote this a bit ago, its far from perfect, but might give you
ideas/serve your purpose.

HTH,

Josh

plot.dist - function(alpha, from = -5, to = 5, n = 1000, filename = NULL,
alternative = c(two.tailed, greater, lesser),
distribution = c(normal, t, F, chisq, binomial),
colour = black, fill = skyblue2, ...) {
alternative - match.arg(alternative)
## Calculate alpha level given hypothesis
alt.alpha - switch(alternative,
two.tailed = alpha/2,
greater = alpha,
lesser = alpha)
## use a ’switch’ to pick the right functions based on distribution
my.den - switch(distribution,
normal = dnorm,
t = dt,
F = df,
chisq = dchisq,
binomial = dbinom)
my.dist - switch(distribution,
normal = qnorm,
t = qt,
F = qf,
chisq = qchisq,
binomial = qbinom)
## Additional arguments passed via ’...’ e.g., degrees of freedom
crit.lower - my.dist(p = alt.alpha, lower.tail = TRUE, ...)
crit.upper - my.dist(p = alt.alpha, lower.tail = FALSE, ...)
## Calculate alpha (lower) region coordinates
cord.x1 - c(from, seq(from = from, to = crit.lower,
length.out = 100), crit.lower)
cord.y1 - c(0, my.den(x = seq(from = from, to = crit.lower,
length.out = 100), ...), 0)
## Calculate alpha (upper) region coordinates
cord.x2 - c(crit.upper, seq(from = crit.upper, to = to,
length.out = 100), to)
cord.y2 - c(0, my.den(x = seq(from = crit.upper, to = to,
length.out = 100), ...), 0)
## Logic test to choose which graphic device to open
if(is.null(filename)) {
dev.new()
} else {
pdf(file = filename)
}
## plot distribution
curve(my.den(x, ...), from = from, to = to,
n = n, col = colour, lty = 1, lwd = 2,
ylab = Density, xlab = Values)
## Add alpha region(s) based on given hypothesis
if(!identical(alternative, greater)) {
polygon(x = cord.x1, y = cord.y1, col = fill)
}
if(!identical(alternative, lesser)) {
polygon(x = cord.x2, y = cord.y2, col = fill)
}
## If the PDF device was started, shut it down
if(!is.null(filename)) {dev.off()}
}


On Mon, Nov 8, 2010 at 8:18 AM, Wu Gong w...@mtmail.mtsu.edu wrote:

 I want to create a graph to express the idea of the area under a pdf curve,
 like

 http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg

 Thank you for any help.

 -
 A R learner.
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] Random Sample

2010-11-08 Thread Xiaoxi Gao

Hello R users,
Here is my question about generating random sample. How to set the random seed 
to recreate the same random numbers?  For example, 10 random numbers is 
generated from N(0,1), then runif(10) is used.What if I want to get the same 
10 random numbers when I run runif(10) again? Is it possible?I think 
.Random.seed should be used here.
Thanks.
Xiaoxi
[[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.


Re: [R] lookup in R - possible to avoid loops?

2010-11-08 Thread Dimitri Liakhovitski
Thanks a lot - extremely heplful!
While I'll definitely try to use merge in the future, in my situation
I run into problems with memory (files are too large).
However, Phil's suggestion is perfect for me - sped me up considerably!
Thank you, again!
Dimitri

On Mon, Nov 8, 2010 at 2:51 PM, Phil Spector spec...@stat.berkeley.edu wrote:
 Dimitri -
   While merge is most likely the fastest way to solve
 your problem, I just want to point out that you can use
 a named vector as a lookup table.  For your example:

 categories = my.lookup$category
 names(categories) = my.lookup$names

 creates the lookup table, and

 my.df$category = categories[my.df$names]

 creates the category column.
                                           - Phil



 On Mon, 8 Nov 2010, Dimitri Liakhovitski wrote:

 Hello!
 Hope there is a nifty way to speed up my code by avoiding loops.
 My task is simple - analogous to the vlookup formula in Excel. Here is
 how I programmed it:

 # My example data frame:
 set.seed(1245)

 my.df-data.frame(names=rep(letters[1:3],3),value=round(rnorm(9,mean=20,sd=5),0))
 my.df-my.df[order(my.df$names),]
 my.df$names-as.character(my.df$names)
 (my.df)

 # My example lookup table:
 my.lookup-data.frame(names=letters[1:3],category=c(AAA,BBB,CCC))
 my.lookup$names-as.character(my.lookup$names)
 my.lookup$category-as.character(my.lookup$category)
 (my.lookup)

 # Just adding an extra column to my.df that contains the categories of
 the names in the column names:
 my.df2-my.df
 my.df2$category-NA
 for(i in unique(my.df$names)){
        my.df2$category[my.df2$names %in%
 i]-my.lookup$category[my.lookup$names %in% i]
 }
 (my.df2)

 It does what I need, but it's way too slow - I need to run it for
 hundreds and hundreds of names in 100 of huge files (tens of
 thousands of rows in each).
 Any way to speed it up?


 Thanks a lot!

 --
 Dimitri Liakhovitski
 Ninah Consulting
 www.ninah.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.





-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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] Random Sample

2010-11-08 Thread Jonathan P Daily
Use set.seed()
--
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
Is the room still a room when its empty? Does the room,
 the thing itself have purpose? Or do we, what's the word... imbue it.
 - Jubal Early, Firefly



From:
Xiaoxi Gao rhel...@hotmail.com
To:
R Help r-help@r-project.org
Date:
11/08/2010 03:59 PM
Subject:
[R] Random Sample
Sent by:
r-help-boun...@r-project.org




Hello R users,
Here is my question about generating random sample. How to set the random 
seed to recreate the same random numbers?  For example, 10 random numbers 
is generated from N(0,1), then runif(10) is used.What if I want to get 
the same 10 random numbers when I run runif(10) again? Is it possible?I 
think .Random.seed should be used here.
Thanks.
Xiaoxi  
 [[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.



[[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.


Re: [R] Random Sample

2010-11-08 Thread Erik Iverson

?set.seed is what you're looking for

Xiaoxi Gao wrote:

Hello R users,
Here is my question about generating random sample. How to set the random seed to 
recreate the same random numbers?  For example, 10 random numbers is generated from 
N(0,1), then runif(10) is used.What if I want to get the same 10 random 
numbers when I run runif(10) again? Is it possible?I think .Random.seed should be used 
here.
Thanks.
Xiaoxi  		 	   		  
	[[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.


__
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] Random Sample

2010-11-08 Thread Jorge Ivan Velez
Hi Xiaoxi,

Take a look at the following:

 set.seed(123)
 rnorm(10)
 [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
 [7]  0.46091621 -1.26506123 -0.68685285 -0.44566197
 rnorm(10)
 [1]  1.2240818  0.3598138  0.4007715  0.1106827 -0.5558411  1.7869131
 0.4978505
 [8] -1.9666172  0.7013559 -0.4727914
 set.seed(123)
 rnorm(10)
 [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
 [7]  0.46091621 -1.26506123 -0.68685285 -0.44566197

and check ?set.seed().

HTH,
Jorge


On Mon, Nov 8, 2010 at 3:57 PM, Xiaoxi Gao  wrote:


 Hello R users,
 Here is my question about generating random sample. How to set the random
 seed to recreate the same random numbers?  For example, 10 random numbers is
 generated from N(0,1), then runif(10) is used.What if I want to get the
 same 10 random numbers when I run runif(10) again? Is it possible?I think
 .Random.seed should be used here.
 Thanks.
 Xiaoxi
[[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.


[[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.


[R] Help with getting ?match to not sort

2010-11-08 Thread Tal Galili
Hello all,

I think I am missing something about the sorting parameter in the match
command/
Here is an example:


a1 - data.frame(name = c(D, B, C, A, A, C))
a2 - data.frame(name = c(A, B, C, D), num = 1:4)
a1
a2
merge(a1, a2, sort = F, by.x = T)



The result is:

  name num
1D   4
2B   2
3C   3
4C   3
5A   1
6A   1


While I wish my rows to be in the same order as in a1, they are having some
other order.

What am I missing here?


Thanks.


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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.


Re: [R] How to plot a normal distribution curve and a shaded tail with alpha?

2010-11-08 Thread RICHARD M. HEIBERGER
You can use the
normal.and.t.dist()
function in the HH package, available from CRAN with
install.packages(HH)
This works on all platforms.  There is menu access to the function through
Rcmdr if you install
install.packages(RcmdrPlugin.HH)

If you are on Windows, you can additionally control that function
interactively
from an Excel spreadsheet with the RExcel package.
Install with the
RthroughExcelWorkbooksInstaller package from CRAN.

Rich

On Mon, Nov 8, 2010 at 11:18 AM, Wu Gong w...@mtmail.mtsu.edu wrote:


 I want to create a graph to express the idea of the area under a pdf curve,
 like

 http://r.789695.n4.nabble.com/file/n3032194/w7295e04.jpg

 Thank you for any help.

 -
 A R learner.
 --
 View this message in context:
 http://r.789695.n4.nabble.com/How-to-plot-a-normal-distribution-curve-and-a-shaded-tail-with-alpha-tp3032194p3032194.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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[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.


[R] How to represent factor levels ordiellipses using different colors?

2010-11-08 Thread trinadh kumar potina
Dear Jari Oksanen,

I am Trinadh Kumar, a student of Biotechnology from Texas Tech University.
I have a question for you regarding constrained ordination graphs.
I had previously plotted constrained ordination graphs using distance based
redundancy analysis for species data on patients.
The species matrix consists  of 70  patients and 274 species of bacteria.The
metadata matrix consists of 10 variables(environmental matrix)
My Professor asked me to do the following.To plot a constrained ordination
plot constrained by tobacco habit(which is one of the factors). However he
asked me to represent  the graph as follows..
Represent the significant species (species that are farthest from the origin
in the direction of  the environmental variable) with biplot arrows pointing
from origin to the species and hide the insignificant species(closer to the
origin) on  the graph. Also he asked me to use colored solid circles for
plotting patients(instead of patient names) with the three levels of the
tobacco factor( for example: red circle to represent tobacco0, green circles
to represent tobacco1, black circles to represent tobacco2).He asked me to
shade the 95% confidence ellipses with the same color as the levels of
tobacco factor.

Please advice.


Thanks,

Trinadh

[[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.


Re: [R] Help with getting ?match to not sort

2010-11-08 Thread jim holtman
Missing: a closer reading of the help page --

Value
A data frame. The rows are by default lexicographically sorted on the
common columns, but for sort = FALSE are in an unspecified order.

So sort = FALSE says unspecified.  If you want the original order,
then add a column to the dataframe with the order and then sort the
result.

On Mon, Nov 8, 2010 at 4:09 PM, Tal Galili tal.gal...@gmail.com wrote:
 Hello all,

 I think I am missing something about the sorting parameter in the match
 command/
 Here is an example:


 a1 - data.frame(name = c(D, B, C, A, A, C))
 a2 - data.frame(name = c(A, B, C, D), num = 1:4)
 a1
 a2
 merge(a1, a2, sort = F, by.x = T)



 The result is:

  name num
 1    D   4
 2    B   2
 3    C   3
 4    C   3
 5    A   1
 6    A   1


 While I wish my rows to be in the same order as in a1, they are having some
 other order.

 What am I missing here?


 Thanks.


 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 --

        [[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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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] sapply

2010-11-08 Thread Dr. Alireza Zolfaghari
 y=sapply(1:nrow(x), function(i) sapply(1:ncol(x), function(j)
getrc(i, j)))



Arvin Zolfaghari, Ph.D.



Aon Benfield  |  Aon Benfield Analytics

55 Bishopsgate, London, EC2N 3BD, UK

t: +44 20 7522 8241 | f: +44 20 7522 3846| M: +44 78 8940 6637

e: arvin.zolfagh...@aonbenfield.com | w:
www.AonBenfield.comhttp://www.aonbenfield.com/



From: Arvin Zolfaghari
Sent: 08 November 2010 14:35
To: 'markus.gesm...@lloyds.com'
Subject: question



Hi List,

I am trying to apply a
function to all elements of a matrix. I can use two consequent ' for'
loops, but it is really slow process. I can also use the sapply as follows,
but it is 10% faster, is there any other faster way (like fft)?

I got a matrix of x=matrix(0,1000,2000)

I want to load it with myfunction

first option:
For ( i in nrow(x)){

  For(j in nrow(x)){

x=myfunction(i,j)

}}

second option:
t(sapply(1:nrow(x), function(i) sapply(1:ncol(x), function(j)
getrc(i, j

both option 1 and 2 work, but so slow. I appreciate your help.
thanks
Alireza

[[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.


Re: [R] Help with getting ?match to not sort

2010-11-08 Thread Phil Spector

Ted -
   If you want to retain the exact order of the rows of one
of the merged matrices, I think you have to merge them 
by hand:



cbind(a1,num=a2[match(a1$name,a2$name),'num'])

  name num
1D   4
2B   2
3C   3
4A   1
5A   1
6C   3

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Mon, 8 Nov 2010, Tal Galili wrote:


Hello all,

I think I am missing something about the sorting parameter in the match
command/
Here is an example:


a1 - data.frame(name = c(D, B, C, A, A, C))
a2 - data.frame(name = c(A, B, C, D), num = 1:4)
a1
a2
merge(a1, a2, sort = F, by.x = T)



The result is:

 name num
1D   4
2B   2
3C   3
4C   3
5A   1
6A   1


While I wish my rows to be in the same order as in a1, they are having some
other order.

What am I missing here?


Thanks.


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--

[[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.



__
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] try (nls stops unexpectedly because of chol2inv error

2010-11-08 Thread Mike Marchywka






 Date: Mon, 8 Nov 2010 06:18:49 -0800
 From: monte.shaf...@gmail.com
 To: r-help@r-project.org
 Subject: [R] try (nls stops unexpectedly because of chol2inv error

 Hi,

 I am running simulations that does multiple comparisons to control.

 For each simulation, I need to model 7 nls functions. I loop over 7 to do
 the nls using try

 if try fails, I break out of that loop, and go to next simulation.

 I get warnings on nls failures, but the simulation continues to run, except
 when the internal call (internal to nls) of the chol2inv fails.

 
 Error in chol2inv(object$m$Rmat()) :
 element (2, 2) is zero, so the inverse cannot be computed
 In addition: Warning messages:
 1: In nls(myModel.nlm, fData, start = initialValues, control =
 nls.control(warnOnly = TRUE), :
 number of iterations exceeded maximum of 50
 2: In nls(myModel.nlm, fData, start = initialValues, control =
 nls.control(warnOnly = TRUE), :
 singular gradient
 ===

 Any suggestions on how to prevent chol2inv from breaking my simulation...

Since no one else has answered, let me supply some thoughts and google hits.

I'm not sure what your question is- the error message suggests the
matrix has no inverse as in A*A-1 =I can't be found- usually these things happen
because the data is not a good fit to the model. Is the message not
literally true as in you know that A has an inverse? It does seem
you posted a good complete example but it may take a bit of effort
for someone to debug.

The reason it is non-invertible probably has to do with the gradient issue,
in any case some good hits on google like this may help,

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

( http://www.google.com/?#hl=enq=r+nls+singular+gradientfp=1 ) 

Personally I
tend to use SVD in my c++ code since it is the only method I know
that provides a good diagnostic on how close I came to having an
ill posed model. In your case, presumably either your model or data or code is
creating an exactly singular matrix, this may be easier to find
than the almost singular situations that often create odd results :) 
I would just ask however if anyone
has more thoughts on inverting mtricies for model fits as someone
previously mentioned that R uses QR decomposition for one task to qualify my
generic response to a question.




 The point of the simulation is to address power. As our data goes down to
 N, of the 100 simulations, only 53 are good simulations because we don't
 have enough data for nls or chol2inv to work correctly.


 monte

 {x:

 ###


 ## case I ## EQUAL SAMPLE SIZES and design points
 nsim = 100;
 N_i = M_i = 10; ## also try (10, 30, 50, 100, 200)
 r = M_i / N_i;

 X.start = 170; # 6 design points, at 170,180,190, etc. where each point has
 N_i elements
 X.increment = 10;
 X.points = 6;
 X.end = 260;
 Xval = seq(X.start,length.out=X.points,by=X.increment );
 Xval = seq(X.start,X.end,length.out=X.points);

 L = 7; ## 6 + control
 k = 3;
 varY = 0.15;

 ### for each simulation, we need to record all of this information, write to
 a table or file.

 ### Under the null of simulation, we assign all locations to have same model
 ## we assume these are the true parameters
 b = 2.87; d = 0.0345; t = 173;


 B = seq(2.5,4.5,length.out=21);
 #B = seq(2.75,3.25,length.out=21);
 #B = seq(2.85,2.95,length.out=21);
 #B = seq(2.8,3.0,length.out=21);
 B = seq(2.5,3.2,length.out=21);
 D = seq(0.02,0.04,length.out=21);
 T = seq(165,185,length.out=21);

 alpha = .05;
 nu = k; ## number of parameters
 tr = L-1; ## number of treatments (including control)
 rho = 1/(1+r); ## dependency parameter
 myCritical = qmvchi(alpha,nu,tr,rho);
 ## we change one parameter at a time until the results fail most of the
 time.


 ## do independent for now, but let's store the parameters and quantiles???
 INFO for one location
 # beta delta tau nsim %Reject(V.pooled) %Reject(V.total) [Simulation level]
 resultS
 # beta delta tau i of nsim max(V.pooled) max(V.total) [Individual level]
 resultI

 resultS = resultI = NULL;
 for(p1 in 1:length(D))
 {
 print(paste(p1,  [D] of ,length(D))); flush.console();
 print(D[p1]);
 myReject.pooled = myReject.pooled.1 = MAX.pooled = rep(-1,nsim);
 gsim = 0; ## good simulations
 for(i in 1:nsim)
 {
 doubleBreak = F;
 print(paste(i,  of ,nsim)); flush.console();
 tData = NULL;
 pooledNum = matrix(0,nrow=k,ncol=k); ##numerator as weighted sum AS
 (n_k-1)cov.scaled
 pooledDen = 0; ##denominator as correction AS N-k
 #Sigma_pooled = ((omit.1-1)*summary.nls.1$cov.scaled +
 (omit.2-1)*summary.nls.2$cov.scaled +
 (omit.L-1)*summary.nls.L$cov.scaled)/(sum(omit.1,omit.2,omit.L)-L);


 for(j in 1:L)
 {
 Y = numeric(N_i);
 X = createDomain(Xval,N_i); noise = rnorm(N_i, mean=0,sd=sqrt(varY) );

 if(j==1)
 {
 ## location #1 is different
 Y = 

[R] : unusual combinations of categorical data

2010-11-08 Thread Alan Chalk
Regarding unusual combinations of factors in categorical data. 
Are there any R packages that can be used to identify the outliers i.e. 
unusual combinations in categorical datasets ? 

Thanks.




Notice of Confidentiality

This transmission contains information that may be confidential and that may 
also be privileged. Unless you are the intended recipient of the message (or 
authorised to receive it for the intended recipient) you may not copy, forward, 
or otherwise use it, or disclose it or its contents to anyone else. If you have 
received this transmission in error please notify us immediately and delete it 
from your system.

RSA Insurance Group plc. Registered in England No. 2339826. The Registered 
Office is 9th Floor, One Plantation Place, 30 Fenchurch Street, London EC3M 3BD


[[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.


Re: [R] : unusual combinations of categorical data

2010-11-08 Thread Joshua Wiley
Hi,

On Mon, Nov 8, 2010 at 2:25 PM, Alan Chalk alan.ch...@gcc.rsagroup.com wrote:
 Regarding unusual combinations of factors in categorical data.

where all variables are categorical?

 Are there any R packages that can be used to identify the outliers i.e.
 unusual combinations in categorical datasets ?

outlier or unusual tends to be rather variable, that is something
unusual in one data set may not be in another.  If you are dealing
with strictly categorical variables, I am not certain how you would
define an outlier.  The categories only have the meaning attached to
them, so it seems like they would only indicate outliers if you
decided that an entire category was an outlier (e.g., males, females,
half-man-half-ox).  If you have one continuous variable in mind by
different levels of a factor, then you could just use some simple
plots (e.g., ggplot() + geom_point() + facet_grid(factor ~ .) or
something similar).  You could also z-score the values by each factor
level and then extract zscores more extreme than +/- 3 or whatever
value you like.  It might be easier to give you feedback if you have a
more specific example.

Cheers,

Josh


 Thanks.


 

 Notice of Confidentiality

 This transmission contains information that may be confidential and that may 
 also be privileged. Unless you are the intended recipient of the message (or 
 authorised to receive it for the intended recipient) you may not copy, 
 forward, or otherwise use it, or disclose it or its contents to anyone else. 
 If you have received this transmission in error please notify us immediately 
 and delete it from your system.

 RSA Insurance Group plc. Registered in England No. 2339826. The Registered 
 Office is 9th Floor, One Plantation Place, 30 Fenchurch Street, London EC3M 
 3BD

 
        [[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.




-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.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] how do i plot this hist?

2010-11-08 Thread casperyc

Hi all,

I have the following data in abc.dat

===
 50 0 1 0 0
 55 114 0 1
 60 786 0 3
 6522   324 2 3
 7058  1035 1 7
 7530  2568 034
 80 9  293615   162
 8527  216946   365
 9080  1439   212   432
 95   236  1670   521   281
100   332   827   709   172
105   156   311   556   103
1106949   14444
11526103617
120 2 9 3 3
125 1 6 1 1
130 014 0 0
135 0 5 0 0
140 0 0 0 0
145 0 0 0 0
150 0 0 0 0
155 0 0 0 0
160 0 0 0 0
165 0 0 0 0
170 0 0 0 0
175 0 0 0 0
180 0 0 0 0
185 0 0 0 0
190 0 0 0 1
195 0 0 0 0
200 0 0 0 0
205 0 0 0 0
210 0 0 0 0
===

which i have used 

abc=read.table(abc.dat)

to read the table into R.

There are two problems:

1- I want the first column of the data to be
the 'column names', how should i read the data?

2- I want to plot the histogram, using the first column as
'x' values, and the 2nd,3rd,4th and 5th columns as the frequencies.

How do I plot it?


I have tried to add a 'row' of variable names to it,
and then read with 'header=T', then the first column 
become 'col.names' as I was expecting it to be.

However, when I plot it using 'hist', 
R uses the 2nd column as the 'x value', where it should be used as
'frequency'.
(the 50,55,60,65,70... should be on the x-axis)

Thanks!

Casper
-- 
View this message in context: 
http://r.789695.n4.nabble.com/how-do-i-plot-this-hist-tp3032796p3032796.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] Random Sample

2010-11-08 Thread Giovanni Petris
Here is an example of what I think the original poster wanted to
achieve.

 rnorm(10)
 [1] -1.2165869 -0.4698460 -0.4209811 -1.4856052  0.3765774 -1.3822470
 [7]  0.2818458  0.5500957 -1.1474455 -1.2221257
 x - .Random.seed
 runif(10)
 [1] 0.5610780 0.5911841 0.5868183 0.3833801 0.7397059 0.4973270 0.6544219
 [8] 0.1257485 0.2756357 0.5672207
 .Random.seed - x
 runif(10)
 [1] 0.5610780 0.5911841 0.5868183 0.3833801 0.7397059 0.4973270 0.6544219
 [8] 0.1257485 0.2756357 0.5672207
 
Best,
Giovanni Petris

On Mon, 2010-11-08 at 16:05 -0500, Jorge Ivan Velez wrote:
 Hi Xiaoxi,
 
 Take a look at the following:
 
  set.seed(123)
  rnorm(10)
  [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
  [7]  0.46091621 -1.26506123 -0.68685285 -0.44566197
  rnorm(10)
  [1]  1.2240818  0.3598138  0.4007715  0.1106827 -0.5558411  1.7869131
  0.4978505
  [8] -1.9666172  0.7013559 -0.4727914
  set.seed(123)
  rnorm(10)
  [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
  [7]  0.46091621 -1.26506123 -0.68685285 -0.44566197
 
 and check ?set.seed().
 
 HTH,
 Jorge
 
 
 On Mon, Nov 8, 2010 at 3:57 PM, Xiaoxi Gao  wrote:
 
 
  Hello R users,
  Here is my question about generating random sample. How to set the random
  seed to recreate the same random numbers?  For example, 10 random numbers is
  generated from N(0,1), then runif(10) is used.What if I want to get the
  same 10 random numbers when I run runif(10) again? Is it possible?I think
  .Random.seed should be used here.
  Thanks.
  Xiaoxi
 [[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.
 
 
   [[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.

-- 

Giovanni Petris  gpet...@uark.edu
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

__
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] Help with getting ?match to not sort

2010-11-08 Thread Peter Alspach
Tena koe Tal

sort: logical.  Should the results be sorted on the 'by' columns?

Thus it is clear what sort=TRUE does, sort=FALSE does not do this.  That 
doesn't mean it leaves the result in the same order as x (your a1), although 
many people (including me at first) assume it does.  It is easy enough to write 
a wrapper function to retain the order of x in cases like yours.  For example:

mergeRO - function (x, y, ...) 
{
myMerge - merge(cbind(x, myOrder = 1:nrow(x)), y, ...)
attr(myMerge, creation time) - Sys.time()
myMerge[order(myMerge$myOrder), colnames(myMerge) != myOrder]
}

but I'm not sure this will work in all circumstances in which people might use 
merge().

HTH ...

Peter Alspach

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Tal Galili
 Sent: Tuesday, 9 November 2010 10:10 a.m.
 To: r-help@r-project.org
 Subject: [R] Help with getting ?match to not sort
 
 Hello all,
 
 I think I am missing something about the sorting parameter in the
 match
 command/
 Here is an example:
 
 
 a1 - data.frame(name = c(D, B, C, A, A, C))
 a2 - data.frame(name = c(A, B, C, D), num = 1:4)
 a1
 a2
 merge(a1, a2, sort = F, by.x = T)
 
 
 
 The result is:
 
   name num
 1D   4
 2B   2
 3C   3
 4C   3
 5A   1
 6A   1
 
 
 While I wish my rows to be in the same order as in a1, they are having
 some
 other order.
 
 What am I missing here?
 
 
 Thanks.
 
 
 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew)
 |
 www.r-statistics.com (English)
 ---
 ---
 
   [[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.

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

__
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 do i plot this hist?

2010-11-08 Thread jim holtman
try this:

 x - read.table('clipboard')
 x
V1  V2   V3  V4  V5
1   50   01   0   0
2   55   1   14   0   1
3   60   7   86   0   3
4   65  22  324   2   3
5   70  58 1035   1   7
6   75  30 2568   0  34
7   80   9 2936  15 162
8   85  27 2169  46 365
9   90  80 1439 212 432
10  95 236 1670 521 281
11 100 332  827 709 172
12 105 156  311 556 103
13 110  69   49 144  44
14 115  26   10  36  17
15 120   29   3   3
16 125   16   1   1
17 130   0   14   0   0
18 135   05   0   0
19 140   00   0   0
20 145   00   0   0
21 150   00   0   0
22 155   00   0   0
23 160   00   0   0
24 165   00   0   0
25 170   00   0   0
26 175   00   0   0
27 180   00   0   0
28 185   00   0   0
29 190   00   0   1
30 195   00   0   0
31 200   00   0   0
32 205   00   0   0
33 210   00   0   0
 x.m - as.matrix(x)  # dataframe - matrix
 barplot(t(x.m), names.arg = x.m[,1], las=2)



On Mon, Nov 8, 2010 at 5:42 PM, casperyc caspe...@hotmail.co.uk wrote:

 Hi all,

 I have the following data in abc.dat

 ===
  50     0     1     0     0
  55     1    14     0     1
  60     7    86     0     3
  65    22   324     2     3
  70    58  1035     1     7
  75    30  2568     0    34
  80     9  2936    15   162
  85    27  2169    46   365
  90    80  1439   212   432
  95   236  1670   521   281
 100   332   827   709   172
 105   156   311   556   103
 110    69    49   144    44
 115    26    10    36    17
 120     2     9     3     3
 125     1     6     1     1
 130     0    14     0     0
 135     0     5     0     0
 140     0     0     0     0
 145     0     0     0     0
 150     0     0     0     0
 155     0     0     0     0
 160     0     0     0     0
 165     0     0     0     0
 170     0     0     0     0
 175     0     0     0     0
 180     0     0     0     0
 185     0     0     0     0
 190     0     0     0     1
 195     0     0     0     0
 200     0     0     0     0
 205     0     0     0     0
 210     0     0     0     0
 ===

 which i have used

 abc=read.table(abc.dat)

 to read the table into R.

 There are two problems:

 1- I want the first column of the data to be
 the 'column names', how should i read the data?

 2- I want to plot the histogram, using the first column as
 'x' values, and the 2nd,3rd,4th and 5th columns as the frequencies.

 How do I plot it?


 I have tried to add a 'row' of variable names to it,
 and then read with 'header=T', then the first column
 become 'col.names' as I was expecting it to be.

 However, when I plot it using 'hist',
 R uses the 2nd column as the 'x value', where it should be used as
 'frequency'.
 (the 50,55,60,65,70... should be on the x-axis)

 Thanks!

 Casper
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/how-do-i-plot-this-hist-tp3032796p3032796.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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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 do i plot this hist?

2010-11-08 Thread jim holtman
Typing too fast; last line should be:

barplot(t(x.m[, 2:5]), names.arg = x.m[,1], las=2)


On Mon, Nov 8, 2010 at 5:42 PM, casperyc caspe...@hotmail.co.uk wrote:

 Hi all,

 I have the following data in abc.dat

 ===
  50     0     1     0     0
  55     1    14     0     1
  60     7    86     0     3
  65    22   324     2     3
  70    58  1035     1     7
  75    30  2568     0    34
  80     9  2936    15   162
  85    27  2169    46   365
  90    80  1439   212   432
  95   236  1670   521   281
 100   332   827   709   172
 105   156   311   556   103
 110    69    49   144    44
 115    26    10    36    17
 120     2     9     3     3
 125     1     6     1     1
 130     0    14     0     0
 135     0     5     0     0
 140     0     0     0     0
 145     0     0     0     0
 150     0     0     0     0
 155     0     0     0     0
 160     0     0     0     0
 165     0     0     0     0
 170     0     0     0     0
 175     0     0     0     0
 180     0     0     0     0
 185     0     0     0     0
 190     0     0     0     1
 195     0     0     0     0
 200     0     0     0     0
 205     0     0     0     0
 210     0     0     0     0
 ===

 which i have used

 abc=read.table(abc.dat)

 to read the table into R.

 There are two problems:

 1- I want the first column of the data to be
 the 'column names', how should i read the data?

 2- I want to plot the histogram, using the first column as
 'x' values, and the 2nd,3rd,4th and 5th columns as the frequencies.

 How do I plot it?


 I have tried to add a 'row' of variable names to it,
 and then read with 'header=T', then the first column
 become 'col.names' as I was expecting it to be.

 However, when I plot it using 'hist',
 R uses the 2nd column as the 'x value', where it should be used as
 'frequency'.
 (the 50,55,60,65,70... should be on the x-axis)

 Thanks!

 Casper
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/how-do-i-plot-this-hist-tp3032796p3032796.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.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

__
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 eliminate this for loop ?

2010-11-08 Thread Erich Neuwirth
Reduce(function(x1,x2)b*x1-x2,c,init=1,accum=TRUE)

might be what you are looking for.
This is not fully tested, so you should test it before
you want to use it.

__
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] How to detect if a vector is FP constant?

2010-11-08 Thread Hadley Wickham
Hi all,

What's the equivalent to length(unique(x)) == 1 if want to ignore
small floating point differences?  Should I look at diff(range(x)) or
sd(x) or something else?  What cut off should I use?

If it helps to be explicit, I'm interested in detecting when a vector
is constant for the purpose of visual display.  In other words, if I
rescale x to [0, 1] do I have enough precision to get at least 100
unique values.

Thanks!

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

__
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 detect if a vector is FP constant?

2010-11-08 Thread Albyn Jones
how about 

   all.equal(x,rep(mean(x),length(x)))
or

   all.equal(x,rep(mean(x),length(x), tolerance=...)

albyn

On Mon, Nov 08, 2010 at 06:45:00PM -0600, Hadley Wickham wrote:
 Hi all,
 
 What's the equivalent to length(unique(x)) == 1 if want to ignore
 small floating point differences?  Should I look at diff(range(x)) or
 sd(x) or something else?  What cut off should I use?
 
 If it helps to be explicit, I'm interested in detecting when a vector
 is constant for the purpose of visual display.  In other words, if I
 rescale x to [0, 1] do I have enough precision to get at least 100
 unique values.
 
 Thanks!
 
 Hadley
 
 -- 
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/
 
 __
 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.
 

-- 
Albyn Jones
Reed College
jo...@reed.edu

__
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] cannot find system Renviron Fatal error: unable to open the base package

2010-11-08 Thread jelas

hi people

I need to make an application with Java and R. 
I installed the library rJava using the command R - install.packages
(rJava),  and i configured my $ R_HOME = / Library / Frameworks /
R.framework / Resources.

My SO is OSX.

When I run an exemple in eclipse, it gives me the following error:

cannot find system Renviron
Fatal error: unable to open the base package

I need help.

Thanks

-- 
View this message in context: 
http://r.789695.n4.nabble.com/cannot-find-system-Renviron-Fatal-error-unable-to-open-the-base-package-tp3032754p3032754.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.


  1   2   >