Re: [R] How to shadow 'power' area?

2007-06-25 Thread Christos Hatzis
Look at the following link:

http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=88 

This should be pretty close to what you want.
HTH

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Andrej Kastrin
> Sent: Monday, June 25, 2007 4:51 PM
> To: R-help
> Subject: [R] How to shadow 'power' area?
> 
> Dear all,
> 
> Suppose I plot two normal distributions (A and B) side by 
> side and add vertical line which hipotheticaly represent 
> alpha value; e.g.:
> 
> x <- seq(-3.5,5, length=1000)
> y <- dnorm(x)
> # Plot distribution A
> plot(y~x, type='l',axes=F,xlab="",ylab="",lwd=2)
> # Plot distribution B
> y2 <- dnorm(x-1.5)
> lines(y2~x,lwd=2)
> # Plot vertical line for alpha value
> abline(h=0)
> segments(qnorm(.5)+1.5,0,qnorm(.5)+1.5,dnorm(qnorm(.5)))
> text(2,0.2,"Power")
> 
> Now I want to shadow area labeled as "Power". Any suggestion 
> how to do that using 'polygon' function?
> 
> Thanks in advance for any suggestion.
> 
> Andrej
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] vectorize a function

2007-06-22 Thread Christos Hatzis
How about:

sum(sapply(unique(a), function(x) {b <- which(a==x); sum(M[b, b])}))

HTH
-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin
> Sent: Friday, June 22, 2007 9:28 AM
> To: RHelp help
> Subject: [R] vectorize a function
> 
> Hello everyone
> 
> suppose I have an integer vector "a" of length "n" and a 
> symmetric matrix "M" of size n-by-n.
> 
> Vector "a" describes a partition of a set of "n" elements and 
> matrix M describes a penalty function: row i column j 
> represents the penalty if element i and element j are in the 
> same partition.
> 
> Toy example follows; the real case is much larger and I need 
> to evaluate my penalty function many times.
> 
> If a <- c(1,1,2,1,3)  then elements 1,2,4 are in the same 
> partition; element 3 is in a partition on its own and element 
> 5 is in a partition on its own.
> 
> The total penalty  can be described by the following (ugly)
> function:
> 
> f <- function(a,M){
>out <- 0
>for(i in unique(a)){
>  out <- out + sum(M[which(a==i),which(a==i)])
>}
>return(out)
> }
> 
> 
> so with
> 
> M <- matrix(rpois(25,3),5,5)
> M <- M+t(M)
> diag(M) <- 0
> a <- c(1,2,1,1,3)
> 
> f(a,M) gives the total penalty.
> 
> 
> QUESTION:  how to rewrite f() so that it has no loop?
> 
> 
> 
> 
> 
> 
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton European Way, 
> Southampton SO14 3ZH, UK
>   tel  023-8059-7743
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Removing vertical line in Tinn R editor

2007-06-06 Thread Christos Hatzis
Go to Options/Main/Editor
Click on EdgeColor and select white as the color (or to whatever color you
have set your page's background).  This will make the edge line disappear.

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Judith Flores
> Sent: Wednesday, June 06, 2007 1:50 PM
> To: RHelp
> Subject: [R] Removing vertical line in Tinn R editor
> 
> Hi,
> 
>I haven't been able to figure out how to remove a vertical 
> line that appears when I open an r file. How can I do this?
> 
> Thank you,
> 
> Judith
> 
> 
>
> __
> __
> Looking for a deal? Find great prices on flights and hotels 
> with Yahoo! FareChase.
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] pie chart in lattice - trellis class

2007-05-28 Thread Christos Hatzis

In case you haven't seen this, there is an example in Paul Murrell's book
that plots temperatures on a map using 'thermometer' charts.  I would
imagine it should be relatively straight forward to combine the floating.pie
function with Paul's grid-base code (but I have not tried it myself).

http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter7.html

See Figure 7.18 and code

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 



> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Ben Bolker
> Sent: Monday, May 28, 2007 8:51 AM
> To: r-help@stat.math.ethz.ch
> Subject: Re: [R] pie chart in lattice - trellis class
> 
> P
> > Yes indeed. Thats' likely what I am going to do. Anyway, to 
> plot axes, 
> > labels of sophisticated graphs on maps may be interesting 
> anyway. For 
> > instance, we are monitoring fox and hare populations in 
> tens of game 
> > areas. Drawing observations (panel.xyplot) over time and 
> representing 
> > the trend variations (panel.loess) at the very place on the 
> map where 
> > the observations were done gives an absolutely interesting 
> view where 
> > spatial relationships between trends can be visualized.
> > 
> > Patrick
> 
>   There is a floating.pie in the plotrix package, and a 
> hidden floating.pie.asp function in the ape package.  I agree 
> that grid objects would be a more elegant way to implement these ...
> (The standard argument is that "thermometers" or 
> mini-barplots would be a better way to view this information, 
> but I agree that pie charts seem familiar to people.)  I have 
> the feeling that I've seen pie-charts-on-maps somewhere ... 
> searching the R Graphics Gallery for "pie" also produces the 
> "hexbin pie" plot (which doesn't use grid either ...)
> 
>   Ben Bolker
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] names of objects in .rda

2007-05-11 Thread Christos Hatzis
You're right.  I didn't realize that what happens when attaching is that

"a new environment is created on the search path and the elements of a list
(including columns of a data frame) or objects in a save file or an
environment are *** copied *** into the new environment" 

Thanks.
-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Seth Falcon
> Sent: Friday, May 11, 2007 1:32 PM
> To: r-help@stat.math.ethz.ch
> Subject: Re: [R] names of objects in .rda
> 
> "Christos Hatzis" <[EMAIL PROTECTED]> writes:
> 
> > An approach would be to attach it and then use ls()
> 
> No, that really is not an approach.  If you load it, then 
> there is no problem to read the names.  The point is not to 
> load it.  This is important when dealing with large objects 
> or large collections of objects.
> 
> + seth
> 
> --
> Seth Falcon | Computational Biology | Fred Hutchinson Cancer 
> Research Center http://bioconductor.org
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] names of objects in .rda

2007-05-11 Thread Christos Hatzis
An approach would be to attach it and then use ls() 

attach(myarchive.rda)
ls(pos=2) 
detach(myarchive.rda)

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Benilton Carvalho
> Sent: Friday, May 11, 2007 11:54 AM
> To: [EMAIL PROTECTED] server posting
> Subject: [R] names of objects in .rda
> 
> Hi everyone,
> 
> sorry if this was discussed before (and in this situation, 
> could you please point me to the discussion in the archive? 
> My search didn't seem to be effective).
> 
> Is there a way of getting the names of objects in a .rda file 
> without having to load it?
> 
> Thank you very much,
> 
> benilton
> 
> --
> PhD Candidate
> Department of Biostatistics
> Bloomberg School of Public Health
> Johns Hopkins University
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] voronoi.mosaic chokes?

2007-05-08 Thread Christos Hatzis
Have you tried 'debug'?

With one of the datasets that crashes your system, run the first
voronoi.mosaic, then the torus function and then

debug(voronoi.mosaic)

and run through the second call of voronoi.mosaic.  You can step though the
code and at least will you find the point where it bombs.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Andrew Pierce
> Sent: Wednesday, May 09, 2007 12:21 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] voronoi.mosaic chokes?
> 
> Hi all,
> 
> I am running R 2.5.0 under Windows XP Media Center Edition.  
> Here's a problem that's been stumping me for a few days now, 
> and I can't find anything useful in the archives.  I am using 
> voronoi.mosaic (tripack
> package) to create proximity polygons for a study of 
> vegetation competition and dynamics.  The points lists are 
> read in from a file for each plot, then 8 duplicates are 
> translated around the edges of the plot (Toroidal edge 
> correction).  This is completed using the torus(...) function 
> that I wrote myself.
> 
> VMuncorrected is the voronoi  mosaic that is not toroidally 
> edge corrected VMcorrected is the voronoi mosaic that is 
> toroidally edge corrected
> 
>  >treemap = read.table('af1.txt', sep = "\t", header = 1)  
> >VMuncorrected = voronoi.mosaic(treemap$X, treemap$Y)
> 
> ###Use the torus function to create 8 copies around the study 
> region  >toroid = torus(treemap$X, treemap$Y, 25, 25)
> 
>  >VMcorrected = voronoi.mosaic(toroid[,1], toroid[,2], 
> duplicate = "remove")
> 
> Here's the problem. When I read in the points for the data 
> file listed above ('af1.txt'), both calls to voronoi.mosaic() 
> work fine.  (The second one takes about 1.5 seconds because 
> there are 1147 points in the toroidally corrected set).
> 
> However, when I read in the points from the next file 
> ('af2.txt'), the first call to voronoi.mosaic() works.  The 
> next call (to torus()) also works fine.  But the second call 
> to voronoi.mosaic() causes R to freeze completely requiring 
> Ctrl-Alt-Del.
> 
> I have 10 sets of points and this problem happens for about 5 of them.
> 
> Factors I have ruled out:
> -too many points in the call (one set had 1147 and worked 
> fine while the next set had 801 and froze R) -duplicate 
> points (taken care of by voronoi.mosaic(..., duplicate =
> "remove") and also independently verified by exporting the 
> data.  no duplicates in either the original or the toroidally 
> corrected set) -points too close together in space (minimum 
> distance between two points in 'af1.txt' is 0.1414 and works 
> fine.  minimum distance in the second set, 'af2.txt', is 
> 0.2236, and this set causes R to freeze) -not enough memory 
> (each data set is run in a new R session-i.e. R was quit 
> between each attempt) -'flukiness' (the problem happens the 
> same way every time for the problem data sets, and the code 
> runs fine every time for the non-problem data sets) -file 
> formats (each text file has the same number of columns, all 
> the labels for the columns are identical, and the columns are 
> always in the same order) -outdated versions (I am using R 
> 2.5.0 and updated the tripack package within the last week.  
> also, I update packages about once a month)
> 
> This is a very frustrating problem because I get no errors 
> indicating any problem with the data, and I have checked the 
> data over and over for any type of error and found none.  If 
> anyone has ANY helpful suggestions, I would love to hear 
> about any and all of them.
> 
> Andrew
> 
> p.s. - for those of you who are really intrigued, I can email 
> you the .txt files and the code for the torus() function.
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 function for raising a matrix to a power?

2007-05-06 Thread Christos Hatzis
Here is a recursive version of the same function:

"%^%" <- function(A, n) if(n == 1) A else A %*% (A %^% (n-1))

> a <- matrix(1:4, 2)

> a %^% 1
 [,1] [,2]
[1,]13
[2,]24
> a %^% 2
 [,1] [,2]
[1,]7   15
[2,]   10   22
> a %^% 3
 [,1] [,2]
[1,]   37   81
[2,]   54  118


-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Ron E. 
> VanNimwegen
> Sent: Sunday, May 06, 2007 10:48 AM
> To: r-help@stat.math.ethz.ch; [EMAIL PROTECTED]
> Subject: Re: [R] A function for raising a matrix to a power?
> 
> >  Hi,
> >
> > Is there a function for raising a matrix to a power? For example if 
> > you like to compute A%*%A%*%A, is there an abbreviation 
> similar to A3?
> >
> > Atte Tenkanen
> Hi Atte,
> 
> I was looking for a similar operator, because R uses scalar products 
> when raising a matrix to a power with "^".  There might be something 
> more elegant, but this little loop function will do what you 
> need for a 
> matrix "mat" raised to a power "pow":
> 
> mp <- function(mat,pow){
> ans <- mat
> for ( i in 1:(pow-1)){
> ans <- mat%*%ans
> }
> return(ans)
> }
> 
> Then, for your example:
> > > A=rbind(c(1,1),c(-1,-2))
> > > mp(A,3)
> >  [,1] [,2]
> > [1,]12
> > [2,]   -2   -5
> Cheers,
> Ron
> 
> ---
> Ron E. VanNimwegen
> Ph.D. Candidate, Division of Biology (EEB)
> Kansas Cooperative Fish & Wildlife Research Unit
> 205 Leasure Hall
> Kansas State University
> Manhattan, KS 66506-3501
> [EMAIL PROTECTED]
> ---
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] R package development in windows

2007-05-04 Thread Christos Hatzis
After cleaning up your workspace to keep only the objects that you will need
to have in your "package", you can save it as MyStuff.RData

save(list=ls(), file=file.path(my.package.dir, "MyStuff.RData"))

To use this "package" in future sessions all you need is

attach(file.path(my.package.dir, "MyStuff.RData"))

This will make your objects available in your current session without
cluttering your workspace.
Of course, there is a price to pay for simplicity (i.e. no error checks, no
documentation etc).

-Christos 

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Lucke, Joseph F
> Sent: Friday, May 04, 2007 10:03 AM
> To: Doran, Harold; Duncan Murdoch
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] R package development in windows
> 
> Might there be an (semi-)automated procedure to create a 
> minimal, personal package, for my eyes only, that I can load 
> with a "libray(MyStuff)" command?  This would be preferable 
> to having to
> source() the files.  Is there already such a procedure?
> Joe
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Doran, Harold
> Sent: Thursday, May 03, 2007 2:33 PM
> To: Duncan Murdoch
> Cc: r-help@stat.math.ethz.ch
> Subject: Re: [R] [SPAM] - Re: R package development in 
> windows - BayesianFilter detected spam
> 
> Thanks, Duncan. I'll look into that. Is there an 
> authoritative document that codifies the new package 
> development procedures for 2.5.0 (windows-specific), or is 
> that Writing R Extensions? In this thread alone I've received 
> multiple emails pointing to multiple web sites with 
> instructions for windows. Inasmuch as its appreciated, I'm a 
> bit confused as to which I should consider authoritative.
> 
> I do hope I can resolve this and appreciate the help I've received.
> However, I feel a bit compelled to note how very difficult 
> this process is. 
> 
> Harold
> 
> 
> > -Original Message-
> > From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, May 03, 2007 3:24 PM
> > To: Doran, Harold
> > Cc: Gabor Grothendieck; r-help@stat.math.ethz.ch
> > Subject: [SPAM] - Re: [R] R package development in windows 
> - Bayesian 
> > Filter detected spam
> > 
> > On 5/3/2007 3:04 PM, Doran, Harold wrote:
> > > Thanks Gabor, Sundar, and Tony. Indeed, Rtools was 
> missing from the 
> > > path. With that resolved, and another 10 minute windows
> > restart, I get
> > > the following below. The log suggests that hhc is not 
> installed. It 
> > > is, and, according to the directions I am following, I have
> > placed it
> > > in the c:\cygwin directory.
> > 
> > I think the problem is that you are following a real mix of 
> > instructions, and they don't make sense.
> > 
> > It would be nice if folks would submit patches to the R 
> Admin manual 
> > (or to the Rtools web site) rather than putting together web sites 
> > with advice that is bad from day one, and quickly gets 
> worse when it 
> > is not updated.
> > 
> > > BTW, package.skeleton() doesn't seem to create the correct
> > DESCRIPTION
> > > template. I had to add the DEPENDS line. Without this, I
> > get another
> > > error.
> > > 
> > > 
> > > C:\Program Files\R\R-2.4.1\bin>Rcmd build --force --binary g:\foo
> > 
> > R 2.4.1 is no longer current; the package building 
> instructions in R 
> > 2.5.0 have been simplified a bit.  You might want to try those.
> > 
> > Duncan Murdoch
> > 
> > > * checking for file 'g:\foo/DESCRIPTION' ... OK
> > > * preparing 'g:\foo':
> > > * checking DESCRIPTION meta-information ... OK
> > > * removing junk files
> > > * checking for LF line-endings in source files
> > > * checking for empty or unneeded directories
> > > * building binary distribution
> > >  WARNING
> > > * some HTML links may not be found
> > > installing R.css in c:/TEMP/Rinst40061099
> > > 
> > > Using auto-selected zip options ''
> > > latex: not found
> > > latex: not found
> > > latex: not found
> > > 
> > > -- Making package foo 
> > > latex: not found
> > >   adding build stamp to DESCRIPTION
> > > latex: not found
> > > latex: not found
&

Re: [R] the Surv function

2007-05-01 Thread Christos Hatzis
Try using the following (without naming the arguments) - it should work.

Surv(fup, status)

I think what is happening is that if you use one or two arguments (unnamed),
Surv assumes that you have right-censored data, with the first argument
being time and the second being status.  By specifying 'event' as you did,
Surv assumes that you have 3 arguments of "type"=counting and it is looking
for the ending time required by the counting data format and this is why you
got the error.

If you are not afraid of R code, type Surv (without the parentheses) to see
the code behind the function.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Jennifer Dillon
> Sent: Tuesday, May 01, 2007 11:16 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] the Surv function
> 
> Hi,
> 
> I'm trying to do a simple survival analysis on some data, and 
> I'm having the following problem (here's my code and the 
> error message):
> 
> out <- Surv(fup,event=status)
> Error in Surv(fup, event = status) : argument "time2" is 
> missing, with no default
> 
> >From reading the documentation, it seems that I should be able to 
> >simply
> write:  Surv(time1, event)  if my data is right-censored, which it is.
> Help!
> 
> Thanks a million,
> 
> Jen
> 
> 
> 
> --
> Jennifer Dillon
> Doctoral Student
> Harvard Biostatistics
> Room 414B, Building 1
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 code the censor variable for "survfit"

2007-04-28 Thread Christos Hatzis
The Surv object contains the information on the type of censoring.  
Look at ?Surv
for an explanation of how censored events are represented.

-Christos 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Lu, Jiang
> Sent: Saturday, April 28, 2007 11:10 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] how to code the censor variable for "survfit"
> 
> Dear r-helpers,
> 
> This is my first time to run survival analysis. Currently, I 
> have a data set which contains two variables, the variable of 
> time to event (or time to censoring) and the variable of 
> censor indicator. For the indicator variable, it was coded as 
> 0 and 1. 0 represents right censor, 1 means event of 
> interest. Now I try to use "survfit" in the package of 
> "survival". I wrote the following code:
> > rptsurv <- survfit(surv(time,censor)~1,data=x)
> 
> Before I run the code, I am concerned with my 0/1 coding to 
> the censor indicator because I did not see any argument in 
> the syntax of "survfit", which may tell the program that 
> value 1 means event. I checked the documentations and R-help 
> archive, but ended in vain.
> 
> Would you please kindly tell me how "survfit" treats censor variables?
> In 0/1 coding, is it the default that 1 means event and 0 
> means right censor? What if the censor was coded as 2 or 3 
> instead of 0 or 1? I means how the "survfit" knows the 
> difference. In SAS, if a "lifetest"
> procedure (similar to survfit) is performed, there is an 
> argument specifying which value in the censor variable is 
> treated as event.
> 
> I know I could just compare the results from R and from SAS 
> to see the difference. However, I really want to know exactly 
> how "survfit" deals with this problem. Thank you very much in advance.
> 
> sincerely,
> 
> Jiang Lu
> University of Pittsburgh
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Extract p-value from survdiff function

2007-04-26 Thread Christos Hatzis
If 

sdf <- survdiff(...)
 
is your survdiff object, the p-value can be computed as follows:

p.val <- 1 - pchisq(sdf$chisq, length(sdf$n) - 1)

and then use it in your K-M plot.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Armin Goralczyk
> Sent: Thursday, April 26, 2007 3:03 PM
> To: R-help@stat.math.ethz.ch
> Subject: [R] Extract p-value from survdiff function
> 
> Hi list,
> I want to use the p-value from the survdiff function (package
> survival) to reuse within a function in a Kaplan-Meier plot. 
> The p-value is somehow not a component of the value list ?!
> 
> Thanks in advance
> --
> A. Goralczyk
> Göttingen, Ger.
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] graphs superimposed on pictures?

2007-04-11 Thread Christos Hatzis
Take a look at Figure 3.26 from Paul Murrell's book and associated code
posted here:

http://www.stat.auckland.ac.nz/~paul/RGraphics/chapter3.html

-Christos

 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Robert Biddle
> Sent: Wednesday, April 11, 2007 9:40 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] graphs superimposed on pictures?
> 
> Hi:
> 
> I am doing some work that involves plotting points of 
> interest superimposed on photographs and maps. I can produce 
> the plots fine in R, but so far I have had to do the 
> superimposition externally, which makes it tedious to do 
> exploratory work.
> I have looked to see if there is some capability to put a 
> background picture on a plot window, but I have not found anything.
> Advice, anyone?
> 
> Cheers
> Robert Biddle
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] ISwR library

