Re: [R] A mistake in garchFit()? {fGarch}

2009-01-03 Thread Yohan Chalabi
 "TY" == Ted Young 
 on Tue, 30 Dec 2008 11:53:23 -0800 (PST)

   TY>
   TY> Hello,
   TY>
   TY> I was using garchFit {fGarch} to fit some GARCH processes.
   TY> I noticed that the result contains Log Likelihood value
   TY> (right above
   TY> Description), but when I use @fit to retrieve Log Likelihood
   TY> value,
   TY> the sign switched.
   TY> I am confused about which value I should choose to report...
   TY> Any help here?
   TY>
   TY> Thanks a lot!
   TY>
   TY> Ted

the result contains the maximized Log likelihood. 

But internally the negative Log likelihood is minimized ... 

hope this helps,
Yohan

-- 
PhD student
Swiss Federal Institute of Technology
Zurich

www.ethz.ch

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


[R] R Stacked Histogram

2009-01-03 Thread Jason Rupert
I've seen this asked, but never fully answered.  

Is it possible to plot stacked histograms in R? 

I have four data sets that I would like to show combined vertically in 
histogram format.  

Is this possible?  

Thank you for any feedback you can provide. 

P.S. I know I can show the four sets side by side, but I want to combine them, 
but still uniquely identify each.   Thanks again.




  
[[alternative HTML version deleted]]

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


[R] R help and finishing an excel project

2009-01-03 Thread Ray Mota
 Hi Yuzhi...I'm not sure if you company gets involve with small
project-but 

 I figure I send the e-mail and maybe you could point me in the right 

direction.

We are a small technology research firm and we do market shares and 

 market sizing. We wanted to automate teh process better. We had hire a 

consultant who develoepd all of the equations for us and process, I 

 have all of the details, the problem we have is that the consulatnt 

 came down with cancer and he has a tough battle ahead of him---he 

 never got a chance to convert it to excel and R so we could use it.
Does 

 your company have person that would get involve to finish this project 

 for us-if not any recommendations would be helpful

 I'm sorry for sending it to this since I wasn't sure which one ot sedn
it to,

 Thanks so Much

 Ray

 

 616-802-0896

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


Re: [R] segfault while running an R script

2009-01-03 Thread mauede
I have installed R-2.8.1 right now and will proceed with my tests. So
far I haven't used it.
The fault is presumably caused by a sort of misuse of the memory on my
part.
The attached R script (whose last Step is not debugged yet) implements
the algorithm for signal features extraction described in the attached
paper. Needless to say, to get good statistics we need plenty of
data.Therefore I started out with a minimum of 30 signals (please find
attached 48 detrended, denoised, centralized, standardized, and
compressed signals I am using with the script). The algorithm generates
many big matrices and vectors. Roughly a matrix is generated at each
step. Of course in my last script version
I will remove the useless data structures dynamically. At the time
being, though, I keep them all because I have to trace back each data
elaboration step.
Between successive runs I clear the console but rarely I clear the
workspace. Even if the data structures are generated again at each run,
maybe the system memory stack gets fragmented ? ... just my worthless
guess ...
I am afraid I cannot  prune the code without changing the algorithm. The
detected fault seems to be a memory problem. Therefore, the allocation
of big data structures over and over again is suspicious ...

About the algorithm... my implementation seems to perform according to
the prescription. However, I am not enthusiastic with results depending
on vague choices of the parameters. Basically the number of signal
features extracted depends on an arbitrary input threshold. Maybe
someone in the R-help list might suggest a better, more robust, way to
extract features from mono-channel signals ...

Kind regards,
   Maura E


Benvenuto in Alice Giga Mail!

mau...@alice.it tramite il servizio Giga Mail ha messo a tua
disposizione i seguenti allegati:
* Archive.zip ( 5980513 bytes )
* Signals-Features-Extraxtion-through-DWT-Coefficients.txt ( 10148 bytes
)
* wave.pdf ( 256758 bytes )

per scaricarli, fai click sul seguente link che ti portera' su una
pagina dove troverai i comandi per visualizzare o scaricare gli allegati
sul tuo PC: 
http://gigamail.rossoalice.alice.it/messages/readMessageFrameset.aspx?De
liveryID=19412684-adf5-4e53-a1fe-a8e58848cb8e
Ti ricordiamo che gli allegati saranno a tua disposizione fino al
08-01-2009 alle ore 11.35.04 e che il mittente potrebbe ricevere le
informazioni relative alla tua apertura della Giga Mail e all'avvenuto
download degli allegati.
GigaMail è il nuovo servizio gratuito di Alice che ti permette di
inviare a chi vuoi, allegati di grandi dimensioni, fino a 2GB, in modo
semplice e veloce, senza occupare spazio utile nella tua casella di
posta. Per saperne di più visita il sito www.alice.it 
Ti ringraziamo per aver utilizzato il servizio Alice GIGA MAIL.

[[alternative HTML version deleted]]

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


[R] How to capture multiple graph pages to .png ?

2009-01-03 Thread Mike Williamson
Hello all and thanks in advance for any help,

There are really two issues that I am having, both related to saving
graphs:
1) It seems that the "dev...()" functions are unstable when using higher
level graphs (specifically I was using levelplot)

2) I have a large grid of levelplot graphs that I can print out into a
subset quite easily when I print to screen, but if I print to a file, I
cannot print the subset.  (I mention .png in the subject because that's what
I used, but really any format is acceptable to me).

=

1) Unstable dev...() functions:


I have the following line of code embedded in a function using simple "plot"
commands and it works fine:

  if(!is.na(plotFileName)) dev.off()