2007-04-09 Thread Christos Hatzis
Take a look at the "R Installation and Administration" manual - 
Section 6.1 Installing packages.

It is platform-dependent and you didn't say what platform you're on. 

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of slomascolo
> Sent: Monday, April 09, 2007 3:04 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] ISwR library
> 
> 
> I am learning to use R using a book that uses examples from 
> the ISwR library so I need to have that library.  When I type 
> library (ISwR), R says: Error in library(ISwR) : there is no 
> package called 'ISwR'
> 
> Do I need to install ISwR separately? How do I do this?
> 
> Thanks!
> --
> View this message in context: 
> http://www.nabble.com/ISwR-library-tf3548959.html#a9907582
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] transition matrices

2007-04-04 Thread Christos Hatzis
I think what you are looking for is also called seriation or ordination,
i.e. find the "best" enumeration order of a set of objects.

Take a look at the following link for more information and on criteria for
defining "best"

http://www.lirmm.fr/~caraux/PermutMatrix/EN/Seriation.htm

The link is for a windows application (PermutMatrix) that can perform
seriation on distance matrices used in hierarchical clustering, but might be
useful in your context as well.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
  

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Richard Rowe
> Sent: Wednesday, April 04, 2007 2:35 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] transition matrices
> 
> I am working with transition matrices of sequences of animal 
> behaviours.  What I would like to do is parse the original 
> matrices, adjusting row/column order so that the matrix has 
> its main values in blocks surrounding the diagonal.  This 
> would cause behaviours involved in functional groupings (e.g. 
> grooming, resting, foraging etc) to appear as blocks.
> This can be done manually by applying subjective 'prior 
> knowledge' of sequences, however I would like to have an 
> algorithmic/objective method to generate at least a first cut ...
> Any suggestions or hints (even just thoughts) would be much 
> appreciated,
> 
> Richard Rowe
> 
> Dr Richard Rowe
> Zoology & Tropical Ecology
> School of Tropical Biology
> James Cook University
> Townsville 4811
> AUSTRALIA
> 
> ph +61 7 47 81 4851
> fax +61 7 47 25 1570
> JCU has CRICOS Provider Code 00117J
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 a new var reflecting the order of subjects in existingvar

2007-04-01 Thread Christos Hatzis
Try this:

y <- rle(dat$ID)
unlist(sapply(y$lengths, FUN=function(x) seq(1,x)))

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Nguyen 
> Dinh Nguyen
> Sent: Sunday, April 01, 2007 10:00 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Create a new var reflecting the order of 
> subjects in existingvar
> 
> Dear R helpers
> I have a data set sth like this:
> set.seed(123);dat <- data.frame(ID= c(rep(1,2),rep(2,3), 
> rep(3,3), rep(4,4), rep(5,5)),
>   var1 =rnorm(17, 35,2),
>   var2=runif(17,0,1))
> dat
>ID var1   var2
> 1   1 33.87905 0.02461368
> 2   1 34.53965 0.47779597
> 3   2 38.11742 0.75845954
> 4   2 35.14102 0.21640794
> 5   2 35.25858 0.31818101
> 6   3 38.43013 0.23162579
> 7   3 35.92183 0.14280002
> 8   3 32.46988 0.41454634
> 9   4 33.62629 0.41372433
> 10  4 34.10868 0.36884545
> 11  4 37.44816 0.15244475
> 12  4 35.71963 0.13880606
> 13  5 35.80154 0.23303410
> 14  5 35.22137 0.46596245
> 15  5 33.88832 0.26597264
> 16  5 38.57383 0.85782772
> 17  5 35.99570 0.04583117
> I would like to create a new var in dat which reflects the 
> order of each subject (ID), like this
>ID var1   var2  IDorder
> 1   1 33.87905 0.02461368   1
> 2   1 34.53965 0.47779597   2
> 3   2 38.11742 0.75845954   1
> 4   2 35.14102 0.21640794   2
> 5   2 35.25858 0.31818101   3
> 6   3 38.43013 0.23162579   1
> 7   3 35.92183 0.14280002   2
> 8   3 32.46988 0.41454634   3
> 9   4 33.62629 0.41372433   1
> 10  4 34.10868 0.36884545   2
> 11  4 37.44816 0.15244475   3
> 12  4 35.71963 0.13880606   4
> 13  5 35.80154 0.23303410   1
> 14  5 35.22137 0.46596245   2
> 15  5 33.88832 0.26597264   3
> 16  5 38.57383 0.85782772   4
> 17  5 35.99570 0.04583117   5
> 
> Thank you very much for your help
> Regards
> Nguyen
> 
>

__
R-help@stat.math.ethz.ch 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] multi-level modeling & R?

2007-03-28 Thread Christos Hatzis
Also, take a look at Andrew Gelman's recent book with Jennifer Hill on
multilevel modeling.
It is written as a practical how-to text book using R as the primary
platform.  I have found it very easy to read, extremely useful and very good
value for its price (I am not related to the authors or the publisher in any
way).

http://www.stat.columbia.edu/~gelman/arm/   

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of John Kane
> Sent: Wednesday, March 28, 2007 2:25 PM
> To: Chuck Cleland
> Cc: R R-help
> Subject: Re: [R] multi-level modeling & R?
> 
> Thanks to everyone for the information and to Chuck for the 
> links. I must have misspelt something because I missed most 
> of them in the RsiteSearch.
> 
> Anyway back to selling R :)
> 
> --- Chuck Cleland <[EMAIL PROTECTED]> wrote:
> 
> > John Kane wrote:
> > > A colleague was asking me if R does multi-level modelling 
> as opposed 
> > > to multiple regression.
> > Since I
> > > have no knowledge of multi-level modelling (except
> > 5
> > > minutes googling )  I thought that I would as
> > here.
> > > 
> > > Does are offer any multi-level modeling packages? 
> > It
> > > looked like arm might be one but I was not sure.
> > 
> >   RSiteSearch("multilevel model") and a search for "multilevel" on 
> > CRAN point to a number of other relevant packages and docs, 
> including:
> > 
> >
> http://finzi.psych.upenn.edu/R/library/nlme/html/lme.html
> > 
> >
> http://cran.r-project.org/src/contrib/Descriptions/lme4.html
> > 
> > http://cran.r-project.org/doc/packages/mlmRev.pdf
> > 
> >
> http://cran.r-project.org/src/contrib/Descriptions/multilevel.html
> > 
> >
> http://cran.r-project.org/doc/contrib/Bliese_Multilevel.pdf
> > 
> > > Thanks
> > > 
> > > __
> > > R-help@stat.math.ethz.ch 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. 
> > 
> > --
> > Chuck Cleland, Ph.D.
> > NDRI, Inc.
> > 71 West 23rd Street, 8th floor
> > New York, NY 10010
> > tel: (212) 845-4495 (Tu, Th)
> > tel: (732) 512-0171 (M, W, F)
> > fax: (917) 438-0894
> >
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] what is the difference between survival analysis and (...)

2007-03-28 Thread Christos Hatzis
On the same point, transforming time-to-event data to binary outcomes so
that contingency-table analysis (odds ratios etc) or logistic regression can
be applied will result in loss of information that could lead to misleading
conclusions. 

For example, assuming that there is a good-prognosis group (low risk) and a
poor-prognosis group (high risk) that need to be compared.  By definition,
patients in the good prognosis group are those that have been followed up
for a longer time in the study, whereas patients with poor prognosis will
tend to die earlier.  Therefore censoring will occur later in the good
prognosis group and thus the two groups will not have a homogeneous
censorship structure. In this case, naïve analysis could be misleading.

For more details and a simulation example take a look at  

http://jnci.oxfordjournals.org/cgi/data/99/2/147/DC1/3

HTH

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Lucke, Joseph F
> Sent: Wednesday, March 28, 2007 12:10 PM
> To: Eric Elguero; R-help@stat.math.ethz.ch
> Subject: Re: [R] what is the difference between survival 
> analysis and (...)
> 
> You can (and I have) fit survival data with logistic 
> regression. Agresti (1990, pp 189--196) has an introductory 
> discussion. 
> 
> The issue is whether the occurrence of the event is of 
> interest or whether the time-to-event is of interest. If the 
> study lasts 180 days (as in my case) logistic regression 
> treats an event at 1 day the same as an event at 179 days. 
> Similarly, non-occurrence censored at 5 days is treated the 
> same as non-occurrence censored at 180 days. These 
> assumptions only make sense if the hazard rate is constant 
> and (therefore) the time-to-failure distribution is exponential.
> 
> One can include exposure time as a offset (non-estimated 
> covariate) to handle non-constant hazard rates. One can also 
> model the hazard rate directly as a log-linear model.
> 
> Based on what he said (number events/sample size, using 
> cumulative times), the hostile medical epidemiologist was 
> implicitly assuming the survival time followed an exponential 
> distribution. This assumption is often incorrect.   His 
> arrogance was exceeded only by his ignorance.
> 
> Joe
> 
> @BOOK{Agresti1990,
>   author = {Agresti, Alan},
>   title = {Categorical data analysis},
>   year = {1990},
>   publisher = {John Wiley \& Sons},
>   address = {New York, NY},
>   series = {Wiley Series in Probability and Mathematical Statistics},
>   keywords = {loglinear; logistic}
> }
> 
> 
>  
> 
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Eric Elguero
> Sent: Wednesday, March 28, 2007 8:40 AM
> To: R-help@stat.math.ethz.ch
> Subject: Re: [R] what is the difference between survival 
> analysis and (...)
> 
> Hi everybody,
> 
> recently I had to teach a course on Cox model, of which I am 
> not a specialist, to an audience of medical epidemiologists.
> Not a good idea you might say.. anyway, someone in the 
> audience was very hostile. At some point, he sayed that Cox 
> model was useless, since all you have to do is count who dies 
> and who survives, divide by the sample sizes and compute a 
> relative risk, and if there was significant censoring, use 
> cumulated follow-up instead of sample sizes and that's it!
> I began arguing that in Cox model you could introduce several 
> variables, interactions, etc, then I remembered of logistic 
> models ;-) The only (and poor) argument I could think of was 
> that if mr Cox took pains to devise his model, there should 
> be some reason...
> 
> but the story doesn't end here. When I came back to my 
> office, I tried these two methods on a couple of data sets, 
> and true, crude RRs are very close to those coming from Cox model.
> 
> hence this question: could someone provide me with a dataset 
> (preferably real) where there is a striking difference 
> between estimated RRs and/or between P-values? and of course 
> I am interested in theoretical arguments and references.
> 
> sorry that this question has nothing to do with R and thank 
> you in advance for your leniency.
> 
> Eric Elguero
> GEMI-UMR 2724 IRD-CNRS,
> Équipe "Évolution des Systèmes Symbiotiques"
> 911 avenue Agropolis, BP 64501,
> 34394 Montpellier cedex 5 FRANCE
> 
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-projec

Re: [R] Replacement in an expression - can't use parse()

2007-03-27 Thread Christos Hatzis
A way to do this is through substitute:

e1 <- substitute(expression(u1 + u2 + u3), list(u2=quote(x), u3=1))

But I am not sure whether you will run into similar limitations regarding
the length of the expression to be substituted. 

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Daniel Berg
> Sent: Tuesday, March 27, 2007 9:57 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Replacement in an expression - can't use parse()
> 
> Dear all,
> 
> Suppose I have a very long expression e. Lets assume, for 
> simplicity, that it is
> 
> e = expression(u1+u2+u3)
> 
> Now I wish to replace u2 with x and u3 with 1. I.e. the 'new'
> expression, after replacement, should be:
> 
> > e
> expression(u1+x+1)
> 
> My question is how to do the replacement?
> 
> I have tried using:
> 
> > e = parse(text=gsub("u2","x",e))
> > e = parse(text=gsub("u3",1,e))
> 
> Even though this works fine in this simple example, the use 
> of parse when e is very long will fail since parse has a 
> maximum line length and will cut my expressions. I need to 
> keep mode(e)=expression since I will use e further in 
> symbolic derivation and division.
> 
> Any suggestions are most welcome.
> 
> Thank you.
> 
> Regards,
> Daniel Berg
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Select the last two rows by id group

2007-03-20 Thread Christos Hatzis
You can try the following:

n.len <- nrow(iris)
n.sel <- 3

iris[(n.len-n.sel+1):n.len, ]

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Lauri Nikkinen
> Sent: Tuesday, March 20, 2007 10:33 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Select the last two rows by id group
> 
> Hi R-users,
> 
> Following this post 
> http://tolstoy.newcastle.edu.au/R/help/06/06/28965.html , how 
> do I get last two rows (or six or ten) by id group out of the 
> data frame? Here the example gives just the last row.
> 
> Sincere thanks,
> Lauri
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Highlight overlapping area between two curves

2007-03-12 Thread Christos Hatzis
See
http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=7

and code therein.

-Christos 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Nguyen 
> Dinh Nguyen
> Sent: Tuesday, March 13, 2007 12:20 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Highlight overlapping area between two curves
> 
> Dear R helpers,
> I have a graph as following; I would like to highlight the 
> overlapping area between the two curves. Do you know how to do this?
> Thank you in advance for your help.
> Nguyen
> 
> ###START
> x1 <- rnorm(1, 0.70,0.12)
> x2 <- rnorm(1, 0.90,0.12)
> 
> d1 <- density(x1)
> d2 <- density(x2)
> 
> plot(range(d1$x,d2$x), range(d1$y, d2$y), type = "n",
>  xlab = "X value", ylab = "Probability Density" )
> 
> lines(d1, col = "red",lwd=4, lty=2)
> lines(d2, col = "blue",lwd=4)
> 
> ##END CODE
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Table Construction from calculations

2007-03-09 Thread Christos Hatzis
Your "data table" basis is actually a dataframe, whose first column is
non-numeric.  That's what is causing the problem.
 
Try removing the first column of the dataframe before adding the row to your
matrix:

test <- latpoints + basis[2, -1]

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Seth Imhoff
> Sent: Friday, March 09, 2007 9:23 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Table Construction from calculations
> 
> Hi-
> 
> I am trying to create a table of values by adding  pairs of 
> vectors, but am running into some problems.  The problem is 
> best expressed by a simple example.
> 
> Starting with a data table "basis":
>   atom   x   y   z
> 1   Cu 0.0 0.0 0.0
> 2   Cu 0.5 0.5 0.5
> 
> I want to add 0.5 0.5 0.5  (and also the 0 0 0 but it 
> wouldn't change the values below so I won't refer to it in 
> the rest of the example) to a list of vectors in the form of:
>  > latpoints
>V1 V2 V3
> 1   0  0  0
> 2   0  0  1
> 3   0  0  2
> 4   0  0  3
> 5   0  1  1
> 
> so that I end up with a table such as:
> V1  V2  V3
> 0.5 0.5 0.5
> 0.5 0.5 1.5
> 0.5 0.5 2.5
> 0.5 0.5 3.5
> 0.5 1.5 1.5
> 
> I've tried many variations on the following: (not just cat, 
> but most of the data/data.table options)
> 
>  test = for(i in 1:5) {cat(basis[1,2:4] + 
> latticemultipliers[i,], append=TRUE)}
> 
> However, I either end up with an error telling me that cat 
> doesn't handle "type 'list' " or with a table with length of 
> 1 such as:
>  xyz
> 2  0.5 1.5 1.5
> 
> Which is simply the last value that the loop calculates.
> 
> Does anyone know what function handles lists of the form I am 
> using, or have a better suggestion on how to get the form that I want.
> 
> Thanks in advance,
> Seth Imhoff
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Duplicate rows of matrix

2007-03-09 Thread Christos Hatzis
Try this:

a <- matrix(c(8, 4.2, 9.4, 1.1),2) 
b <- c(3,1)

a[rep(1:nrow(a), b), ] 

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Bruno C.
> Sent: Friday, March 09, 2007 12:17 PM
> To: r-help
> Subject: [R] Duplicate rows of matrix
> 
> Hello my problem is the following:
> 
> I have a matrix A and a vector B which contains as many rows as A.
> 
> I need to build a matrix C which contains B[i]-times the row 
> A[i,] and this for each line of A.
> 
> if for example A is
> 
> [1][2]
> [1]  8  9.4
> [2]  4.21.1
> 
> and B is (3,1). Then C will be:
> [1][2]
> [1]  8  9.4
> [2]  8  9.4
> [3]  8  9.4
> [4]  4.21.1
> 
> 
> I have some working code which go through all the lines of A 
> and for each line does a rbind(C, A[i,]) B[i]-times But this 
> is quite time consuming given that each rbind rebuild a new 
> matrix ... is there any faster way?
> I can think of some minor improvements like building a matrix 
> C of zeros, containing as many columns as A and as many 
> columns as the sum of elements of B ... and the filing it.
> 
> But I was more looking for some already implemented 
> function/package, is there any?
> 
> Thanx
> 
> 
> 
> --
> Leggi GRATIS le tue mail con il telefonino i-modeT di Wind 
> http://i-mode.wind.it
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Matrix conversion question

2007-03-09 Thread Christos Hatzis
Try

split(x, row(x)) 

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Johannes Graumann
> Sent: Friday, March 09, 2007 10:30 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Matrix conversion question
> 
> Hello,
> 
> Please help - I'm blanking on this ...
> 
> I have a matrix like this:
> 
>  [,1] [,2]
> [1,]12
> [2,]13
> [3,]23
> 
> and would like to have a list of vectors, where a vector 
> contains the entries in a matrix row ...
> 
> Can somebody nudge me to the place I need to go?
> 
> Thanks, Joh
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] understanding print.summary.lm and perhaps print/show in general

2007-03-09 Thread Christos Hatzis
Paul,

Usually summary methods perform some computations if needed and then change
the class of the original object so that a print method can be called for
the new summary object.

In this case, this is done at the end of the summary.lm method:

...
if (!is.null(z$na.action)) 
ans$na.action <- z$na.action
class(ans) <- "summary.lm"
^^
ans
}

So then print.summary.lm does all the job displaying the summary.lm object.
To see that function do

getAnywhere(print.summary.lm)

Then you can then modify that function as needed.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Paul Bailey
> Sent: Friday, March 09, 2007 9:34 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] understanding print.summary.lm and perhaps 
> print/show in general
> 
> I'm trying to understand how R prints summary.lm objects and 
> trying to change it slightly for a summary function that 
> calculates standard errors using an alternative method.
> 
> I've found that I can modify a summary.lm object and then it 
> prints the modified way but I want to change a few things in 
> the print method that I think I might just be able to do. One 
> is that I want the coefficients table to print a different 
> header (other than "Std. Error"). I've tried changing the 
> column name of the summary$coef matrix and this works for 
> calls to printCoefmat but it still prints out "Std. Error"
> when I pass  the summary.lm to the command line by itself. I 
> don't understand this behavior. When I do this (enter an 
> object on the command line by itself), does it then calls the 
> print / show method associated with that objects class, in 
> this case, summary.lm? Below is some sample code to reproduce 
> the behavior I don't understand and a comment regarding the 
> result I don't understand.
> 
> Cheers,
> Paul
> 
> #
> lma <- lm(dist ~ speed, data=cars)
> suma <- summary(lma)
> colnames(suma$coef) <- c(LETTERS[1:4])
> printCoefmat(suma$coef) # prints what I expect suma # the 
> above is the print behavior question regards, # why does the 
> coefficients matrix have in its header # the usual "Estimate 
> Std. Error t value Pr(>|t|)"
> # I expect "A B C D" as above in the call to printCoefmat
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Memory Limits in Ubuntu Linux

2007-03-06 Thread Christos Hatzis
Take a look at Windows FAQ 2.9.  Following the instructions there, I was
able to make WinXP use at least 3GB of RAM (physical RAM installed) with
Rgui.exe.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> [EMAIL PROTECTED]
> Sent: Tuesday, March 06, 2007 3:44 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Memory Limits in Ubuntu Linux
> 
> I am an R user trying to get around the 2Gig memory limit in 
> Windows, so here I am days later with a working Ubuntu, and R 
> under Ubuntu. But - the memory problems seem worse than ever. 
> R code that worked under windows fails, unable to allocate memory.
> 
> Searching around the web, it appears that the problem may be 
> the ability to find contguous memory for my big vectors, but 
> a fresh boot of Ubuntu does not help either.
> 
> Which way to go?
> 
> 1) Try to install 64-bit version for bigger address space. 
> Would this help? Is this workable for my Athlon 64 Dual-core? 
> (the live cd seems to work but I never got it to boot after a 
> disk install, but then the 386 version was no better until I 
> learned more about Grub...I could try again if this might solve the
> problem)
> 
> 2) Recompile R to get bigger memory capability? (I'll have to 
> cross-post to some R forums too) This will be a challenge for 
> a Linux newbie...like me.
> 
> 3) Any other suggestions? My goal is to create a bigger 
> neural network than fits in my Windows R version.
> --
> David Katz
>  www.davidkatzconsulting.com
>541 482-1137
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 paste()

2007-03-03 Thread Christos Hatzis
What do you want to do with rbind?
paste produces a single vector of 24 character-valued elements.
If you want a column vector, you could do that by

x <- paste('txt.est',1:24, sep = '')
matrix(x, ncol=1)

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
  

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Michael Kubovy
> Sent: Saturday, March 03, 2007 2:30 PM
> To: r-help@stat.math.ethz.ch list
> Subject: [R] Help with paste()
> 
> Dear r-helpers,
> 
> Could you please tell me what's missing:
> rbind(paste('txt.est',1:24, sep = ''))
> txt.est1, ... txt.est24 are vectors that I wish to rbind.
> _
> Professor Michael Kubovy
> University of Virginia
> Department of Psychology
> USPS: P.O.Box 400400Charlottesville, VA 22904-4400
> Parcels:Room 102Gilmer Hall
>  McCormick RoadCharlottesville, VA 22903
> Office:B011+1-434-982-4729
> Lab:B019+1-434-982-4751
> Fax:+1-434-982-4766
> WWW:http://www.people.virginia.edu/~mk9y/
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Can a data.frame column contain lists/arrays?

2007-02-12 Thread Christos Hatzis
Why do you need to use a data frame?  A list will give you the flexibility
you want:

d <- list( x=list( c(1,2), c(5,2), c(9,1) ), y=c( 1, -1, -1) )

Then you can access the individual elements 

> d$x
[[1]]
[1] 1 2

[[2]]
[1] 5 2

[[3]]
[1] 9 1

> d$y
[1]  1 -1 -1

> d$x[[1]]
[1] 1 2
  
-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Christian Convey
> Sent: Monday, February 12, 2007 11:29 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Can a data.frame column contain lists/arrays?
> 
> I'd like to have a data.frame structured something like the following:
> 
> d <- data.frame (
>x=list( c(1,2), c(5,2), c(9,1) ),
>y=c( 1, -1, -1)
> )
> 
> The reason is this: 'd' is the training data for a machine 
> learning algorithm.  d$x is the independent data, and d$y is 
> the dependent data.
> 
> In general my machine learning code will work where each 
> element of d$x is a vector of one or more real numbers.  So 
> for instance, the same code should work when d$x[1] = 42, or 
> when d$x[1] = (42, 3, 5).
> All that matters is that all element within d$x are 
> lists/vectors of the same length.
> 
> Does anyone know if/how I can get a data.frame set up like that?
> 
> Thanks,
> Christian
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] blank upper or lower triangle of cor-matrix

2007-02-07 Thread Christos Hatzis
And if you want to know how it is done, take a look at 

stats:::print.dist

-Christos 

> -Original Message-
> From: Christos Hatzis [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, February 07, 2007 2:16 PM
> To: 'Leo Gürtler'; 'r-help@stat.math.ethz.ch'
> Subject: RE: [R] blank upper or lower triangle of cor-matrix
> 
> You can try
> 
> as.dist(d)
> 
> 
> Christos Hatzis, Ph.D.
> Nuvera Biosciences, Inc.
> 400 West Cummings Park
> Suite 5350
> Woburn, MA 01801
> Tel: 781-938-3830
> www.nuverabio.com
>  
>  
> 
> > -Original Message-
> > From: [EMAIL PROTECTED] 
> > [mailto:[EMAIL PROTECTED] On Behalf Of Leo Gürtler
> > Sent: Wednesday, February 07, 2007 1:36 PM
> > To: r-help@stat.math.ethz.ch
> > Subject: [R] blank upper or lower triangle of cor-matrix
> > 
> > Dear altogether,
> > 
> > I want to blank the lower (or upper) part of a correlation 
> matrix as 
> > it is done by dist()
> > 
> > example:
> > 
> > ( d <- cor(matrix(runif(12),nrow=4)) )
> > 
> > If I do the following
> > 
> > d[lower.tri(d)] <- ""
> > 
> > of course everything is changed to character - that's not 
> what should 
> > be.
> > Additionally, it does not work to assign "0" or anything else. The 
> > same is true for assigning "NA".
> > 
> > However, what I want is like the following:
> > 
> > ( dist(matrix(runif(12),nrow=4)) )
> > 
> > Looking into dist(), it seems that the calculation and the 
> matrix are 
> > done in C and not in plain R.
> > 
> > How can I realize it?
> > 
> > thanks!
> > 
> > best,
> > 
> > leo
> > 
> > __
> > R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] blank upper or lower triangle of cor-matrix

2007-02-07 Thread Christos Hatzis
You can try

as.dist(d)


Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Leo Gürtler
> Sent: Wednesday, February 07, 2007 1:36 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] blank upper or lower triangle of cor-matrix
> 
> Dear altogether,
> 
> I want to blank the lower (or upper) part of a correlation 
> matrix as it is done by dist()
> 
> example:
> 
> ( d <- cor(matrix(runif(12),nrow=4)) )
> 
> If I do the following
> 
> d[lower.tri(d)] <- ""
> 
> of course everything is changed to character - that's not 
> what should be.
> Additionally, it does not work to assign "0" or anything 
> else. The same is true for assigning "NA".
> 
> However, what I want is like the following:
> 
> ( dist(matrix(runif(12),nrow=4)) )
> 
> Looking into dist(), it seems that the calculation and the 
> matrix are done in C and not in plain R.
> 
> How can I realize it?
> 
> thanks!
> 
> best,
> 
> leo
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Adding Histograms to Leaves of Rpart Tree or other Dendrogram

2007-02-02 Thread Christos Hatzis
Hi Jon,

Take a look at this graph

http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=85

I think it is very close to what you need (source code provided at the
site).

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
  

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Jonathan Zelner
> Sent: Friday, February 02, 2007 5:07 PM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Adding Histograms to Leaves of Rpart Tree or 
> other Dendrogram
> 
> Hi - I'm trying to append simple density histograms of a 
> continuous variable to the leaves of an rpart tree.
> 
> The splits in the tree are all levels of a factor and I'm 
> hoping to make the histograms out of the subsets of the 
> dataframe corresponding to the splits and for them to be 
> attached to the appropriate leaf of the final tree.
> 
> Any help would be much appreciated,
> thanks,
> Jon Zelner
> 
> University of Michigan
> Gerald R. Ford School of Public Policy
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Lining up x-y datasets based on values of x

2007-02-01 Thread Christos Hatzis
Marc,

The data structure is a list of data frames generated from read.table:

> class(nmr.spectra.serum)
[1] "list"
> class(nmr.spectra.serum[[1]])
[1] "data.frame" 
> dim(nmr.spectra.serum[[1]])
[1] 32768 2

Converting the data.frames to matrices does not have much of an effect on
timing.

-Christos

-Original Message-
From: Marc Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 01, 2007 11:06 PM
To: [EMAIL PROTECTED]
Cc: 'Prof Brian Ripley'; r-help@stat.math.ethz.ch
Subject: Re: [R] Lining up x-y datasets based on values of x