I set "plotFIleName" as "NA" by default, in which case the plot prints
to screen.  If a name is given, the print goes to the png() function.
Therefore, I want to turn the device off to ensure that the next plot isn't
sent to the same device & overwrites it.
This works *perfectly fine* when using the plot function.  This exact
same code, however, does not work for levelplot or (I am assuming) any other
higher level trellis (sp!) graphs.  Below are snippets of the entire code,
edited a bit for

  if(!is.na(plotFileName)) {
print(paste("Saving Zonal plot to file ",plotFileName,".png",sep=""))
print("(To display instead, do not pass any 'plotFileName' argument to
cro.zone.plot function.)")
maxLayout <- c(0,length(unique(miniDataSet$splitCol)))
png(filename =
paste(as.character(plotFileName),".png",sep=""),width=(1.2*plotSize*(maxLayout[2]^(1/3))),
height=(plotSize*(maxLayout[2]^(1/3
  } else {
devAskNewPage(ask = TRUE)
maxLayout <- c(0,min(16,length(unique(miniDataSet$splitCol
  }
  levelplot(dataCol ~ siteX * siteY | splitCol,data = miniDataSet,

col.regions=rainbow(n=length(unique(miniDataSet$dataCol))+5,start=0.5,end=0.95),
layout = maxLayout,
shrink = c(0.6,1.1),at =
keyCols,xlab=list(label=xlab,cex=labelScale),
ylab=list(label=ylab,cex=labelScale),scales =
list(cex=axisScale),
main=list(label=paste(dataCol,plotTitle,splitCol),
  cex=titleScale),colorkey=list(labels=list(cex=labelScale)))

  if(!is.na(plotFileName)) dev.off()

If I keep the code exactly as is, it will not work.  If I remove *just the
last line*, the function will work, and then I simply have to manually
remove the device "by hand" (also by using dev.off() ) outside of the
function code.  Now the *really weird* thing:  if I comment out that last
"if(!is.na... dev.off()" line, the function *still does not work*.  I
literally have to remove the line, I cannot simply comment it out!  This is
why I think it is "unstable".
I have found a way around this (I simply put a loop in the front of any
of my plotting functions to ensure they have turned off all devices before
doing anything... this seems to work), so this is not my biggest problem,
personally.  But it does seem to be a bigger problem for R itself, and for
this community.
On a related note:  I have noticed that sometimes "devAskNewPage(ask =
TRUE)" is also buggy.  Normally I can just alter the code slightly to get it
to work, but the solutions are odd.  (For instance, I have found that if
"devAskNewPage(ask = TRUE)" is in an "if" clause, it sometimes won't work
unless I use the { } brackets around it, even with a one line if clause.



2) Printing multiple pages to png:

If you look through the code above, you'll see that I have altered the size
of the grid that is printed, depending upon whether it is printed to screen
or to png.  Specifically, look at:

  if(!is.na(plotFileName)) {
...
maxLayout <- c(0,length(unique(miniDataSet$splitCol)))
...
  } else {
...
maxLayout <- c(0,min(16,length(unique(miniDataSet$splitCol
  }
  levelplot(...layout = maxLayout...)

The reason I do this is because when I print to screen, the "askNewPage"
will allow me to look at the screen before the next one is printed.  I could
even screen capture that, if I wanted to choose a slow, ugly, and
non-scriptable solution.  But if I try to send to png, each of the new pages
of the grid overwrite each other.
Specifically, this levelplot is making a grid of ~ 60 graphs.  Since the
layout maxes to 16 graphs per page, it nicely forces it to a 4 x 4 matrix of
graphs, 4 pages long.  For the visual display, this is fine, as I mention.
For the save to png, only one of the pages is captured.  And, oddly, it is
rarely the last page.  I don't quite understand this, but it is usually
either the 2nd or the 3rd page that is saved to the png.
You can see my solution to it in the code above:  when saving to png,
all of the graphs are printed out in a gigantic grid, but I also increase
the height & width of the graph set so that each individual plot isn't too
tiny.  It isn't a totally useless solution, but still

[R] Equivalent of match for data.frame

2009-01-03 Thread Sébastien

Dear R-users,

I am translating a S script into R and having some troubles with the 
match function. This function appears to work with vector and data.frame 
in S, but not in R, e.g.:

a <- rep((1:4), each = 10)
b <- rep((1:10), times = 4)
mydf <- data.frame(a,b)
myarg <- mydf[1,]
match(myarg, mydf)

# S returns 1 but R returns NA NA

I guess one could use match(interaction(myarg), interaction(mydf)) to do 
the job but I was just wondering if there was a more direct function.


Thanks,

Sebastien

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


Re: [R] Equivalent of match for data.frame

2009-01-03 Thread Carlos J. Gil Bellosta
Hello,

Why not something like

lapply(mydf, function(x) match(myarg, x) )

?

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com


On Sat, 2009-01-03 at 07:24 -0500, Sébastien wrote:
> Dear R-users,
> 
> I am translating a S script into R and having some troubles with the 
> match function. This function appears to work with vector and data.frame 
> in S, but not in R, e.g.:
> a <- rep((1:4), each = 10)
> b <- rep((1:10), times = 4)
> mydf <- data.frame(a,b)
> myarg <- mydf[1,]
> match(myarg, mydf)
> 
> # S returns 1 but R returns NA NA
> 
> I guess one could use match(interaction(myarg), interaction(mydf)) to do 
> the job but I was just wondering if there was a more direct function.
> 
> Thanks,
> 
> Sebastien
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


Re: [R] Equivalent of match for data.frame

2009-01-03 Thread Prof Brian Ripley

On Sat, 3 Jan 2009, Carlos J. Gil Bellosta wrote:


Why not something like

lapply(mydf, function(x) match(myarg, x) )


I don't think that is what is intended (it does not give the quoted result 
in 'S'), but I don't actually know (and we were not told what 'S' this 
is).  My guess is that the whole row has to match element by element. 
For that I would hash rows as in duplicated.data.frame.  Something like


match.data.frame <- function(x, table, ...)
match(do.call("paste", c(x, sep = "\r")),
  do.call("paste", c(table, sep = "\r")), ...)

maybe with some added as.data.frame() calls for safety.



?

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com


On Sat, 2009-01-03 at 07:24 -0500, Sébastien wrote:

Dear R-users,

I am translating a S script into R and having some troubles with the
match function. This function appears to work with vector and data.frame
in S, but not in R, e.g.:
a <- rep((1:4), each = 10)
b <- rep((1:10), times = 4)
mydf <- data.frame(a,b)
myarg <- mydf[1,]
match(myarg, mydf)

# S returns 1 but R returns NA NA

I guess one could use match(interaction(myarg), interaction(mydf)) to do
the job but I was just wondering if there was a more direct function.

Thanks,

Sebastien

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


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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R Stacked Histogram

2009-01-03 Thread hadley wickham
On Fri, Jan 2, 2009 at 11:00 PM, Jason Rupert  wrote:
> I've seen this asked, but never fully answered.
>
> Is it possible to plot stacked histograms in R?
>
> I have four data sets that I would like to show combined vertically in 
> histogram format.
>
> Is this possible?

Yes, but it's generally not a terribly good way to display your data,
as it is hard to read the values of all except the series on the
bottom.

install.packages("ggplot2")
library(ggplot2)
qplot(carat, data = diamonds, binwidth = 0.1)
qplot(carat, data = diamonds, binwidth = 0.1, fill = cut)
qplot(carat, data = diamonds, binwidth = 0.1, fill = color)
qplot(carat, data = diamonds, binwidth = 0.1, fill = clarity)

More examples at http://had.co.nz/ggplot2/geom_histogram.html

Hadley


-- 
http://had.co.nz/

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


Re: [R] R Stacked Histogram

2009-01-03 Thread John Kane
Is this of any help?

http://www.cse.unsw.edu.au/~mike/myrlibrary/geneplotter/html/histStack.html


--- On Sat, 1/3/09, Jason Rupert  wrote:

> From: Jason Rupert 
> Subject: [R] R Stacked Histogram
> To: r-help@r-project.org
> Received: Saturday, January 3, 2009, 12:00 AM
> I've seen this asked, but never fully answered.  
> 
> Is it possible to plot stacked histograms in R? 
> 
> I have four data sets that I would like to show combined
> vertically in histogram format.  
> 
> Is this possible?  
> 
> Thank you for any feedback you can provide. 
> 
> P.S. I know I can show the four sets side by side, but I
> want to combine them, but still uniquely identify each.  
> Thanks again.
> 
> 
> 
> 
>   
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.


  __
Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your 
favourite sites. Download it now at
http://ca.toolbar.yahoo.com.

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


Re: [R] runif (and other generator) "precision" / man pages

2009-01-03 Thread John C Nash
I'm inclined to agree with the view that the "precision" of a generator 
should be highlighted better in the manual pages. When I do


?runif

I don't see a mention, but ?.Random.seed DOES give the info, as Duncan 
points out, and it is suggested to look there.


A 1-liner with each random number generator

"CAUTION: random number generators use different mechanisms and provide 
different properties of output that may not match your expectations, 
e.g., precision and periodicity. Do read details (... reference here ... 
) if they may be important to you."


could be helpful to folk who are not familiar with the subject.

An important underlying issue with RNGs is that "precision" -- really 
size of the underlying integer process -- can be highly relevant if we 
use them to build multivariate "random" vectors. This is apparently not 
"well known". I've once had a paper turned down by a respected journal 
because the referees thought "more than 32 bits was idiotic". The same 
journal published some similar work 15 years later because "existing 
generators were only 32 bits". Sigh. At least it wasn't our generator, 
which is actually a 10^30 period decimal one, implemented on quite an 
array of systems / languages, and we had a program generator to build 
Fortran, BASIC, Pascal and C "versions" for particular platforms.


JN

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


Re: [R] How to capture multiple graph pages to .png ?

2009-01-03 Thread jim holtman
W.R.T. multiple pages, the HELP page says to use a filename like this:

png(filename = "Rplot%03d.png",

where %03d is an incremented value for each page.

On Fri, Jan 2, 2009 at 2:23 PM, Mike Williamson  wrote:
> Hello all and thanks in advance for any help,
>
>There are really two issues that I am having, both related to saving
> graphs:
> 1) It seems that the "dev...()" functions are unstable when using higher
> level graphs (specifically I was using levelplot)
>
> 2) I have a large grid of levelplot graphs that I can print out into a
> subset quite easily when I print to screen, but if I print to a file, I
> cannot print the subset.  (I mention .png in the subject because that's what
> I used, but really any format is acceptable to me).
>
> =
>
> 1) Unstable dev...() functions:
>
>
> I have the following line of code embedded in a function using simple "plot"
> commands and it works fine:
>
>  if(!is.na(plotFileName)) dev.off()
>
>I set "plotFIleName" as "NA" by default, in which case the plot prints
> to screen.  If a name is given, the print goes to the png() function.
> Therefore, I want to turn the device off to ensure that the next plot isn't
> sent to the same device & overwrites it.
>This works *perfectly fine* when using the plot function.  This exact
> same code, however, does not work for levelplot or (I am assuming) any other
> higher level trellis (sp!) graphs.  Below are snippets of the entire code,
> edited a bit for
>
>  if(!is.na(plotFileName)) {
>print(paste("Saving Zonal plot to file ",plotFileName,".png",sep=""))
>print("(To display instead, do not pass any 'plotFileName' argument to
> cro.zone.plot function.)")
>maxLayout <- c(0,length(unique(miniDataSet$splitCol)))
>png(filename =
> paste(as.character(plotFileName),".png",sep=""),width=(1.2*plotSize*(maxLayout[2]^(1/3))),
>height=(plotSize*(maxLayout[2]^(1/3
>  } else {
>devAskNewPage(ask = TRUE)
>maxLayout <- c(0,min(16,length(unique(miniDataSet$splitCol
>  }
>  levelplot(dataCol ~ siteX * siteY | splitCol,data = miniDataSet,
>
> col.regions=rainbow(n=length(unique(miniDataSet$dataCol))+5,start=0.5,end=0.95),
>layout = maxLayout,
>shrink = c(0.6,1.1),at =
> keyCols,xlab=list(label=xlab,cex=labelScale),
>ylab=list(label=ylab,cex=labelScale),scales =
> list(cex=axisScale),
>main=list(label=paste(dataCol,plotTitle,splitCol),
>  cex=titleScale),colorkey=list(labels=list(cex=labelScale)))
>
>  if(!is.na(plotFileName)) dev.off()
>
> If I keep the code exactly as is, it will not work.  If I remove *just the
> last line*, the function will work, and then I simply have to manually
> remove the device "by hand" (also by using dev.off() ) outside of the
> function code.  Now the *really weird* thing:  if I comment out that last
> "if(!is.na... dev.off()" line, the function *still does not work*.  I
> literally have to remove the line, I cannot simply comment it out!  This is
> why I think it is "unstable".
>I have found a way around this (I simply put a loop in the front of any
> of my plotting functions to ensure they have turned off all devices before
> doing anything... this seems to work), so this is not my biggest problem,
> personally.  But it does seem to be a bigger problem for R itself, and for
> this community.
>On a related note:  I have noticed that sometimes "devAskNewPage(ask =
> TRUE)" is also buggy.  Normally I can just alter the code slightly to get it
> to work, but the solutions are odd.  (For instance, I have found that if
> "devAskNewPage(ask = TRUE)" is in an "if" clause, it sometimes won't work
> unless I use the { } brackets around it, even with a one line if clause.
>
> 
>
> 2) Printing multiple pages to png:
>
> If you look through the code above, you'll see that I have altered the size
> of the grid that is printed, depending upon whether it is printed to screen
> or to png.  Specifically, look at:
>
>  if(!is.na(plotFileName)) {
> ...
>maxLayout <- c(0,length(unique(miniDataSet$splitCol)))
> ...
>  } else {
> ...
>maxLayout <- c(0,min(16,length(unique(miniDataSet$splitCol
>  }
>  levelplot(...layout = maxLayout...)
>
> The reason I do this is because when I print to screen, the "askNewPage"
> will allow me to look at the screen before the next one is printed.  I could
> even screen capture that, if I wanted to choose a slow, ugly, and
> non-scriptable solution.  But if I try to send to png, each of the new pages
> of the grid overwrite each other.
>Specifically, this levelplot is making a grid of ~ 60 graphs.  Since the
> layout maxes to 16 graphs per page, it nicely forces it to a 4 x 4 matrix of
> graphs, 4 pages long.  For the visual display, this is fine, as I mention.
> For the save to png, only one of the pages is captured.  And, oddly, it is
> rarely the last page.  I don't quite

Re: [R] How to capture multiple graph pages to .png ?

2009-01-03 Thread Mike Williamson
Jim,

Thanks so much!  I feel kinda stupid now.  I read that part, but I
didn't really get what it was talking about... despite the fact that I am
fairly familiar with the %d syntax when setting up formatting.

  Regards,
 Mike

On Sat, Jan 3, 2009 at 8:36 AM, jim holtman  wrote:

> W.R.T. multiple pages, the HELP page says to use a filename like this:
>
> png(filename = "Rplot%03d.png",
>
> where %03d is an incremented value for each page.
>
> On Fri, Jan 2, 2009 at 2:23 PM, Mike Williamson 
> wrote:
> > Hello all and thanks in advance for any help,
> >
> >There are really two issues that I am having, both related to saving
> > graphs:
> > 1) It seems that the "dev...()" functions are unstable when using higher
> > level graphs (specifically I was using levelplot)
> >
> > 2) I have a large grid of levelplot graphs that I can print out into a
> > subset quite easily when I print to screen, but if I print to a file, I
> > cannot print the subset.  (I mention .png in the subject because that's
> what
> > I used, but really any format is acceptable to me).
> >
> > =
> >
> > 1) Unstable dev...() functions:
> >
> >
> > I have the following line of code embedded in a function using simple
> "plot"
> > commands and it works fine:
> >
> >  if(!is.na(plotFileName)) dev.off()
> >
> >I set "plotFIleName" as "NA" by default, in which case the plot prints
> > to screen.  If a name is given, the print goes to the png() function.
> > Therefore, I want to turn the device off to ensure that the next plot
> isn't
> > sent to the same device & overwrites it.
> >This works *perfectly fine* when using the plot function.  This exact
> > same code, however, does not work for levelplot or (I am assuming) any
> other
> > higher level trellis (sp!) graphs.  Below are snippets of the entire
> code,
> > edited a bit for
> >
> >  if(!is.na(plotFileName)) {
> >print(paste("Saving Zonal plot to file ",plotFileName,".png",sep=""))
> >print("(To display instead, do not pass any 'plotFileName' argument to
> > cro.zone.plot function.)")
> >maxLayout <- c(0,length(unique(miniDataSet$splitCol)))
> >png(filename =
> >
> paste(as.character(plotFileName),".png",sep=""),width=(1.2*plotSize*(maxLayout[2]^(1/3))),
> >height=(plotSize*(maxLayout[2]^(1/3
> >  } else {
> >devAskNewPage(ask = TRUE)
> >maxLayout <- c(0,min(16,length(unique(miniDataSet$splitCol
> >  }
> >  levelplot(dataCol ~ siteX * siteY | splitCol,data = miniDataSet,
> >
> >
> col.regions=rainbow(n=length(unique(miniDataSet$dataCol))+5,start=0.5,end=0.95),
> >layout = maxLayout,
> >shrink = c(0.6,1.1),at =
> > keyCols,xlab=list(label=xlab,cex=labelScale),
> >ylab=list(label=ylab,cex=labelScale),scales =
> > list(cex=axisScale),
> >main=list(label=paste(dataCol,plotTitle,splitCol),
> >  cex=titleScale),colorkey=list(labels=list(cex=labelScale)))
> >
> >  if(!is.na(plotFileName)) dev.off()
> >
> > If I keep the code exactly as is, it will not work.  If I remove *just
> the
> > last line*, the function will work, and then I simply have to manually
> > remove the device "by hand" (also by using dev.off() ) outside of the
> > function code.  Now the *really weird* thing:  if I comment out that last
> > "if(!is.na... dev.off()" line, the function *still does not work*.  I
> > literally have to remove the line, I cannot simply comment it out!  This
> is
> > why I think it is "unstable".
> >I have found a way around this (I simply put a loop in the front of
> any
> > of my plotting functions to ensure they have turned off all devices
> before
> > doing anything... this seems to work), so this is not my biggest problem,
> > personally.  But it does seem to be a bigger problem for R itself, and
> for
> > this community.
> >On a related note:  I have noticed that sometimes "devAskNewPage(ask =
> > TRUE)" is also buggy.  Normally I can just alter the code slightly to get
> it
> > to work, but the solutions are odd.  (For instance, I have found that if
> > "devAskNewPage(ask = TRUE)" is in an "if" clause, it sometimes won't work
> > unless I use the { } brackets around it, even with a one line if clause.
> >
> > 
> >
> > 2) Printing multiple pages to png:
> >
> > If you look through the code above, you'll see that I have altered the
> size
> > of the grid that is printed, depending upon whether it is printed to
> screen
> > or to png.  Specifically, look at:
> >
> >  if(!is.na(plotFileName)) {
> > ...
> >maxLayout <- c(0,length(unique(miniDataSet$splitCol)))
> > ...
> >  } else {
> > ...
> >maxLayout <- c(0,min(16,length(unique(miniDataSet$splitCol
> >  }
> >  levelplot(...layout = maxLayout...)
> >
> > The reason I do this is because when I print to screen, the "askNewPage"
> > will

[R] R badly lags matlab on performance?

2009-01-03 Thread Ajay Shah
Here's a small R program:

---
a <- rep(1,1000)

system.time(a <- a + 1)

system.time(for (i in 1:1000) {a[i] <- a[i] + 1})
---

and here's its matlab version:

---
function forloop()

  a = ones(1e7,1);

  tic; a = a + 1; toc

  tic
  for i=1:1e7
a(i) = a(i) + 1;
  end
  toc
---

The machine used for testing was an i386 core 2 duo machine at 2.2
GHz, running OS X `Tiger'. The R was 2.8.0 and the matlab was 2008a.

Here's the performance (time taken in seconds):

MatlabRTimes
Vector version  0.04460.0671.5x
For loop version0.099242.209   425.5x

So the R is 1.5x costlier for the vector version and 425.5x costlier
with matlab.

I wonder what we're doing wrong!

-- 
Ajay Shah  http://www.mayin.org/ajayshah  
ajays...@mayin.org http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.

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


Re: [R] runif (and other generator) "precision" / man pages

2009-01-03 Thread Ben Bolker
John C Nash  uottawa.ca> writes:

> 
> I'm inclined to agree with the view that the "precision" of a generator 
> should be highlighted better in the manual pages. When I do
> 
> ?runif
> 
> I don't see a mention, but ?.Random.seed DOES give the info, as Duncan 
> points out, and it is suggested to look there.
> 
> A 1-liner with each random number generator
> 
> "CAUTION: random number generators use different mechanisms and provide 
> different properties of output that may not match your expectations, 
> e.g., precision and periodicity. Do read details (... reference here ... 
> ) if they may be important to you."
> 
> could be helpful to folk who are not familiar with the subject.

 [snip]

  I would suggest that this would be most (only?) useful
under runif().  I'm not sure how much people are using other
random distributions as the basis for generating derived
quantities/deviates that depend on the detailed properties
of the deviates ... and I might suggest

The characteristics of output from pseudo-random
number generators (such as precision and periodicity) vary widely.  See
?.Random.seed for more information

  as a slightly shorter version.

  Ben Bolker

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


Re: [R] Calculating signicance value

2009-01-03 Thread Ben Bolker
Moumita Das  gmail.com> writes:

 [snip snip snip]

> But how do i get significance of
> e say:--
> recmeanC1&recmeanC2 or say recmeanC1 & i1.
> I can add this in my corr function shown above but:
> 
> #Finding out significance of the two items whose correlations are being
> found
> sig_value<-cor.test(corr_dataset)
> and also return that :-
> return(list(matrix=BPcor,sig=sig_value))
> 
>  For example recmeanC1 and i1 has to be passed here..as 2 separate
> dataframes,shown below if i pass the dataset for (recmeanC1 & i1 ) as as
> single datframe,cor.test() function doesn't accept it.Moreover cor()
> function took care of what will be crossed with what and the correlation
> produced.Now do i have to manually get possible pairs of the column names of
> my dataset(shown above dataset 1),and also the data and then pass to
> cor.test and calculate the significance.
> Isn't there any easier way to do this,with minimum number of lines of
> code.Because I am dealing with huge datasets.

  Take a look at stats:::cor.test.default .  It's pretty
long and complicated but most of the complication is for
dealing with different correlations (i.e., other than Pearson),
and the key lines for your purposes are:

r <- cor(x, y)
df <- n - 2
ESTIMATE <- c(cor = r)
PARAMETER <- c(df = df)
STATISTIC <- c(t = sqrt(df) * r/sqrt(1 - r^2))
p <- pt(STATISTIC, df)

  You can incorporate this in your function.
(I'm assuming you're not treating these computed values
as actual probabilities of observing the data given
the null hypothesis, since there is a huge multiple testing
issue ...)

 good luck
   Ben Bolker

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Stefan Grosse
On Sat, 3 Jan 2009 22:25:38 +0530 Ajay Shah  wrote:

AS> system.time(for (i in 1:1000) {a[i] <- a[i] + 1})

AS> I wonder what we're doing wrong!

it is no secret that R does badly with loops. Thats why it is
recommended to use vectorized operations.

Another approach is just in time compilation, which would speed up
simple loops. 

There is an interesting entry on R-wiki showing speeding up things:

http://wiki.r-project.org/rwiki/doku.php?id=tips:programming:code_optim2&s=just%20time

hth
Stefan

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Ben Bolker
Ajay Shah  mayin.org> writes:

> 
> Here's a small R program:
> 
> ---
> a <- rep(1,1000)
> 
> system.time(a <- a + 1)
> 
> system.time(for (i in 1:1000) {a[i] <- a[i] + 1})
> ---
> 
> and here's its matlab version:
> 
> ---
> function forloop()
> 
>   a = ones(1e7,1);
> 
>   tic; a = a + 1; toc
> 
>   tic
>   for i=1:1e7
> a(i) = a(i) + 1;
>   end
>   toc
> ---
> 
> The machine used for testing was an i386 core 2 duo machine at 2.2
> GHz, running OS X `Tiger'. The R was 2.8.0 and the matlab was 2008a.
> 
> Here's the performance (time taken in seconds):
> 
> MatlabRTimes
> Vector version  0.04460.0671.5x
> For loop version0.099242.209   425.5x
> 
> So the R is 1.5x costlier for the vector version and 425.5x costlier
> with matlab.
> 
> I wonder what we're doing wrong!

  OK, I'll bite.

  1. are you sure that the difference in the vector version is
real?  On my computer the R system time for the
vector computation ranges from 0.052 to 0.1.
I would definitely check how much variation there is.

  2. Every language has different advantages and disadvantages.
I believe Matlab does a lot of byte-code compiling.  If you're
interested in this sort of thing, try Ra
 , a version
of R that allows similar speed-ups.

  3. I appreciate that every language can be improved, but this
feels like something that is not "fixable" without changing
the language significantly.  You have lots of options if you need
to do these kinds of operations -- Matlab (if you can afford it),
Octave (does it run as quickly as Matlab?), programming in C
(see http://modelingwithdata.org/ ), coding the critical
non-vectorizable bits of your algorithm in C or FORTRAN, etc. etc.
etc..

  cheers
Ben Bolker

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Ajay Shah
On Sat, Jan 03, 2009 at 06:59:29PM +0100, Stefan Grosse wrote:
> On Sat, 3 Jan 2009 22:25:38 +0530 Ajay Shah  wrote:
> 
> AS> system.time(for (i in 1:1000) {a[i] <- a[i] + 1})
> 
> AS> I wonder what we're doing wrong!
> 
> it is no secret that R does badly with loops. Thats why it is
> recommended to use vectorized operations.

But there's a big difference even on the vectorised version: a <- a +
1. Why should that be? Both systems should merely be handing down to
the BLAS. The (stock) R install has a less carefully setup BLAS as
compared with the (stock) matlab install?

-- 
Ajay Shah  http://www.mayin.org/ajayshah  
ajays...@mayin.org http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Ben Bolker
Ajay Shah  mayin.org> writes:

> 
> On Sat, Jan 03, 2009 at 06:59:29PM +0100, Stefan Grosse wrote:
> > On Sat, 3 Jan 2009 22:25:38 +0530 Ajay Shah  mayin.org> wrote:
> > 
> > AS> system.time(for (i in 1:1000) {a[i] <- a[i] + 1})
> > 
> > AS> I wonder what we're doing wrong!
> > 
> > it is no secret that R does badly with loops. Thats why it is
> > recommended to use vectorized operations.
> 
> But there's a big difference even on the vectorised version: a <- a +
> 1. Why should that be? Both systems should merely be handing down to
> the BLAS. The (stock) R install has a less carefully setup BLAS as
> compared with the (stock) matlab install?

  See my other message. I'm suspicious of the real size of
the difference, I think the difference could well be
noise.   Also, this particular bit of arithmetic doesn't
involve BLAS -- see arithmetic.c (dig down until you get to
integer_binary) ...

  Ben Bolker

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Dirk Eddelbuettel

On 3 January 2009 at 23:40, Ajay Shah wrote:
| On Sat, Jan 03, 2009 at 06:59:29PM +0100, Stefan Grosse wrote:
| > On Sat, 3 Jan 2009 22:25:38 +0530 Ajay Shah  wrote:
| > 
| > AS> system.time(for (i in 1:1000) {a[i] <- a[i] + 1})
| > 
| > AS> I wonder what we're doing wrong!
| > 
| > it is no secret that R does badly with loops. Thats why it is
| > recommended to use vectorized operations.
| 
| But there's a big difference even on the vectorised version: a <- a +
| 1. Why should that be? Both systems should merely be handing down to
| the BLAS. The (stock) R install has a less carefully setup BLAS as
| compared with the (stock) matlab install?

Your example does not involve BLAS.  

As for jit and Ra, that was immediate reaction too but I found that jit does
not help on your example.  But I concur fully with what Ben said --- use the
tool that is appropriate for the task at hand.  If your task is running for
loops, Matlab does it faster and you have Matlab, well then you should by all
means use Matlab.

Dirk

-- 
Three out of two people have difficulties with fractions.

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Ajay Shah
> As for jit and Ra, that was immediate reaction too but I found that jit does
> not help on your example.  But I concur fully with what Ben said --- use the
> tool that is appropriate for the task at hand.  If your task is running for
> loops, Matlab does it faster and you have Matlab, well then you should by all
> means use Matlab.

A good chunk of statistical computation involves loops. We are all
happy R users. I was surprised to see that we are so far from matlab
in the crucial dimension of performance.

-- 
Ajay Shah  http://www.mayin.org/ajayshah  
ajays...@mayin.org http://ajayshahblog.blogspot.com
<*(:-? - wizard who doesn't know the answer.

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


[R] passing parameters to an R script

2009-01-03 Thread mauede
I knowf R functions ca be called passing some parameters.
My first question is: how are parameters passed to R functions ?
Browsing through R archives I found an answer confirming taht parameters can 
be passed to the  called function by value. I wonder whether passing the 
parameter 
address is possible somehow to allow the function to actually change its value.

My second question is about running R scripts with parameters. Something 
similar to the 
s/w device (argc, argv) which is used to run a C program with initial 
parameters. 
Is this possible at all ?

Thank you very much.
Maura 



tutti i telefonini TIM!


[[alternative HTML version deleted]]

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


[R] hexbin plot

2009-01-03 Thread Rodrigo Fernandes Ramalho
Hello,

I would like some help to plot a vertical line on a scatterplot build with
hexbin package.

I just need to plot a vertical line on the graph to mark a threshold value
on x axis.

It would be better if the parameter of the plot line function respect
the x axis scale.

Thanks,

Rodrigo

[[alternative HTML version deleted]]

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


[R] how specify lme() with multiple within-subject factors?

2009-01-03 Thread Ben Meijering

I have some questions about the use of lme().
Below, I constructed a minimal dataset to explain what difficulties I  
experience:


# two participants
subj <- factor(c(1, 1, 1, 1, 2, 2, 2, 2))
# within-subjects factor Word Type
wtype <- factor(c("nw", "w", "nw", "w", "nw", "w", "nw", "w"))
# within-subjects factor Target Present/Absent
present <- factor(c(0, 0, 1, 1, 0, 0, 1, 1))
# dependend variable Accuracy
acc <- c(.74, .81, .84, .88, .75, .95, .88, .94)

# repeated-measures analysis of variance
acc.aov <- aov(acc ~ wtype * present + Error(subj/wtype*present))
summary(acc.aov)

# to use lme
library(nlme)
# mixed-effects model
acc.lme <- lme(acc ~ wtype * present, random = ~ 1 | subj)
anova(acc.lme)

How do I have to specify the model to have 1 degree of freedom for the  
denominator or error-term, as in aov()?

I know how to do this for the first factor:

lme(.., .., random = ~1 | subj/wtype),

or

lme(.., .., random = list( ~ 1 | subj, ~1 | wtype))

, but not how to get the same degrees of freedom as in the specified  
aov(), i.e., 1 degree of freedom of the denominator for both factors  
and the interaction term.


How do I specify such a model?

~ Ben

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


[R] Non-Latin labels in identify

2009-01-03 Thread Aleksandr Andreev
Greetings.

I'm trying to label some points using the identify() command. The
labels and the coordinates are coming from a csv file. The file
encoding is UTF-8.
If I use labels in Latin characters, everything comes out OK.  But
when I switch to using labels in Cyrillic, I get garbage.

To check that my file is not corrupt, I've attempted to create the
labels using the text() command and just typing text in Russian into
the R prompt (my locale is set to UTF-8).  Once again, I get garbage.

My R version is 2.6.2 running on 64-bit Ubuntu Hardy.

Cordially,

Aleks Andreev

-- 

Aleksandr Andreev
Fulbright Fellow
Graduate School of Management
St Petersburg State University
Skype: typiconman

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Ted Harding
On 03-Jan-09 18:28:03, Ben Bolker wrote:
> Ajay Shah  mayin.org> writes:
>> On Sat, Jan 03, 2009 at 06:59:29PM +0100, Stefan Grosse wrote:
>> > On Sat, 3 Jan 2009 22:25:38 +0530 Ajay Shah 
>> > mayin.org> wrote:
>> > 
>> > AS> system.time(for (i in 1:1000) {a[i] <- a[i] + 1})
>> > 
>> > AS> I wonder what we're doing wrong!
>> > 
>> > it is no secret that R does badly with loops. Thats why it is
>> > recommended to use vectorized operations.
>> 
>> But there's a big difference even on the vectorised version: a <- a +
>> 1. Why should that be? Both systems should merely be handing down to
>> the BLAS. The (stock) R install has a less carefully setup BLAS as
>> compared with the (stock) matlab install?
> 
>   See my other message. I'm suspicious of the real size of
> the difference, I think the difference could well be
> noise.   Also, this particular bit of arithmetic doesn't
> involve BLAS -- see arithmetic.c (dig down until you get to
> integer_binary) ...
>   Ben Bolker

I just ran Ajay's examples 3 times over:
R 2.8.1 on Debian Etch using 1MB of RAM in a VirtualBox VM
running on a 1.73GHz CPU. Results:

  user  system elapsed
Vector:  0.112   0.288   0.393
Loop:   65.276   0.300  65.572

Vector:  0.076   0.312   0.389
Loop:   65.744   0.332  66.076

Vector:  0.068   0.328   0.394
Loop:   65.292   0.308  65.597

Not dissimilar to Ajay's R times (though my loop was about 50% longer).

However, all three runs were very similar -- a little noise,
but not much!

I don't have octave (on the same machine) to compare these with.
And I don't have MatLab at all. So I can't provide a comparison
on that front, I'm afraid.
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 03-Jan-09   Time: 19:10:51
-- XFMail --

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


Re: [R] extend summary.lm for hccm?

2009-01-03 Thread John Fox
Dear Achim,

I suspect that the problem, involving a fifth-degree raw polynomial, is
very ill-conditioned, and that the computation in linear.hypothesis()
fails because it is not as stable as lm() and summary.lm(). (BTW, one
would not normally call summary.lm() directly, but rather use the
generic summary() function instead.) A possible solution would be to
use a fifth-degree orthogonal polynomial, with the formula energyshare
~ poly(x.log, 5). (You don't need the 1 for the constant, since it's
implied.)

That said, it's hard for me to understand why it's interesting to have
standard errors for the individual coefficients of a high-degree
polynomial, and I'd also be concerned about the sensibleness of fitting
a fifth-degree polynomial in the first place.

I hope this helps,
 John


John Fox, Professor
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/


 original message --
Achim Voß achim.voss at uni-muenster.de
Tue Dec 30 14:15:37 CET 2008

Hi!


I am trying to estimate Engel curves using a big sample (>42,000) using
lm and
taking heteroskedasticity into account by using the summaryHCCM posted
here by
John Fox (Mon Dec 25 16:01:59 CET 2006).

Having used the SIC (with MASS stepAIC) to determine how many powers to
use I
estimate the model:

> # =
> summary.lm(fit.lm.5)

Call:
lm(formula = energyshare ~ 1 + I(x.log) + I(x.log^2) + I(x.log^3) +
I(x.log^4) + I(x.log^5), data = ev)

Residuals:
  Min1QMedian3Q   Max
-0.098819 -0.023682 -0.007043  0.013924  0.486615

Coefficients:
  Estimate Std. Error t value Pr(>|t|)
(Intercept) -5.452e+01  1.234e+01  -4.418 9.97e-06 ***
I(x.log) 3.177e+01  6.966e+00   4.560 5.13e-06 ***
I(x.log^2)  -7.330e+00  1.567e+00  -4.677 2.93e-06 ***
I(x.log^3)   8.395e-01  1.757e-01   4.778 1.78e-06 ***
I(x.log^4)  -4.775e-02  9.814e-03  -4.865 1.15e-06 ***
I(x.log^5)   1.079e-03  2.185e-04   4.939 7.90e-07 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.03748 on 42738 degrees of freedom
Multiple R-squared: 0.09236,Adjusted R-squared: 0.09226
F-statistic: 869.8 on 5 and 42738 DF,  p-value: < 2.2e-16
> # =




Now I use summaryHCCM(fit.lm.5):

> # =
> summaryHCCM(fit.lm.5)
Fehler in solve.default(L %*% V %*% t(L)) :
  System ist für den Rechner singulär: reziproke Konditionszahl =
6.98689e-19
> # =

("Error in solve.default(L %*% V %*% t(L)) :
  System is singulary for the computer: reciprocal number of conditions
=
  6.98689e-19")



This does not happen if I omit I(x.log^5). I do not know what it means
and I'd
be grateful if anyone could help. And I'd like to add a (more or less)
related
question: Can I still use AIC, SIC etc. if I know there's a
heteroskedasticity
problem?


Thanks in advance,
Achim

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread hadley wickham
On Sat, Jan 3, 2009 at 12:37 PM, Ajay Shah  wrote:
>> As for jit and Ra, that was immediate reaction too but I found that jit does
>> not help on your example.  But I concur fully with what Ben said --- use the
>> tool that is appropriate for the task at hand.  If your task is running for
>> loops, Matlab does it faster and you have Matlab, well then you should by all
>> means use Matlab.
>
> A good chunk of statistical computation involves loops. We are all
> happy R users. I was surprised to see that we are so far from matlab
> in the crucial dimension of performance.

I would disagree: only a small amount of statistical computation
involves explicit loops at the R level.  More importantly, the time
taken for this looping is a very small fraction of the total time
spent doing statistical computation.

Hadley

-- 
http://had.co.nz/

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


Re: [R] passing parameters to an R script

2009-01-03 Thread jim holtman
No you can not pass an address to a function.  If you want to change
the value of something, then return it as a value and assign it to the
object so you can see what is going on.  Must be coming from the "C"
environment where such things are allowed and lead to a number of
problems.

If you really have your heart set to do it, look at the '<<-' operator
(or 'assign'), but use it with care.

To retrieve environment values, use "Sys.getenv".

On Sat, Jan 3, 2009 at 1:32 PM,   wrote:
> I knowf R functions ca be called passing some parameters.
> My first question is: how are parameters passed to R functions ?
> Browsing through R archives I found an answer confirming taht parameters can
> be passed to the  called function by value. I wonder whether passing the 
> parameter
> address is possible somehow to allow the function to actually change its 
> value.
>
> My second question is about running R scripts with parameters. Something 
> similar to the
> s/w device (argc, argv) which is used to run a C program with initial 
> parameters.
> Is this possible at all ?
>
> Thank you very much.
> Maura
>
>
>
> tutti i telefonini TIM!
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem that you are trying to solve?

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Stefan Grosse

> I don't have octave (on the same machine) to compare these with.
> And I don't have MatLab at all. So I can't provide a comparison
> on that front, I'm afraid.
> Ted.
>   

Just to add some timings, I was running 1000 repetitions (adding up to
a=1001) on a notebook with core 2 duo T7200

R 2.8.1 on Fedora 10: mean 0.10967, st.dev 0.005238
R 2.8.1 on Windows Vista: mean 0.13245, st.dev 0.00943

Octave 3.0.3 on Fedora 10: mean 0.097276, st.dev 0.0041296

Matlab 2008b on Windows Vista: 0.0626 st.dev 0.005

But I am not sure how representative this is with that very simple
example. To compare Matlab speed with R a kind of benchmark suite is
necessary. Like: http://www.sciviews.org/benchmark/index.html but that
one is very old. I would guess that there did not change much: sometimes
R is faster, sometimes not.

This difference between the Windows and Linux timing is probably not
really relevant: when I was comparing the timings of my usual analysis
there was no difference between the two operating systems. (count data
and time series stuff)

Cheers
Stefan

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


Re: [R] passing parameters to an R script

2009-01-03 Thread Stavros Macrakis
R's variable passing mechanism is not call by value, but a mixture of
unevaluated arguments (like the obsolete Lisp FEXPR) and call-by-need.
 It is like FEXPR in that the function can capture the unevaluated
argument (using 'substitute').  But it is like call-by-need in that
normal use of the argument (without 'substitute') evaluates the
expression the first time the variable is evaluated and caches the
result as the value of the variable.  If the argument's value is never
evaluated, the argument is not evaluated.

For example:

 (function(x){print(1);x;print(2);x;print(substitute(x));4})(print(3))
[1] 1   << prints 1 before evaluating argument
[1] 3   << evaluates argument
[1] 2   << after evaluating argument
 << x has already been evaluated; is not reevaluated
print(3)  << quoted argument
[1] 4   << returns 4

You will sometimes here the terms call-by-name or lazy evaluation used
to describe R's mechanism, but those mean quite different things in
other programming languages, so it's best to avoid those terms.

So it is in fact possible to 'capture' a variable and modify it:

 increment <- function(var) eval(substitute(var<-var+1),parent.frame())
 x<-23
 increment(x)
 x  ==> 24

The 'substitute' operates in the function's own frame, so 'var'
evaluates to the argument; but then the evaluation is specified to
happen in the parent frame.

That said, as a general rule, it is very poor practice to do this sort of thing.

   -s

On Sat, Jan 3, 2009 at 1:32 PM,   wrote:
> I knowf R functions ca be called passing some parameters.
> My first question is: how are parameters passed to R functions ?
> Browsing through R archives I found an answer confirming taht parameters can
> be passed to the  called function by value. I wonder whether passing the 
> parameter
> address is possible somehow to allow the function to actually change its 
> value.

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


[R] R: passing parameters to an R script

2009-01-03 Thread mauede
Thank you.
You're right. I come from C and C++ programming.
I wonder whether to pass parameters to an R script I have to set environment 
variables ... ?

Best regards,
Maura 


-Messaggio originale-
Da: jim holtman [mailto:jholt...@gmail.com]
Inviato: sab 03/01/2009 21.12
A: mau...@alice.it
Cc: r-h...@stat.math.ethz.ch; r-help@r-project.org
Oggetto: Re: [R] passing parameters to an R script
 
No you can not pass an address to a function.  If you want to change
the value of something, then return it as a value and assign it to the
object so you can see what is going on.  Must be coming from the "C"
environment where such things are allowed and lead to a number of
problems.

If you really have your heart set to do it, look at the '<<-' operator
(or 'assign'), but use it with care.

To retrieve environment values, use "Sys.getenv".

On Sat, Jan 3, 2009 at 1:32 PM,   wrote:
> I knowf R functions ca be called passing some parameters.
> My first question is: how are parameters passed to R functions ?
> Browsing through R archives I found an answer confirming taht parameters can
> be passed to the  called function by value. I wonder whether passing the 
> parameter
> address is possible somehow to allow the function to actually change its 
> value.
>
> My second question is about running R scripts with parameters. Something 
> similar to the
> s/w device (argc, argv) which is used to run a C program with initial 
> parameters.
> Is this possible at all ?
>
> Thank you very much.
> Maura
>
>
>
> tutti i telefonini TIM!
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem that you are trying to solve?




tutti i telefonini TIM!


[[alternative HTML version deleted]]

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


[R] Power functions?

2009-01-03 Thread rkevinburton
I had a question about the basic power functions in R.

For example from the R console I enter:

-1 ^ 2
[1] -1

but also

-1^3
[1] -1

-0.1^2
[1]  -0.01

Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over the math 
functions? If so I would think that -1^2 is 1 not -1 and -0.1^2 is 0.01 not 
-0.01.

Thank you.

Kevin

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


[R] Linux words file

2009-01-03 Thread Erin Hodgess
Dear R People:

I have a small function that solves the "Jumble" puzzle from the
newspaper (I know...big deal).  It uses the the Linux "words" file.

My question is:  is there a similar words file for Windows, please?

Thanks,
Happy New (Gnu) Year.
Sincerely,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

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


Re: [R] Power functions?

2009-01-03 Thread Prof Brian Ripley

Please post to only one of

r-help@r-project.org
r-h...@stat.math.ethz.ch

not to both, as the same list then got two copies.

On Sat, 3 Jan 2009, rkevinbur...@charter.net wrote:


I had a question about the basic power functions in R.

For example from the R console I enter:

-1 ^ 2
[1] -1

but also

-1^3
[1] -1

-0.1^2
[1]  -0.01

Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over
the math functions? If so I would think that -1^2 is 1 not -1 and -0.1^2 
is 0.01 not -0.01.


See ?Syntax, linked from ?`^` :

 The following unary and binary operators are defined.  They are
 listed in precedence groups, from highest to lowest.

   '[ [[' indexing
   ':: :::'   access variables in a name space
   '$ @'  component / slot extraction
   '^'exponentiation (right to left)
   '- +'  unary minus and plus

so -1^2 is -(1^2) not (-1)^2.

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

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


Re: [R] Linux words file

2009-01-03 Thread Duncan Murdoch

On 03/01/2009 4:39 PM, Erin Hodgess wrote:

Dear R People:

I have a small function that solves the "Jumble" puzzle from the
newspaper (I know...big deal).  It uses the the Linux "words" file.

My question is:  is there a similar words file for Windows, please?


As far as I know Windows doesn't include its own, but if you have one in 
Linux, it's GPL'd, isn't it?  So it would be fine to use it on Windows, too.


Duncan Murdoch

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


Re: [R] Power functions?

2009-01-03 Thread Stavros Macrakis
Watch the operator precedences.  In R (and many other languages)

-1^2 == -(1^2) == -1

Perhaps you intended:

(-1)^2 == 1

On Sat, Jan 3, 2009 at 3:32 PM,   wrote:
> I had a question about the basic power functions in R.
>
> For example from the R console I enter:
>
> -1 ^ 2
> [1] -1
>
> but also
>
> -1^3
> [1] -1
>
> -0.1^2
> [1]  -0.01
>
> Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over the math 
> functions? If so I would think that -1^2 is 1 not -1 and -0.1^2 is 0.01 not 
> -0.01.
>
> Thank you.
>
> Kevin
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] Power functions?

2009-01-03 Thread YH Deng
(-1)^2
 Or
a <- -1
a^2
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of rkevinbur...@charter.net
Sent: January 3, 2009 3:33 PM
To: r-help@r-project.org; r-h...@stat.math.ethz.ch
Subject: [R] Power functions?

I had a question about the basic power functions in R.

For example from the R console I enter:

-1 ^ 2
[1] -1

but also

-1^3
[1] -1

-0.1^2
[1]  -0.01

Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over the
math functions? If so I would think that -1^2 is 1 not -1 and -0.1^2 is 0.01
not -0.01.

Thank you.

Kevin

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

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Wacek Kusnierczyk
(Ted Harding) wrote:
> On 03-Jan-09 18:28:03, Ben Bolker wrote:
>   
>> Ajay Shah  mayin.org> writes:
>> 
>>> On Sat, Jan 03, 2009 at 06:59:29PM +0100, Stefan Grosse wrote:
>>>   
 On Sat, 3 Jan 2009 22:25:38 +0530 Ajay Shah 
 mayin.org> wrote:

 AS> system.time(for (i in 1:1000) {a[i] <- a[i] + 1})

 AS> I wonder what we're doing wrong!

 it is no secret that R does badly with loops. Thats why it is
 recommended to use vectorized operations.
 
>>> But there's a big difference even on the vectorised version: a <- a +
>>> 1. Why should that be? Both systems should merely be handing down to
>>> the BLAS. The (stock) R install has a less carefully setup BLAS as
>>> compared with the (stock) matlab install?
>>>   
>>   See my other message. I'm suspicious of the real size of
>> the difference, I think the difference could well be
>> noise.   Also, this particular bit of arithmetic doesn't
>> involve BLAS -- see arithmetic.c (dig down until you get to
>> integer_binary) ...
>>   Ben Bolker
>> 
>
> I just ran Ajay's examples 3 times over:
> R 2.8.1 on Debian Etch using 1MB of RAM in a VirtualBox VM
> running on a 1.73GHz CPU. Results:
>
>   user  system elapsed
> Vector:  0.112   0.288   0.393
> Loop:   65.276   0.300  65.572
>
> Vector:  0.076   0.312   0.389
> Loop:   65.744   0.332  66.076
>
> Vector:  0.068   0.328   0.394
> Loop:   65.292   0.308  65.597
>
> Not dissimilar to Ajay's R times (though my loop was about 50% longer).
>
> However, all three runs were very similar -- a little noise,
> but not much!
>
> I don't have octave (on the same machine) to compare these with.
> And I don't have MatLab at all. So I can't provide a comparison
> on that front, I'm afraid.
> Ted.
>
>   

on my machine, matlab and r perform as in to ajay's results, but octave
runs the for loop matlab code painfully slowly, worse than r.

vQ

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


Re: [R] Power functions?

2009-01-03 Thread Marc Schwartz
on 01/03/2009 02:32 PM rkevinbur...@charter.net wrote:
> I had a question about the basic power functions in R.
> 
> For example from the R console I enter:
> 
> -1 ^ 2 [1] -1
> 
> but also
> 
> -1^3 [1] -1
> 
> -0.1^2 [1]  -0.01
> 
> Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over
> the math functions? If so I would think that -1^2 is 1 not -1 and
> -0.1^2 is 0.01 not -0.01.
> 
> Thank you.
> 
> Kevin

Kevin,

See R FAQ 7.33 Why are powers of negative numbers wrong?

http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-are-powers-of-negative-numbers-wrong_003f


For the issue of returning -Inf or NaN, I suspect that you are thinking
about negative numbers being raised to non-integer powers. For example,
taking into consideration the enlightenment in the above FAQ:

> (-1) ^ (1 / 2)
[1] NaN

> (-2) ^ (1/2)
[1] NaN

> sqrt(-2)
[1] NaN
Warning message:
In sqrt(-2) : NaNs produced

> (-2) ^ 2.5
[1] NaN


HTH,

Marc Schwartz

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


Re: [R] Power functions?

2009-01-03 Thread Wacek Kusnierczyk
rkevinbur...@charter.net wrote:
> I had a question about the basic power functions in R.
>
> For example from the R console I enter:
>
> -1 ^ 2
> [1] -1
>
> but also
>
> -1^3
> [1] -1
>
> -0.1^2
> [1]  -0.01
>
> Normally pow(-1, 2) return either -Infinity or NaN. Has R taken over the math 
> functions? If so I would think that -1^2 is 1 not -1 and -0.1^2 is 0.01 not 
> -0.01.
>   

(-1)^2
# 1, not -1

it's similar to the case

1:3-1
1:(3-1)

it's about operator precedence.

vQ

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Wacek Kusnierczyk
Ajay Shah wrote:
>> As for jit and Ra, that was immediate reaction too but I found that jit does
>> not help on your example.  But I concur fully with what Ben said --- use the
>> tool that is appropriate for the task at hand.  If your task is running for
>> loops, Matlab does it faster and you have Matlab, well then you should by all
>> means use Matlab.
>> 
>
> A good chunk of statistical computation involves loops. We are all
> happy R users. I was surprised to see that we are so far from matlab
> in the crucial dimension of performance.
>
>   

this list has a tradition of encouraging users to use apply&relatives
instead of for loops (and to use vectorised code instead of both).

compare the following for n = 10^6 and n = 10^7:

x = 1:n
system.time({for (i in 1:n) x[i] = x[i] + 1})

x = 1:n
system.time({x = sapply(x, `+`, 1)})


vQ

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Duncan Murdoch

On 03/01/2009 1:37 PM, Ajay Shah wrote:

As for jit and Ra, that was immediate reaction too but I found that jit does
not help on your example.  But I concur fully with what Ben said --- use the
tool that is appropriate for the task at hand.  If your task is running for
loops, Matlab does it faster and you have Matlab, well then you should by all
means use Matlab.


A good chunk of statistical computation involves loops. We are all
happy R users. I was surprised to see that we are so far from matlab
in the crucial dimension of performance.



I don't know Matlab, but I think the thing that is slowing R down here 
is its generality.  When you write


a[i] <- a[i] + 1

in R, it could potentially change the meaning of a, [, <-, and + on each 
step through the loop, so R looks them up again each time.  I would 
guess that's not possible in Matlab, or perhaps Matlab has an optimizer 
that can recognize that in the context where the loop is being 
evaluated, those changes are known not to happen.  It *would* be 
possible to write such an optimizer for R, and Luke Tierney's byte code 
compiler-in-progress might incorporate such a thing.


For the difference in timing on the vectorized versions, I'd guess that 
Matlab uses a better compiler than gcc.  It's also likely that R 
incorporates some unnecessary testing even in a case like this, because 
it's easier to maintain code that is obviously sane than it is to 
maintain code that may not be.  R has a budget which is likely several 
orders of magnitude smaller than Mathworks has, so it makes sense to 
target our resources at more important issues than making fast things 
run a bit faster.


Duncan Murdoch

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


Re: [R] Linux words file

2009-01-03 Thread Ted Harding
On 03-Jan-09 21:39:55, Erin Hodgess wrote:
> Dear R People:
> 
> I have a small function that solves the "Jumble" puzzle from the
> newspaper (I know...big deal).  It uses the the Linux "words" file.
> 
> My question is:  is there a similar words file for Windows, please?
> 
> Thanks,
> Happy New (Gnu) Year.
> Sincerely,
> Erin

And the same to you!
I don't know whether you can easily find the same readymade
for Windows, but you could always make one from the Linux file,
since it is a plain text file.

I have it in /etc/dictionaries-common/words

You might need to DOSify it first (i.e. end lines with CRLF
instead of just LF), though I don't know how Windows reacts
to Unix text files these days. In that case (in Linux):

  cp /etc/dictionaries-common/words words.txt
  unix2dos words.txt

unix2dos is an old program which is not present on all Linux
distributions. Maybe you don't need it anyway, in which case
just do the 'cp' (to get the extension ".txt").

And are you going to share your R program?

Hoping this helps,
Ted.


E-Mail: (Ted Harding) 
Fax-to-email: +44 (0)870 094 0861
Date: 03-Jan-09   Time: 22:30:06
-- XFMail --

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


[R] [R-pkgs] RQDA-0.1-6 is on CRAN

2009-01-03 Thread ronggui
Major new features of RQDA-0.1-6:
GUI:
* GUI for file-organization (e.g searching, categorization etc.).
* GUI for settings (e.g. colors for )

Functions:
* Import a batch of files
* Calculate the relation between two codings, given the coding index
* Gives a summary of coding and inter-code relationship

-- 
HUANG Ronggui, Wincent
Tel: (00852) 3442 3832
PhD Candidate, City University of Hong Kong
Website: http://ronggui.huang.googlepages.com/
RQDA project: http://rqda.r-forge.r-project.org/

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

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread luke

On Sat, 3 Jan 2009, Duncan Murdoch wrote:


On 03/01/2009 1:37 PM, Ajay Shah wrote:
As for jit and Ra, that was immediate reaction too but I found that jit 
does
not help on your example.  But I concur fully with what Ben said --- use 
the
tool that is appropriate for the task at hand.  If your task is running 
for
loops, Matlab does it faster and you have Matlab, well then you should by 
all

means use Matlab.


A good chunk of statistical computation involves loops. We are all
happy R users. I was surprised to see that we are so far from matlab
in the crucial dimension of performance.



I don't know Matlab, but I think the thing that is slowing R down here is its 
generality.  When you write


a[i] <- a[i] + 1

in R, it could potentially change the meaning of a, [, <-, and + on each step 
through the loop, so R looks them up again each time.  I would guess that's 
not possible in Matlab, or perhaps Matlab has an optimizer that can recognize 
that in the context where the loop is being evaluated, those changes are 
known not to happen.


R's interpreter is fairly slow due in large part to the allocation of
argument lists and the cost of lookups of variables, including ones
like [<- that are assembled and looked up as strings on every call.

It *would* be possible to write such an optimizer for 
R, and Luke Tierney's byte code compiler-in-progress might incorporate such a 
thing.


The current byte code compiler available from my web site speeds this
(highly artificial) example by about a factor of 4.  The experimental
byte code engine I am currently working on (and that can't yet do much
more than an example like this) speeds this up by a factor of
80. Whether that level of improvement (for toy examples like this)
will remain once the engine is more complete and whether a reasonable
compiler can optimize down to the assembly code I used remain to be
seen.

For the difference in timing on the vectorized versions, I'd guess that 
Matlab uses a better compiler than gcc.  It's also likely that R incorporates 
some unnecessary testing even in a case like this, because it's easier to 
maintain code that is obviously sane than it is to maintain code that may not 
be.  R has a budget which is likely several orders of magnitude smaller than 
Mathworks has, so it makes sense to target our resources at more important 
issues than making fast things run a bit faster.


Another possibility is optimization setting tht may be higher and/or
more processor specific than those used by R.

We do handle the case where both arguments to + are scalar (i.e. of
length 1) separately but I don't recall if we do so for the
vector/scalar case also -- I suspect not as that would make the code
less maintainable for not a very substantial gain.

luke


Duncan Murdoch

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



--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:  l...@stat.uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu

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


Re: [R] R badly lags matlab on performance?

2009-01-03 Thread Dirk Eddelbuettel

On 3 January 2009 at 18:02, l...@stat.uiowa.edu wrote:
| The current byte code compiler available from my web site speeds this
| (highly artificial) example by about a factor of 4.  The experimental
| byte code engine I am currently working on (and that can't yet do much
| more than an example like this) speeds this up by a factor of
| 80. Whether that level of improvement (for toy examples like this)
| will remain once the engine is more complete and whether a reasonable
| compiler can optimize down to the assembly code I used remain to be
| seen.

Stephen Milborrow's jit compiler and Ra variant -- for which the R 2.8.1
version was released today -- already delivers improvements somewhere near
the middle of 'four' to 'eighty' times:

e...@ron:~> R --slave < /tmp/ajayshah.R
   user  system elapsed
  0.052   0.056   0.109
   user  system elapsed
 68.984   0.088  69.384
e...@ron:~> Ra --slave < /tmp/ajayshah.Ra
   user  system elapsed
  0.096   0.068   0.162
   user  system elapsed
   2.060.102.16
e...@ron:~> diff -u /tmp/ajayshah.R*
--- /tmp/ajayshah.R 2009-01-03 11:05:03.0 -0600
+++ /tmp/ajayshah.Ra2009-01-03 18:37:20.0 -0600
@@ -2,4 +2,4 @@

 system.time(a <- a + 1)

-system.time(for (i in 1:1000) {a[i] <- a[i] + 1})
+system.time({ jit(1); for (i in 1:1000) {a[i] <- a[i] + 1} })
e...@ron:~>

The vectorised example shows highly variable times anywhere between 0.11 to
0.17 seconds so taking ratios is speculative.  Either way, you can get a
speedup of maybe 30 times by switching to a just-in-time compiler for R and
adding an additional function call.

Dirk

-- 
Three out of two people have difficulties with fractions.

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


[R] POSIXct and chron issues with tz

2009-01-03 Thread Sherri Heck

Dear All-

I am trying to merge two data files - they have different date formats 
and different times zones.  I need to match up the date/time of the 
datasets and then invoke a conditional statement, such as: if dataC$mph 
is >= 12 then keep dataM$co23 for the corresponding time/date stamp.


snippets of data files:

*dataC.txt*
LST   in mphDeg   DegF  DegF2%volts   Degmph2   w/m2
050601   0.00   13.6  218.1   36.8   -999   65.1   -999   -999   
18.20.2
0506010005   0.00   12.9  214.3   36.8   -999   65.5   -999   -999   
16.90.2
0506010010   0.00   14.4  215.7   36.9   -999   65.4   -999   -999   
20.40.2


*dataM.txt*
doy yr mon day hr hgt1 hgt2 hgt3 co21 co22 co23 sig1 sig2 sig3 dif flag

244.02083 2005 09 01 00 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 
-999.99 -999.99 -999.99 PRE
244.0625 2005 09 01 01 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 
-999.99 -999.99 -999.99 PRE
244.10417 2005 09 01 02 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 
-999.99 -999.99 -999.99 PRE


*Code:*

z <- read.zoo("dataC.txt", header = TRUE, na.strings = -999,  
   format = "%y%m%d%H%M", FUN = 
as.chron,
   colClasses = c("character", rep("numeric", 10)))


DF <- read.table("C:/R/dataM.txt", header = TRUE, na.strings = -999.99)
tt <- with(DF, chron(paste(mon, day, yr, sep = "/"),
  paste(hr, 0, 0, sep = ":")))
  timeconv <-  as.POSIXct(tt, tz="")
  z2 <- zoo(data.matrix(DF), timeconv)


*example of output of data files*

>z[1,]
   in.  mph   Deg DegF DegF2   X. volts Deg.1 mph2 w.m2
(06/01/05 00:00:00)   0 13.6 218.1 36.8NA 65.1NANA 18.2  0.2


> z2[1,]
doy   yr mon day hr hgt1 hgt2 hgt3 co21 co22 
co23 sig1 sig2 sig3 dif flag
2005-08-31 18:00:00 244.0208 2005   9   1  0  2.5  5.8  9.1   NA   NA   
NA   NA   NA   NA  NA1


*#merging data files z, z2*
m <- merge(z, z2, all = c(FALSE, TRUE))
m[m==-999.99]<-NA
m2 <- m[m$mon %in% c(6,7,8),]

*returns the following warning message:*
Warning message:
In merge.zoo(z, z2, all = c(FALSE, TRUE)) :
 Index vectors are of different classes: chron POSIXt

I cannot find a way to deal with the timezone in chron.  But, I found 
through the help pages that POSIXct deals with tz.  However, it doesn't 
seem these two different formats are compatible to merge.  Any thoughts 
would be appreciated.


cheers,

sherri

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


Re: [R] R: passing parameters to an R script

2009-01-03 Thread jim holtman
?commandArgs

On Sat, Jan 3, 2009 at 4:17 PM,   wrote:
> Thank you.
> You're right. I come from C and C++ programming.
> I wonder whether to pass parameters to an R script I have to set environment
> variables ... ?
>
> Best regards,
> Maura
>
>
> -Messaggio originale-
> Da: jim holtman [mailto:jholt...@gmail.com]
> Inviato: sab 03/01/2009 21.12
> A: mau...@alice.it
> Cc: r-h...@stat.math.ethz.ch; r-help@r-project.org
> Oggetto: Re: [R] passing parameters to an R script
>
> No you can not pass an address to a function.  If you want to change
> the value of something, then return it as a value and assign it to the
> object so you can see what is going on.  Must be coming from the "C"
> environment where such things are allowed and lead to a number of
> problems.
>
> If you really have your heart set to do it, look at the '<<-' operator
> (or 'assign'), but use it with care.
>
> To retrieve environment values, use "Sys.getenv".
>
> On Sat, Jan 3, 2009 at 1:32 PM,   wrote:
>> I knowf R functions ca be called passing some parameters.
>> My first question is: how are parameters passed to R functions ?
>> Browsing through R archives I found an answer confirming taht parameters
>> can
>> be passed to the  called function by value. I wonder whether passing the
>> parameter
>> address is possible somehow to allow the function to actually change its
>> value.
>>
>> My second question is about running R scripts with parameters. Something
>> similar to the
>> s/w device (argc, argv) which is used to run a C program with initial
>> parameters.
>> Is this possible at all ?
>>
>> Thank you very much.
>> Maura
>>
>>
>>
>> tutti i telefonini TIM!
>>
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>
>
>
> Alice Messenger ;-) chatti anche con gli amici di Windows Live Messenger e
> tutti i telefonini TIM!
> Vai su http://maileservizi.alice.it/alice_messenger/index.html?pmk=footer



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

What is the problem that you are trying to solve?

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


Re: [R] POSIXct and chron issues with tz

2009-01-03 Thread Gabor Grothendieck
There seems to be no reason to use POSIXct in the first place.
Just use chron everywhere and read R News 4/1.
Suppose we just want month 9 from the merged object:

z2 <- zoo(data.matrix(DF), tt)

m <- merge(z, z2, all = c(FALSE, TRUE))
m[ m$mon %in% 9 ]


On Sat, Jan 3, 2009 at 7:57 PM, Sherri Heck  wrote:
> Dear All-
>
> I am trying to merge two data files - they have different date formats and
> different times zones.  I need to match up the date/time of the datasets and
> then invoke a conditional statement, such as: if dataC$mph is >= 12 then
> keep dataM$co23 for the corresponding time/date stamp.
>
> snippets of data files:
>
> *dataC.txt*
> LST   in mphDeg   DegF  DegF2%volts   Degmph2   w/m2
> 050601   0.00   13.6  218.1   36.8   -999   65.1   -999   -999   18.2
>  0.2
> 0506010005   0.00   12.9  214.3   36.8   -999   65.5   -999   -999   16.9
>  0.2
> 0506010010   0.00   14.4  215.7   36.9   -999   65.4   -999   -999   20.4
>  0.2
>
> *dataM.txt*
> doy yr mon day hr hgt1 hgt2 hgt3 co21 co22 co23 sig1 sig2 sig3 dif flag
>
> 244.02083 2005 09 01 00 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 -999.99
> -999.99 -999.99 PRE
> 244.0625 2005 09 01 01 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 -999.99
> -999.99 -999.99 PRE
> 244.10417 2005 09 01 02 2.5 5.8 9.1 -999.99 -999.99 -999.99 -999.99 -999.99
> -999.99 -999.99 PRE
>
> *Code:*
>
> z <- read.zoo("dataC.txt", header = TRUE, na.strings = -999,
> format = "%y%m%d%H%M", FUN = as.chron,
> colClasses = c("character", rep("numeric",
> 10)))
>
> DF <- read.table("C:/R/dataM.txt", header = TRUE, na.strings = -999.99)
> tt <- with(DF, chron(paste(mon, day, yr, sep = "/"),
>  paste(hr, 0, 0, sep = ":")))
>  timeconv <-  as.POSIXct(tt, tz="")
>  z2 <- zoo(data.matrix(DF), timeconv)
>
>
> *example of output of data files*
>
>>z[1,]
>   in.  mph   Deg DegF DegF2   X. volts Deg.1 mph2 w.m2
> (06/01/05 00:00:00)   0 13.6 218.1 36.8NA 65.1NANA 18.2  0.2
>
>
>> z2[1,]
>doy   yr mon day hr hgt1 hgt2 hgt3 co21 co22 co23
> sig1 sig2 sig3 dif flag
> 2005-08-31 18:00:00 244.0208 2005   9   1  0  2.5  5.8  9.1   NA   NA   NA
> NA   NA   NA  NA1
>
> *#merging data files z, z2*
> m <- merge(z, z2, all = c(FALSE, TRUE))
> m[m==-999.99]<-NA
> m2 <- m[m$mon %in% c(6,7,8),]
>
> *returns the following warning message:*
> Warning message:
> In merge.zoo(z, z2, all = c(FALSE, TRUE)) :
>  Index vectors are of different classes: chron POSIXt
>
> I cannot find a way to deal with the timezone in chron.  But, I found
> through the help pages that POSIXct deals with tz.  However, it doesn't seem
> these two different formats are compatible to merge.  Any thoughts would be
> appreciated.
>
> cheers,
>
> sherri
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


Re: [R] hexbin plot

2009-01-03 Thread jim holtman
Have you considered using the lattice-style panel functions that
hexbin provides:

mixdata <-
data.frame(x = c(rnorm(5000),rnorm(5000,4,1.5)),
   y = c(rnorm(5000),rnorm(5000,2,3)),
   a = gl(2, 5000))
hexbinplot(y ~ x, mixdata, aspect = 1,
   panel=function(x, y, ...){
   panel.hexbinplot(x,y,...)
   panel.abline(v=c(-1,0,1), h=c(-1,0,1), col='red', lwd=3)
   },
   trans = sqrt, inv = function(x) x^2)



On Sat, Jan 3, 2009 at 12:43 PM, Rodrigo Fernandes Ramalho
 wrote:
> Hello,
>
> I would like some help to plot a vertical line on a scatterplot build with
> hexbin package.
>
> I just need to plot a vertical line on the graph to mark a threshold value
> on x axis.
>
> It would be better if the parameter of the plot line function respect
> the x axis scale.
>
> Thanks,
>
> Rodrigo
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem that you are trying to solve?

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


[R] example of using loess()

2009-01-03 Thread cruz
Hi,

I have read ?loess help page and did some google on loess, however
there are insufficient information on weighted variance. I am
wondering that if any of you know of an example or document on
weighted variance using loess (), especially for the cases when more
than one explanatory variable is involved.

Thanks a lot,
cruz

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


[R] Newbie question

2009-01-03 Thread greggallen
Hi:

I'm loading in students test scores with:

> abntest <- read.table("scores.txt")

if I type:

>abntest

I get ALL the values.  I want to be able to filter it by various things such as:


if( abntesr > 90) Print abntest;

and other logical operators.  I'm sure this is simple for someone experienced.


Thanks,

Gregg Allen

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


Re: [R] Newbie question

2009-01-03 Thread cruz
abntest[abntest$abntesr > 90,]


On Sun, Jan 4, 2009 at 11:55 AM,   wrote:
> Hi:
>
> I'm loading in students test scores with:
>
>> abntest <- read.table("scores.txt")
>
> if I type:
>
>>abntest
>
> I get ALL the values.  I want to be able to filter it by various things such 
> as:
>
>
> if( abntesr > 90) Print abntest;
>
> and other logical operators.  I'm sure this is simple for someone experienced.
>
>
> Thanks,
>
> Gregg Allen
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

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


[R] How do I find the index for a value in an array

2009-01-03 Thread George Chen
Hello,
Could anybody tell me how to find the index for a value which I define in an 
array?

ie.

c<-matrix(1:9,1,9)  #A 1x9 matrix filled with numbers 1 - 9 in order
I want to know the index for the value 5. 

Thanks in advance,

George Chen

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


Re: [R] How do I find the index for a value in an array

2009-01-03 Thread Jorge Ivan Velez
Dear George,
Try this:

mat<-matrix(1:9,1,9)
which(mat==5,arr.ind=TRUE)
 row col
[1,]   1   5


HTH,

Jorge



On Sun, Jan 4, 2009 at 1:21 AM, George Chen  wrote:

> Hello,
> Could anybody tell me how to find the index for a value which I define in
> an array?
>
> ie.
>
> c<-matrix(1:9,1,9)  #A 1x9 matrix filled with numbers 1 - 9 in order
> I want to know the index for the value 5.
>
> Thanks in advance,
>
> George Chen
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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