On Thu, 2007-02-01 at 22:46 -0500, Christos Hatzis wrote:
> Marc,
> 
> I don't think the issue is duplicates in the matching columns.  The 
> data were generated by an instrument (NMR spectrometer), processed by 
> the instrument's software through an FFT transform and other 
> transformations and finally reported as a sequence of chemical shift (x)
vs intensity (y) pairs.
> So all x values are unique.  For the example that I reported earlier:
> 
> > length(nmr.spectra.serum[[1]]$V1)
> [1] 32768
> > length(unique(nmr.spectra.serum[[1]]$V1))
> [1] 32768
> > length(nmr.spectra.serum[[2]]$V1)
> [1] 32768
> > length(unique(nmr.spectra.serum[[2]]$V1))
> [1] 32768
> 
> And most of the x-values are common
> > sum(nmr.spectra.serum[[1]]$V1 %in% nmr.spectra.serum[[2]]$V1)
> [1] 32625
> 
> For this reason, merge is probably an overkill for this problem and my 
> initial thought was to align the datasets through some simple 
> index-shifting operation.
> 
> Profiling of the merge code in my case shows that most of the time is 
> spent on data frame subsetting operations and on internal merge and 
> rbind calls secondarily (if I read the summary output correctly).  So 
> even if most of the time in the internal merge function is spent on 
> sorting (haven't checked the source code), this is in the worst case a 
> rather minor effect, as suggested by Prof. Ripley.
>   
> > Rprof("merge.out")
> > zz <- merge(nmr.spectra.serum[[1]], nmr.spectra.serum[[2]], by="V1",
> all=T, sort=T)
> > Rprof(NULL)
> > summaryRprof("merge.out")
> 
> $by.self
>self.time self.pct total.time total.pct
> merge.data.frame6.56 50.0  11.84  90.2
> [.data.frame2.42 18.4   3.68  28.0
> merge   1.28  9.8  13.12 100.0
> rbind   1.24  9.5   1.36  10.4
> names<-.default 1.16  8.8   1.16   8.8
> row.names<-.data.frame  0.12  0.9   0.18   1.4
> duplicated.default  0.12  0.9   0.12   0.9
> make.unique 0.10  0.8   0.10   0.8
> data.frame  0.02  0.2   0.04   0.3
> *   0.02  0.2   0.02   0.2
> is.na   0.02  0.2   0.02   0.2
> match   0.02  0.2   0.02   0.2
> order   0.02  0.2   0.02   0.2
> unclass 0.02  0.2   0.02   0.2
> [   0.00  0.0   3.68  28.0
> do.call 0.00  0.0   1.18   9.0
> names<- 0.00  0.0   1.16   8.8
> row.names<- 0.00  0.0   0.18   1.4
> any 0.00  0.0   0.14   1.1
> duplicated  0.00  0.0   0.12   0.9
> cbind   0.00  0.0   0.04   0.3
> as.vector   0.00  0.0   0.02   0.2
> seq 0.00  0.0   0.02   0.2
> seq.default 0.00  0.0   0.02   0.2
> 
> $by.total
>total.time total.pct self.time self.pct
> merge   13.12 100.0  1.28  9.8
> merge.data.frame11.84  90.2  6.56 50.0
> [.data.frame 3.68  28.0  2.42 18.4
> [3.68  28.0  0.00  0.0
> rbind1.36  10.4  1.24  9.5
> do.call  1.18   9.0  0.00  0.0
> names<-.default  1.16   8.8  1.16  8.8
> names<-  1.16   8.8  0.00  0.0
> row.names<-.data.frame   0.18   1.4  0.12  0.9
> row.names<-  0.18   1.4  0.00  0.0
> any  0.14   1.1  0.00  0.0
> duplicated.default   0.12   0.9  0.12  0.9
> duplicated   

Re: [R] Lining up x-y datasets based on values of x

2007-02-01 Thread Christos Hatzis
Thanks Gabor.

This is along the lines of what I was looking for.  In fact the merge
function for zoo objects (ordered) turns out to be almost an order of
magnitude faster than the generic merge function for my problem:

> system.time(
+ zz <- merge( spec.1 = zoo(nmr.spectra.serum[[1]]$V2,
nmr.spectra.serum[[1]]$V1),
+spec.2 = zoo(nmr.spectra.serum[[2]]$V2, nmr.spectra.serum[[2]]$V1),
fill=NA )
+ )
[1] 0.74 0.07 0.82   NA   NA
> system.time(
+ ww <- merge(nmr.spectra.serum[[1]], nmr.spectra.serum[[2]], by="V1",
all=T, sort=T)
+ )
[1] 6.85 0.05 6.94   NA   NA
> head(zz)
spec.1 spec.2
-1322.2 -0.651 NA
-1321.9 -0.266 NA
-1321.7 -0.962 NA
-1321.4 -0.602 NA
-1321.2  0.753 NA
-1320.9  1.212 NA
> head(ww)
   V1   V2.x V2.y
1 -1322.2 -0.651   NA
2 -1321.9 -0.266   NA
3 -1321.7 -0.962   NA
4 -1321.4 -0.602   NA
5 -1321.2  0.753   NA
6 -1320.9  1.212   NA
> 

Thanks again.
-Christos 

-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 01, 2007 7:25 PM
To: [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Lining up x-y datasets based on values of x

The zoo package has a multiway merge with optional zero fill.
Here are two ways:

library(zoo)
merge(x = zoo(x[,2], x[,1]),
  y = zoo(y[,2], y[,1]),
  z = zoo(z[,2], z[,1]),
  fill = 0)

# or

library(zoo)
X <- list(x = x, y = y, z = z)
merge0 <- function(..., fill = 0) merge(..., fill = fill) do.call("merge0",
lapply(X, function(x) zoo(x[,2], x[,1])))

To get more info on zoo try:

vignette("zoo")

On 2/1/07, Christos Hatzis <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I was wondering if there is a direct approach for lining up 2-column 
> matrices according to the values of the first column.  An example and 
> a brute-force approach is given below:
>
> x <- cbind(1:10, runif(10))
> y <- cbind(5:14, runif(10))
> z <- cbind((-4):5, runif(10))
>
> xx <- seq( min(c(x[,1],y[,1],z[,1])), max(c(x[,1],y[,1],z[,1])), 1) w 
> <- cbind(xx, matrix(rep(0, 3*length(xx)), ncol=3))
>
> w[ xx >= x[1,1] & xx <= x[10,1], 2 ] <- x[,2] w[ xx >= y[1,1] & xx <= 
> y[10,1], 3 ] <- y[,2] w[ xx >= z[1,1] & xx <= z[10,1], 4 ] <- z[,2]
>
> w
>
> I appreciate any pointers.
>
> Thanks.
>
> Christos Hatzis, Ph.D.
> Nuvera Biosciences, Inc.
> 400 West Cummings Park
> Suite 5350
> Woburn, MA 01801
> Tel: 781-938-3830
> www.nuverabio.com
>
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Lining up x-y datasets based on values of x

2007-02-01 Thread Christos Hatzis
Marc,

I don't think the issue is duplicates in the matching columns.  The data
were generated by an instrument (NMR spectrometer), processed by the
instrument's software through an FFT transform and other transformations and
finally reported as a sequence of chemical shift (x) vs intensity (y) pairs.
So all x values are unique.  For the example that I reported earlier:

> length(nmr.spectra.serum[[1]]$V1)
[1] 32768
> length(unique(nmr.spectra.serum[[1]]$V1))
[1] 32768
> length(nmr.spectra.serum[[2]]$V1)
[1] 32768
> length(unique(nmr.spectra.serum[[2]]$V1))
[1] 32768

And most of the x-values are common
> sum(nmr.spectra.serum[[1]]$V1 %in% nmr.spectra.serum[[2]]$V1)
[1] 32625

For this reason, merge is probably an overkill for this problem and my
initial thought was to align the datasets through some simple index-shifting
operation. 

Profiling of the merge code in my case shows that most of the time is spent
on data frame subsetting operations and on internal merge and rbind calls
secondarily (if I read the summary output correctly).  So even if most of
the time in the internal merge function is spent on sorting (haven't checked
the source code), this is in the worst case a rather minor effect, as
suggested by Prof. Ripley.
  
> Rprof("merge.out")
> zz <- merge(nmr.spectra.serum[[1]], nmr.spectra.serum[[2]], by="V1",
all=T, sort=T)
> Rprof(NULL)
> summaryRprof("merge.out")

$by.self
   self.time self.pct total.time total.pct
merge.data.frame6.56 50.0  11.84  90.2
[.data.frame2.42 18.4   3.68  28.0
merge   1.28  9.8  13.12 100.0
rbind   1.24  9.5   1.36  10.4
names<-.default 1.16  8.8   1.16   8.8
row.names<-.data.frame  0.12  0.9   0.18   1.4
duplicated.default  0.12  0.9   0.12   0.9
make.unique 0.10  0.8   0.10   0.8
data.frame  0.02  0.2   0.04   0.3
*   0.02  0.2   0.02   0.2
is.na   0.02  0.2   0.02   0.2
match   0.02  0.2   0.02   0.2
order   0.02  0.2   0.02   0.2
unclass 0.02  0.2   0.02   0.2
[   0.00  0.0   3.68  28.0
do.call 0.00  0.0   1.18   9.0
names<- 0.00  0.0   1.16   8.8
row.names<- 0.00  0.0   0.18   1.4
any 0.00  0.0   0.14   1.1
duplicated  0.00  0.0   0.12   0.9
cbind   0.00  0.0   0.04   0.3
as.vector   0.00  0.0   0.02   0.2
seq 0.00  0.0   0.02   0.2
seq.default 0.00  0.0   0.02   0.2

$by.total
   total.time total.pct self.time self.pct
merge   13.12 100.0  1.28  9.8
merge.data.frame11.84  90.2  6.56 50.0
[.data.frame 3.68  28.0  2.42 18.4
[3.68  28.0  0.00  0.0
rbind1.36  10.4  1.24  9.5
do.call  1.18   9.0  0.00  0.0
names<-.default  1.16   8.8  1.16  8.8
names<-  1.16   8.8  0.00  0.0
row.names<-.data.frame   0.18   1.4  0.12  0.9
row.names<-  0.18   1.4  0.00  0.0
any  0.14   1.1  0.00  0.0
duplicated.default   0.12   0.9  0.12  0.9
duplicated   0.12   0.9  0.00  0.0
make.unique  0.10   0.8  0.10  0.8
data.frame   0.04   0.3  0.02  0.2
cbind0.04   0.3  0.00  0.0
*0.02   0.2  0.02  0.2
is.na0.02   0.2  0.02  0.2
match0.02   0.2  0.02  0.2
order0.02   0.2  0.02  0.2
unclass  0.02   0.2  0.02  0.2
as.vector0.02   0.2  0.00  0.0
seq  0.02   0.2  0.00  0.0
seq.default  0.02   0.2  0.00  0.0

$sampling.time
[1] 13.12


Thanks again for your time in looking into this.
-Christos

-Original Message-
From: Marc Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 01, 2007 9:59 PM
To: Prof Brian 

Ripley
Cc: r-help@stat.math.ethz.ch; [EMAIL PROTECTED]
Subject: Re: [R] Lining up x-y datasets based on values of x

On Thu, 2007-02-01 at 23:34 +, Prof Brian Ripley wrote:
> On Thu, 1 Feb 2007, Marc Schwar

Re: [R] Lining up x-y datasets based on values of x

2007-02-01 Thread Christos Hatzis
[Sorry I meant to reply to the list]

Thanks, Marc.

That's what I have done.
However, there seems to be a penalty from using merge repeatedly as it
appears to internally re-sort the datasets.  In my case the datasets are
long (~35K rows) and already sorted so this step adds considerable and
unnecessary overhead.  There doesn't seem to be an option for disabling
sorting. Setting 'sort=F' only affects sorting of the final data.frame.

> system.time(merge(nmr.spectra.serum[[1]], nmr.spectra.serum[[2]], 
> by="V1", all=T, sort=T))
[1] 6.96 0.00 7.24   NA   NA
> system.time(merge(nmr.spectra.serum[[1]], nmr.spectra.serum[[2]], 
> by="V1", all=T, sort=F))
[1] 6.82 0.00 7.14   NA   NA
> 

I was wondering if perhaps there is a parallel between this problem and
methods for linining up time-series data, since such data are also usually
sorted on the time dimension. 

-Christos  

-Original Message-
From: Marc Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 01, 2007 4:21 PM
To: [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Lining up x-y datasets based on values of x

On Thu, 2007-02-01 at 15:45 -0500, Christos Hatzis wrote:
> Thanks Marc and Phil.
> 
> My dataset actually consists of 50+ individual files, so I will have 
> to do this one column at a time in a loop...
> I might look into SQL and outer joints as an alternative to avoid looping.
> 
> Thanks again.
> -Christos

If the files conform to some naming convention and/or are all located in a
common sub-directory, you can use list.files() to get the file names into a
vector.  If not, you could use file.choose() interactively.

Then use either a for() loop or sapply() to loop over the filenames, read
them in to data frames using read.table() and merge them together in the
same loop.

When it comes to basic data manipulation like this, loops are not a bad
thing. The overhead of a loop is typically outweighed by the file I/O and
related considerations.

HTH,

Marc

__
R-help@stat.math.ethz.ch 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] Lining up x-y datasets based on values of x

2007-02-01 Thread Christos Hatzis
Thanks Marc and Phil.

My dataset actually consists of 50+ individual files, so I will have to do
this one column at a time in a loop...
I might look into SQL and outer joints as an alternative to avoid looping.

Thanks again.
-Christos 

-Original Message-
From: Marc Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 01, 2007 3:29 PM
To: [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Lining up x-y datasets based on values of x

On Thu, 2007-02-01 at 15:05 -0500, Christos Hatzis wrote:
> Hi,
> 
> I was wondering if there is a direct approach for lining up 2-column 
> matrices according to the values of the first column.  An example and 
> a brute-force approach is given below:
> 
> x <- cbind(1:10, runif(10))
> y <- cbind(5:14, runif(10))
> z <- cbind((-4):5, runif(10))
> 
> xx <- seq( min(c(x[,1],y[,1],z[,1])), max(c(x[,1],y[,1],z[,1])), 1) w 
> <- cbind(xx, matrix(rep(0, 3*length(xx)), ncol=3))
> 
> w[ xx >= x[1,1] & xx <= x[10,1], 2 ] <- x[,2] w[ xx >= y[1,1] & xx <= 
> y[10,1], 3 ] <- y[,2] w[ xx >= z[1,1] & xx <= z[10,1], 4 ] <- z[,2]
> 
> w
> 
> I appreciate any pointers.
> 
> Thanks.

How about this:

x <- cbind(1:10, runif(10))
y <- cbind(5:14, runif(10))
z <- cbind((-4):5, runif(10))

colnames(x) <- c("X", "Y")
colnames(y) <- c("X", "Y")
colnames(z) <- c("X", "Y")

xy <- merge(x, y, by = "X", all = TRUE)
xyz <- merge(xy, z, by = "X", all = TRUE)

xyz[is.na(xyz)] <- 0

> xyz
X   Y.x   Y.y Y
1  -4 0.000 0.000 0.3969099
2  -3 0.000 0.000 0.8943127
3  -2 0.000 0.000 0.4882819
4  -1 0.000 0.000 0.0275787
5   0 0.000 0.000 0.7562341
6   1 0.6873130 0.000 0.6185218
7   2 0.1930880 0.000 0.2318025
8   3 0.1164783 0.000 0.7336057
9   4 0.7408532 0.000 0.3006347
10  5 0.7112887 0.6383823 0.8515126
11  6 0.2719079 0.5952721 0.000
12  7 0.2067017 0.8178048 0.000
13  8 0.2085043 0.5714917 0.000
14  9 0.2251435 0.4032660 0.000
15 10 0.3471888 0.5247478 0.000
16 11 0.000 0.6899197 0.000
17 12 0.000 0.7188912 0.000
18 13 0.000 0.9133252 0.000
19 14 0.000 0.9186001 0.000

Note that 'xyz' will be a data frame, so just use as.matrix(xyz) to coerce
back to a numeric matrix if needed.

See ?merge

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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] Lining up x-y datasets based on values of x

2007-02-01 Thread Christos Hatzis
Hi,

I was wondering if there is a direct approach for lining up 2-column
matrices according to the values of the first column.  An example and a
brute-force approach is given below:

x <- cbind(1:10, runif(10))
y <- cbind(5:14, runif(10))
z <- cbind((-4):5, runif(10))

xx <- seq( min(c(x[,1],y[,1],z[,1])), max(c(x[,1],y[,1],z[,1])), 1)
w <- cbind(xx, matrix(rep(0, 3*length(xx)), ncol=3)) 

w[ xx >= x[1,1] & xx <= x[10,1], 2 ] <- x[,2]
w[ xx >= y[1,1] & xx <= y[10,1], 3 ] <- y[,2]
w[ xx >= z[1,1] & xx <= z[10,1], 4 ] <- z[,2]

w 

I appreciate any pointers.

Thanks.
 
Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com

__
R-help@stat.math.ethz.ch 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] Loading functions in R

2007-01-31 Thread Christos Hatzis
The recommended approach is to make a package for your functions that will
include documentation, error checks etc.
Another way to accomplish what you want is to start a new R session and
'source' your .R files and then to save the workspace in a .RData file, e.g.
myFunctions.RData.

Finally

attach(myFunctions.RData)  

should do the trick without cluttering your workspace.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Forest Floor
Sent: Wednesday, January 31, 2007 10:41 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Loading functions in R

Hi all,

This information must be out there, but I can't seem to find it.  What I
want to do is to store functions I've created (as .R files or in whatever
form) and then load them when I need them (or on startup) so that I can
access without cluttering my program with the function code.  
This seems like it should be easy, but

Thanks!

Jeff

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Matrix operations in a list

2007-01-23 Thread Christos Hatzis
Try,

mapply('%*%', a, b, SIMPLIFY=FALSE)

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Doran, Harold
Sent: Tuesday, January 23, 2007 10:22 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Matrix operations in a list

I have matrices stored within a list like something as follows:

a <- list(matrix(rnorm(50), ncol=5), matrix(rnorm(50), ncol=5)) b <-
list(matrix(rnorm(50), nrow=5), matrix(rnorm(50), nrow=5))

I don't recall how to perform matrix multiplication on each list element
such that the result is a new list 

result <- list(a[[1]]%*%b[[1]], a[[2]]%*%b[[2]])

I think I'm close with mapply(), but I'm doing something silly

mapply('%*%', a,b)

Thanks.
Harold


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] comparing two matrices

2007-01-20 Thread Christos Hatzis
Here is a slightly more compact version of your function which might run
faster (I did not test timings) since it does not use the sum:

apply(mat2, 1, function(x) which(apply(mat1, 1, function(y) all(x == y)) ==
TRUE))

-Christos
 
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Adrian Dusa
Sent: Saturday, January 20, 2007 5:15 PM
To: r-help@stat.math.ethz.ch
Subject: [R] comparing two matrices


Dear helpeRs,

I have two matrices:
mat1 <- expand.grid(0:2, 0:2, 0:2)
mat2 <- aa[c(19, 16, 13, 24, 8), ]

where mat2 is always a subset of mat1

I need to find the corersponding row numbers in mat1 for each row in mat2.
For this I have the following code:

apply(mat2, 1, function(x) {
which(apply(mat1, 1, function(y) {
sum(x == y)
}) == ncol(mat1))
})

The code is vectorized, but I wonder if there is a simpler (hence faster)
matrix computation that I miss.

Thank you,
Adrian


--
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd
050025 Bucharest sector 5
Romania
Tel./Fax: +40 21 3126618 \
  +40 21 3120210 / int.101

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] simple q: returning a logical vector of substring matches

2007-01-20 Thread Christos Hatzis
You can try the following:

 a == grep("ear", a, value=T)

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Saturday, January 20, 2007 1:31 PM
To: r-help@stat.math.ethz.ch
Subject: [R] simple q: returning a logical vector of substring matches

I'm a relative R novice, and sometimes the simple things trip me up.

Suppose I have

a <- c("apple", "pear")

and I want a logical vector of whether each of these strings contains "ear"
(in this case, F T). What is the idiom?

Quizzically,
Mark Lindeman

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 get the index of entry with max value in an array?

2007-01-17 Thread Christos Hatzis
Or
which.max(a)

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of talepanda
Sent: Wednesday, January 17, 2007 11:45 PM
To: Feng Qiu
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] how to get the index of entry with max value in an array?

In R language, one solution is:

a<-c(3,4,6,2,3)
which(a==max(a))


On 1/18/07, Feng Qiu <[EMAIL PROTECTED]> wrote:
> Hi all:
>  A short question:
>  For example,  a=[3,4,6,2,3], obviously the 3rd entry of the 
> array has the maxium value, what I want is index of the maxium value: 
> 3. is there a neat expression to get this index?
>
> Thank you!
>
> Best,
>
> Feng
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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 vectorization question

2007-01-09 Thread Christos Hatzis

That's true.  Just need to negate the difference.  Actually, straight diff
can be used after reversing the vector:

apply(mat, 1, function(x) diff(sort(x, decreasing = TRUE)[2:1]))

I only have 3 columns in my matrix so sorting should not add much overhead,
but I will time both versions.

Thanks again.
-Christos 

-Original Message-
From: Marc Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 09, 2007 5:07 PM
To: [EMAIL PROTECTED]
Cc: 'R-help'
Subject: RE: [R] A vectorization question

Welcome Christos.

Note that my first example can actually be simplified to:

  apply(mat, 1, function(x) -diff(sort(x, decreasing = TRUE)[1:2]))

Since we really just need to negate the difference, rather than take the
abs().

The advantage of this approach is that the two max values will always be the
first and second values, so will be independent of the length of 'x' (number
of columns in the matrix).

Using the second example more generally, you would have to use something
like:

  apply(mat, 1, function(x) diff(sort(x)[-c(1:(length(x) - 2))]))

in the subsetting of the sort() results or precalcuate the indices (ie.
ncol(mat) and ncol(mat) - 1).

Might add a bit more overhead, but testing would give you more empiric
timing data. That might have to be balanced by whether the rows tend to be
random in order or closer to being sorted in increasing/decreasing order,
which would affect the sort time. Worst case scenario is generally having to
reverse the sort order. Of course, if the matrices are "relatively" small,
sorting time would likely be a non-issue.

HTH,

Marc

On Tue, 2007-01-09 at 16:39 -0500, Christos Hatzis wrote:
> Thanks, Marc.
> This is what I was trying to do but could not get it to work.
> 
> -Christos



__
R-help@stat.math.ethz.ch 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 vectorization question

2007-01-09 Thread Christos Hatzis
Thanks, Marc.
This is what I was trying to do but could not get it to work.

-Christos 

-Original Message-
From: Marc Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 09, 2007 4:32 PM
To: [EMAIL PROTECTED]
Cc: 'R-help'
Subject: Re: [R] A vectorization question

On Tue, 2007-01-09 at 16:10 -0500, Christos Hatzis wrote:
> Hi,
>  
> A function calculates the absolute difference between the two largest 
> values of each row of a matrix, as shown in the following example code:
>  
> cx <- matrix(runif(15),5)
> cy <- t( apply(cx, 1, order, decreasing=TRUE) )
>  
> cz <- rep(0, nrow(cx))
> for( i in 1:nrow(cx) ) cz[i] <- abs(diff(cx[i, cy[i,1:2]]))
>  
> Anybody has any ideas on how the last loop can be vectorized?
> 
> Thanks. 


How about this:

> mat <- matrix(sample(1:50, 12), ncol = 4)

> mat
 [,1] [,2] [,3] [,4]
[1,]   391   22   11
[2,]   34   28   13   48
[3,]   25   40   383


> apply(mat, 1, function(x) abs(diff(sort(x, decreasing = TRUE)[1:2])))
[1] 17 14  2

Or

> apply(mat, 1, function(x) diff(sort(x)[3:4]))
[1] 17 14  2

HTH,

Marc Schwartz

__
R-help@stat.math.ethz.ch 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 vectorization question

2007-01-09 Thread Christos Hatzis
Hi,
 
A function calculates the absolute difference between the two largest values
of each row of a matrix, as shown in the following example code:
 
cx <- matrix(runif(15),5)
cy <- t( apply(cx, 1, order, decreasing=TRUE) )
 
cz <- rep(0, nrow(cx))
for( i in 1:nrow(cx) ) cz[i] <- abs(diff(cx[i, cy[i,1:2]]))
 
Anybody has any ideas on how the last loop can be vectorized?

Thanks. 
 
Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com <http://www.nuverabio.com/>

__
R-help@stat.math.ethz.ch 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] vectorizing an iterative process.

2006-12-26 Thread Christos Hatzis
In your case, the recurrence relationship for x can be solved easily:
Notice that 

sum{i=1,n}(x[i]-x[i-1]) = x[n] - x[0] 

and therefore

x[n] = x[0] + sum{i=1,n}(y[i-1] for n=1, N, with the appropriate initial
condition for i=0, (x[0],y[0]).

Thus cumsum on y will give you a direct answer.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
  

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Zhu
Sent: Tuesday, December 26, 2006 11:06 AM
To: r-help@stat.math.ethz.ch
Subject: Re: [R] vectorizing an iterative process.

I meant  x[i] <- x[i-1] + y[i-1] and Y[i] <- y[i-1] + x[i] below.

The mailing list software just keep adding 3D's. Sorry. 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Geoffrey Zhu
Sent: Tuesday, December 26, 2006 10:03 AM
To: Richard M. Heiberger; r-help@stat.math.ethz.ch
Subject: Re: [R] vectorizing an iterative process.

Hi Richard,

3D is automatically generated by the mailing list software, probably because
I had ] followed by =3D3D without a space in the original post. 

What I meant was to calculate x[i] =3D3D x[i-1] + y[i-1] 

For example, if X <- 1:10

Then I want the vector Y to be 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, or in
other words Y[i] =3D3D y[i-1] + x[i]. 

Yes, cumsum does the trick for this. This is what I need. Thanks.

Just curious, do you know how to calculate the more generic x[i] <- f(
x[i-1], y[i-1] )?

Thanks,
Geoffrey



-Original Message-
From: Richard M. Heiberger [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 26, 2006 9:56 AM
To: Geoffrey Zhu; r-help@stat.math.ethz.ch
Subject: Re: [R] vectorizing an iterative process.

> x[i]=3D3D3Dx[i-1]+y[i-1] for all i, how can I do this without a loop? 

It looks like
   x <- cumsum(y)

What does 3D mean?



___=3D0A=3D
=3D0A=3D
=3D0A=3D
The information in this email or in any file attached hereto is=3D0A=3D
intended only for the personal and confidential use of the
individual=3D0A=3D or entity to which it is addressed and may contain
information that is=3D0A=3D proprietary and confidential. If you are not the
intended recipient of=3D0A=3D this message you are hereby notified that any
review, dissemination,=3D0A=3D distribution or copying of this message is
strictly prohibited. This communi=3D cation is for information purposes only
and should not be regarded as an off=3D er to sell or as a solicitation of
an offer to buy any financial product. Em=3D ail transmission cannot be
guaranteed to be secure or error-free.

__
R-help@stat.math.ethz.ch 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.



___=0A=
=0A=
=0A=
The information in this email or in any file attached hereto is=0A= intended
only for the personal and confidential use of the individual=0A= or entity
to which it is addressed and may contain information that is=0A= proprietary
and confidential. If you are not the intended recipient of=0A= this message
you are hereby notified that any review, dissemination,=0A= distribution or
copying of this message is strictly prohibited. This communi= cation is for
information purposes only and should not be regarded as an off= er to sell
or as a solicitation of an offer to buy any financial product. Em= ail
transmission cannot be guaranteed to be secure or error-free.

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 'get' an object that is part of a list

2006-12-25 Thread Christos Hatzis
True.  Thanks again. 

-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 25, 2006 8:34 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [R] how to 'get' an object that is part of a list

my.length.2 also has the advantage of eliminating the eval.

On 12/25/06, Christos Hatzis <[EMAIL PROTECTED]> wrote:
> Thank you Gabor.  Very interesting solution.
> If I get it right, the first argument in function f is just a 
> placeholder to help extract the right element out of the list(...) 
> that is passed to length.  Very smart trick.
>
> Jim's solution appears a bit simpler, at least along the lines that I 
> was
> thinking:
>
> my.length <- function(...) {
>names <- as.character(substitute(list(...)))[-1]
>sapply(names, function(x){y <- eval(parse(text=x)); length(y)}) 
> }
>
> -Christos
>
> -Original Message-
> From: Gabor Grothendieck [mailto:[EMAIL PROTECTED]
> Sent: Sunday, December 24, 2006 7:41 AM
> To: jim holtman
> Cc: [EMAIL PROTECTED];
> Subject: Re: [R] how to 'get' an object that is part of a list
>
> Is this what you are looking for:
>
> > my.length.2 <- function(...) {
> +f <- function(nm, val) length(val)
> +mapply(f, make.names(as.list(match.call()[-1])), list(...)) }
> > my.length.2(xx, xx$b)
>  xx xx.b
>   25
>
> On 12/24/06, jim holtman <[EMAIL PROTECTED]> wrote:
> > use 'eval' and 'parse'
> >
> >
> > > xx
> > $a
> > [1] 1 2 3 4 5
> >
> > $b
> > [1] "a" "b" "c" "d" "e"
> >
> > > eval(parse(text='xx$a'))
> > [1] 1 2 3 4 5
> > >
> >
> > So that way you can pass in the character string and then 'parse' it.
> >
> >
> >
> > On 12/24/06, Christos Hatzis <[EMAIL PROTECTED]> wrote:
> > >
> > > This might be an trivial thing but I am stuck.
> > >
> > > Consider:
> > >
> > > xx <- list(a=1:5, b=letters[1:5])
> > >
> > > Although object xx is accessible through its name, how can object 
> > > xx$b be accessed similarly through its name?
> > >
> > > > get("xx")
> > > $a
> > > [1] 1 2 3 4 5
> > >
> > > $b
> > > [1] "a" "b" "c" "d" "e"
> > >
> > > > get("xx$b")
> > > Error in get(x, envir, mode, inherits) : variable "xx$b" was not 
> > > found
> > >
> > > get("xx")$b will not work in my case because it will probably 
> > > require parsing to make it work within a function. E.g.
> > >
> > > my.length <- function(...) {
> > >names <- as.character(substitute(list(...)))[-1]
> > >sapply(names, FUN=function(x){y <- get(x); length(y)}) }
> > > > my.length(xx)
> > > xx
> > > 2
> > > > my.length(xx$a)
> > > Error in get(x, envir, mode, inherits) : variable "xx$a" was not 
> > > found
> > > > my.length(xx$a, xx$b)
> > > Error in get(x, envir, mode, inherits) : variable "xx$a" was not 
> > > found
> > >
> > > Thank you.
> > >
> > > Christos Hatzis, Ph.D.
> > > Nuvera Biosciences, Inc.
> > > 400 West Cummings Park
> > > Suite 5350
> > > Woburn, MA 01801
> > > Tel: 781-938-3830
> > > www.nuverabio.com
> > >
> > > __
> > > R-help@stat.math.ethz.ch 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 you are trying to solve?

__
R-help@stat.math.ethz.ch 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 'get' an object that is part of a list

2006-12-24 Thread Christos Hatzis
Thank you Gabor.  Very interesting solution.
If I get it right, the first argument in function f is just a placeholder to
help extract the right element out of the list(...) that is passed to
length.  Very smart trick.

Jim's solution appears a bit simpler, at least along the lines that I was
thinking:

my.length <- function(...) {
names <- as.character(substitute(list(...)))[-1]
sapply(names, function(x){y <- eval(parse(text=x)); length(y)})
} 

-Christos

-Original Message-
From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 24, 2006 7:41 AM
To: jim holtman
Cc: [EMAIL PROTECTED]; 
Subject: Re: [R] how to 'get' an object that is part of a list

Is this what you are looking for:

> my.length.2 <- function(...) {
+f <- function(nm, val) length(val)
+mapply(f, make.names(as.list(match.call()[-1])), list(...)) }
> my.length.2(xx, xx$b)
  xx xx.b
   25

On 12/24/06, jim holtman <[EMAIL PROTECTED]> wrote:
> use 'eval' and 'parse'
>
>
> > xx
> $a
> [1] 1 2 3 4 5
>
> $b
> [1] "a" "b" "c" "d" "e"
>
> > eval(parse(text='xx$a'))
> [1] 1 2 3 4 5
> >
>
> So that way you can pass in the character string and then 'parse' it.
>
>
>
> On 12/24/06, Christos Hatzis <[EMAIL PROTECTED]> wrote:
> >
> > This might be an trivial thing but I am stuck.
> >
> > Consider:
> >
> > xx <- list(a=1:5, b=letters[1:5])
> >
> > Although object xx is accessible through its name, how can object 
> > xx$b be accessed similarly through its name?
> >
> > > get("xx")
> > $a
> > [1] 1 2 3 4 5
> >
> > $b
> > [1] "a" "b" "c" "d" "e"
> >
> > > get("xx$b")
> > Error in get(x, envir, mode, inherits) : variable "xx$b" was not 
> > found
> >
> > get("xx")$b will not work in my case because it will probably 
> > require parsing to make it work within a function. E.g.
> >
> > my.length <- function(...) {
> >names <- as.character(substitute(list(...)))[-1]
> >sapply(names, FUN=function(x){y <- get(x); length(y)}) }
> > > my.length(xx)
> > xx
> > 2
> > > my.length(xx$a)
> > Error in get(x, envir, mode, inherits) : variable "xx$a" was not 
> > found
> > > my.length(xx$a, xx$b)
> > Error in get(x, envir, mode, inherits) : variable "xx$a" was not 
> > found
> >
> > Thank you.
> >
> > Christos Hatzis, Ph.D.
> > Nuvera Biosciences, Inc.
> > 400 West Cummings Park
> > Suite 5350
> > Woburn, MA 01801
> > Tel: 781-938-3830
> > www.nuverabio.com
> >
> > __
> > R-help@stat.math.ethz.ch 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 you are trying to solve?
>
>[[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 'get' an object that is part of a list

2006-12-23 Thread Christos Hatzis
Great.  Thanks, Jim.

  _  

From: jim holtman [mailto:[EMAIL PROTECTED] 
Sent: Sunday, December 24, 2006 1:11 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [R] how to 'get' an object that is part of a list


use 'eval' and 'parse'
 

> xx
$a
[1] 1 2 3 4 5

$b
[1] "a" "b" "c" "d" "e"

> eval(parse(text='xx$a'))
[1] 1 2 3 4 5
> 


So that way you can pass in the character string and then 'parse' it.



 
On 12/24/06, Christos Hatzis <[EMAIL PROTECTED]> wrote: 

This might be an trivial thing but I am stuck.

Consider:

xx <- list(a=1:5, b=letters[1:5]) 

Although object xx is accessible through its name,
how can object xx$b be accessed similarly through its name?

> get("xx")
$a
[1] 1 2 3 4 5

$b
[1] "a" "b" "c" "d" "e" 

> get("xx$b")
Error in get(x, envir, mode, inherits) : variable "xx$b" was not found

get("xx")$b will not work in my case because it will probably require
parsing to make it work within a function. E.g.

my.length <- function(...) {
   names <- as.character(substitute(list(...)))[-1]
   sapply(names, FUN=function(x){y <- get(x); length(y)})
}
> my.length(xx)
xx
2
> my.length (xx$a)
Error in get(x, envir, mode, inherits) : variable "xx$a" was not found
> my.length(xx$a, xx$b)
Error in get(x, envir, mode, inherits) : variable "xx$a" was not found

Thank you. 

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com

__ 
R-help@stat.math.ethz.ch 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 you are trying to solve? 

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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 'get' an object that is part of a list

2006-12-23 Thread Christos Hatzis
This might be an trivial thing but I am stuck.

Consider: 
 
xx <- list(a=1:5, b=letters[1:5])
 
Although object xx is accessible through its name,
how can object xx$b be accessed similarly through its name?
 
> get("xx")
$a
[1] 1 2 3 4 5

$b
[1] "a" "b" "c" "d" "e"

> get("xx$b")
Error in get(x, envir, mode, inherits) : variable "xx$b" was not found
 
get("xx")$b will not work in my case because it will probably require
parsing to make it work within a function. E.g.

my.length <- function(...) {
names <- as.character(substitute(list(...)))[-1]
sapply(names, FUN=function(x){y <- get(x); length(y)})
}
> my.length(xx)
xx 
 2 
> my.length(xx$a)
Error in get(x, envir, mode, inherits) : variable "xx$a" was not found
> my.length(xx$a, xx$b)
Error in get(x, envir, mode, inherits) : variable "xx$a" was not found

Thank you.
 
Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com

__
R-help@stat.math.ethz.ch 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] Speeding up small functions

2006-11-19 Thread Christos Hatzis
Wee-Jin,

The other option that you have is to set up your function as an expression
and then evaluate the expression for each new value of x.  This might be
faster in some cases.

sigmoid.fun <- function(x) 1/(1+exp(-x))
sigmoid.expr <- expression( 1/(1+exp(-x)) )

x <- runif(10^6)

# non-vectorized function
system.time(
for(i in seq(along=x)) sigmoid.fun(x[i])
)
[1] 6.76 0.01 7.13   NA   NA

# vectorized function
system.time(
sigmoid.fun(x)
)
[1] 0.56 0.00 0.59   NA   NA

# vectorized expression
system.time(
eval(sigmoid.expr)
) 
[1] 0.37 0.01 0.39   NA   NA

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Wee-Jin Goh
Sent: Sunday, November 19, 2006 4:26 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Speeding up small functions

Greetings list,

In my code, I have a few small functions that are called very very
frequently. An example of one such function is the following :

sigmoid<-function(x) 1/(1+exp(-x))

Now, is there anyway to make this go faster? For example, in C++ we could
make it inline. Is there a corresponding feature in R?

Cheers,
Wee-Jin

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] X-fold cross validation function for discriminant analysis

2006-11-16 Thread Christos Hatzis
Apologies for the typos there.
I meant to say see the Bioconductor web site for details.

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Christos Hatzis
Sent: Thursday, November 16, 2006 11:53 AM
To: 'Wensui Liu'; 'Wade Wall'
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] X-fold cross validation function for discriminant analysis

One option is the Bioconductor package MLInterfaces that provides a unified
interface for several machine learning alrogirithms and methods for
cross-validation etc.  See the algorithms web site for details.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Wensui Liu
Sent: Thursday, November 16, 2006 11:37 AM
To: Wade Wall
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] X-fold cross validation function for discriminant analysis

how hard is it to write one though?

On 11/16/06, Wade Wall <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I ran a discriminant analysis with some data and want to get a general 
> idea of prediction error rate.  Some have suggested using X-fold cross 
> validation procedure.  Anyone know if there is a function for this in R?
>
> Thanks,
>
> Wade
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch 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.
>


--
WenSui Liu
(http://spaces.msn.com/statcompute/blog)
Senior Decision Support Analyst
Cincinnati Children Hospital Medical Center

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] X-fold cross validation function for discriminant analysis

2006-11-16 Thread Christos Hatzis
One option is the Bioconductor package MLInterfaces that provides a unified
interface for several machine learning alrogirithms and methods for
cross-validation etc.  See the algorithms web site for details.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Wensui Liu
Sent: Thursday, November 16, 2006 11:37 AM
To: Wade Wall
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] X-fold cross validation function for discriminant analysis

how hard is it to write one though?

On 11/16/06, Wade Wall <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I ran a discriminant analysis with some data and want to get a general 
> idea of prediction error rate.  Some have suggested using X-fold cross 
> validation procedure.  Anyone know if there is a function for this in R?
>
> Thanks,
>
> Wade
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch 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.
>


--
WenSui Liu
(http://spaces.msn.com/statcompute/blog)
Senior Decision Support Analyst
Cincinnati Children Hospital Medical Center

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Matrix-vector multiplication without loops

2006-11-14 Thread Christos Hatzis
Ravi,

Here is another version, somewhat similar to what Dimitris proposed but
without using 'rep'.  For large n, K 'rep' tries allocating two vectors,
each of length n*(K+1)^2, which can be a problem.  In this version 'outer'
buys you some efficiency and compactness, but your looping version is
faster.

n <- 1000
K <- 1000
p <- rep(0, n)
cf <- runif(K+1)
U <- matrix(runif(n*(2*K+1)), n, 2*K+1)

# original code
system.time(
{
for (i in 0:K)
for (j in 0:K)
p <- p + cf[i+1]* cf[j+1] * U[,i+j+1]
p.1 <- p
} )

# 'vectorized'
system.time(
{
ind <- sapply(1:(K+1), seq, length = K+1)
cc <- outer(cf,cf)
p.2 <- apply(U, 1, FUN=function(u) sum(cc * u[ind]))
} )


all.equal(p.1, p.2)
rm(n,K,p,U,cf,cc,ind,p.1,p.2) 

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Dimitris Rizopoulos
Sent: Tuesday, November 14, 2006 11:20 AM
To: Ravi Varadhan
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Matrix-vector multiplication without loops

I think you need something along these lines:

ind <- c(sapply(1:(K+1), seq, length = K + 1))
cf1 <- rep(rep(coef, each = n), K + 1)
cf2 <- rep(rep(coef, each = n), each = K + 1)
rowSums(cf1 * cf2 * U[, ind])


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message -
From: "Ravi Varadhan" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, November 14, 2006 4:45 PM
Subject: [R] Matrix-vector multiplication without loops


> Hi,
>
>
>
> I am trying to do the following computation:
>
>
>
>  p <- rep(0, n)
>
>  coef <- runif(K+1)
>
>  U <- matrix(runif(n*(2*K+1)), n, 2*K+1)
>
>  for (i in 0:K){
>
>  for (j in 0:K){
>
>  p <- p + coef[i+1]* coef[j+1] * U[,i+j+1]
>
>  } }
>
>
>
> I would appreciate any suggestions on how to perform this 
> computation
> efficiently without the "for" loops?
>
>
>
> Thank you,
>
> Ravi.
>
>

> ---
>
> Ravi Varadhan, Ph.D.
>
> Assistant Professor, The Center on Aging and Health
>
> Division of Geriatric Medicine and Gerontology
>
> Johns Hopkins University
>
> Ph: (410) 502-2619
>
> Fax: (410) 614-9625
>
> Email: [EMAIL PROTECTED]
>
> Webpage: 
> http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
>
>
>
>

> 
>
>
>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch 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.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] R and Fortran 9x -- advice

2006-11-13 Thread Christos Hatzis
Mike,

Can you recommend any good books on Fortran 90/95?  I had been an old user
of Fortran 77 but haven't followed the developments in the last 15 years or
so...

Thanks.

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Mike Prager
Sent: Monday, November 13, 2006 1:00 PM
To: r-help@stat.math.ethz.ch
Subject: Re: [R] R and Fortran 9x -- advice

Tamas K Papp <[EMAIL PROTECTED]> wrote:

> I found some bottlenecks in my R code with Rprof.  First I wanted to 
> rewrite them in C, but a colleague keeps suggesting that I learn 
> Fortran, so maybe this is the time to do it...
> 
> 1) I hear bad things about Fortran.  Sure, F77 looks archaic, but
> F90/95 seems nicer.  Is it worth learning, especially when I plan to 
> use it mainly from R?  Dusting off my C knowledge would take a bit of 
> time too, and I never liked C that much.

I'll answer this from the perspective of someone who uses Fortran 95
regularly.  It is a modern language, far more reliable and flexible than
Fortran 77 and quite well suited to most scientific problems.  I do think
it's worth learning, particularly if C is not to your taste.

Two free compilers for Fortran 95 are available.  It seems that
g95 is complete, while gfortran is nearing completion.  There are also
several high-quality commercial compilers, some of which are free under
certain operating systems and/or conditions and others of which (Lahey) are
quite inexpensive if one is willing to work from the command line or one's
own editor.

I can't address questions of R interoperability  -- not something I've done.

--
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] CPU or memory

2006-11-08 Thread Christos Hatzis
Great.  I will try it.
Thank you.

-Christos 

-Original Message-
From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, November 08, 2006 1:21 PM
To: Christos Hatzis
Cc: 'Stefan Grosse'; r-help@stat.math.ethz.ch; 'Taka Matzmoto'
Subject: RE: [R] CPU or memory

On Wed, 8 Nov 2006, Christos Hatzis wrote:

> Prof. Ripley,
>
> Do you mind providing some pointers on how "coarse-grained parallelism"
> could be implemented on a Windows environment?  Would it be as simple 
> as running two R-console sessions and then (manually) combining the 
> results of these simulations.  Or it would be better to run them as batch
processes.

That is what I would do in any environment (I don't do such things under
Windows since all my fast machines run Linux/Unix).

Suppose you want to do 1 simulations.  Set up two batch scripts that
each run 5000, and save() the results as a list or matrix under different
names, and set a different seed at the top.  Then run each via R CMD BATCH
simultaneously.  When both have finished, use an interactive session to
load() both sets of results and merge them.

> RSiteSearch('coarse grained') did not produce any hits so this topic 
> might have not been discussed on this list.
>
> I am not really familiar with running R in any mode other than the 
> default (R-console in Windows) so I might be missing something really 
> obvious. I am interested in running Monte-Carlo cross-validation in 
> some sort of a parallel mode on a dual core (Pentium D) Windows XP
machine.
>
> Thank you.
> -Christos
>
> Christos Hatzis, Ph.D.
> Nuvera Biosciences, Inc.
> 400 West Cummings Park
> Suite 5350
> Woburn, MA 01801
> Tel: 781-938-3830
> www.nuverabio.com
>
>
>
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian 
> Ripley
> Sent: Wednesday, November 08, 2006 5:29 AM
> To: Stefan Grosse
> Cc: r-help@stat.math.ethz.ch; Taka Matzmoto
> Subject: Re: [R] CPU or memory
>
> On Wed, 8 Nov 2006, Stefan Grosse wrote:
>
>> 64bit does not make anything faster. It is only of use if you want to 
>> use more then 4 GB of RAM of if you need a higher precision of your 
>> variables
>>
>> The dual core question: dual core is faster if programs are able to 
>> use that. What is sure that R cannot make (until now) use of the two 
>> cores if you are stuck on Windows. It works excellent if you use 
>> Linux. So if you want dual core you should work with linux (and then 
>> its faster of course).
>
> Not necessarily.  We have seen several examples in which using a 
> multithreaded BLAS (the only easy way to make use of multiple CPUs 
> under Linux for a single R process) makes things many times slower.  
> For tasks that are do not make heavy use of linear algebra, the 
> advantage of a multithreaded BLAS is small, and even from those which 
> do the speed-up is rarely close to double for a dual-CPU system.
>
> John mentioned simulations.  Often by far the most effective way to 
> use a multi-CPU platform (and I have had one as my desktop for over a 
> decade) is to use coarse-grained parallelism: run two or more 
> processes each doing some of the simulation runs.
>
>> The Core 2 duo is the fastest processor at the moment however.
>>
>> (the E6600 has a good price/performance ration)
>>
>> What I already told Taka is that it is probably always a good idea to 
>> improve your code for which purpose you could ask in this mailing 
>> list... (And I am very sure that you have there a lot of potential).
>> Another speeding up possibility is e.g. using the atlas library...
>> (where I am not sure if you already use it)
>>
>> Stefan
>>
>> John C Frain schrieb:
>>> *Can I extend Taka's question?*
>>> **
>>> *Many of my programs in (mainly simulations in R which are cpu 
>>> bound) on a year old PC ( Intel(R) Pentium(R) M processor 1.73GHz or 
>>> Dell GX380 with 2.8Gh Pentium) are taking hours and perhaps days to 
>>> complete on a one year old PC.  I am looking at an upgrade but the 
>>> variety of cpu's available is
>>> confusing at least.   Does any one know of comparisons of the Pentium
>>> 9x0, Pentium(r)
>>> Extreme/Core 2 Duo,   AMD(r) Athlon(r) 64 , AMD(r) Athlon(r) 64
>>> FX/Dual Core AM2 and
>>> similar chips when used for this kind of work.  Does anyone have any 
>>> advice on (1)  the use of a single core or dual core cpu or (2) on 
>>> the use of 32 bit and 64 bit cpu.  This question is now much more 
>>> difficult as the numbers on the various chips do not necessarily 
>&

Re: [R] CPU or memory

2006-11-08 Thread Christos Hatzis
Prof. Ripley,

Do you mind providing some pointers on how "coarse-grained parallelism"
could be implemented on a Windows environment?  Would it be as simple as
running two R-console sessions and then (manually) combining the results of
these simulations.  Or it would be better to run them as batch processes.
RSiteSearch('coarse grained') did not produce any hits so this topic might
have not been discussed on this list.

I am not really familiar with running R in any mode other than the default
(R-console in Windows) so I might be missing something really obvious. I am
interested in running Monte-Carlo cross-validation in some sort of a
parallel mode on a dual core (Pentium D) Windows XP machine.

Thank you.
-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley
Sent: Wednesday, November 08, 2006 5:29 AM
To: Stefan Grosse
Cc: r-help@stat.math.ethz.ch; Taka Matzmoto
Subject: Re: [R] CPU or memory

On Wed, 8 Nov 2006, Stefan Grosse wrote:

> 64bit does not make anything faster. It is only of use if you want to 
> use more then 4 GB of RAM of if you need a higher precision of your 
> variables
>
> The dual core question: dual core is faster if programs are able to 
> use that. What is sure that R cannot make (until now) use of the two 
> cores if you are stuck on Windows. It works excellent if you use 
> Linux. So if you want dual core you should work with linux (and then 
> its faster of course).

Not necessarily.  We have seen several examples in which using a
multithreaded BLAS (the only easy way to make use of multiple CPUs under
Linux for a single R process) makes things many times slower.  For tasks
that are do not make heavy use of linear algebra, the advantage of a
multithreaded BLAS is small, and even from those which do the speed-up is
rarely close to double for a dual-CPU system.

John mentioned simulations.  Often by far the most effective way to use a
multi-CPU platform (and I have had one as my desktop for over a decade) is
to use coarse-grained parallelism: run two or more processes each doing some
of the simulation runs.

> The Core 2 duo is the fastest processor at the moment however.
>
> (the E6600 has a good price/performance ration)
>
> What I already told Taka is that it is probably always a good idea to 
> improve your code for which purpose you could ask in this mailing 
> list... (And I am very sure that you have there a lot of potential).
> Another speeding up possibility is e.g. using the atlas library...
> (where I am not sure if you already use it)
>
> Stefan
>
> John C Frain schrieb:
>> *Can I extend Taka's question?*
>> **
>> *Many of my programs in (mainly simulations in R which are cpu bound) 
>> on a year old PC ( Intel(R) Pentium(R) M processor 1.73GHz or Dell 
>> GX380 with 2.8Gh Pentium) are taking hours and perhaps days to 
>> complete on a one year old PC.  I am looking at an upgrade but the 
>> variety of cpu's available is
>> confusing at least.   Does any one know of comparisons of the Pentium
>> 9x0, Pentium(r)
>> Extreme/Core 2 Duo,   AMD(r) Athlon(r) 64 , AMD(r) Athlon(r) 64
>> FX/Dual Core AM2 and
>> similar chips when used for this kind of work.  Does anyone have any 
>> advice on (1)  the use of a single core or dual core cpu or (2) on 
>> the use of 32 bit and 64 bit cpu.  This question is now much more 
>> difficult as the numbers on the various chips do not necessarily 
>> refer to the relative speed of the chips.
>> *
>> *John
>>
>> * On 06/11/06, Taka Matzmoto <[EMAIL PROTECTED]> wrote:
>>
>>
>>> Hi R users
>>>
>>> Having both a faster CPU and more memory will boost computing power. 
>>> I was wondering if only adding more memory (1GB -> 2GB)  will 
>>> significantly reduce R computation time?
>>>
>>> Taka,
>>>
>>> _
>>> Get FREE company branded e-mail accounts and business Web site from 
>>> Microsoft Office Live
>>>
>>> __
>>> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch mailing list
> https://stat.

Re: [R] subsetting a matrix and filling other

2006-11-07 Thread Christos Hatzis
Use a list to store the partial matrices:

z <- vector("list", 189) 

for(i in 1:189)
z[[i]] <- subset(...)

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of antonio rodriguez
Sent: Tuesday, November 07, 2006 2:01 PM
To: R-Help
Subject: [R] subsetting a matrix and filling other

Hi,

Having a matrix F(189,6575) I want to do this:

z1<-subset(F[,1], F[,1] >= 5 & F[,1] <= 10) .
.
.
z189<-subset(F[,189], F[,189] >= 5 & F[,189] <= 10)

I would prefer to have an empty matrix, say 'z' in order to fill its columns
with the output of subsetting F. But each of the subsets can differ in
length. It's to say:

length(z1)
1189

length(z2)
1238

Don't know how to set up this with a for loop or the use of apply:

z<-189
for (i in 1:189)
{z[i]<-subset(F.zoo[,i], F.zoo[,i] >= 5 & z1 <= 10)}

Error in z[i] <- subset(F.zoo[, i], F.zoo[, i] >= 5 & z1 <= 10) :
nothing to replace with

or

z<-matrix(0,6575,189)
for (i in 1:189)
{z[i]<-subset(F.zoo[,i], F.zoo[,i] >= 5 & z1 <= 10)}

new error


Thanks,

Antonio

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] alist()

2006-11-06 Thread Christos Hatzis
You need to start by first allocating the list.  The problem is that you
cannot reference a list member that does not exist yet (as in x$two):

x <- vector("list", 10)
x

List x has 10 NULL elements by default.  You can then assign values to these
as needed.

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Glen Herrmannsfeldt
Sent: Monday, November 06, 2006 3:37 PM
To: r-help@stat.math.ethz.ch
Subject: [R] alist()

In trying to get NULL members into a list, I found out about alist().

x<-alist()

x$one<-1
x$two<-NULL

but x$two doesn't exist.

It seems, though, that an alist is just a list.

How can one put NULL members into a list?

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Subset and levels

2006-11-06 Thread Christos Hatzis
Hi Florent,

A simple example with the expected output would help.  If I understood
correctly what you want, perhaps the following would work:

X[ X$code %in% levels(Y$code), ]

assuming Y$code is a factor.  If not, you can used instead unique(Y$code) in
the above.

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Florent Bresson
Sent: Monday, November 06, 2006 12:15 PM
To: R-help
Subject: [R] Subset and levels

Hi, I've got a very simple problem but cannot find the solution. I'm using
two data frames (say X and Y) and I want to get a subset of one according to
the different levels of a variable "code" of the other data frame. I tried
something like
Z<-subset(X, code==levels(Y$code))(1)

but it does not work. I do not want to do something like
Z<-subset(X,code==level1 | code==level2...)

because length(levels(Y$code)) is 130. So what's wrong with (1)?

Thanks

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 obtain the estimate of baseline survival function?

2006-11-03 Thread Christos Hatzis
See ?basehaz in 'survival' package.

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Zheng Yuan
Sent: Friday, November 03, 2006 6:20 PM
To: r-help@stat.math.ethz.ch
Subject: [R] How to obtain the estimate of baseline survival function?

Hi,

If I fit a Cox model using "coxph", is there a R function so that I could
obtain the estimate of baseline survival function? Thank you.

Zheng
--
Zheng Yuan
Ph.D student
Department of Biostatistics
University of Michigan
Ann Arbor, MI 48109

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] multiple plots in the same graph

2006-11-03 Thread Christos Hatzis
See ?points and ?lines for adding new groups of points or lines to an
existing graph created by plot. 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Li Zhang
Sent: Friday, November 03, 2006 9:55 PM
To: R-help@stat.math.ethz.ch
Subject: [R] multiple plots in the same graph

I'd like to plot y vs x according to the third variable "group" which has
three levels. I am wondering how can I put the three plots in one graph?

Thank you 


 



(http://groups.yahoo.com)

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] psigamma derivative

2006-10-30 Thread Christos Hatzis
Try

?Special

For information on the special functions included in the base R
distribution.

Also, 

RSiteSearch("digamma")

gives several hits on additional packages that might be useful.

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Monday, October 30, 2006 3:26 PM
To: r-help@stat.math.ethz.ch
Subject: [R] psigamma derivative

Hello,

I am trying to find a hessian matrix  that involves log(gamma(1/p)) second
derivative, p being one of the parameters of the function. I am using a
function "deriv" with the hessian=TRUE option, but psigamma is not on the
list of derivative functions.
I know that it is possible to use 'psigamma(p,deriv)', but it doesn't work
with 1/p. Does anybody can help with this?

Thanks,
Ana Maria

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 fo finding R package "utils"

2006-10-26 Thread Christos Hatzis
Please reply to the list, not to me personally.

When I want to import an Excel file, I usually save it as a tab-delimited
text file and use read.delim to import it:
 
my.dataframe <- read.delim("file.name.txt", header=TRUE, sep="\t") 

See ?read.delim for further details.  There are many other options, I'm
sure, but this is simple and flexible and does not require any additional
packages.

Good luck.
-Christos



From: amna khan [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 26, 2006 2:41 PM
To: [EMAIL PROTECTED]
Subject: Re: [R] help fo finding R package "utils"


sir i have downloaded  poptools for excel to import data but still feeling
problems. I am not understanding what I should do?


On 10/26/06, Christos Hatzis <[EMAIL PROTECTED]> wrote: 

Amina,
 
The best way for entering data in R is by importing an existing data
file (text, Excel etc).  This will reduce time and potential data entry
errors. 
Please read Section 7 of the "Introduction to R" manual for a
detailed discussion of available options.  The manuals are available on your
system (Help menu in the R Console for Windows) or through the R web site. 
 
Regards,
 
-Christos



From: amna khan [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 26, 2006 1:21 PM 
To: [EMAIL PROTECTED]
Subject: Re: [R] help fo finding R package "utils" 

 
Respected sir
I have a great problem for data entry in R. using sessionInfo()
utils has appeared. but while entring data there is a message of no object
found. Sir is there any option for spreadsheet for data entry.
I shall be thankful to you.
     
Amina


 
On 10/25/06, Christos Hatzis <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote: 

Amina,

utils is a base package and should be already installed in a
functional R
system.

You can try
sessionInfo()

to verify that it is loaded.

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto: [EMAIL PROTECTED] On Behalf Of amna
khan 
Sent: Thursday, October 26, 2006 12:11 AM
To: R-help@stat.math.ethz.ch
<mailto:R-help@stat.math.ethz.ch> 
Subject: [R] help fo finding R package "utils" 

Sir I have a problem that from which country i can assess R
package "utils"
for data entry for loading it in R
Please help me in this regard. 


--
AMINA SHAHZADI
Department of Statistics 
GC University Lahore, Pakistan.
Email:
[EMAIL PROTECTED]
[EMAIL PROTECTED] 
[EMAIL PROTECTED]

   [[alternative HTML version deleted]]

__ 
R-help@stat.math.ethz.ch <mailto:R-help@stat.math.ethz.ch>
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.








-- 
AMINA SHAHZADI
Department of Statistics
GC University Lahore, Pakistan.
Email: 
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED] 




-- 
AMINA SHAHZADI
Department of Statistics
GC University Lahore, Pakistan.
Email: 
[EMAIL PROTECTED]
[EMAIL PROTECTED] 
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch 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 fo finding R package "utils"

2006-10-26 Thread Christos Hatzis
Amina,
 
The best way for entering data in R is by importing an existing data file
(text, Excel etc).  This will reduce time and potential data entry errors.
Please read Section 7 of the "Introduction to R" manual for a detailed
discussion of available options.  The manuals are available on your system
(Help menu in the R Console for Windows) or through the R web site.
 
Regards,
 
-Christos

  _  

From: amna khan [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 26, 2006 1:21 PM
To: [EMAIL PROTECTED]
Subject: Re: [R] help fo finding R package "utils"


Respected sir
I have a great problem for data entry in R. using sessionInfo() utils has
appeared. but while entring data there is a message of no object found. Sir
is there any option for spreadsheet for data entry.
I shall be thankful to you.
 
Amina


 
On 10/25/06, Christos Hatzis <[EMAIL PROTECTED]> wrote: 

Amina,

utils is a base package and should be already installed in a functional R
system.

You can try
sessionInfo()

to verify that it is loaded.

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto: [EMAIL PROTECTED] On Behalf Of amna khan
Sent: Thursday, October 26, 2006 12:11 AM
To: R-help@stat.math.ethz.ch  <mailto:R-help@stat.math.ethz.ch> 
Subject: [R] help fo finding R package "utils"

Sir I have a problem that from which country i can assess R package "utils"
for data entry for loading it in R
Please help me in this regard. 


--
AMINA SHAHZADI
Department of Statistics
GC University Lahore, Pakistan.
Email:
[EMAIL PROTECTED]
[EMAIL PROTECTED]  <mailto:[EMAIL PROTECTED]> 
[EMAIL PROTECTED]

   [[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch  <mailto:R-help@stat.math.ethz.ch> mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
<http://www.R-project.org/posting-guide.html> 
and provide commented, minimal, self-contained, reproducible code.








-- 
AMINA SHAHZADI
Department of Statistics
GC University Lahore, Pakistan.
Email: 
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED] 

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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 fo finding R package "utils"

2006-10-25 Thread Christos Hatzis
Amina,

utils is a base package and should be already installed in a functional R
system.

You can try
sessionInfo()

to verify that it is loaded.

-Christos  

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of amna khan
Sent: Thursday, October 26, 2006 12:11 AM
To: R-help@stat.math.ethz.ch
Subject: [R] help fo finding R package "utils"

Sir I have a problem that from which country i can assess R package "utils"
for data entry for loading it in R
Please help me in this regard.


--
AMINA SHAHZADI
Department of Statistics
GC University Lahore, Pakistan.
Email:
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] avoiding a loop

2006-10-24 Thread Christos Hatzis
Try this (essentially the trick is to shift the invector to get the y[i-i]
effect):

constructLt<-function(invector, a=1) {
invector[invector aa <- c(1,1,0.5,2,3,0.4,4,5)
> aa
[1] 1.0 1.0 0.5 2.0 3.0 0.4 4.0 5.0
> constructLt(aa)
[1] 1.0 1.0 0.5 2.0 3.0 1.2 4.0 5.0

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Leeds, Mark (IED)
Sent: Tuesday, October 24, 2006 2:36 PM
To: R-help@stat.math.ethz.ch
Subject: [R] avoiding a loop

I think I asked a similar question 3 years ago to the  Splus list and I
think the answer was no or noone answered so noone should spend more than 5
minutes on this because it could definitely be a waste of time.
 
My question is whether the function below can be rewritten without a for
loop. apply is fine if it can be done that way but i doubt it. I call it a
lot and would prefer to not loop.
 
#---
--
 
constructLt<-function(invector) {
 
outvector<-invector
 
 for ( i in 2:length(invector) ) {
 if ( invector[i] < 1 ) {
  outvector[i]<-invector[i]*outvector[i-1]
 }
}
 
return(outvector)
 
}

#---
-


This is not an offer (or solicitation of an offer) to buy/sell the
securities/instruments mentioned or an official confirmation.  Morgan
Stanley may deal as principal in or own or act as market maker for
securities/instruments mentioned or may advise the issuers.  This is not
research and is not from MS Research but it may refer to a research
analyst/research report.  Unless indicated, these views are the author's and
may differ from those of Morgan Stanley research or others in the Firm.  We
do not represent this is accurate or complete and we may not update this.
Past performance is not indicative of future returns.  For additional
information, research reports and important disclosures, contact me or see
https://secure.ms.com/servlet/cls.  You should not use e-mail to request,
authorize or effect the purchase or sale of any security or instrument, to
send transfer instructions, or to effect any other transactions.  We cannot
guarantee that any such requests received via !
 e-mail will be processed in a timely manner.  This communication is solely
for the addressee(s) and may contain confidential information.  We do not
waive confidentiality by mistransmission.  Contact me if you do not wish to
receive these communications.  In the UK, this communication is directed in
the UK to those persons who are market counterparties or intermediate
customers (as defined in the UK Financial Services Authority's rules).

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Plotmath expression

2006-10-24 Thread Christos Hatzis
Excellent! Thank you.
I am reading now your article in R-News (2/3 p.32-34) to understand the
logic behind substitute in the expression.

-Christos 

-Original Message-
From: Uwe Ligges [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 24, 2006 12:27 PM
To: [EMAIL PROTECTED]
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Plotmath expression



Christos Hatzis wrote:
> Hello,
>  
> I've been trying to plot a subscript in a text formula using plotmath 
> but I haven't been able to do so.
>  
> In my example below I would like the text label to show X[min] = 10.1 
> +/- 5.5
> 
> Here is the code:
> 
> ll <- c(x=10.1, sde=5.5)
> plot(1:10)
> text(x=9, y=2, pos=2, expression(paste(X[min], "=", paste(ll,
> collapse="+/-"


  plot(1:10)
  text(x=9, y=2, pos=2, substitute(X[min] == x %+-% sde, as.list(ll)))

Uwe Ligges

> This works fine up to the inner paste call that collapses the vector
values.
> I also tried assigning the value of the inner paste to a variable and 
> then use it inside the expression but that did not work either:
> 
> ll.txt <- paste(ll, collapse="+/-")
> text(x=9, y=2, pos=2, expression(paste(X[min], "=", ll.txt)))
> 
> Any help is much appreciated.
> 
> Thanks.
>  
> Christos Hatzis, Ph.D.
> Nuvera Biosciences, Inc.
> 400 West Cummings Park
> Suite 5350
> Woburn, MA 01801
> Tel: 781-938-3830
> www.nuverabio.com
> 
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Plotmath expression

2006-10-24 Thread Christos Hatzis
Hello,
 
I've been trying to plot a subscript in a text formula using plotmath but I
haven't been able to do so.
 
In my example below I would like the text label to show
X[min] = 10.1 +/- 5.5 

Here is the code:

ll <- c(x=10.1, sde=5.5)
plot(1:10)
text(x=9, y=2, pos=2, expression(paste(X[min], "=", paste(ll,
collapse="+/-"

This works fine up to the inner paste call that collapses the vector values.
I also tried assigning the value of the inner paste to a variable and then
use it inside the expression but that did not work either:

ll.txt <- paste(ll, collapse="+/-")
text(x=9, y=2, pos=2, expression(paste(X[min], "=", ll.txt)))

Any help is much appreciated.

Thanks.
 
Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com

__
R-help@stat.math.ethz.ch 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 coef

2006-10-20 Thread Christos Hatzis
Tom,

coef returns a "named" vector, which is a vector with an extra attribute
called "names".
To remove the extra attribute you can:

names(a) <- NULL# through the accessor function
[EMAIL PROTECTED] <- NULL   # directly accessing the attribute names

or by creating a new vector as you did without setting its names attribute:

as.vector(a)

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of tom soyer
Sent: Saturday, October 21, 2006 1:00 AM
To: Gabor Grothendieck
Cc: r-help
Subject: Re: [R] help with coef

Gabor,

Thanks for the code example, but it seems that BOD is not needed. I still
don't understand what is going on with the data structure returned by
coef(). The strangness is illustrated by the following example:

> a=coef(lm(y~miles))
> is.vector(a)
[1] TRUE
> a[2]
  miles
-7.2875
> a=as.vector(a)
> is.vector(a)
[1] TRUE
> a[2]
[1] -7.2875

As you can see, although coef() returns a vector already, only after
as.vector(a) is used, did a[2] include the slope without the name of the
slope. Why is that, and what happened to the name of the slope (names(a)
returns NULL)?

Tom

On 10/20/06, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
>
> Using the builtin BOD data frame:
>
> as.vector(coef(lm(demand ~ Time, BOD)))[2]
>
>
> On 10/21/06, tom soyer <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I am trying to get R to return just the slope of a linear regression
> line,
> > but it seems that R has to return both the slope and the name of the
> slope.
> > For example,
> >
> > > a=coef(lm(y~miles))
> > > a
> > (Intercept)   miles
> >   360.3778 -7.2875
> > > names(a)
> > [1] "(Intercept)" "miles"
> > > a[1]
> > (Intercept)
> >   360.3778
> > > a[2]
> >  miles
> > -7.2875
> >
> > I don't understand the data structure that's returned from coef().
> names(a)
> > seems to suggest that coef() returns two columns of data, column one 
> > is
> the
> > Intercept, and column two miles. But R keeps telling me that the 
> > return value from coef() has only one dimension, i.e., a[,2] doesn't 
> > work, but
> a[2]
> > works. However, a[2] contains more than the slope, it also has the 
> > name
> of
> > the slope. Does anyone know how to access just the slope without its
> name?
> >
> > Thanks,
> >
> > Tom
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] sort question in a dataset?

2006-10-14 Thread Christos Hatzis
Another way to do this is:

o <- order(a[,"y"],-a[,"x"], decreasing=TRUE)
a[o,] 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Richard M. Heiberger
Sent: Sunday, October 15, 2006 1:32 AM
To: zhijie zhang
Cc: R-help@stat.math.ethz.ch
Subject: Re: [R] sort question in a dataset?

Your desired answer just interchanges the sequence of the steps

x <-  c(2, 9, 18, 3, 2)
y <-  c(2,9,8,9,8)
z <-  c(21,5,5,19,7)
a <-  cbind(x, y, z)  #dataset

bb <- a[order(a[,"x"], decreasing=FALSE),] bbb <- bb[order(bb[,"y"],
decreasing=TRUE),] bbb

>From ?sort
Sort (or order) a vector or factor (partially) into ascending (or
descending) order. For ordering along more than one variable, e.g., for
sorting data frames, see order. 

>From ?order
order returns a permutation which rearranges its first argument into
ascending or descending order, breaking ties by further arguments. 


tmp <- c(10,15,12,7)
sort(tmp)
order(tmp)
tmp[order(tmp)]

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] combinatorics

2006-10-13 Thread Christos Hatzis
Hi Robin,

This approach first generates all combinations and then eliminates the
non-feasible ones.  It should work fine for smallish vectors but might not
scale well for larger vectors.  Hopefully it gives you what you need for
this problem.

xx <- c("A","A","B","B","C")
yy <- 1:length(xx)
zz <- expand.grid(yy,yy,yy,yy,yy)

ss <- zz[ apply(zz, 1, FUN=function(x) length(unique(x))) == length(xx), ] 
ss <- as.matrix(ss)

pp <- apply(ss, 1, FUN=function(x,v) paste(v[as.vector(x)], collapse=""),
v=xx) 
res <- unique(pp)

> res
 [1] "CBBAA" "BCBAA" "BBCAA" "CBABA" "BCABA" "CABBA" "ACBBA" "BACBA" "ABCBA"
"BBACA" "BABCA"
[12] "ABBCA" "CBAAB" "BCAAB" "CABAB" "ACBAB" "BACAB" "ABCAB" "CAABB" "ACABB"
"AACBB" "BAACB"
[23] "ABACB" "AABCB" "BBAAC" "BABAC" "ABBAC" "BAABC" "ABABC" "AABBC"
> length(res)
[1] 30 

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin
Sent: Friday, October 13, 2006 10:19 AM
To: [EMAIL PROTECTED]
Subject: [R] combinatorics

Hi

How do I generate all ways of ordering  sets of indistinguishable items?

suppose I have two A's, two B's and a C.

Then I want

AABBC
AABCB
AACBC
ABABC
. . .snip...
BBAAC
. . .snip...
CBBAA

[there are 5!/(2!*2!) = 30 arrangements.  Note AABBC != BBAAC]

How do I do this?





--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton European Way, Southampton SO14
3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] The W statistic in wilcox.exact

2006-10-05 Thread Christos Hatzis
Jue,

On a second look, it appears that wilcox.test does report the
offset-adjusted statistic U, as also mentioned in the help page.

wilcox.test returns W=6 (instead of 12 as your example showed, unless
"wilcox_test" is a different function).

> wilcox.test( 1:5 ~ c(1,1,0,0,0) )$statistic  # or wilcox.test( 1:5 ~
factor(c(1,1,0,0,0)) )$statistic
W 
6  

So there does not appear to be a difference between the two methods.  Did I
miss something?

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Christos Hatzis
Sent: Thursday, October 05, 2006 4:41 PM
To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch
Subject: Re: [R] The W statistic in wilcox.exact

Probably because of the offset:

U = W - n*(n+1)/2 

In your example, W=12 (=3+4+5) as reported by wilcox.test.  The offset is 6
(=3*4/2) and therefore U=6.
I am not certain as I haven't installed the exactRankTests package, but it
seems that wilcox.exact reports U instead of W.

-Christos Hatzis

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Thursday, October 05, 2006 1:35 PM
To: r-help@stat.math.ethz.ch
Subject: [R] The W statistic in wilcox.exact

Does anyone know why wilcox.exact gives W-statistic 6 instead of 12 as
indicated below.

12 is the rank sum of group 0 of x, which is the linear statistic computed
by wilcox_test.

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


(a) wilcox.exact

wilcox.exact(y~x)
Exact Wilcoxon rank sum test
data:  y by x
W = 6, p-value = 0.2
alternative hypothesis: true mu is not equal to 0 


(b) wilcox_test

tt<-wilcox_test(y~factor(x),distribution="exact")
statistic(tt,"linear")
   
0 12



Jue Wang, Biostatistician
Contracted Position for Preclinical & Research Biostatistics PrO Unlimited
(908) 231-3022

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] The W statistic in wilcox.exact

2006-10-05 Thread Christos Hatzis
Probably because of the offset:

U = W - n*(n+1)/2 

In your example, W=12 (=3+4+5) as reported by wilcox.test.  The offset is 6
(=3*4/2) and therefore U=6.
I am not certain as I haven't installed the exactRankTests package, but it
seems that wilcox.exact reports U instead of W.

-Christos Hatzis

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Thursday, October 05, 2006 1:35 PM
To: r-help@stat.math.ethz.ch
Subject: [R] The W statistic in wilcox.exact

Does anyone know why wilcox.exact gives W-statistic 6 instead of 12 as
indicated below.

12 is the rank sum of group 0 of x, which is the linear statistic computed
by wilcox_test.

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


(a) wilcox.exact

wilcox.exact(y~x)
Exact Wilcoxon rank sum test
data:  y by x
W = 6, p-value = 0.2
alternative hypothesis: true mu is not equal to 0 


(b) wilcox_test

tt<-wilcox_test(y~factor(x),distribution="exact")
statistic(tt,"linear")
   
0 12



Jue Wang, Biostatistician
Contracted Position for Preclinical & Research Biostatistics
PrO Unlimited
(908) 231-3022

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] inserting columns in the middle of a dataframe

2006-09-13 Thread Christos Hatzis
Sorry, I guess I did not explain at all how append 
could work in a one-liner:

data.frame(df, v5)[append(1:4,5,2)]

Your method is fine as well.  The above might be more
flexible if you need a more general solution, e.g. if you wanted
to make it a function.

-Christos

-Original Message-
From: Jon Minton [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 13, 2006 6:43 PM
To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch
Cc: 'Jon Minton'
Subject: RE: [R] inserting columns in the middle of a dataframe

Thanks, but isn't that only for elements in vectors?

I think I've found the following method to work:

e.g. for
df <- data.frame(v1,v2,v3,v4)

use:

df <- data.frame(df[1:2],v5,df[-c(1:2)])

I *believe* this is the one-line solution I was looking for. Can anyone see
why this wouldn't work?

Jon 



-----Original Message-
From: Christos Hatzis [mailto:[EMAIL PROTECTED]
Sent: 13 September 2006 23:22
To: 'Jon Minton'; r-help@stat.math.ethz.ch
Subject: RE: [R] inserting columns in the middle of a dataframe

See ?append

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jon Minton
Sent: Wednesday, September 13, 2006 5:14 PM
To: r-help@stat.math.ethz.ch
Cc: 'Jon Minton'
Subject: Re: [R] inserting columns in the middle of a dataframe

Dear R users:

 

Is there a built-in and simple way to insert new columns after other columns
in a dataframe?

 

I.e. currently I have:

 

V1 V2 V3 V4

[1,]

[2,]

Etc.

 

But I want 

V1 V5 V2 V3 V4

[1,] 

[2,]

Etc.

 

Can this be done in one line?

 

Jon Minton

 

 


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] inserting columns in the middle of a dataframe

2006-09-13 Thread Christos Hatzis
See ?append

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jon Minton
Sent: Wednesday, September 13, 2006 5:14 PM
To: r-help@stat.math.ethz.ch
Cc: 'Jon Minton'
Subject: Re: [R] inserting columns in the middle of a dataframe

Dear R users:

 

Is there a built-in and simple way to insert new columns after other columns
in a dataframe?

 

I.e. currently I have:

 

V1 V2 V3 V4

[1,]

[2,]

Etc.

 

But I want 

V1 V5 V2 V3 V4

[1,] 

[2,]

Etc.

 

Can this be done in one line?

 

Jon Minton

 

 


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] rename cols

2006-09-11 Thread Christos Hatzis
Try this:

old.colnames <- colnames(my.439.vars.df)
old.colnames[old.colnames=="fksm"] <- "new.name.a" 
old.colnames[old.colnames=="klmk"] <- "new.name.b"

I don't think it would be too complicated to put this into a function.

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Anupam Tyagi
Sent: Tuesday, September 12, 2006 12:34 AM
To: r-help@stat.math.ethz.ch
Subject: Re: [R] rename cols

For a newcomer who wants to rename variable "fksm" and "klmk" in a dataframe
of with 439 variables there is not easy and intuitive solution. That person
has to spend a lot of time listing columns and counting columns or doing
string searches or using brackets within brackets within brackets to get a
simple thing done. Is there a simple function or solution to this in R
without using an add-on package?

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Matrix multiplication using apply() or lappy() ?

2006-09-06 Thread Christos Hatzis
See ?sweep

sweep(a, 2, a[1,],"/")

-Christos  

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Wednesday, September 06, 2006 11:49 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Matrix multiplication using apply() or lappy() ?

I am trying to divide the columns of a matrix by the first row in the
matrix.

I have tried to get this using apply and I seem to be missing a concept
regarding the apply w/o calling a function but rather command args %*% /
etc.  Would using apply be more efficient than this approach? 

I have observed examples in the archives using this type of approach. Does
anybody have a snippet of a call to apply() that would accomplish this as
well?

Thanks!


seed=50
$a = array(rnorm(20),dim=c(4,5))
$b = matrix(a[1,],dim(a)[1],dim(a)[2],byrow=T)
$a
   [,1]   [,2]   [,3][,4]   [,5]
[1,] -1.3682810 -0.4314462 1.57572752  0.67928882 -0.3672346 [2,]  0.4328180
0.6556479 0.64289931  0.08983289  0.1852306 [3,] -0.8113932  0.3219253
0.08976065 -2.99309008  0.5818237 [4,]  1.4441013 -0.7838389 0.27655075
0.28488295  1.3997368

$a/b
   [,1]   [,2]   [,3]   [,4]  [,5]
[1,]  1.000  1.000 1.  1.000  1.00 [2,] -0.3163225
-1.5196515 0.40800157  0.1322455 -0.504393 [3,]  0.5930018 -0.7461539
0.05696457 -4.4062113 -1.584338 [4,] -1.0554128  1.8167710 0.17550671
0.4193841 -3.811560




CONFIDENTIALITY NOTICE: This electronic mail transmission (i...{{dropped}}

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Quick question about lm()

2006-09-04 Thread Christos Hatzis
Say,

my.lm <- lm(y ~ x, data=my.data)

Then if you try:

names(summary(my.lm)) 

you will see the components of the summary.lm object.  The coefficients and
t-statistics can be extracted by

summary(my.lm)$coefficients

and similarly for the r-squared and other statistics provided in the summary
report.

-Christos
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Tong Wang
Sent: Tuesday, September 05, 2006 1:35 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Quick question about lm()

Hi, 
 Feel awkward to ask , but really couldn't find a answer anywhere,   How
could I extract the R^2 and t-stat. from the 
result of lm()?
 Thanks a lot. 

best

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Plots Without Displaying

2006-08-16 Thread Christos Hatzis
Yes, you can do that for lattice-based plots.  The functions in the lattice
package produce objects of class "trellis" which can be stored in a list and
processed or updated at a later time:

library(lattice)
attach(barley)
plotList <- list(length=3)
plotList[[1]] <- xyplot(yield ~ site, data=barley)
plotList[[2]] <- xyplot(yield ~ variety, data=barley) 
plotList[[3]] <- xyplot(yield ~ year, data=barley)

plotList
plotList[[3]] <- update(plotList[[3]], yaxis="Yield (bushels/acre)")
print(plotList[[3]])

Obviously, you can store any lattice-based plot in the list.

HTH.

-Christos

Christos Hatzis, Ph.D.
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Lothar
Botelho-Machado
Sent: Wednesday, August 16, 2006 4:49 PM
To: r-help@stat.math.ethz.ch
Subject: Re: [R] Plots Without Displaying

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Prof Brian Ripley wrote:
> Yes, see
> 
> ?jpeg
> ?bitmap
> 
> and as you didn't tell us your OS we don't know if these are available 
> to you.
> 
> jpeg(file="test.jpg")
> boxplot(sample(100))
> dev.off()
> 
> may well work.
> 
> 'An Introduction to R' explains about graphics devices, including these.
> 
> 
> On Wed, 16 Aug 2006, Lothar Botelho-Machado wrote:
> 
>> -BEGIN PGP SIGNED MESSAGE-
>> Hash: SHA1
>>
>> R Help Mailing List,
>>
>>
>> I'd like to generate a plot that I could display and/or store it as e.g.
>> jpeg. But unfortunately always a plotting window opens. Is it 
>> possible to prevent that?
>>
>> I tried the following:
>> R> bp<-boxplot( sample(100), plot=FALSE)
>>
>> This works somehow, but it only stores data (as discribed in the 
>> help) in bp and it is not possible afaik to display bp later on or 
>> store them as a jpeg.
>>
>> The next:
>> R> p<-plot(sample(100), sample(100), plot=FALSE)
>> ..and also a variant using jpeg() didn't work at all.
>>
>> Is there a way to generally store the plots as object, without 
>> displaying them, or perhaps directly saving them to disc as jpeg?
>>
>> A "Yes" or "No" or any further help/links are appreciated!!!
> 
> 



Thank you for the explanation and your patience in answering me this
obviously very simple question!!

Originally I tried to store plots directly in a list. So writing them
directly to disc was just a good alternative. I knew that that jpeg()
provides functionality for that, but didn't use it correctly.

Hence, is it also possible to store a plot in a list, somehow?

Kind regards,
 Lothar
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFE44S8HRf7N9c+X7sRAgCpAKC3NhjCYwkteksOljUKWrO3166nCwCgsfLI
EPGVIoqc2dla5t6s9mmZQqE=
=h+Az
-END PGP SIGNATURE-

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] invisible() - does not return immediately as return() does

2006-08-11 Thread Christos Hatzis
Hi,

The difference is in the _return_ value of the function.

E.g.
> foo <- function() { cat("before\n"); cat("after\n"); return("done")}
> foo()
before
after
[1] "done"

i.e. returns the return value "done".

However
> foo2 <- function() { cat("before\n"); cat("after\n"); invisible("done")}
> foo2()
before
after 

does not show the return value (invisible), but it actually returns it
invisibly:

> x <- foo2()
before
after
> x
[1] "done"


HTH.

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Matthias Burger
Sent: Friday, August 11, 2006 4:45 PM
To: r-help@stat.math.ethz.ch
Subject: [R] invisible() - does not return immediately as return() does


Hi,

I stumbled across the following (unexpected for me) behavior after replacing
a return() statement in the middle of a function by invisible().

Example:
foo <- function() { cat("before\n"); return(); cat("after\n")}
>foo()
before
NULL

foo2 <- function() { cat("before\n"); invisible(TRUE); cat("after\n")}
>foo2()
before
after

I expected invisible to have the same behavior as return, namely immediately
return execution to the calling environment.

I rechecked ?invisible and ?return
and here I read in section 'See Also'
[...]
'invisible' for 'return(.)'ing _invisibly_.

Do I just misunderstand what this implies?
Put another way what is the intention behind invisible() continuing until
the last statement before returning? ?invisible does not hint at this.


Regards,

  Matthias


>R.version.string
[1] "Version 2.3.1 (2006-06-01)"

same behavior in R 2.2.1 or
R.version.string
[1] "R version 2.4.0 Under development (unstable) (2006-07-29 r38715)"

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] Pairwise n for large correlation tables?

2006-08-07 Thread Christos Hatzis
Hi,

You can use complete.cases
It should run faster than the code you suggested.

See following example:

x <- matrix(runif(30),10,3)

# introduce missing values
x[sample(1:10,3),1] <- NA
x[sample(1:10,3),2] <- NA
x[sample(1:10,3),3] <- NA

cor(x,use="pairwise.complete.obs")

n <- ncol(x)
n.na <- matrix(0, n, n)
for (i in seq(1, n)) {
n.na[i,i] <- sum( complete.cases(x[, i]) )
for (j in seq(i+1, length=n-i)) {
ok <- sum( complete.cases(x[, i], x[, j]) )
n.na[i,j] <- n.na[j,i] <- ok
}
}
 
HTH

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Adam D. I. Kramer
Sent: Monday, August 07, 2006 10:04 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Pairwise n for large correlation tables?

Hello,

I'm using a very large data set (n > 100,000 for 7 columns), for which I'm
pretty happy dealing with pairwise-deleted correlations to populate my
correlation table. E.g.,

a <- cor(cbind(col1, col2, col3),use="pairwise.complete.obs")

...however, I am interested in the number of cases used to compute each cell
of the correlation table. I am unable to find such a function via google
searches, so I wrote one of my own. This turns out to be highly inefficient
(e.g., it takes much, MUCH longer than the correlations do). Any hints,
regarding other functions to use or ways to maket his speedier, would be
much appreciated!

pairwise.n <- function(df=stop("Must provide data frame!")) {
   if (!is.data.frame(df)) {
 df <- as.data.frame(df)
   }
   colNum <- ncol(df)
   result <-
matrix(data=NA,nrow=colNum,ncol=ncolNum,dimnames=list(colnames(df),colnames(
df)))
   for(i in 1:colNum) {
 for (j in i:colNum) {
   result[i,j] <- length(df[!is.na(df[i])&!is.na(df[j])])/colNum
 }
   }
   result
}

--
Adam D. I. Kramer
University of Oregon

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] inserting rows into a matrix

2006-07-27 Thread Christos Hatzis
Hi Robin,

Ok.  I see.  Try this then:

f <- function(a){if( any(a==0) ) stop("Zeros in input vector") else
cbind(a,a+1,rev(a))}
a2 <- c(1,0,0,2,4,0,3)

f(a2) # error message

f2 <- function(a) {
indx.zero <- which(a==0)
indx.nz <- (1:length(a))[-indx.zero]

x <- f(a[indx.nz])
xx <- matrix(NA,length(a),ncol(x))
xx[ indx.zero, ] <- rep(0,ncol(x))
xx[ indx.nz, ] <- x
xx
}

> f2(a2)
 [,1] [,2] [,3]
[1,]123
[2,]000
[3,]000
[4,]234
[5,]452
[6,]000
[7,]341

-Christos

-Original Message-
From: Robin Hankin [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 27, 2006 10:16 AM
To: [EMAIL PROTECTED]
Cc: 'Robin Hankin'; 'RHelp'
Subject: Re: [R] inserting rows into a matrix

Hi Christos

thanks for this, but it won't work because in my application
f(A2) will fail if there are any zeroes in A2.


cheers

rksh


On 27 Jul 2006, at 15:10, Christos Hatzis wrote:

> This is not as elegant, but should work:
>
> a3 <- f(A2)
> a3[ which( apply(a3,1,prod) == 0 ), ] <- rep(0,ncol(a3))
> a3
>
> Essentially use the product to pick out the rows with at least one 0 
> and replace these rows with 0s.
>
> HTH.
> -Christos
>
> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin
> Sent: Thursday, July 27, 2006 9:54 AM
> To: RHelp
> Subject: [R] inserting rows into a matrix
>
> Hi
>
>
> I have a little vector function that takes a vector A of strictly 
> positive integers and outputs a matrix M  each of whose columns is the 
> vector, modified in a complicated combinatorical way.
>
> Now I want to generalize the function so that A can include zeroes.
> Given A,
> I want to strip out the zeroes, pass it to my function, and pad  M
>   with rows at positions corresponding to the zeroes of A.
>
> Commented, minimal, self-contained, reproducible toy example follows.
>
>
> f <- function(a){cbind(a,a+1,rev(a))}  #real function a ghastly 
> nightmare
>
>   A <- 1:5
>   f(A)
>   a
> [1,] 1 2 5
> [2,] 2 3 4
> [3,] 3 4 3
> [4,] 4 5 2
> [5,] 5 6 1
>
>
> # f() works as desired.
>
> # Now introduce A2, that includes zeroes.  In my application, f(A2) 
> would fail because of the zeroes.
>
> A2 <- c(1,0,0,2,4,0,3)
>
> I can strip the zeroes out and call f():
>   f(A2[A2>0])
>   a
> [1,] 1 2 3
> [2,] 2 3 4
> [3,] 4 5 2
> [4,] 3 4 1
>
> which is fine.  How to put the zeroes back in in the appropriate rows 
> and get the following:
>
>> cbind(c(1,0,0,2,4,0,3),c(2,0,0,3,5,0,4),c(3,0,0,4,2,0,1))
>   [,1] [,2] [,3]
> [1,]123
> [2,]000
> [3,]000
> [4,]234
> [5,]452
> [6,]000
> [7,]341
>>
>
>
>
> anyone?
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton European Way, Southampton
> SO14
> 3ZH, UK
>   tel  023-8059-7743
>
> __
> R-help@stat.math.ethz.ch 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.
>
>

--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton European Way, Southampton SO14
3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch 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] inserting rows into a matrix

2006-07-27 Thread Christos Hatzis
This is not as elegant, but should work:

a3 <- f(A2)
a3[ which( apply(a3,1,prod) == 0 ), ] <- rep(0,ncol(a3))
a3

Essentially use the product to pick out the rows with at least one 0 and
replace these rows with 0s.

HTH.
-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Robin Hankin
Sent: Thursday, July 27, 2006 9:54 AM
To: RHelp
Subject: [R] inserting rows into a matrix

Hi


I have a little vector function that takes a vector A of strictly positive
integers and outputs a matrix M  each of whose columns is the vector,
modified in a complicated combinatorical way.

Now I want to generalize the function so that A can include zeroes.   
Given A,
I want to strip out the zeroes, pass it to my function, and pad  M
  with rows at positions corresponding to the zeroes of A.

Commented, minimal, self-contained, reproducible toy example follows.


f <- function(a){cbind(a,a+1,rev(a))}  #real function a ghastly nightmare

  A <- 1:5
  f(A)
  a
[1,] 1 2 5
[2,] 2 3 4
[3,] 3 4 3
[4,] 4 5 2
[5,] 5 6 1


# f() works as desired.

# Now introduce A2, that includes zeroes.  In my application, f(A2) would
fail because of the zeroes.

A2 <- c(1,0,0,2,4,0,3)

I can strip the zeroes out and call f():
  f(A2[A2>0])
  a
[1,] 1 2 3
[2,] 2 3 4
[3,] 4 5 2
[4,] 3 4 1

which is fine.  How to put the zeroes back in in the appropriate rows and
get the following:

 > cbind(c(1,0,0,2,4,0,3),c(2,0,0,3,5,0,4),c(3,0,0,4,2,0,1))
  [,1] [,2] [,3]
[1,]123
[2,]000
[3,]000
[4,]234
[5,]452
[6,]000
[7,]341
 >



anyone?



--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton European Way, Southampton SO14
3ZH, UK
  tel  023-8059-7743

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] bilinear regression

2006-07-18 Thread Christos Hatzis
It appears that you might have a latent (hidden) explanatory variable that
causes the two-population appearance.  If you have some ideas on what that
other factor might be, you could try two separate linear regressions for
each value of the latent factor and compare the slopes and intercepts.  You
can then do some formal tests on the slopes and intercepts to see if you can
further simplify the model.  Depending on what you find, you can formulate a
linear regression model that incorporates such dependence on the slopes or
intercepts to fit the "bilinear" trend.

You might find helpful the discussion and example in Ch.10 of Venables &
Ripley, 4th ed, that introduces the concepts behind random and mixed effects
models.

-Christos

Christos Hatzis, Ph.D.
Vice President, Technology
Nuvera Biosciences, Inc.
400 West Cummings Park
Suite 5350
Woburn, MA 01801
Tel: 781-938-3830
www.nuverabio.com
 


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Crabb, David
Sent: Tuesday, July 18, 2006 1:36 PM
To: r-help@stat.math.ethz.ch
Subject: [R] bilinear regression

I think this is an easy question, but I would be grateful for any advice on
how to implement this in R.

I simply have a response variable (y) that I am trying to predict with one
explanatory variable (x) but the shape of the scatter plot is distinctly
bilinear. It would be best described by two straight lines.
Is there a way of fitting a linear model to give me a bilinear fit and (more
importantly) automatically determine the 'cut off' point? I would also want
some statistic to convince myself that the bilinear fit is better.

Many thanks for your help.

David


Dr. David Crabb
Department of Optometry and Visual Science, City University, Northampton
Square, London EC1V OHB
Tel: 44 207 040 0191   [EMAIL PROTECTED]
http://www.city.ac.uk/optometry/html/david_crabb.html

__
R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] String manipulation and formatting

2006-07-17 Thread Christos Hatzis
Ok.  You needed the format string.  
 
xify(4.1) would be equivalent to the following:
 
paste(paste(rep("X",4),collapse=""),paste(rep("X",1),collapse=""),sep=".")
 
It should be straightforward to write the wrapper function for this.
 
HTH.
 
-Christos

  _  

From: Bashir Saghir (Aztek Global) [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 17, 2006 10:39 AM
To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: [R] String manipulation and formatting



Thanks. 

I should have been clearer. The output is the string "XXX.XX" and "XXX". 

So xify(4.1) should produce "XXX.X" as character string. 

Any pointers? Or did I miss something with formatC? 

-Original Message- 
From: Christos Hatzis [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 17, 2006 16:21 
To: Bashir Saghir (Aztek Global); [EMAIL PROTECTED] 
Subject: RE: [R] String manipulation and formatting 


See ?formatC 

You might need to write a simple wrapper function to implement the interface

that you want. 

-Christos 

-Original Message- 
From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Bashir Saghir (Aztek 
Global) 
Sent: Monday, July 17, 2006 10:07 AM 
To: '[EMAIL PROTECTED]' 
Subject: [R] String manipulation and formatting 

I'm trying to write a simple function that does the following: 

  [command] xify(5.2) 
  [output] XXX.XX 

  [command] xify(3) 
  [output] XXX 

Any simple solutions (without using python/perl/unix script/...)? 

Thanks, 
Saghir 


- 
Legal Notice: This electronic mail and its attachments are i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] String manipulation and formatting

2006-07-17 Thread Christos Hatzis
See ?formatC

You might need to write a simple wrapper function to implement the interface
that you want. 

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Bashir Saghir (Aztek
Global)
Sent: Monday, July 17, 2006 10:07 AM
To: '[EMAIL PROTECTED]'
Subject: [R] String manipulation and formatting

I'm trying to write a simple function that does the following:

  [command] xify(5.2)
  [output] XXX.XX

  [command] xify(3)
  [output] XXX

Any simple solutions (without using python/perl/unix script/...)?

Thanks,
Saghir


-
Legal Notice: This electronic mail and its attachments are i...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Negative value on ternaryplot

2006-05-18 Thread Christos Hatzis
Ternary plots are typically used to plot triplets of values (e.g.
composition of 3 components) that add up to 100% or 1. In this context, I am
not sure what a negative value means.  Do the 3 numbers in your application
still add up to 100%?  Alternatively, would it be meaningful to translate
the data along the dimension with negative values to shift them to the
positive quadrant?

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Greg Snow
Sent: Thursday, May 18, 2006 2:37 PM
To: Poizot Emmanuel; r-help@stat.math.ethz.ch
Subject: Re: [R] Negative value on ternaryplot

There are also the functions: triangle.plot in package ade4, triplot in
package TeachingDemos, tri in package cwhtool, and soil.texture in package
plotrix.  Perhaps one of these other functions will work better for you (all
do the triangular plots, each with different bells and whistles).

triplot from TeachingDemos has an option to add to an existing plot (the
idea being that you already created one triplot and are now adding more
points/lines to it).  You could set up your own plot and axes then use
triplot with add=TRUE to plot your points.

If none of those work for you then you could look at the source code of
any of them to see what modifications would help.   

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Poizot Emmanuel
Sent: Thursday, May 18, 2006 7:05 AM
To: r-help@stat.math.ethz.ch
Subject: [R] Negative value on ternaryplot

Dear all,
I found a wonderful package (vcd) able to plot ternary diagrams, i.e. 
ternaryplot (thanks D. Meyer).
The problem is that one of three variable has negative values.
If I use the ternaryplot function but some points are outside the
triangle, as value en negative.
Is it possible to make the ternary diagram fit exactly the cloud points
?
Regards


Emmanuel Poizot
Cnam/Intechmer
B.P. 324
50103 Cherbourg Cedex

Phone (Direct) : (00 33)(0)233887342
Fax : (00 33)(0)233887339

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] create a vector

2006-05-17 Thread Christos Hatzis
paste("A", 1:300, sep="") 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of YIHSU CHEN
Sent: Thursday, May 18, 2006 12:56 AM
To: R-help@stat.math.ethz.ch
Subject: [R] create a vector

Dear R users:

I have an elementary question:  how to creat a vector of [A1, A2, A3..
A300]?  I know c(1:300) would give 1, 2, 3, , 300 but not sure how to
attch a A to each element.  

Thank you

Yihsu Chen
The Johns Hopkins University

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] everytime I download a new version of R, need I reinstall all packages?

2006-05-16 Thread Christos Hatzis
The process that you outlined is described in the Windows R FAQ 2.8 "What's
the best way to upgrade?".
The same process should apply to other platforms as well, but I don't think
it is in the general R FAQ.  Perhaps it should.

-Christos   

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Berton Gunter
Sent: Tuesday, May 16, 2006 8:16 PM
To: 'Michael'
Cc: R-help@stat.math.ethz.ch
Subject: Re: [R] everytime I download a new version of R,need I reinstall
all packages?

> 
> I think you did not answer my question... I now upgraded my main R 
> program from 2.2.1 to 2.3.0 and I removed the 2.2.1 installation, but 
> all the

Wait until after you use update.packages() to remove your previous
installation. You can keep multiple versions of R simultaneously, so this is
no problem. That is:

1) Install new R version
2) Run update.packages() on old library version
3) Copy updated old library to new library location (or point new library
location to old)
4) Remove old R version (and its libraries if you copied them)

There are probably better ways to do this, which this message may stimulate.


-- Bert

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] remove Punctuation characters

2006-05-09 Thread Christos Hatzis
Try 

gsub('[[:punct:]]', '', str)

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Filipe Almeida
Sent: Tuesday, May 09, 2006 11:51 AM
To: r-help@stat.math.ethz.ch
Subject: [R] remove Punctuation characters

Hi,

I want to remove all punctuation characters in a string. I was trying it use
a regular expressions but it doesn't work.
Here is a sample os what i want:

str <- 'ABD - remove de punct, and dot characters.'
str <- gsub('[:punct:]','',str)
str
"'ABD remove de punct and dot characters"

is there any function that do this kind of thing?

Thanks to all.

Filipe Almeida

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] predict.lm

2006-05-02 Thread Christos Hatzis
I think you got it right.

The mean of the (weighted) sum of a set of random variables is the
(weighted) sum of the means and its variance is the (weighted) sum of the
individual variances (using squared weights).  Here you don't have to worry
about weights.

So what you proposed does exactly this.

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Bill Szkotnicki
Sent: Tuesday, May 02, 2006 2:59 PM
To: 'R-Help help'
Subject: [R] predict.lm

I have a model with a few correlated explanatory variables.
i.e.
> m1=lm(y~x1+x2+x3+x4,protdata)
and I have used predict as follows:

> x=data.frame(x=1:36)
> yp=predict(m1,x,se.fit=T)
> tprot=sum(yp$fit) # add up the predictions tprot

tprot is the sum of the 36 predicted values and I would like the se of that
prediction.
I think  
> sqrt(sum(yp$se.fit^2))
is not correct.

Would anyone know the correct approach?
i.e. How to get the se of a function of predicted values (in this case sum)
 
Thanks, Bill

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] random walk on graph

2006-04-27 Thread Christos Hatzis
I did not look at your code in detail, but I see a potential problem in your
inner loop.  I think you intended k to be in 2,3,...N+1.  What you get from
your code is (2:N)+1 according to the operator precedence rules.  You need
2:(N+1).

HTH,
-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Eric Blabac
Sent: Thursday, April 27, 2006 11:28 AM
To: r-help@stat.math.ethz.ch
Subject: [R] random walk on graph

Hi all,
I'm having issues coding a random walk on a fully connected, undirected
graph G with probability transition matrix P = (p_ij). Here is what I have
so far ...

for(i in 1:n){
for(m in 1:M){
x <- as.vector(matrix(rep(0,N+1),nc=N+1))
x[1] <- i

for(k in 2:N+1){
y <- as.vector(matrix(rep(0,n),nc=n))
r <- runif(1)
c <- c(0,cumsum(P[x[k-1],]))

for(j in 1:n){
y[j] <- (r >= c[j] & r < c[j+1])
}
x[k] <- which(y == 1)
}
L[i,m] <- x[N+1]
}
}

its giving me the error:

Error in "[<-"(`*tmp*`, k, value = integer(0)) :
nothing to replace with

no matter what I do I cant fix it ... any suggestions ?
Thanks

Eric Blabac
PhD Student - ASU Dept of Mathematics/Statistics

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] copying previously installed libraries to R 2.3.0

2006-04-26 Thread Christos Hatzis
See Windows FAQ 2.8 - works well.

-Christos
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Thomas Harte
Sent: Wednesday, April 26, 2006 2:54 PM
To: r-help@stat.math.ethz.ch
Subject: [R] copying previously installed libraries to R 2.3.0

hi all,

is there a new mechanism in R 2.3.0 for copying libraries from, say, R 2.2.1
to R 2.3.0? i ask because gabor grothendieck comments in his copydir.bat
(from gabor's batchfiles at:
http://cran.r-project.org/contrib/extra/batchfiles/batchfiles_0.2-5.zip ):

``::   I personally upgraded my 2.1.0 to 2.2.0 this way so it seems ok until
  ::   R replaces this with something better which is expected for 2.3.0.
'''

see also the posting below.

cheers,

thomas.
 

[R] copy contributed packages from R 2.2.0 to 2.2.1
This message: [ Message body ]  [ More options ] 
Related messages:  [ Next message ] [ Previous message ] [ In reply to ]
[ Next in thread ]  
  
 From: Ronnie Babigumira 
Date: Fri, 23 Dec 2005 15:58:36 +0100
Hi Helli, this came up last week, Here are some of the replys posted 
 
1. 
 In http://cran.r-project.org/contrib/extra/batchfiles/batchfiles_0.2-5.zip 
 
are two Windows XP batch files: 
 
movedir.bat
 copydir.bat 
 
which will move the packages (which is much faster and suitable if you don't
need the old version of R any more) or copy  the packages (which takes
longer but preserves the old version). 
 
2. 
 x <- installed.packages()[,1]
 install.packages(x) 
 
3. 
 This is one reason we normally recommend that you install into a separate
library.  Then update.packages(checkBuilt =
 TRUE) is all that is needed. However, 
 
foo <- installed.packages()
 as.vector(foo[is.na(foo[, "Priority"]), 1]) 
 
will give you a character vector which you can feed to install.packages(),
so it's not complex to do manually. 
 
4. 
 If the previous installation is still alive, fire it up and 
 
pS <- packageStatus()
 pkgs <- pS$inst$Package[!pS$inst$Priority %in% c("base", "recommended")]
save(pkgs, file = "foo") 
 
In the new installation, 
 
load("foo")
 install.packages(pkgs) 
 
Helmut Kudrnovsky wrote: 
> hi R-users,
>  
> a few days ago R 2.2.1 came out. on my win xp i'installed R 2.2.0. along
the time i've installed a lot of contributed packages. my
internet-connection is not very fast. 
>  
> so my question: is it possible after installing R 2.2.1 to do copy/paste
the contributed packages from the C:\Programme\R221 to the
C:\Programme\R2.2.1- location in the files system? 
>  
> or have i to download and install the packages new? 
>  
>  
> greetings from the snowy austria
> merry christmas
> helli
>  
> system
> R.2.2.0
> win xp
>  
> __
> R-help at stat.math.ethz.ch mailing list 
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
Received on Fri Dec 23 2005 - 15:58:36 EST


   This message: [ Message body ]
   Next message: Matthias Kohl: "[R] convolution of the double exponential
distribution"
   Previous message: Helmut Kudrnovsky: "[R] copy contributed packages from
R 2.2.0 to 2.2.1"
   In reply to: Helmut Kudrnovsky: "[R] copy contributed packages from R
2.2.0 to 2.2.1"
   Next in thread: Uwe Ligges: "[R] copy contributed packages from R 2.2.0
to 2.2.1"
 
   Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [
by author ] [ by messages with attachments ]
  
   This archive was generated by hypermail 2.2.0  : Sat Dec 31 2005 -
19:09:32 EST 

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] variable labels in pairs

2006-04-25 Thread Christos Hatzis
Hello,

I am using 'pairs' to produce a scatter plot matrix with a custom
upper.panel function to plot the Pearson's correlation coefficients for the
pairs of variables.  

I would like to be able to use the actual variable names as subscripts in
rho in the printed text.  I know these labels are accessible to diag.panel
but cannot find a good way to access them within panel.cor.

Any suggestions?

Thank you.
-Christos  

### --- code snip ---

panel.cor <-
function(x, y, digits=3, subscripts, groups, cex.cor=2) {
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- abs(cor(x, y))
txt <- format(c(r, 0.123456789), digits=digits)[1]
txt <- substitute(italic(rho) == txt)
text(0.5, 0.5, txt, cex = cex.cor, col="blue")
}
pairs(my.df, upper.panel=panel.cor)

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Store results of for loop

2006-04-24 Thread Christos Hatzis
It is not very clear how you want to index your results vector.

If ss contains the indices of the results vector that you are trying to
change, this implies that you have a vector of length 9.  In this case 

results <- numeric(max(ss))
results[ss] <- ss + 1

will do the trick.

Or in case that ss contains the values that you want to augment by 1

results <- numeric(length(ss))
Results <- ss + 1

Am I missing something?

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Doran, Harold
Sent: Monday, April 24, 2006 4:32 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Store results of for loop

I have what I'm sure will turn out to be straightforward. I want to store
the results of a loop for some operations from a patterned vector.
For example, the following doesn't give what I would hope for

ss <- c(2,3,9)
results <- numeric(length(ss))
for (i in seq(along=ss)){
   results[i] <- i + 1
   }

The following does give what I expect, but creates a vector of length 9.

ss <- c(2,3,9)
results <- numeric(length(ss))
for (i in ss){
   results[i] <- i + 1
   }

What I am hoping for is that results should be a vector of length 3.

Harold


[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] how to do Splus compare() function in R

2006-04-20 Thread Christos Hatzis
As suggested below,

sign(ii*1e9-f) 

will give you the same result as the S-plus
 
compare(ii*1e-9,f)

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Bellinger Instruments
P/L
Sent: Thursday, April 20, 2006 11:02 PM
To: 'Prof Brian Ripley'
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] how to do Splus compare() function in R

The sign() function requires one argument, and returns the sign of the
value, where I require a number -1, 0, or 1 depending on if the value is <,
==, or > the first argument.

This is the Splus function when listed,
> compare
function(e1, e2)
.Internal(compare(e1, e2), "do_op", T, 18)

unfortunately I do not understand the .internal function and cannot find any
description of this type of programming on the CRAN site



This is how I am using it in the source file. 


zz <- readline()# keyboard input eg: f15


if (charmatch(substring(zz,1,1),"f",  
nomatch=-1) >0){
ii <- as.numeric(substring(zz,2,99))

iii <- compare(ii*1e9,f) # f is a vector of length(146) frequencies 
 # compare() searches thru f and
 # creates vector iii with 
   # -1 if numeric is < f[i],  
   #  0 if numeric is == f[i], and
 #  1 if numeric is > f[i]

# the end result is a vector(iii) length(146) 
  # with -1,0,1 if the numeric is in f


   i <- match(-1,c(iii,-1))-1 # if vector(iii) contains 0 assign the
index
  }

# error traps for if 0 is not in vector(iii)

if (i<1){cat("Min n = 1\n")
  i <- 1}
if (i>length(f)){cat("Max n =",length(f),"\n")
  i <- length(f)} 

-Original Message-
From: Prof Brian Ripley [mailto:[EMAIL PROTECTED]
Sent: Thursday, 20 April 2006 4:02 PM
Subject: Re: [R] how to do Splus compare() function in R

You would need to tell us what it does (and what the inputs are).

I think it is likely that compare(x, y) in S-PLUS is the same as sign(x-y)
in R, at least with numeric vector inputs.

-- 
Bob Kelly   [EMAIL PROTECTED]
Metrologist & Microwave Eng.http://www.bellinger.com.au
Bellinger Instruments Pty Ltd   Tel: 612 9684 1442
4 Muriel AveFax: 612 9638 4435
Rydalmere NSW
Australia  2116

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] The contrary of command %in%

2006-04-20 Thread Christos Hatzis
A flexible way for doing this is to define logical vectors for the types of
samples that you want to include or exclude.  You can then use logical
negation to select the complementary set:

inSet1 <- HData$H < 1.3
inSet2 <- HData$H < 8 & Hdata$DBH > 20

HDataPart1 <- Hdata[!inSet1, ]
HDataPart2 <- Hdata[!inSet2, ] 

-Christos

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ghislain Vieilledent
Sent: Thursday, April 20, 2006 8:55 AM
To: r-help@stat.math.ethz.ch
Subject: [R] The contrary of command %in%

Dear r-list,

I've got a data base:
> HData[1:10,]
   NumTree   Site Species Date Age DBHH IdentTree
11 Queige  Spruce 2002 184  49 33.5  Queige 1
22 Queige Fir 2002  NA   5  4.6  Queige 2
33 Queige Fir 2002  25   8  6.6  Queige 3
44 Queige  Spruce 2002 198  47 32.5  Queige 4
55 Queige Fir 2002 200  59 35.3  Queige 5
66 Queige  Spruce 2002  80  16  9.4  Queige 6
77 Queige Fir 2002  NA   5  4.2  Queige 7
88 Queige Fir 2002 200  44 32.5  Queige 8
99 Queige Fir 2002  NA   5  3.4  Queige 9
10  10 Queige  Spruce 2002 167  48 32.8 Queige 10
...

I want to remove particular points determined by
> HDataPartP<-HData[H<1.30,]
and
> HDataPartP2<-HData[H<8&DBH>20,]

That's why I want to use subset in a close form to:
HData2<-subset(HData,HData$H>1.30&HData$IdentTree
"not"%in%HDataPartP2$IdentTree)

How should I do that ?
Is there any R-syntax saying "not element of that object" ?

Thanks for your help.

Ghislain.

--
Ghislain Vieilledent
06 24 62 65 07

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] Basic vector operations was: Function to approximatecomplex integral

2006-04-19 Thread Christos Hatzis
You get the same result with

sum(outer(a,b))

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of jim holtman
Sent: Wednesday, April 19, 2006 3:32 PM
To: Doran, Harold
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Basic vector operations was: Function to approximatecomplex
integral

You can always write your own function that will take the values, multiply
and then sum them:

> a <- c(2,3)
> b <- c(4,5,6)
> total <- 0
> for (i in a) total <- sum(total, i * b) total
[1] 75
>


On 4/19/06, Doran, Harold <[EMAIL PROTECTED]> wrote:
>
> Dear List
>
> I apologize for the multiple postings. After being in the weeds on this
> problem for a while I think my original post may have been a little
> cryptic. I think I can be clearer. Essentially, I need the following
>
> a <- c(2,3)
> b <- c(4,5,6)
>
> (2*4) + (2*5) + (2*6) + (3*4) + (3*5) +(3*6)
>
> But I do not know of a built in function that would do this. Any
> suggestions?
>
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Doran, Harold
> Sent: Wednesday, April 19, 2006 11:51 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] Function to approximate complex integral
>
>
>
> I am writing a small function to approximate an integral that cannot be
> evaluated in closed form. I am partially successful at this point and am
> experiencing one small, albeit important problem. Here is part of my
> function below.
>
> This is a psychometric problem for dichotomously scored test items where
> x is a vector of 1s or 0s denoting whether the respondent answered the
> item correctly (1) or otherwise (0), b is a vector of item difficulties,
> and theta is an ability estimate for the individual.
>
> rasch <- function(b,theta){
>   1 / ( 1 + exp(b - theta))
>   }
>
> The function rasch gives the probability of a correct response to item i
> conditional on theta, the individuals ability estimate
>
> myfun <- function(x, b, theta){
>   sum(rasch(b, theta)^x * ( 1 - rasch(b,theta) )^(1-x) * dnorm(theta))
>   }
>
> This is the likelihood function assuming the data are Bernoulli
> distributed multiplied by a population distribution.
>
> Now, when x,b, and theta are of equal length the function works fine as
> below x <- c(1,1,0)
> b <-   c(-2,-1,0)
> t <-   c(-2,-1.5,-1)
> > myfun(x,b,t)
> [1] 0.2527884
>
> However, I want theta to be a vector of discrete values that will be
> larger than both x and b, something like
>
> t <- seq(-5, 0, by = .01)
>
> However, this gives me the error
> > myfun(x,b,t)
>
> Warning messages:
> 1: longer object length
>is not a multiple of shorter object length in: b - theta
>
> So, for the problem above, I want item 1 to be evaluated at theta 1
> through theta q and then item 2 is evaluated at theta 1 and through
> theta q and so forth for each item.
>
> Can anyone recommend a way for me to modify my function above to
> accomplish this?
>
> Harold
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
> __
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



--
Jim Holtman
Cincinnati, OH
+1 513 646 9390 (Cell)
+1 513 247 0281 (Home)

What the problem you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] how funciton "expression" produces subscript

2006-04-18 Thread Christos Hatzis
See ?plotmath for the answer to your question and many more regarding math
expression drawing.
It might be worth printing this help page for future reference.

-Christos 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jing Yang
Sent: Tuesday, April 18, 2006 10:24 AM
To: r-help
Subject: [R] how funciton "expression" produces subscript

Dear R-users,

does anyone know how funciton "expression" produces subscript?

Best,Jing

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


  1   2   >