Re: [R] Creating bibtex file of all installed packages?

2009-12-11 Thread Romain Francois

On 12/11/2009 08:41 AM, Achim Zeileis wrote:


On Fri, 11 Dec 2009, Rainer M Krug wrote:


Hi

is there an easy and fast way, to generate a BibTeX file of all
installed /
loaded packages and R?

I know about toBibtex(citation()) to extract the BibTeX for a single
package, but how can I generate a file containg citations for all
installed
/ loaded packages?


I don't think that there is a way other than calling citation() for each
of the installed.packages(). You could do something like this:

## try to get BibTeX for each of the installed packages
b - lapply(installed.packages()[,1], function(x)
try(toBibtex(citation(x
## omit failed citation calls
b - b[-which(sapply(b, class) == try-error)]


I would use logical indexing instead of which because if none actually 
fail, you end up indexing by integer(0) so b is empty.


b - b[!(sapply(b, class) == try-error)]


## unify to list of Bibtex
b - lapply(b, function(x) if(inherits(x, Bibtex)) list(x) else x)
## list of unique entries
b - unique(do.call(c, b))
## write everything to a single .bib file
writeLines(do.call(c, lapply(b, as.character)), Rpackages.bib)

hth,
Z


If you then want to do the reversed operation, read a bibtex file into a 
citationList object, you can use the unreleased(*) package bibtex.


 install.packages(bibtex, repos=http://R-Forge.R-project.org;)
 require( bibtex )
Loading required package: bibtex
 bib - read.bib( Rpackages.bib )
There were 50 or more warnings (use warnings() to see the first 50)

(*) because I have been lazy

The warnings are all about the lack of keys in the entries cooked by 
toBibtex. no big deal.


Romain


Cheers,

Rainer

--
NEW GERMAN FAX NUMBER!!!

Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell: +27 - (0)83 9479 042
Fax: +27 - (0)86 516 2782
Fax: +49 - (0)321 2125 2244
email: rai...@krugs.de

Skype: RMkrug
Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]




--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/Gq7i : ohloh
|- http://tr.im/FtUu : new package : highlight
`- http://tr.im/EAD5 : LondonR slides

__
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 draw three line on the same picture ?

2009-12-11 Thread Patrick Connolly
On Thu, 10-Dec-2009 at 10:14PM -0800, z_axis wrote:

| 
| The following is  sampling data:
| No   V1  V2 V3
| 1 0.23 0.12 0.89
| 2 0.11 0;56 0.12
| ...
| 
| I just want to draw three lines on same picture according to value of V1, V2
| and V3.  

?lines


-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
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] copyING directories and files

2009-12-11 Thread Paul Evans
Hi,

I am using the windows version of R. I wanted to copy a directory (containing 
several files) to another directory. Is there any command in R that will let me 
do this (something like the 'cp' command in UNIX)? I have looked at 
'file.copy', but as the name implies I think it only copies one file at a time.
thanks!


  
[[alternative HTML version deleted]]

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


Re: [R] Creating bibtex file of all installed packages?

2009-12-11 Thread Rainer M Krug
On Fri, Dec 11, 2009 at 9:41 AM, Achim Zeileis
achim.zeil...@wu-wien.ac.atwrote:

 On Fri, 11 Dec 2009, Rainer M Krug wrote:

  Hi

 is there an easy and fast way, to generate a BibTeX file of all installed
 /
 loaded packages and R?

 I know about toBibtex(citation()) to extract the BibTeX for a single
 package, but how can I generate a file containg citations for all
 installed
 / loaded packages?


 I don't think that there is a way other than calling citation() for each of
 the installed.packages(). You could do something like this:

 ## try to get BibTeX for each of the installed packages
 b - lapply(installed.packages()[,1], function(x)
  try(toBibtex(citation(x
 ## omit failed citation calls
 b - b[-which(sapply(b, class) == try-error)]
 ## unify to list of Bibtex
 b - lapply(b, function(x) if(inherits(x, Bibtex)) list(x) else x)
 ## list of unique entries
 b - unique(do.call(c, b))
 ## write everything to a single .bib file
 writeLines(do.call(c, lapply(b, as.character)), Rpackages.bib)


Thanks a lot Achim. That works.

It would actually be nice, if the citation() function could take more then
one package name, and probably have an option to save the citations into a
BibTeX file.

Thanks,

Rainer



 hth,
 Z

  Cheers,

 Rainer

 --
 NEW GERMAN FAX NUMBER!!!

 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
 Biology,
 UCT), Dipl. Phys. (Germany)

 Centre of Excellence for Invasion Biology
 Natural Sciences Building
 Office Suite 2039
 Stellenbosch University
 Main Campus, Merriman Avenue
 Stellenbosch
 South Africa

 Cell:   +27 - (0)83 9479 042
 Fax:+27 - (0)86 516 2782
 Fax:+49 - (0)321 2125 2244
 email:  rai...@krugs.de

 Skype:  RMkrug
 Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]

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





-- 
NEW GERMAN FAX NUMBER!!!

Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)321 2125 2244
email:  rai...@krugs.de

Skype:  RMkrug
Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] How to figure out which the version of split is used?

2009-12-11 Thread Karl Ove Hufthammer
On Thu, 10 Dec 2009 13:56:12 -0600 Peng Yu pengyu...@gmail.com wrote:
  type data.frame, split.data.frame will be called? Is it the case that
  if the argument is not of type data.frame, Date or POSIXct,
  split.default will be called?
 
  Yes. See ?UseMethod
 
 I tried it. But I'm not sure how to use it. Would you please give me a
 working example?

Typing 'split' shows a nice example ... :-)

-- 
Karl Ove Hufthammer

__
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] Gamma correlation

2009-12-11 Thread Manuel Jesús López Rodríguez
Dear all,
does anybody know if it is possible, and how, to compute the Gamma correlation 
in R?
Thank you very much in advance!

Manuel
__
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 draw three line on the same picture ?

2009-12-11 Thread z_axis

thanks for your answer ! Would you mind giving me an example using my data ?

Sincerely!


Patrick Connolly-4 wrote:
 
 On Thu, 10-Dec-2009 at 10:14PM -0800, z_axis wrote:
 
 | 
 | The following is  sampling data:
 | No   V1  V2 V3
 | 1 0.23 0.12 0.89
 | 2 0.11 0;56 0.12
 | ...
 | 
 | I just want to draw three lines on same picture according to value of
 V1, V2
 | and V3.  
 
 ?lines
 
 
 -- 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
___Patrick Connolly   
  {~._.~}   Great minds discuss ideas
  _( Y )_   Average minds discuss events 
 (:_~*~_:)  Small minds discuss people  
  (_)-(_). Eleanor Roosevelt
 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 
 __
 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.
 
 

-- 
View this message in context: 
http://n4.nabble.com/How-to-draw-three-line-on-the-same-picture-tp960823p960897.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] mutlidimensional in.convex.hull (was multidimensional point.in.polygon??)

2009-12-11 Thread baptiste auguie
2009/12/10 Charles C. Berry cbe...@tajo.ucsd.edu:
[snipped]
 Many?


 set.seed(1234)
 ps - matrix(rnorm(4000),ncol=4)
 phull -  convhulln(ps)
 xs - matrix(rnorm(1200),ncol=4)
 phull2 - convhulln(rbind(ps,xs))
 nrp - nrow(ps)
 nrx - nrow(xs)
 outside - unique(phull2[phull2nrp])-nrp
 done - FALSE
 while(!done){

 +     phull3 - convhulln(rbind(ps,xs[-(outside),]))
 +     also.outside - (1:nrx)[-outside][unique(phull3[phull3nrp])-nrp]
 +     print(length(also.outside))
 +     outside - c(outside,also.outside)
 +     done - length(also.outside)==0
 + }
 [1] 3
 [1] 0


 phull2 was evaluated once, phull3 twice.

 Any point that is in the convex hull of rbind(ps,xs) is either in or outside
 the convex hull of ps. Right? So, just recursively eliminate points that are
 in the convex hull of the larger set.


If I'm not mistaken this method is efficient only because the two
point distributions are very similar (drawn from rnorm, so they look
like two concentric balls). If one of the convex hulls is very
distorted along one axis, say, I believe the method will involve many
more iterations and in the limit will require computing a convex hull
for each test point as Duncan suggested.

Such a pathological of test points example might be,

xs - matrix(0,ncol=4,nrow=100)
xs[,1] - seq(1,100)

Or did I completely miss something? (quite possible)




Regarding the inhull Matlab code, I came to the opposite conclusion:
it should be easily ported to R. 1) it is a very short piece of code
(even more so if one disregards the various checks and handling of
special cases), with no Matlab-specific objects (only integers,
booleans, matrices and vectors). 2) The core of the program relies on
the qhull library, and the same applies to R I think. 3) Matlab and R
use very similar indexing for matrices and similar linear algebra in
general.

That said, I'm a bit short on time to give it a go myself. I think the
open-source Octave could run this code too, so it might help in
checking the code step-by-step.


All the best,

baptiste

__
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 get the runtime as well as the result?

2009-12-11 Thread Uwe Ligges



Peng Yu wrote:

On Thu, Dec 10, 2009 at 7:03 PM, Dirk Eddelbuettel e...@debian.org wrote:

On 10 December 2009 at 18:12, Peng Yu wrote:
| If I use system.time() to measure the runtime of an expression, I will
| not get the result. Is there a way to measure the runtime and get the
| result as well?

Use an assignment inside system.time():

   R system.time( m - max(rnorm(1e6)) )
  user  system elapsed
 0.328   0.008   0.340
   R m
   [1] 4.993
   R


I see. In this case, I'll have to use '-' rather than '='.



Thanks to point it out on the list. This is one of the reasons not to 
use = as assignment operator at all: it is confusing.


Best,
Uwe Ligges




__
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] Greek symbols on ylab= using barchart() {Lattice}

2009-12-11 Thread Gavin Simpson
On Wed, 2009-12-09 at 18:46 +0100, baptiste auguie wrote:
 barchart(1:2, ylab=expression(Concentration (*mu*g/m^3*)))

or

barchart(1:2, ylab=expression(Concentration ~ (mu*g/m^3)))

That way you don't have to worry about quoting parts of the expression.

G

 
 2009/12/9 Peng Cai pengcaimaill...@gmail.com:
  Hi Baptiste and Others,
 
  Thanks for your help. I'm writing:
 
  ylab=expression(Concentration(mu*g/m^3))
 
  And its working fine, but is it possible to add a space between
  Concentration and (mu*g/m^3).
 
  Thanks again,
  Peng Cai
 
  On Wed, Dec 9, 2009 at 12:02 PM, baptiste auguie 
  baptiste.aug...@googlemail.com wrote:
 
  Hi,
 
  try this,
 
  barchart(1:2, ylab=expression(mu*g/m^3))
 
  ?plotmath
 
  baptiste
 
  2009/12/9 Peng Cai pengcaimaill...@gmail.com:
Hi All,
  
   I'm trying to write ug/m3 as y-label, with greek letter mu replacing
  u
   AND 3 going as a power.
  
   These commands works in general:
  
   plot.new()
   text(0.5, 0.5, expression(symbol(m)))
  
   But, I'm sure about how to do it using barchart() from Lattice. Can
  anyone
   help please?
  
   Thanks,
   Peng Cai
  
  [[alternative HTML version deleted]]
  
   __
   R-help@r-project.org mailing list
   https://stat.ethz.ch/mailman/listinfo/r-help
   PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
   and provide commented, minimal, self-contained, reproducible code.
  
 
 
 [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-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.
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,  [f] +44 (0)20 7679 0565
 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London  [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

__
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] Warning for data.table (with ref)?

2009-12-11 Thread Uwe Ligges
This is the intended startup message for that package (and not a 
warning), nothing to fix.


Uwe Ligges




Peng Yu wrote:

I have following the message dim(refdata) and dimnames(refdata) no
longer allow parameter ref=TRUE, use dim(derefdata(refdata)),
dimnames(derefdata(refdata)) instead when I loaded data.table. Is it
from the package ref? Could it be fixed? Or there is something wrong
with my installation?


library(data.table)

Loading required package: ref
dim(refdata) and dimnames(refdata) no longer allow parameter ref=TRUE,
use dim(derefdata(refdata)), dimnames(derefdata(refdata)) instead

sessionInfo()

R version 2.10.0 (2009-10-26)
x86_64-unknown-linux-gnu

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

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

other attached packages:
[1] data.table_1.2 ref_0.97

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


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


Re: [R] How to draw three line on the same picture ?

2009-12-11 Thread jim holtman
try this:

x - read.table(textConnection(No   V1  V2 V3
1 0.23 0.12 0.89
2 0.11 0.56 0.12), header=TRUE)
matplot(x[,1], x[,-1], type='l')


On Fri, Dec 11, 2009 at 3:39 AM, z_axis z_a...@163.com wrote:


 thanks for your answer ! Would you mind giving me an example using my data
 ?

 Sincerely!


 Patrick Connolly-4 wrote:
 
  On Thu, 10-Dec-2009 at 10:14PM -0800, z_axis wrote:
 
  |
  | The following is  sampling data:
  | No   V1  V2 V3
  | 1 0.23 0.12 0.89
  | 2 0.11 0;56 0.12
  | ...
  |
  | I just want to draw three lines on same picture according to value of
  V1, V2
  | and V3.
 
  ?lines
 
 
  --
  ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 ___Patrick Connolly
   {~._.~}   Great minds discuss ideas
   _( Y )_   Average minds discuss events
  (:_~*~_:)  Small minds discuss people
   (_)-(_). Eleanor Roosevelt
 
  ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 

 --
 View this message in context:
 http://n4.nabble.com/How-to-draw-three-line-on-the-same-picture-tp960823p960897.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

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


Re: [R] copyING directories and files

2009-12-11 Thread Uwe Ligges
I'd use a shell() command to call xcopy or robocopy, or cp given you 
have some unix tools installed.


Uwe Ligges



Paul Evans wrote:

Hi,

I am using the windows version of R. I wanted to copy a directory (containing 
several files) to another directory. Is there any command in R that will let me 
do this (something like the 'cp' command in UNIX)? I have looked at 
'file.copy', but as the name implies I think it only copies one file at a time.
thanks!


  
	[[alternative HTML version deleted]]


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


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


Re: [R] Recoding factor labels that are lists into first element of list

2009-12-11 Thread jim holtman
try this:

 x - data.frame(a=c('cat', 'cat,dog', 'dog', 'dog,cat'))
 x
a
1 cat
2 cat,dog
3 dog
4 dog,cat
 levels(x$a)
[1] cat cat,dog dog dog,cat
 # change the factors
 x$a - factor(sapply(strsplit(as.character(x$a), ','), '[[', 1))
 x
a
1 cat
2 cat
3 dog
4 dog
 levels(x$a)
[1] cat dog


On Thu, Dec 10, 2009 at 10:53 PM, Jennifer Walsh walsh...@umich.edu wrote:

 Hi all,

 I've Googled far and wide but don't think I know the correct terms to
 search for to find an answer.

 I have a massive dataset where one of the factors is made up of both
 individual items and lists of items (for example, cat and cat, dog,
 bird). I would like to recode this factor somehow into only the first
 element of the list (so every list starting with cat, plus the
 observations that were already just cat would all be set equal to cat).
 I would ideally like to do this in some simple way that does not require me
 to write hundreds of different sets of code (since the lists probably start
 with 300+ different items). Is this possible? Extremely complicated?

 Also, I am sure this is much simpler, but I cannot seem to get rid of
 levels of a factor that have no observations. I have tried setting the
 levels of the factor to only the ones with observations that I am interested
 in, but every time I summarize the variable there are still 100+ labels all
 with 0 as their count. This hasn't happened to me before; is there an
 explanation for it?

 Thanks very much,
 Jen

 ---
 Jennifer Walsh
 Graduate Student, Developmental Psychology
 University of Michigan
 2020 East Hall, 530 Church St.
 Ann Arbor, MI 48109-1043

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




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

What is the problem that you are trying to solve?

[[alternative HTML version deleted]]

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


Re: [R] Help with beanplot fromatting

2009-12-11 Thread Uwe Ligges
Easiest way is probably to make grouprep a factor and insert a level 
without observations such as in:


mydata$grouprep - factor(mydata$grouprep, levels =
  paste(rep(LETTERS[1:5], each=2), paste(grp, 1:2, sep=)))
beanplot(val~grouprep, data = mydata, ll = 0.04,
  main = example, ylab = Size, xlab = tank,
  side = both,  border = NA,
  col = list(c(blue, white), c(red, yellow)))

Uwe Ligges




James Widman wrote:

Sorry for the previous error.

Dear Helpful R Users,

I am graphing some data using the beanplot, but I am having trouble 
getting the output I desire. I have five tanks (A-E) and 2 groups for 
each tank grp1 or grp2, except tank C where there is only grp1. (I only 
changed the grouprep to C grp1 for the example) When I plot them,  I 
would like A B C(only grp1 - half of the bean plot) then D and E (as 
full beans). I assume there is some way to do this, but searching the 
help archives, I haven't been able to find it.


I would also like to thank all of you, for your answers to others 
questions, I have been gathering many useful tips.


# example
library(beanplot)
mydata - data.frame(tank = rep(c(A,B,C,D,E), 
c(100,100,50,100,100)), group = rep(c(grp1, grp2)), val = rnorm(450))

mydata$grouprep - paste( mydata$tank,  mydata$group)
mydata$grouprep -with(mydata, ifelse((tank==C), C grp1, grouprep))
beanplot(val~grouprep, data = mydata, ll = 0.04,
 main = example, ylab = Size,
 xlab = tank,
 side = both,  border = NA, col = list(c(blue, white), c(red, 
yellow)))


Thanks,
Jim

James C. Widman Jr.
Research Fishery Biologist
NOAA Fisheries
Milford, CT

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

and provide commented, minimal, self-contained, reproducible code.


__
R-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] copyING directories and files

2009-12-11 Thread Romain Francois

What about this as a start :

dir.copy - function( source = getwd(), target ){

files - list.files( source, recursive = TRUE )
dirs  - unique( gsub( /[^/]+$, , files[grepl(/, files)] ) )

if( !file.exists( target ) ){
dir.create( target )
}

for( d in dirs){
dir.create( file.path( target, d) , recursive = TRUE )
}
for( f in files ){
file.copy( file.path(source, f) , file.path( target, f ) )
}
invisible(NULL)
}


# what I am copying :
 system( tree )
.
└── bar
├── blabla.txt
├── bla.txt
└── foobar
└── blabla.txt

2 directories, 3 files

 dir.copy( getwd(), /tmp/target )
 system( tree /tmp/target )
/tmp/target
└── bar
├── blabla.txt
├── bla.txt
└── foobar
└── blabla.txt

2 directories, 3 files

Romain

On 12/11/2009 11:18 AM, Uwe Ligges wrote:


I'd use a shell() command to call xcopy or robocopy, or cp given you
have some unix tools installed.

Uwe Ligges



Paul Evans wrote:

Hi,

I am using the windows version of R. I wanted to copy a directory
(containing several files) to another directory. Is there any command
in R that will let me do this (something like the 'cp' command in
UNIX)? I have looked at 'file.copy', but as the name implies I think
it only copies one file at a time.
thanks!


--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/Gq7i : ohloh
|- http://tr.im/FtUu : new package : highlight
`- http://tr.im/EAD5 : LondonR slides

__
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] Reducing the dimension of a list object

2009-12-11 Thread Uwe Ligges



Bogaso wrote:

Please consider following code :

set.seed(1)
res - vector(list)
for (i in 1:5) {
   res1 - vector(list)
   res1[[1]] - letters[1:5]
   res1[[2]] - rnorm(5)
   res1[[3]] - rnorm(5); res[[i]] - res1 }
res[[1]]

# Now I want to reduce the dimension of res through creating a data frame
like that
mat - data.frame(nrow=5, ncol=2)
for (i in 1:5) {
   mat[i,1] - res[[i]][[1]][1]
   mat[i,2] - res[[i]][[2]][1] }; mat

Here I am looking for more efficient code by avoiding the loop. Is there
any smart way to do that ?



Perhaps directly rewritten without thinking:

mat - data.frame(
letters = sapply(res, [[, c(1,1)),
numbers = sapply(res, [[, c(2,1)))

which should be roughly 2.5 times faster.

Uwe Ligges



Thanks,


__
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] Recoding factor labels that are lists into first element of list

2009-12-11 Thread Gabor Grothendieck
Or this which removing the comma and everything thereafter in each
level that has a comma:

levels(x$a) - sub(,.*, , levels(x$a))

On Fri, Dec 11, 2009 at 5:21 AM, jim holtman jholt...@gmail.com wrote:
 try this:

 x - data.frame(a=c('cat', 'cat,dog', 'dog', 'dog,cat'))
 x
        a
 1     cat
 2 cat,dog
 3     dog
 4 dog,cat
 levels(x$a)
 [1] cat     cat,dog dog     dog,cat
 # change the factors
 x$a - factor(sapply(strsplit(as.character(x$a), ','), '[[', 1))
 x
    a
 1 cat
 2 cat
 3 dog
 4 dog
 levels(x$a)
 [1] cat dog


 On Thu, Dec 10, 2009 at 10:53 PM, Jennifer Walsh walsh...@umich.edu wrote:

 Hi all,

 I've Googled far and wide but don't think I know the correct terms to
 search for to find an answer.

 I have a massive dataset where one of the factors is made up of both
 individual items and lists of items (for example, cat and cat, dog,
 bird). I would like to recode this factor somehow into only the first
 element of the list (so every list starting with cat, plus the
 observations that were already just cat would all be set equal to cat).
 I would ideally like to do this in some simple way that does not require me
 to write hundreds of different sets of code (since the lists probably start
 with 300+ different items). Is this possible? Extremely complicated?

 Also, I am sure this is much simpler, but I cannot seem to get rid of
 levels of a factor that have no observations. I have tried setting the
 levels of the factor to only the ones with observations that I am interested
 in, but every time I summarize the variable there are still 100+ labels all
 with 0 as their count. This hasn't happened to me before; is there an
 explanation for it?

 Thanks very much,
 Jen

 ---
 Jennifer Walsh
 Graduate Student, Developmental Psychology
 University of Michigan
 2020 East Hall, 530 Church St.
 Ann Arbor, MI 48109-1043

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




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

 What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

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


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


[R] Literature analysis

2009-12-11 Thread Schwan
Dear all, 

i am new in R. I am writing a review paper about batteries. However, i
am interested in analyzing all the papers by keywords, author,
references and year.
This could be done by refviz a software, which is only running on
windows machines and which is not free.

So my question to you is, is it somehow possible to write a script that
can do all of this work?

And if yes, with what i should start?

Thanks a lot in advance,

Schwan 

-- 
---
Hosseiny, MSc. S.S. (Seyed Schwan)
University of Twente Science and Technology
Meander, ME 322
P.O. Box 217 7500 AE Enschede
The Netherlands
Phone +31 534892869
Email:  s.s.hosse...@utwente.n

__
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] copyING directories and files

2009-12-11 Thread Paul Evans
Thanks Romain, Uwe!





From: Romain Francois romain.franc...@dbmail.com
To: Uwe Ligges lig...@statistik.tu-dortmund.de

Sent: Fri, December 11, 2009 5:35:57 AM
Subject: Re: [R] copyING directories and files

What about this as a start :

dir.copy - function( source = getwd(), target ){

files - list.files( source, recursive = TRUE )
dirs  - unique( gsub( /[^/]+$, , files[grepl(/, files)] ) )

if( !file.exists( target ) ){
dir.create( target )
}

for( d in dirs){
dir.create( file.path( target, d) , recursive = TRUE )
}
for( f in files ){
file.copy( file.path(source, f) , file.path( target, f ) )
}
invisible(NULL)
}


# what I am copying :
 system( tree )
.
└── bar
├── blabla.txt
├── bla.txt
└── foobar
└── blabla.txt

2 directories, 3 files

 dir.copy( getwd(), /tmp/target )
 system( tree /tmp/target )
/tmp/target
└── bar
├── blabla.txt
├── bla.txt
└── foobar
└── blabla.txt

2 directories, 3 files

Romain

On 12/11/2009 11:18 AM, Uwe Ligges wrote:
 
 I'd use a shell() command to call xcopy or robocopy, or cp given you
 have some unix tools installed.
 
 Uwe Ligges
 
 
 
 Paul Evans wrote:
 Hi,
 
 I am using the windows version of R. I wanted to copy a directory
 (containing several files) to another directory. Is there any command
 in R that will let me do this (something like the 'cp' command in
 UNIX)? I have looked at 'file.copy', but as the name implies I think
 it only copies one file at a time.
 thanks!

-- Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/Gq7i : ohloh
|- http://tr.im/FtUu : new package : highlight
`- http://tr.im/EAD5 : LondonR slides


  
[[alternative HTML version deleted]]

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


Re: [R] Literature analysis

2009-12-11 Thread nshephard



Schwan wrote:
 
 Dear all, 
 
 i am new in R. I am writing a review paper about batteries. However, i
 am interested in analyzing all the papers by keywords, author,
 references and year.
 This could be done by refviz a software, which is only running on
 windows machines and which is not free.
 
 So my question to you is, is it somehow possible to write a script that
 can do all of this work?

Describing what you mean by all of this work would be useful as the above
is rather vague as you don't describe what analysis refviz actually
performs.


Schwan wrote:
 
 And if yes, with what i should start?
 

Start learning how to use R.  There are good links from the R-project
homepage under the Wiki, Other and Books section.  I've found Braun 
Murdoch A First Course in Statistical Programming with R to be a good book
to get me going.

Neil

-- 
View this message in context: 
http://n4.nabble.com/Literature-analysis-tp960960p960968.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Notification of false convergence with lmer()

2009-12-11 Thread jjh

I am running the lmer() command in a for loop and occasionally a particular
iteration is producing the false convergence warning. I would like to be
able to mark these iterations with a dummy variable, but I can't find any
other notification besides the warning message, which, in a for loop, only
is printed after the loop is finished (which does not allow me to see which
iteration it happened on). Is there any way I can mark which iteration in
the loop produces the false convergence?

Thank you.
-- 
View this message in context: 
http://n4.nabble.com/Notification-of-false-convergence-with-lmer-tp960969p960969.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] mutlidimensional in.convex.hull (was multidimensionalpoint.in.polygon??)

2009-12-11 Thread Keith Jewell
baptiste auguie baptiste.aug...@googlemail.com wrote in message 
news:de4e29f50912110200g7e43551kef5e8053fbf6e...@mail.gmail.com...
2009/12/10 Charles C. Berry cbe...@tajo.ucsd.edu:
[snipped]
 Many?


snip Charles' elegant coding of the algorithm he summarises as:
 Any point that is in the convex hull of rbind(ps,xs) is either in or 
 outside
 the convex hull of ps. Right? So, just recursively eliminate points that 
 are
 in the convex hull of the larger set.


Baptiste commented:

If I'm not mistaken this method is efficient only because the two
point distributions are very similar (drawn from rnorm, so they look
like two concentric balls). If one of the convex hulls is very
distorted along one axis, say, I believe the method will involve many
more iterations and in the limit will require computing a convex hull
for each test point as Duncan suggested.

Such a pathological of test points example might be,

xs - matrix(0,ncol=4,nrow=100)
xs[,1] - seq(1,100)

Or did I completely miss something? (quite possible)



Until now I thought the same as Baptiste and (mea culpe) had rejected that 
algorithm without testing it. Now I've tried it and it works!

Here's the result on my real test data; sorry it's long, but it shows some 
important features:
 a) ps is quite pathological?; some substantial correlations
 b) xs - expand.grid(lapply(ps, unique));
 this is the reason I'm doing it in the first place. I want to
expand.grid without 'extrapolating' beyound the (convex hull of)
the original data
 c) xs has lost the correlation structure of ps
 d) 1170 'outside' points removed in 23 iterations
 e) xs[-(outside)] has regained (some of) the correlation structure of ps

### begin example
 source(.trPaths[5], echo=TRUE, max.deparse.length=150)

 describe(ps)
ps
 5  Variables  2637  Observations
-
t
  n missing  uniqueMean .05 .10 .25 .50 .75 
.90 .95
   2637   0  35   136.2   0   0  30 120 194 
312 360
lowest :   0   2   3   4  24, highest: 312 336 360 384 504
-
pH
  n missing  uniqueMean
   2637   0   4   5.707
4.6 (727, 28%), 5.4 (729, 28%), 6.2 (624, 24%), 7 (557, 21%)
-
T
  n missing  uniqueMean
   2637   0   5   10.75
2   5   8  15  22
Frequency 447 510 593 537 550
%  17  19  22  20  21
-
S
  n missing  uniqueMean
   2637   0   4   3.097
0 (631, 24%), 2 (648, 25%), 4 (638, 24%), 6 (720, 27%)
-
N
  n missing  uniqueMean
   2637   0   4   118.6
0 (701, 27%), 80 (636, 24%), 160 (628, 24%), 240 (672, 25%)
-
 cor(ps)
  t  pHT  SN
t   1.0  0.02255541 -0.425911455 0.05541686  0.004447023
pH  0.022555414  1. -0.029277466 0.05630345 -0.031032641
T  -0.425911455 -0.02927747  1.0 0.05948337  0.003595186
S   0.055416859  0.05630345  0.059483366 1.  0.014074045
N   0.004447023 -0.03103264  0.003595186 0.01407404  1.0
 xs - expand.grid(lapply(ps, unique))
 describe(xs)
xs
 5  Variables  11200  Observations
-
t
  n missing  uniqueMean .05 .10 .25 .50 .75 
.90 .95
  11200   0  35   141.7   2   4  48 123 194 
336 384
lowest :   0   2   3   4  24, highest: 312 336 360 384 504
-
pH
  n missing  uniqueMean
  11200   0   4 5.8
4.6 (2800, 25%), 5.4 (2800, 25%), 6.2 (2800, 25%), 7 (2800, 25%)
-
T
  n missing  uniqueMean
  11200   0   510.4
 258   15   22
Frequency 2240 2240 2240 2240 2240
%   20   20   20   20   20
-
S
  n missing  uniqueMean
  11200   0   4   3
0 (2800, 25%), 2 (2800, 25%), 4 (2800, 

Re: [R] Literature analysis

2009-12-11 Thread Stephan Kolassa

Hi,

from what I understand, you may be interested in text mining, so perhaps 
you want to look at the tm package.


Then again, depending on what you are really trying to do, you may be 
better served with perl, awk and similar tools than with R...


HTH,
Stephan


Schwan schrieb:
Dear all, 


i am new in R. I am writing a review paper about batteries. However, i
am interested in analyzing all the papers by keywords, author,
references and year.
This could be done by refviz a software, which is only running on
windows machines and which is not free.

So my question to you is, is it somehow possible to write a script that
can do all of this work?

And if yes, with what i should start?

Thanks a lot in advance,

Schwan 



__
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 can generate from trunceted gamma distribution in R ?

2009-12-11 Thread khazaei

Hi, all
How can generate a sample from truncated inverse  gamma distribution in R?

thanks

__
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] Literature analysis

2009-12-11 Thread Schwan
Thanks for all the comments,

and sorry about the unstructured question! I am trying to:

1: analyze keywords, names from Authors and year of publication from
citations (with abstracts) i downloaded fron various sites(these
downloads can be converted into .txt files as well)
2: to cluster these literature according to the analyzed keywords,
authors or year of publication

The software Refviz I was referring to earlier can be found here:
http://refviz.com/

As I said, I have never worked with R before so I can not send any
example.

Hope this helps to understand my question better.

Cheers



On Fri, 2009-12-11 at 13:06 +0100, Stephan Kolassa wrote:
 Hi,
 
 from what I understand, you may be interested in text mining, so perhaps 
 you want to look at the tm package.
 
 Then again, depending on what you are really trying to do, you may be 
 better served with perl, awk and similar tools than with R...
 
 HTH,
 Stephan
 
 
 Schwan schrieb:
  Dear all, 
  
  i am new in R. I am writing a review paper about batteries. However, i
  am interested in analyzing all the papers by keywords, author,
  references and year.
  This could be done by refviz a software, which is only running on
  windows machines and which is not free.
  
  So my question to you is, is it somehow possible to write a script that
  can do all of this work?
  
  And if yes, with what i should start?
  
  Thanks a lot in advance,
  
  Schwan 
  
 


-- 
---
Hosseiny, MSc. S.S. (Seyed Schwan)
University of Twente Science and Technology
Meander, ME 322
P.O. Box 217 7500 AE Enschede
The Netherlands
Phone +31 534892869
Email:  s.s.hosse...@utwente.n

__
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] Literature analysis

2009-12-11 Thread nshephard



Schwan wrote:
 
 Thanks for all the comments,
 
 and sorry about the unstructured question! I am trying to:
 
 1: analyze keywords, names from Authors and year of publication from
 citations (with abstracts) i downloaded fron various sites(these
 downloads can be converted into .txt files as well)

Sorry to bang the drum but what do you mean by analyse, is it to simply
count keywords and rank them, investigate which keywords occur together,
look at trends in keywords by year or something else completely.

Its a very general term (at least for me as I've no knowledge or experience
of text mining)!

Neil
-- 
View this message in context: 
http://n4.nabble.com/Literature-analysis-tp960960p961019.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] lattice - 2 graphs per panel with 2 differents colours

2009-12-11 Thread PtitBleu

Hello,

I would like to get a lattice plot of 8 panels (unique(df$fact)=8) with 2
graphs (df$y1 and df$y2 as a function of df$x) and 1 red point at (500,
ymax) per panel.

The script below is quite ok but I'm not able to define two different colors
for the two graphs.
If you have an idea how to use the col function in order to attribute the
colors, it will be very kind of you to share it with a newbie.

Have a nice week-end,
Ptit Bleu.


x11(15,12)
xyplot(df$y1 + df$y1/df$coeff ~ df$x | df$fact,
panel = function(x, y) {
panel.grid(h=-1, v=-1, col=gray)
panel.xyplot(x, y, type=p, pch=20)
panel.points(500, ymax[panel.number()], col=red, pch=20,
cex=1.6)
},
 xlab=X, ylab=Y)

-- 
View this message in context: 
http://n4.nabble.com/lattice-2-graphs-per-panel-with-2-differents-colours-tp961037p961037.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Literature analysis

2009-12-11 Thread Schwan
Ok good question I havent explain!

Well,lets keep it simple for the begining. By analyzing the
keywords(which can also include the authors name) I mean,

1) investigate in which paper the keyword occur and how often
2) investigate if keywords occur together

X axis can show the paper title (or authors name)
y axis shows the keywords

if a keyword occurs more often in a paper then the dot on the graph
changes the color

if keywords occur together then a symbol the same symbol appears.







On Fri, 2009-12-11 at 04:33 -0800, nshephard wrote:
 
 
 Schwan wrote:
  
  Thanks for all the comments,
  
  and sorry about the unstructured question! I am trying to:
  
  1: analyze keywords, names from Authors and year of publication from
  citations (with abstracts) i downloaded fron various sites(these
  downloads can be converted into .txt files as well)
 
 Sorry to bang the drum but what do you mean by analyse, is it to simply
 count keywords and rank them, investigate which keywords occur together,
 look at trends in keywords by year or something else completely.
 
 Its a very general term (at least for me as I've no knowledge or experience
 of text mining)!
 
 Neil


-- 
---
Hosseiny, MSc. S.S. (Seyed Schwan)
University of Twente Science and Technology
Meander, ME 322
P.O. Box 217 7500 AE Enschede
The Netherlands
Phone +31 534892869
Email:  s.s.hosse...@utwente.n

__
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] export anova table

2009-12-11 Thread Ivan Calandra

Hi everybody,

It might be a stupid question, but please excuse it!

I would just like to export my ANOVA table from that kind of code:
stats - lm(Asfc~TO_POS, ssfa)
anova(stats)

into a *.csv or *.txt file.

Can anyone help please?
Thanks in advance
Ivan

__
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] incorrect multiple outputs

2009-12-11 Thread Ista Zahn
The lack of a reproducible example is a bigger problem than any lack
of clarity of the explanation.

-Ista

On Fri, Dec 11, 2009 at 2:08 AM,  bawa...@googlemail.com wrote:
 Apologies,
 I didn't explain this clearly. The Rscript is called by a perl script, which 
 creates input_file.txt by inserting 288 lines of (reformatted) data for 
 each data file in the directory.  So the Rscript will (and is doing) run the 
 loop a number of times equal to the number of files the perl script read in. 
 The problem is that it should only create the data.frame and write to the 
 file after the last iteration, but it's (creating and)writing the complete 
 data.frame every iteration.
 Sent using BlackBerry® from Orange

 -Original Message-
 From: jim holtman jholt...@gmail.com
 Date: Thu, 10 Dec 2009 18:00:54
 To: biscuitbawa...@googlemail.com
 Cc: r-help@r-project.org
 Subject: Re: [R] incorrect multiple outputs

 If I rad you code right, file.rows is equal to 1 and your 'for' loop will
 only iterate once.  Is that what you were expecting?

 No reproducible code provided, so that is my best guess.

file.rows- c(nrow(file)/288)  # input_file.txt contains 288 reformatted
 lines for each original data file
 ...
for (k in 1:file.rows){  # iterates code for each 288 line block of
 input_file.txt
 ...

 On Thu, Dec 10, 2009 at 11:39 AM, biscuit bawa...@googlemail.com wrote:


 HI,
 I'm having trouble with a piece of Rscript which keeps outputting
 incorrectly. it's something like this: the code reads in from a file which
 contains (reformated) input

 file-read.table(file=input_file.txt,sep=\t)[,c(1,3:5)]
 
 file.rows- c(nrow(file)/288)  # input_file.txt contains 288 reformatted
 lines for each original data file
 ...
 for (k in 1:file.rows){  # iterates code for each 288 line block of
 input_file.txt
 ...
 cv[k] - 100*(sd(x.blank)/mean(x.blank))
 t[k] -
 (mean(x.note)-mean(x.blank))/sqrt(((sd(x.note)^2)/8)+((sd(x.blank)^2)/16))
 t11[k] -
 (sqrt(8)*(mean(x.note11)-mean(x.blank)))/sqrt(sd(x.note11)^2+sd(x.blank)^2)
 }
 

 all.data-data.frame(barcodes,t=format(as.numeric(t),digits=3),t11=format(as.numeric(t11),digits=3),cv=format(as.numeric(cv),digits=3))
 write.table(all.data, file=
 R_drug_plot.log,append=TRUE,sep=\t,row.names=FALSE)

 this all works correctly except that I believed it would output to file
 after completing the loop, instead it's writing to file every iteration. so
 the output file looks like:

 headers
 a1
 headers
 a1
 a2
 headers
 a1
 a2
 a3
 ...

 I have checked the missing sections of code and can confirm there are no
 missing/additional brackets. Has anyone any idea why this is happening and
 what I can do about it?
 --
 View this message in context:
 http://n4.nabble.com/incorrect-multiple-outputs-tp957192p957192.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

 What is the problem that you are trying to solve?


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





-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] Literature analysis

2009-12-11 Thread Ista Zahn
It sounds pretty simple so far. Just put the citation info in a data
frame, and plot it. I would use ggplot2 for plotting, but it could be
done in base or lattice too.

On Fri, Dec 11, 2009 at 8:04 AM, Schwan s.s.hosse...@utwente.nl wrote:
 Ok good question I havent explain!

 Well,lets keep it simple for the begining. By analyzing the
 keywords(which can also include the authors name) I mean,

 1) investigate in which paper the keyword occur and how often
 2) investigate if keywords occur together

 X axis can show the paper title (or authors name)
 y axis shows the keywords

 if a keyword occurs more often in a paper then the dot on the graph
 changes the color

 if keywords occur together then a symbol the same symbol appears.







 On Fri, 2009-12-11 at 04:33 -0800, nshephard wrote:


 Schwan wrote:
 
  Thanks for all the comments,
 
  and sorry about the unstructured question! I am trying to:
 
  1: analyze keywords, names from Authors and year of publication from
  citations (with abstracts) i downloaded fron various sites(these
  downloads can be converted into .txt files as well)

 Sorry to bang the drum but what do you mean by analyse, is it to simply
 count keywords and rank them, investigate which keywords occur together,
 look at trends in keywords by year or something else completely.

 Its a very general term (at least for me as I've no knowledge or experience
 of text mining)!

 Neil


 --
 ---
 Hosseiny, MSc. S.S. (Seyed Schwan)
 University of Twente Science and Technology
 Meander, ME 322
 P.O. Box 217 7500 AE Enschede
 The Netherlands
 Phone +31 534892869
 Email:  s.s.hosse...@utwente.n

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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] get the enclosing function name

2009-12-11 Thread Hao Cen
Hi,

Is there a way to get the enclosing function name within a function?

For example, I would like to have a function getEnclosingFunctionName().
It works like below

f = function(){
  print(getEnclosingFunctionName())

}


f()  # will print  f


Thanks

Jeff

__
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] get the enclosing function name

2009-12-11 Thread Gabor Grothendieck
Try placing this in your function:

Name - match.call()[[1]]

On Fri, Dec 11, 2009 at 8:50 AM, Hao Cen h...@andrew.cmu.edu wrote:
 Hi,

 Is there a way to get the enclosing function name within a function?

 For example, I would like to have a function getEnclosingFunctionName().
 It works like below

 f = function(){
  print(getEnclosingFunctionName())

 }


 f()  # will print  f


 Thanks

 Jeff

 __
 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] export anova table

2009-12-11 Thread David Winsemius


On Dec 11, 2009, at 8:17 AM, Ivan Calandra wrote:


Hi everybody,

It might be a stupid question, but please excuse it!

I would just like to export my ANOVA table from that kind of code:
stats - lm(Asfc~TO_POS, ssfa)
anova(stats)

into a *.csv or *.txt file.



capture.output(anova(model), file=test.txt)



Can anyone help please?
Thanks in advance
Ivan



David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] copyING directories and files

2009-12-11 Thread Henrik Bengtsson
copyDirectory() in the R.utils package.

/Henrik

On Fri, Dec 11, 2009 at 1:01 AM, Paul Evans p.evan...@yahoo.com wrote:
 Hi,

 I am using the windows version of R. I wanted to copy a directory (containing 
 several files) to another directory. Is there any command in R that will let 
 me do this (something like the 'cp' command in UNIX)? I have looked at 
 'file.copy', but as the name implies I think it only copies one file at a 
 time.
 thanks!



        [[alternative HTML version deleted]]

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


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


Re: [R] get the enclosing function name

2009-12-11 Thread Henrique Dallazuanna
Try this;

f - function()as.character(sys.call())

On Fri, Dec 11, 2009 at 11:50 AM, Hao Cen h...@andrew.cmu.edu wrote:
 Hi,

 Is there a way to get the enclosing function name within a function?

 For example, I would like to have a function getEnclosingFunctionName().
 It works like below

 f = function(){
  print(getEnclosingFunctionName())

 }


 f()  # will print  f


 Thanks

 Jeff

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




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

__
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] Subset sum problem.

2009-12-11 Thread Geert Janssens
Hans, you're my personal hero today !

The function seems to work fine for the tests I did already.

Thank you very much !

Geert

On Thursday 10 December 2009, Hans W Borchers wrote:
 Geert Janssens janssens-geert at telenet.be writes:
  On Wednesday 9 December 2009, Hans W Borchers wrote:
   Geert Janssens janssens-geert at telenet.be writes:
[ ... ]
Has anybody tackled this issue before in R ? If so, I would be very
grateful if you could share your solution with me.
  
   Is it really true that you only want to see a Yes or No answer to
   this question whether a subset sums up to s --- without learning which
   numbers this subset is composed of (the pure SUBSET SUM problem)?
   Then the following procedure does that in a reasonable amount of time
   (returning 'TRUE' or 'FALSE' instead of Y-or-N):
 
  Unfortunately no. I do need the numbers in the subset. But thank you for
  presenting this code.
 
  Geert

 Okay then, here we go. But don't tell later that your requirement was to
 generate _all_ subsets that add up to a certain amount.  I will generate
 only one (with largest elements).

 For simplicity I assume that the set is prepared s.t. it is decreasingly
 ordered, has no elements larger than the amount given, and has a total sum
 larger than this amount.

 # Assume S decreasing, no elements  t, total sum = t
 solveSubsetSum - function(S, t) {
   L - c(0)
   inds - NULL
   for (i in 1:length(S)) {
 # L - unique(sort(c(L, L + S[i])))
 L - c(L, L+S[i])
 L - L[L = t]
 if (max(L) == t) {
   inds - c(i)
   t - t - S[i]
   while (t  0) {
 K - c(0)
 for (j in 1:(i-1)) {
   K - c(K, K+S[j])
   if (t %in% K) break
 }
 inds - c(inds, j)
 t - t - S[j]
   }
   break
 }
   }
   return(inds)
 }

 # former example
 amount - 4748652
 products -
 c(30500,30500,30500,30500,42000,42000,42000,42000,
   42000,42000,42000,42000,42000,42000,71040,90900,
   76950,35100,71190,53730,456000,70740,70740,533600,
   83800,59500,27465,28000,28000,28000,28000,28000,
   26140,49600,77000,123289,27000,27000,27000,27000,
   27000,27000,8,33000,33000,55000,77382,48048,
   51186,4,35000,21716,63051,15025,15025,15025,
   15025,80,111,59700,25908,829350,1198000,1031655)

 # prepare set
 prods - products[products = amount]  # no elements  amount
 prods - sort(prods, decreasing=TRUE)  # decreasing order

 # now find one solution
 system.time(is - solveSubsetSum(prods, amount))
 #  user  system elapsed
 # 0.320   0.032   0.359

 prods[is]
 #  [1]   70740   70740   71190   76950   77382   8   83800
 #  [8]   90900  456000  533600  829350 111 1198000

 sum(prods[is]) == amount
 # [1] TRUE

 Note that running times and memory needs will be much higher when more
 summands are needed.  To mention that too: I have not tested the code
 extensively.

 Regards
 Hans Werner

 __
 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] Please help with a basic function

2009-12-11 Thread Mark Na
Hello,

I am learning how to use functions, but I'm running into a roadblock.

I would like my function to do two things: 1) convert an object to a
dataframe, 2) and then subset the dataframe. Both of these commands work
fine outside the function, but I would like to wrap them in a function so I
can apply the code iteratively to many such objects.

Here's what I wrote, but it doesn't work:

convert-function(d) {
 d-data.frame(d); #convert object to dataframe
 d-subset(d,select=c(time,coords.x1,coords.x2)) #select some columns
}
convert(data) #the problem is that data is the same as it was before
running the function

The objects being processed through my function are SpatialPointsDataFrames
but I'm quite sure that's not my problem, as I can process these outside of
the function (using the above code) ... it's when I try to wrap the code in
a function that it doesn't work.

Thanks, Mark

[[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] Fonts and axes using persp3d

2009-12-11 Thread Paul Simonin

Greetings,

 I am making 3D plots using persp3d, and would like to set z-axis 
limits and make axis labels (the automatic numbers at tick marks) bold. 
I have tried zlim, but this does not seem to force the plot to 
restrain itself within certain bounds (e.g., 0-1). The surface I am 
plotting (z values) does contain some values outside the range I am 
setting. Maybe this overrides the zlim? Is there a way to fix this 
without manually removing negative z values?
 Also, is there any way to make the numerical axis labels bold, or 
generally darker or larger?


My code currently reads:

xtemp   - 6:22
ylight  - seq(from=-7.5, to=-5, by=0.5)
wDeltaT - 0
code- 1
grid.tld - expand.grid(temp=xtemp, logwm2=ylight, DeltaT=wDeltaT, 
code=code)   
YaoRasPred-predict(YaoRas.Distribution.T.L.DT.gamm$gam,newdata=grid.tld,se.fit=T)


Rel.Dens - matrix(YaoRasPred$fit, nrow=17 , byrow=F)   # use predict 
instead here

library(rgl)
persp3d(xtemp,ylight,Rel.Dens, 
zlim=c(min=0.0,max=0.032),xlab=,ylab=,zlab=,col=gray)





Thanks for any advice, and thanks again to Duncan Murdoch for suggesting 
persp3d for my purposes!


Sincerely,
Paul Simonin

__
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] get the enclosing function name

2009-12-11 Thread baptiste auguie
Hi,

.NotYetImplemented gives an example,

function ()
stop(gettextf('%s' is not implemented yet,
as.character(sys.call(sys.parent())[[1L]])),
call. = FALSE)
environment: namespace:base

HTH,

baptiste

2009/12/11 Hao Cen h...@andrew.cmu.edu:
 Hi,

 Is there a way to get the enclosing function name within a function?

 For example, I would like to have a function getEnclosingFunctionName().
 It works like below

 f = function(){
  print(getEnclosingFunctionName())

 }


 f()  # will print  f


 Thanks

 Jeff

 __
 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] Literature analysis

2009-12-11 Thread Schwan
Thanks, but how should I put the citation inside a data frame?

data.frame(first txt file, second txt file...)
plot (what should I insert here) type=p

And how should I load the txt files anyway inside the frame?






On Fri, 2009-12-11 at 08:37 -0500, Ista Zahn wrote:
 It sounds pretty simple so far. Just put the citation info in a data
 frame, and plot it. I would use ggplot2 for plotting, but it could be
 done in base or lattice too.
 
 On Fri, Dec 11, 2009 at 8:04 AM, Schwan s.s.hosse...@utwente.nl wrote:
  Ok good question I havent explain!
 
  Well,lets keep it simple for the begining. By analyzing the
  keywords(which can also include the authors name) I mean,
 
  1) investigate in which paper the keyword occur and how often
  2) investigate if keywords occur together
 
  X axis can show the paper title (or authors name)
  y axis shows the keywords
 
  if a keyword occurs more often in a paper then the dot on the graph
  changes the color
 
  if keywords occur together then a symbol the same symbol appears.
 
 
 
 
 
 
 
  On Fri, 2009-12-11 at 04:33 -0800, nshephard wrote:
 
 
  Schwan wrote:
  
   Thanks for all the comments,
  
   and sorry about the unstructured question! I am trying to:
  
   1: analyze keywords, names from Authors and year of publication from
   citations (with abstracts) i downloaded fron various sites(these
   downloads can be converted into .txt files as well)
 
  Sorry to bang the drum but what do you mean by analyse, is it to simply
  count keywords and rank them, investigate which keywords occur together,
  look at trends in keywords by year or something else completely.
 
  Its a very general term (at least for me as I've no knowledge or experience
  of text mining)!
 
  Neil
 
 
  --
  ---
  Hosseiny, MSc. S.S. (Seyed Schwan)
  University of Twente Science and Technology
  Meander, ME 322
  P.O. Box 217 7500 AE Enschede
  The Netherlands
  Phone +31 534892869
  Email:  s.s.hosse...@utwente.n
 
  __
  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.
 
 
 
 


-- 
---
Hosseiny, MSc. S.S. (Seyed Schwan)
University of Twente Science and Technology
Meander, ME 322
P.O. Box 217 7500 AE Enschede
The Netherlands
Phone +31 534892869
Email:  s.s.hosse...@utwente.n

__
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] Literature analysis

2009-12-11 Thread Schwan
They are in Bibtex

For example:

@ARTICLE{adsdifvanadiumcationexchange,
  author = {Jin-qing Chen and Bao-guo Wang and Ji-chu Yang},
  title = {Adsorption and Diffusion of VOsup2+/sup and
VOsub2/sub sup+/sup
across Cation Membrane for All-Vanadium Redox Flow Battery},
  journal = {Solvent Extraction and Ion Exchange},
  year = {2009},
  volume = {27},
  pages = {312--327},
  number = {2},
  abstract = {A method based on a selectivity coefficient and the
Nernst-Planck
equation is proposed to determine diffusion coefficients of vanadium
ions across a cation exchange membrane in VOsup2+/sup/Hsup+/sup
and VOsub2/sub sup+/sup/Hsup+/sup systems. This simplified
method can be applied to high concentrations of vanadium ions. Three
cation exchange membranes were studied. The logarithmic value of
the selectivity coefficient was linearly dependent on the molar
fraction
of vanadium ions in solution. The diffusion coefficient of vanadium
ions decreased with decreasing water content. The membrane with the
lowest diffusion coefficient was selected as a battery separator
and showed the lowest capacity loss of the studied membranes.},
  issn = {0736-6299},
  publisher = {Taylor \ Francis},
  url = {http://www.informaworld.com/10.1080/07366290802674614}
}

@ARTICLE{Chieng1992,
  author = {Chieng, S.C. and Kazacos, M. and Skyllas-Kazacos, M.},
  title = {Modification of Daramic, microporous separator, for redox
flow battery
applications},
  journal = {Journal of Membrane Science},
  year = {1992},
  volume = {75},
  pages = {81--91},
  number = {1-2},
  month = dec,
  issn = {0376-7388},
  keywords = {Daramic, microporous separator, redox flow cell and
battery},
  owner = {schwan},
  timestamp = {2009.11.30},
  url =
{http://www.sciencedirect.com/science/article/B6TGK-43S71CR-7K/2/06f90d391c0eff0ff5df3f282ad5fe28}
}



On Fri, 2009-12-11 at 15:37 +0100, Gustaf Rydevik wrote:
 
 
 On Fri, Dec 11, 2009 at 3:04 PM, Schwan s.s.hosse...@utwente.nl
 wrote:
 Thanks, but how should I put the citation inside a data frame?
 
 data.frame(first txt file, second txt file...)
 plot (what should I insert here) type=p
 
 And how should I load the txt files anyway inside the frame?
 
 
 
 
 Can you give an example of a couple of text files? Are they in a
 standardised format (i.e. bibTEX or similar)? 
 
 
 /Gustaf
 
 -- 
 Gustaf Rydevik, M.Sci.
 tel: +46(0)703 051 451
 address:Essingetorget 40,112 66 Stockholm, SE
 skype:gustaf_rydevik


-- 
---
Hosseiny, MSc. S.S. (Seyed Schwan)
University of Twente Science and Technology
Meander, ME 322
P.O. Box 217 7500 AE Enschede
The Netherlands
Phone +31 534892869
Email:  s.s.hosse...@utwente.n

__
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] plotting with varying dot sizes

2009-12-11 Thread servet ahmet çizmeli
I think I located the problem. the data frame associated with my spatial object
(Insitu_sp) contains some NAs. And in this case, the function plot does not
like NAs. It simply behaved strangely. The code below did the trick :

idx = is.na(Insitu[,SPM])
ptsize = 0.35*(sqrt(Insitu[!idx,SPM])+1)
plot(Insitu_sp[!idx,SPM],col=red,pch=19,cex=ptsize)

Does the symbols function supports spatial (sp) objects? I could not manage to
make it work with my sp data.



Quoting Greg Snow greg.s...@imail.org:

 The symbols function may work better than plot for this situation.

__
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] Literature analysis

2009-12-11 Thread Gustaf Rydevik
On Fri, Dec 11, 2009 at 3:04 PM, Schwan s.s.hosse...@utwente.nl wrote:

 Thanks, but how should I put the citation inside a data frame?

 data.frame(first txt file, second txt file...)
 plot (what should I insert here) type=p

 And how should I load the txt files anyway inside the frame?


 Can you give an example of a couple of text files? Are they in a
standardised format (i.e. bibTEX or similar)?

/Gustaf

-- 
Gustaf Rydevik, M.Sci.
tel: +46(0)703 051 451
address:Essingetorget 40,112 66 Stockholm, SE
skype:gustaf_rydevik

[[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] foreach and deparse(substitute(x))

2009-12-11 Thread Hao Cen
Hi,

I would like to get the actual object name passed as a parameter of a
function and am using deparse(substitute(x)) to do that. It doesn't work
when it is used along with the foreach package. Appreciate if any one can
give some suggestions on how to make it work with foreach.

FUN.aaa - function() {
}

ff =  function( FUN){
foreach(i = 1:3) %dopar% {
print(sprintf(deparse(substitute(FUN)) = %s, 
deparse(substitute(FUN
return(NULL)
}
}

ff(FUN.aaa)

# will print
ff(FUN.aaa)
[1] deparse(substitute(FUN)) = FUN
[1] deparse(substitute(FUN)) = FUN
[1] deparse(substitute(FUN)) = FUN
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL


If there is no foreach, it works

FUN.aaa - function() {
}

ff =  function( FUN){
print(sprintf(deparse(substitute(FUN)) = %s, 
deparse(substitute(FUN
}
}

ff(FUN.aaa)

#It works and prints
 ff(FUN.aaa)
ff(FUN.aaa)
[1] deparse(substitute(FUN)) = FUN.aaa
thanks

Jeff

__
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] Literature analysis

2009-12-11 Thread Neil Shephard
On Fri, Dec 11, 2009 at 2:04 PM, Schwan s.s.hosse...@utwente.nl wrote:
 Thanks, but how should I put the citation inside a data frame?

 data.frame(first txt file, second txt file...)
 plot (what should I insert here) type=p

 And how should I load the txt files anyway inside the frame?


Check out the resources I recommended in my first reply.  These are
aspects of using R that are fundamental and completely independent of
what analysis you want to do.

Neil


-- 
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey (1986), Sunset salvo. The American
Statistician 40(1).

Email - nsheph...@gmail.com
Website - http://slack.ser.man.ac.uk/
Photos - http://www.flickr.com/photos/slackline/

__
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] non-linear regression

2009-12-11 Thread Alane

Katharine,

The problem of estimation of parameters in R is that you have to know the 
value of the initial estimates very accurately, otherwise it does not 
converge.


The example below could be resolved in Excel, however in  does not converge. 
How to solve the problem?


I made the chart on a logarithmic scale to better visualize the differences.

Send the data file attached.

The commands are below:

tx.br - read.table('c:/tx.br.H.txt',header=F,dec=',')
tx.br -tx.br[,1]
id-1:100

qx.suav - function(id,A,B,C,D,E,F,G,H,K)
 (A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))

HP - nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),
 data=data.frame(id=id,tx.br=tx.br),
 trace=TRUE,nls.control(maxiter=5,warnOnly=TRUE,minFactor = 
0.1),

algorithm='port',
start=list(A=0.000644,B=0.016761290,C=0.10927095582,D=0.00094877,
  
E=5.949082737,F=24.526811,G=0.46733960,H=1.0970550987,K=0.771722501657),
 lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))

HP

matplot(cbind(log(fitted(HP)), log(tx.br)),type=l)



- Original Message - 
From: Katharine Mullen k...@few.vu.nl

To: AneSR citb...@terra.com.br
Cc: r-help@r-project.org
Sent: Thursday, December 10, 2009 9:55 PM
Subject: Re: [R] non-linear regression



You did not provide the data or a way of generating it.

I would guess that Excel finds the same solution (the same residual sum-of
squares) as nls but that it uses a weak convergence criterion and/or does
not give you information regarding why it terminates.

Regarding the step size:  you can set the minimum step size factor via the
minFactor argument of control.

qx.suav - function(id,A,B,C,D,E,F,G,H,K)
 (A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))

## make noisy data from model
id - 1:1000
tx.br - qx.suav(id,A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,
E=0.0002127,F=38.5448420,G=0.115,H=1.1109286,
K=0.382070638)
set.seed(1)
tx.br - tx.br + rnorm(length(tx.br),0,.0001)

HP - nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),
 data=data.frame(id=id,tx.br=tx.br),
 trace=TRUE,nls.control(maxiter=5000,warnOnly=TRUE),
 algorithm='port',
 start=list(A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,
   E=0.0002127,F=38.5448420,G=0.115,H=1.1109286,
   K=0.382070638),
 lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))
matplot(cbind(fitted(HP), tx.br),type=l)

On Thu, 10 Dec 2009, AneSR wrote:



I have a non-linear regression with 8 parameters to solve  however it
does not converge ... easily solves the excel ... including the initial
estimates used in the R were found in the excel ... Another question is 
how

to establish the increments of R by the parameters in the search ..


qx.suav-function(id,A,B,C,D,E,F,G,H,K){(A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))}
HP-nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),data=data.frame(id=id,tx.br=tx.br),
trace=TRUE,nls.control(maxiter=5000),algorithm='port',start=list(A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,E=0.0002127,F=38.5448420,G=0.115,H=1.1109286,K=0.382070638),lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))
summary(HP)

How to solve this problem in R?

Ane
--
View this message in context: 
http://n4.nabble.com/non-linear-regression-tp959977p959977.html

Sent from the R help mailing list archive at Nabble.com.

[[alternative HTML version deleted]]

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

and provide commented, minimal, self-contained, reproducible code.










No virus found in this incoming message.
Checked by AVG - www.avg.com

07:36:00

0,000757
0,000356
0,000290
0,000232
0,000199
0,000283
0,000128
0,000235
0,000230
0,000179
0,000197
0,000172
0,000294
0,000307
0,000411
0,000619
0,000812
0,000949
0,001116
0,001134
0,001159
0,001151
0,001321
0,001235
0,001296
0,001287
0,001241
0,001469
0,001278
0,001466
0,001440
0,001881
0,001457
0,001843
0,001754
0,001796
0,001915
0,002199
0,002120
0,002471
0,002213
0,002478
0,002975
0,002583
0,002751
0,003388
0,003956
0,004369
0,004062
0,004410
0,004939
0,005492
0,005961
0,006311
0,006846
0,007637
0,008968
0,010612
0,010907
0,011986
0,013174
0,014316
0,015557
0,017824
0,018740
0,020338
0,022034
0,022339
0,025929
0,030967
0,033520
0,039556
0,041168
0,044811
0,049932
0,047401
0,060318
0,063559
0,064084
0,077614
0,080425
0,094073
0,102383
0,116288
0,112727
0,114192
0,137330
0,159065
0,138378
0,135844
0,148244
0,165927
0,180803
0,217185
0,241570
0,249358
0,309202
0,269479
0,325142
0,461620
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide 

Re: [R] How to draw three line on the same picture ?

2009-12-11 Thread z_axis

It works !  thank you very much.
Moreover, How about reading data from file ?   The file is formatted as:
No V1 V2 V3
1   0.23 0.12 0.89
2   0.11 0.56 0.12
..


jholtman wrote:
 
 try this:
 
 x - read.table(textConnection(No   V1  V2 V3
 1 0.23 0.12 0.89
 2 0.11 0.56 0.12), header=TRUE)
 matplot(x[,1], x[,-1], type='l')
 
 
 On Fri, Dec 11, 2009 at 3:39 AM, z_axis z_a...@163.com wrote:
 

 thanks for your answer ! Would you mind giving me an example using my
 data
 ?

 Sincerely!


 Patrick Connolly-4 wrote:
 
  On Thu, 10-Dec-2009 at 10:14PM -0800, z_axis wrote:
 
  |
  | The following is  sampling data:
  | No   V1  V2 V3
  | 1 0.23 0.12 0.89
  | 2 0.11 0;56 0.12
  | ...
  |
  | I just want to draw three lines on same picture according to value
 of
  V1, V2
  | and V3.
 
  ?lines
 
 
  --
 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 ___Patrick Connolly
   {~._.~}   Great minds discuss ideas
   _( Y )_   Average minds discuss events
  (:_~*~_:)  Small minds discuss people
   (_)-(_). Eleanor Roosevelt
 
 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 

 --
 View this message in context:
 http://n4.nabble.com/How-to-draw-three-line-on-the-same-picture-tp960823p960897.html
 Sent from the R help mailing list archive at Nabble.com.

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

 
 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 
   [[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.
 
 

-- 
View this message in context: 
http://n4.nabble.com/How-to-draw-three-line-on-the-same-picture-tp960823p960986.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Subset sum problem.

2009-12-11 Thread Geert Janssens
Hans, you're my personal hero today !

The function seems to work fine for the tests I did already.

Thank you very much !

Geert

On Thursday 10 December 2009, Hans W Borchers wrote:
 Geert Janssens janssens-geert at telenet.be writes:
  On Wednesday 9 December 2009, Hans W Borchers wrote:
   Geert Janssens janssens-geert at telenet.be writes:
[ ... ]
Has anybody tackled this issue before in R ? If so, I would be very
grateful if you could share your solution with me.
  
   Is it really true that you only want to see a Yes or No answer to
   this question whether a subset sums up to s --- without learning which
   numbers this subset is composed of (the pure SUBSET SUM problem)?
   Then the following procedure does that in a reasonable amount of time
   (returning 'TRUE' or 'FALSE' instead of Y-or-N):
 
  Unfortunately no. I do need the numbers in the subset. But thank you for
  presenting this code.
 
  Geert

 Okay then, here we go. But don't tell later that your requirement was to
 generate _all_ subsets that add up to a certain amount.  I will generate
 only one (with largest elements).

 For simplicity I assume that the set is prepared s.t. it is decreasingly
 ordered, has no elements larger than the amount given, and has a total sum
 larger than this amount.

 # Assume S decreasing, no elements  t, total sum = t
 solveSubsetSum - function(S, t) {
   L - c(0)
   inds - NULL
   for (i in 1:length(S)) {
 # L - unique(sort(c(L, L + S[i])))
 L - c(L, L+S[i])
 L - L[L = t]
 if (max(L) == t) {
   inds - c(i)
   t - t - S[i]
   while (t  0) {
 K - c(0)
 for (j in 1:(i-1)) {
   K - c(K, K+S[j])
   if (t %in% K) break
 }
 inds - c(inds, j)
 t - t - S[j]
   }
   break
 }
   }
   return(inds)
 }

 # former example
 amount - 4748652
 products -
 c(30500,30500,30500,30500,42000,42000,42000,42000,
   42000,42000,42000,42000,42000,42000,71040,90900,
   76950,35100,71190,53730,456000,70740,70740,533600,
   83800,59500,27465,28000,28000,28000,28000,28000,
   26140,49600,77000,123289,27000,27000,27000,27000,
   27000,27000,8,33000,33000,55000,77382,48048,
   51186,4,35000,21716,63051,15025,15025,15025,
   15025,80,111,59700,25908,829350,1198000,1031655)

 # prepare set
 prods - products[products = amount]  # no elements  amount
 prods - sort(prods, decreasing=TRUE)  # decreasing order

 # now find one solution
 system.time(is - solveSubsetSum(prods, amount))
 #  user  system elapsed
 # 0.320   0.032   0.359

 prods[is]
 #  [1]   70740   70740   71190   76950   77382   8   83800
 #  [8]   90900  456000  533600  829350 111 1198000

 sum(prods[is]) == amount
 # [1] TRUE

 Note that running times and memory needs will be much higher when more
 summands are needed.  To mention that too: I have not tested the code
 extensively.

 Regards
 Hans Werner

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


-- 
Kobalt W.I.T.
Web  Information Technology
Brusselsesteenweg 152
1850 Grimbergen

Tel  : +32 479 339 655
Email: i...@kobaltwit.be

__
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] cluster size

2009-12-11 Thread karuna m
hi r-help,
i am doing kmeans clustering in stats. i tried for five clusters clustering 
using:
kcl1 - kmeans(as1[,c(contlife,somlife,agglife,sexlife,
    rellife,hordlife,doutlife,symtlife,washlife,
   chcklife,rptlife,countlife,coltlife,ordlife)], 
5, iter.max = 10, nstart = 1,
     algorithm = Hartigan-Wong)
  table(kcl1$cluster)
every time i am getting five clusters of different sizes like first time with 
cluster sizes
table(kcl1$cluster)
  1   2   3   4   5 
140  72 105  98 112
second time with cluster sizes
table(kcl1$cluster)
  1   2   3   4   5 
 91 149 106  76 105 and so on.
I wish to know that whether there is any function to get same sizes of clusters 
everytime when we do kmeans clustering.
Thanks in advance.
regards,
Ms.Karunambigai M
PhD Scholar
Dept. of Biostatistics
NIMHANS
Bangalore
India


  The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
[[alternative HTML version deleted]]

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


Re: [R] Literature analysis

2009-12-11 Thread Ista Zahn
I think I my original response was bad. And I also realize that I
don't really understand what you want to do.

Here is what I was thinking:

Format your bibliography as CSV (you can convert common bibliography
formats to .csv using Tellico or similar software). Then read the
references into a data frame:

Refs - read.csv(textConnection('Title,Entry Type,Author,Bibtex
Key,Book 
Title,Editor,Organization,Publisher,Address,Edition,Pages,Year,ISBN#,Journal,DOI,Month,Number,How
Published,Chapter,Series,Volume,Cross-Reference,Keywords,URL,Abstract,Notes,ID,Date
Created,Date Modified
Unconscious authorship ascription: The effects of success and
effect-specific information priming on experienced
authorship,article,Aarts, H.,Aarts2007,,,119–126,2007,,Journal
of Experimental Social Psychology,,,43,,Lexical Decision;
unconscious; Perception; presentation of words; effect-specific
information; experienced authorship; authorship ascription; priming;
lexical decisions; subliminal perception; Self
Perception,http://localhost/refbase/Papers/Aarts/Unconscious%20authorship%20ascription:%20The%20effects%20of%20success.pdf,Abstract
goes here,exported from refbase
(http://ista.scp.rochester.edu/refbase/show.php?record=14), last
updated on Tue, 17 Nov 2009 10:23:27 -0500,0,2009-12-11,2009-12-11
Goal contagion: Perceiving is for pursuing,article,Aarts, H.;
Gollwitzer, P.; Hassin, R.,Aarts_etal2004,,,23–37,2004,,Journal
of Personality and Social Psychology,,,87,,Contagion; goal
contagion; automatic goal adion; Motivation; Perception; implied
behavioral goals; goal perception; Theories; Automatism; behavioral
information; goal directedness; Attention; Stimulus Parameters; Goals;
goal 
characteristics,http://localhost/refbase/Papers/Aarts/Goal%20contagion:%20Perceiving%20is%20for%20pursuing.pdf,Abstract
goes here.,exported from refbase
(http://ista.scp.rochester.edu/refbase/show.php?record=15), last
updated on Tue, 17 Nov 2009 10:23:27 -0500,1,2009-12-11,2009-12-11'))

closeAllConnections()

(sorry, I know that's going to get all screwed up by word wrapping).
Next split out the keywords into separate columns, and then combine
them again into a value column:

library(ggplot2)
Refs - as.data.frame(cbind(Refs, colsplit(Refs$Keywords, split=; ,
names=Keyword)))
Refs - melt(Refs, measure.vars=31:45)

And then that's were I get stuck. I have authors and keywords for each
publication, but I'm not sure how you want this represented.

-Ista

On Fri, Dec 11, 2009 at 9:04 AM, Schwan s.s.hosse...@utwente.nl wrote:
 Thanks, but how should I put the citation inside a data frame?

 data.frame(first txt file, second txt file...)
 plot (what should I insert here) type=p

 And how should I load the txt files anyway inside the frame?






 On Fri, 2009-12-11 at 08:37 -0500, Ista Zahn wrote:
 It sounds pretty simple so far. Just put the citation info in a data
 frame, and plot it. I would use ggplot2 for plotting, but it could be
 done in base or lattice too.

 On Fri, Dec 11, 2009 at 8:04 AM, Schwan s.s.hosse...@utwente.nl wrote:
  Ok good question I havent explain!
 
  Well,lets keep it simple for the begining. By analyzing the
  keywords(which can also include the authors name) I mean,
 
  1) investigate in which paper the keyword occur and how often
  2) investigate if keywords occur together
 
  X axis can show the paper title (or authors name)
  y axis shows the keywords
 
  if a keyword occurs more often in a paper then the dot on the graph
  changes the color
 
  if keywords occur together then a symbol the same symbol appears.
 
 
 
 
 
 
 
  On Fri, 2009-12-11 at 04:33 -0800, nshephard wrote:
 
 
  Schwan wrote:
  
   Thanks for all the comments,
  
   and sorry about the unstructured question! I am trying to:
  
   1: analyze keywords, names from Authors and year of publication from
   citations (with abstracts) i downloaded fron various sites(these
   downloads can be converted into .txt files as well)
 
  Sorry to bang the drum but what do you mean by analyse, is it to simply
  count keywords and rank them, investigate which keywords occur together,
  look at trends in keywords by year or something else completely.
 
  Its a very general term (at least for me as I've no knowledge or 
  experience
  of text mining)!
 
  Neil
 
 
  --
  ---
  Hosseiny, MSc. S.S. (Seyed Schwan)
  University of Twente Science and Technology
  Meander, ME 322
  P.O. Box 217 7500 AE Enschede
  The Netherlands
  Phone +31 534892869
  Email:  s.s.hosse...@utwente.n
 
  __
  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.
 





 --
 ---
 Hosseiny, MSc. S.S. (Seyed Schwan)
 University of Twente Science and Technology
 Meander, ME 322
 P.O. 

[R] memory problem on Suse

2009-12-11 Thread Ambrosi Alessandro

Dear all, I am meeting some problems with  memory allocation. I know it is an 
old issue, I'm sorry. 
I looked for a solution in the FAQs and manuals, mails, but without finding the 
working answer. 
I really hope you can help me. 
For instance, if I try to read micorarray data I get:

 mab=ReadAffy(cdfname=hgu133plus2cdf)
Error: cannot allocate vector of size 858.0 Mb
 

I get similar errors with smaller objects, smaller data sets or other 
procedures 
(Error: cannot allocate vector of size 123.0 Mb).
I'm running R with Suse 11.1 Linux OS, on two Xeon processors (8 cores), 32 GB 
RAM.
I suppose I have enough resources to manage these objects and data files

Any suggestions or hints will be really appreciated!
Many thanks in advance.
Alessandro 
__
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] Array of legend text with math symbols from predefined variables

2009-12-11 Thread Koen
Hello,

I am trying to include legend text with math symbols from a predefined
character variable that is read in from a file.
 
If there is only one line of text in the legend, the following, although
cumbersome, works for me:

   LegendText =  'U' [infinity], '=10 m/s'    # (read in from a file)
   LegendName = paste(bquote(paste(,LegendText, )))
   plot( c(1,2,3), c(1,2,3) )
   legend(‘topleft’,1, eval(parse(text=LegendName)) ) 

 If I now have more than one line in a plot and hence want to include more
than one line of legendtext, I run into problems because

   legend(‘topleft’,1, c(
 eval(parse(text=LegendName1)),eval(parse(text=LegendName2))  ) 

will not result in evaluation of the character string but just a paste of
the string and

   legend(‘topleft’,1, eval(parse(text=c(LegendName1, LegendName2)))  ) 

will only evaluate the first element of the array.

Am I trying to do the impossible or is my approach totally wrong? Any help
would be greatly appreciated!

Koen

__
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 draw three line on the same picture ?

2009-12-11 Thread z_axis

%cat test.csv
No,HS,ZangF,ZenF
1,0.25,0.5,0.57
2,0.10,0.23,0.12
3,0.20,0.25,0.1
..
d - read.csv(000301.txt)
matplot(d[,1], d[,-1], type='l')

It works. However, i hope the legend is displayed.

Sincerely!




z_axis wrote:
 
 It works !  thank you very much.
 Moreover, How about reading data from file ?   The file is formatted as:
 No V1 V2 V3
 1   0.23 0.12 0.89
 2   0.11 0.56 0.12
 ..
 
 
 jholtman wrote:
 
 try this:
 
 x - read.table(textConnection(No   V1  V2 V3
 1 0.23 0.12 0.89
 2 0.11 0.56 0.12), header=TRUE)
 matplot(x[,1], x[,-1], type='l')
 
 
 On Fri, Dec 11, 2009 at 3:39 AM, z_axis z_a...@163.com wrote:
 

 thanks for your answer ! Would you mind giving me an example using my
 data
 ?

 Sincerely!


 Patrick Connolly-4 wrote:
 
  On Thu, 10-Dec-2009 at 10:14PM -0800, z_axis wrote:
 
  |
  | The following is  sampling data:
  | No   V1  V2 V3
  | 1 0.23 0.12 0.89
  | 2 0.11 0;56 0.12
  | ...
  |
  | I just want to draw three lines on same picture according to value
 of
  V1, V2
  | and V3.
 
  ?lines
 
 
  --
 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 ___Patrick Connolly
   {~._.~}   Great minds discuss ideas
   _( Y )_   Average minds discuss events
  (:_~*~_:)  Small minds discuss people
   (_)-(_). Eleanor Roosevelt
 
 
 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 
 http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 

 --
 View this message in context:
 http://n4.nabble.com/How-to-draw-three-line-on-the-same-picture-tp960823p960897.html
 Sent from the R help mailing list archive at Nabble.com.

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

 
 
 
 -- 
 Jim Holtman
 Cincinnati, OH
 +1 513 646 9390
 
 What is the problem that you are trying to solve?
 
  [[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.
 
 
 
 

-- 
View this message in context: 
http://n4.nabble.com/How-to-draw-three-line-on-the-same-picture-tp960823p961035.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Problem with calibrate function

2009-12-11 Thread Rodrigo

Hi,

I´m trying to use the calibrate function from rms package (made by prof.
Harrell) after fitting a model using cph. But it returns the following error
message:

 calibrate(modelo1,B=200,bw=F,u=13)

Using Cox survival estimates at  13 Days
Convergence problems stopping addition
Error in hare(S[, 1], S[, 2], fun(est.surv), maxdim = maxdim, ...) :
 no convergence
 this is serious!

Has anybody experienced the same problem? Can anyone help me?

many thanks,
Rodrigo
-- 
View this message in context: 
http://n4.nabble.com/Problem-with-calibrate-function-tp961100p961100.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] question about centroid-linkage (cluster analysis) (2)

2009-12-11 Thread james.foadi
Dear R community,
just in case some haven't noticed my previous email.
I realize hclust relies on a Fortran routine, but I hoped
some of you might exactly know how that Y.hc_c$height
is computed. And, thus, explain the anomaly I found.

Thank you.

J

Dr James Foadi PhD
Membrane Protein Laboratory (MPL)
Diamond Light Source Ltd
Diamond House
Harewell Science and Innovation Campus
Chilton, Didcot
Oxfordshire OX11 0DE

Email:  james.fo...@diamond.ac.uk
Alt Email:  j.fo...@imperial.ac.uk



-Original Message-
From: r-help-boun...@r-project.org on behalf of james.fo...@diamond.ac.uk
Sent: Thu 10/12/2009 13:26
To: r-help@r-project.org
Subject: [R] question about centroid-linkage (cluster analysis)
 
Dear R community,
I would be greatful if somebody could shed light on the following.

I have created a set of 6 points to check how centroid
agglomeration works in cluster analysis:

 Y - data.frame(x=c(-1,1,1,-1,10,12),y=c(1,1,-1,-1,0,0))

It is quite intuitive to understand that the last clusters to be joined will be
{1,2,3,4} with {5,6}. Now, the centroid for the first cluster has coordinates 
(0,0),
while the centroid for the second cluster has coordinates (11,0). Therefore, the
distance between these two cluster should be 11. But:

 Y.dist - dist(Y)
 Y.hc_c - hclust(Y.dist,method=centroid)
 Y.hc_c$merge
 [,1] [,2]
[1,]   -1   -2
[2,]   -31
[3,]   -42
[4,]   -5   -6
[5,]34
 Y.hc_c$height
[1] 2.00 1.914214 1.517428 2.00 9.692575


So, from this it would appear that the distance between the last two clusters 
is 9.692575!
How can it be?

J

Dr James Foadi PhD
Membrane Protein Laboratory (MPL)
Diamond Light Source Ltd
Diamond House
Harewell Science and Innovation Campus
Chilton, Didcot
Oxfordshire OX11 0DE

Email:  james.fo...@diamond.ac.uk
Alt Email:  j.fo...@imperial.ac.uk


-- 
This e-mail and any attachments may contain confidential...{{dropped:19}}

__
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] shared axes in multipanel plot

2009-12-11 Thread Jennifer Young
Hello

I've created a function to make a plot with multiple pannels from columns
of data that are created in a previous function.  In the example below the
number of columns is 8, giving 4 pannels, but in general it takes data
with any number of columns and figures out a nice layout.

The panels all have the same axes, and so I wonder what functions are
avialable to create axes only on the left and bottom of the whole plot
rather than each pannel.
I'd really like a generic way to do this for any number of plots, but was
even having trouble figuring out how to do it manually for this example;
How are pannels referred to, in a layout context?
That is, how do I say,

if(current.pannel==4) {do stuff}

Here's a simple version of the code.

baseline - (1:20)/20#example data
dat1 - matrix(baseline,20,8)
dat - dat1+matrix(rnorm(20*8)/30, 20,8)

nstrat - ncol(dat)
rows - ceiling(nstrat/4)
layout(matrix(1:(rows*2), rows, 2, T))
par(oma=c(4,4,3,1))
par(mar=c(1,1,0,1))
for(i in which(1:nstrat%%2!=0)){
plot(baseline, type=l, col=grey, lwd=2,
xlab=, ylab=, ylim=c(0,1), xaxt='n', yaxt='n')
axis(1, labels=F); axis(2, labels=F)
points(dat[,i], type=l, lty=2)
points(dat[,i+1], type=l, lty=2)
}



Thank you muchly
Jennifer Young

PS: I am a subscriber, but can't for the life of me figure out how to send
an email while logged in so that the moderators don't have to take the
time to read it over.  I always get the please wait while we check it
over email.  Likely I'm being dumb.

__
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] incorrect multiple outputs

2009-12-11 Thread Richard Thompson
Ista,

Here is the full code:

file-read.table(file=input_file.txt,sep=\t)[,c(1,3:5)]
file.rows- c(nrow(file)/288)
full.array - array(0,dim=c(8,file.rows,12))

cellnames - rep(A,file.rows)
barcodes - rep(A,file.rows)
t - rep(A,file.rows)
t11 - rep(A,file.rows)
cv - rep(A,file.rows)

for (k in 1:file.rows){

plate- file[(((k-1)*288)+1),1]

barcodes[k] - levels(plate)[plate]

l - k*288
a - l-287
x-file[a:l,]
x.array-matrix(0,ncol=12,nrow=8)
n.array-matrix(0,ncol=12,nrow=8)
x.blank2 - matrix(0,ncol=3,nrow=24)
x.nodrug2 - matrix(0,ncol=6,nrow=24)
value - data.frame(conc=0,fluor=2)

# reformat (mean) input data into 96 well format
q-1
for (m in 1:8){ for (n in 1:12){ p- 3*q; x.array[m,n] -
mean(as.matrix(x[(p-2):p,2:4])); q - q+1; if (n == 1){z-3*m;
x.blank2[(z-2):z,]-as.matrix(x[(p-2):p,2:4])}; if
(n==11){z-3*m;x.nodrug2[(z-2):z,1:3]-as.matrix(x[(p-2):p,2:4])}; if
(n==12){z-3*m; x.nodrug2[(z-2):z,4:6]-as.matrix(x[(p-2):p,2:4])}}}
x.blank-c(x.blank2[,1],x.blank2[,3],x.blank2[,2])

x.nodrug
-c(x.nodrug2[,1],x.nodrug2[,2],x.nodrug2[,3],x.nodrug2[,4],x.nodrug2[,5],x.nodrug2[,6])
x.nodrug11 -c(x.nodrug2[,1],x.nodrug2[,2],x.nodrug2[,3])

# calculate output values

cv[k] - 100*(sd(x.blank)/mean(x.blank))
t[k] -
(mean(x.nodrug)-mean(x.blank))/sqrt(((sd(x.nodrug)^2)/8)+((sd(x.blank)^2)/16))
t11[k] -
(sqrt(8)*(mean(x.nodrug11)-mean(x.blank)))/sqrt(sd(x.nodrug11)^2+sd(x.blank)^2)
}


all.data
-data.frame(barcodes,t=format(as.numeric(t),digits=3),t11=format(as.numeric(t11),digits=3),cv=format(as.numeric(cv),digits=3))
#write(format(t,digits=6), file= R_drug_plot.log,append=TRUE,sep=\t)
write.table(all.data, file=
R_drug_plot.log,append=TRUE,sep=\t,row.names=FALSE)

When I first tried the mail list wouldn't let me send it as it contains the
word drug too many times! so I only included the problematic parts.
Rich

2009/12/11 Ista Zahn istaz...@gmail.com

 The lack of a reproducible example is a bigger problem than any lack
 of clarity of the explanation.

 -Ista

 On Fri, Dec 11, 2009 at 2:08 AM,  bawa...@googlemail.com wrote:
  Apologies,
  I didn't explain this clearly. The Rscript is called by a perl script,
 which creates input_file.txt by inserting 288 lines of (reformatted) data
 for each data file in the directory.  So the Rscript will (and is doing) run
 the loop a number of times equal to the number of files the perl script read
 in. The problem is that it should only create the data.frame and write to
 the file after the last iteration, but it's (creating and)writing the
 complete data.frame every iteration.
  Sent using BlackBerry® from Orange
 
  -Original Message-
  From: jim holtman jholt...@gmail.com
  Date: Thu, 10 Dec 2009 18:00:54
  To: biscuitbawa...@googlemail.com
  Cc: r-help@r-project.org
  Subject: Re: [R] incorrect multiple outputs
 
  If I rad you code right, file.rows is equal to 1 and your 'for' loop will
  only iterate once.  Is that what you were expecting?
 
  No reproducible code provided, so that is my best guess.
 
 file.rows- c(nrow(file)/288)  # input_file.txt contains 288
 reformatted
  lines for each original data file
  ...
 for (k in 1:file.rows){  # iterates code for each 288 line block of
  input_file.txt
  ...
 
  On Thu, Dec 10, 2009 at 11:39 AM, biscuit bawa...@googlemail.com
 wrote:
 
 
  HI,
  I'm having trouble with a piece of Rscript which keeps outputting
  incorrectly. it's something like this: the code reads in from a file
 which
  contains (reformated) input
 
  file-read.table(file=input_file.txt,sep=\t)[,c(1,3:5)]
  
  file.rows- c(nrow(file)/288)  # input_file.txt contains 288
 reformatted
  lines for each original data file
  ...
  for (k in 1:file.rows){  # iterates code for each 288 line block of
  input_file.txt
  ...
  cv[k] - 100*(sd(x.blank)/mean(x.blank))
  t[k] -
 
 (mean(x.note)-mean(x.blank))/sqrt(((sd(x.note)^2)/8)+((sd(x.blank)^2)/16))
  t11[k] -
 
 (sqrt(8)*(mean(x.note11)-mean(x.blank)))/sqrt(sd(x.note11)^2+sd(x.blank)^2)
  }
  
 
 
 all.data-data.frame(barcodes,t=format(as.numeric(t),digits=3),t11=format(as.numeric(t11),digits=3),cv=format(as.numeric(cv),digits=3))
  write.table(all.data, file=
  R_drug_plot.log,append=TRUE,sep=\t,row.names=FALSE)
 
  this all works correctly except that I believed it would output to file
  after completing the loop, instead it's writing to file every iteration.
 so
  the output file looks like:
 
  headers
  a1
  headers
  a1
  a2
  headers
  a1
  a2
  a3
  ...
 
  I have checked the missing sections of code and can confirm there are no
  missing/additional brackets. Has anyone any idea why this is happening
 and
  what I can do about it?
  --
  View this message in context:
  http://n4.nabble.com/incorrect-multiple-outputs-tp957192p957192.html
  Sent from the R help mailing list archive at Nabble.com.
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  

Re: [R] Please help with a basic function

2009-12-11 Thread Ista Zahn
Hi Mark,
You're on the right track. You just need your function to return dataframe. Try

convert-function(d) {
 d-data.frame(d); #convert object to dataframe
 d-subset(d,select=c(time,coords.x1,coords.x2)) #select some columns
return(d)
}

-Ista

On Fri, Dec 11, 2009 at 9:19 AM, Mark Na mtb...@gmail.com wrote:
 Hello,

 I am learning how to use functions, but I'm running into a roadblock.

 I would like my function to do two things: 1) convert an object to a
 dataframe, 2) and then subset the dataframe. Both of these commands work
 fine outside the function, but I would like to wrap them in a function so I
 can apply the code iteratively to many such objects.

 Here's what I wrote, but it doesn't work:

 convert-function(d) {
  d-data.frame(d); #convert object to dataframe
  d-subset(d,select=c(time,coords.x1,coords.x2)) #select some columns
 }
 convert(data) #the problem is that data is the same as it was before
 running the function

 The objects being processed through my function are SpatialPointsDataFrames
 but I'm quite sure that's not my problem, as I can process these outside of
 the function (using the above code) ... it's when I try to wrap the code in
 a function that it doesn't work.

 Thanks, Mark

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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] incorrect multiple outputs

2009-12-11 Thread Richard Thompson
Sorry, the nasty for (min... loop is probably easier to read like this:

for (m in 1:8){
for (n in 1:12){
p- 3*q; x.array[m,n] - mean(as.matrix(x[(p-2):p,2:4])); q - q+1;
if (n == 1){
z-3*m; x.blank2[(z-2):z,]-as.matrix(x[(p-2):p,2:4])
}; if (n==11){
z-3*m; x.nodrug2[(z-2):z,1:3]-as.matrix(x[(p-2):p,2:4])
}; if (n==12){
z-3*m; x.nodrug2[(z-2):z,4:6]-as.matrix(x[(p-2):p,2:4])
}
}
}

 Richard

2009/12/11 Richard Thompson bawa...@googlemail.com

 Ista,

 Here is the full code:


 file-read.table(file=input_file.txt,sep=\t)[,c(1,3:5)]
 file.rows- c(nrow(file)/288)
 full.array - array(0,dim=c(8,file.rows,12))

 cellnames - rep(A,file.rows)
 barcodes - rep(A,file.rows)
 t - rep(A,file.rows)
 t11 - rep(A,file.rows)
 cv - rep(A,file.rows)


 for (k in 1:file.rows){

 plate- file[(((k-1)*288)+1),1]

 barcodes[k] - levels(plate)[plate]

 l - k*288
 a - l-287
 x-file[a:l,]
 x.array-matrix(0,ncol=12,nrow=8)
 n.array-matrix(0,ncol=12,nrow=8)
 x.blank2 - matrix(0,ncol=3,nrow=24)
 x.nodrug2 - matrix(0,ncol=6,nrow=24)
 value - data.frame(conc=0,fluor=2)

 # reformat (mean) input data into 96 well format
 q-1
 for (m in 1:8){ for (n in 1:12){ p- 3*q; x.array[m,n] -
 mean(as.matrix(x[(p-2):p,2:4])); q - q+1; if (n == 1){z-3*m;
 x.blank2[(z-2):z,]-as.matrix(x[(p-2):p,2:4])}; if
 (n==11){z-3*m;x.nodrug2[(z-2):z,1:3]-as.matrix(x[(p-2):p,2:4])}; if
 (n==12){z-3*m; x.nodrug2[(z-2):z,4:6]-as.matrix(x[(p-2):p,2:4])}}}
 x.blank-c(x.blank2[,1],x.blank2[,3],x.blank2[,2])

 x.nodrug
 -c(x.nodrug2[,1],x.nodrug2[,2],x.nodrug2[,3],x.nodrug2[,4],x.nodrug2[,5],x.nodrug2[,6])
 x.nodrug11 -c(x.nodrug2[,1],x.nodrug2[,2],x.nodrug2[,3])

 # calculate output values


 cv[k] - 100*(sd(x.blank)/mean(x.blank))
 t[k] -
 (mean(x.nodrug)-mean(x.blank))/sqrt(((sd(x.nodrug)^2)/8)+((sd(x.blank)^2)/16))
 t11[k] -
 (sqrt(8)*(mean(x.nodrug11)-mean(x.blank)))/sqrt(sd(x.nodrug11)^2+sd(x.blank)^2)

 }


 all.data
 -data.frame(barcodes,t=format(as.numeric(t),digits=3),t11=format(as.numeric(t11),digits=3),cv=format(as.numeric(cv),digits=3))
 #write(format(t,digits=6), file= R_drug_plot.log,append=TRUE,sep=\t)

 write.table(all.data, file=
 R_drug_plot.log,append=TRUE,sep=\t,row.names=FALSE)

 When I first tried the mail list wouldn't let me send it as it contains the
 word drug too many times! so I only included the problematic parts.
 Rich

 2009/12/11 Ista Zahn istaz...@gmail.com

 The lack of a reproducible example is a bigger problem than any lack
 of clarity of the explanation.

 -Ista

 On Fri, Dec 11, 2009 at 2:08 AM,  bawa...@googlemail.com wrote:
  Apologies,
  I didn't explain this clearly. The Rscript is called by a perl script,
 which creates input_file.txt by inserting 288 lines of (reformatted) data
 for each data file in the directory.  So the Rscript will (and is doing) run
 the loop a number of times equal to the number of files the perl script read
 in. The problem is that it should only create the data.frame and write to
 the file after the last iteration, but it's (creating and)writing the
 complete data.frame every iteration.
  Sent using BlackBerry® from Orange
 
  -Original Message-
  From: jim holtman jholt...@gmail.com
  Date: Thu, 10 Dec 2009 18:00:54
  To: biscuitbawa...@googlemail.com
  Cc: r-help@r-project.org
  Subject: Re: [R] incorrect multiple outputs
 
  If I rad you code right, file.rows is equal to 1 and your 'for' loop
 will
  only iterate once.  Is that what you were expecting?
 
  No reproducible code provided, so that is my best guess.
 
 file.rows- c(nrow(file)/288)  # input_file.txt contains 288
 reformatted
  lines for each original data file
  ...
 for (k in 1:file.rows){  # iterates code for each 288 line block of
  input_file.txt
  ...
 
  On Thu, Dec 10, 2009 at 11:39 AM, biscuit bawa...@googlemail.com
 wrote:
 
 
  HI,
  I'm having trouble with a piece of Rscript which keeps outputting
  incorrectly. it's something like this: the code reads in from a file
 which
  contains (reformated) input
 
  file-read.table(file=input_file.txt,sep=\t)[,c(1,3:5)]
  
  file.rows- c(nrow(file)/288)  # input_file.txt contains 288
 reformatted
  lines for each original data file
  ...
  for (k in 1:file.rows){  # iterates code for each 288 line block of
  input_file.txt
  ...
  cv[k] - 100*(sd(x.blank)/mean(x.blank))
  t[k] -
 
 (mean(x.note)-mean(x.blank))/sqrt(((sd(x.note)^2)/8)+((sd(x.blank)^2)/16))
  t11[k] -
 
 (sqrt(8)*(mean(x.note11)-mean(x.blank)))/sqrt(sd(x.note11)^2+sd(x.blank)^2)
  }
  
 
 
 all.data-data.frame(barcodes,t=format(as.numeric(t),digits=3),t11=format(as.numeric(t11),digits=3),cv=format(as.numeric(cv),digits=3))
  write.table(all.data, file=
  R_drug_plot.log,append=TRUE,sep=\t,row.names=FALSE)
 
  this all works correctly except that I believed it would output to file
  after completing the loop, instead it's writing to file every
 iteration. so
  the output file looks like:
 
  headers
  a1
  headers
  a1
  a2
  headers
  a1

[R] ggplot: Problem with legend background

2009-12-11 Thread MUHC_Research

Dear R-users,

I am preparing graphs for an upcoming article using the different functions
of the ggplot2 package and I've been having problems with the legend
background. It doesn't seem to scale when the text size is increased. Here's
the mandatory reproducible example:

library(ggplot2)
repFrame - data.frame(A= 1:10, B= rnorm(1:10), groupNum = rep(c(First
group, Second group),each=5))
testPlot - ggplot(repFrame, aes(x=A, y = B, group = groupNum)) +
opts(legend.position=c(0.85,0.3), legend.background =
theme_rect(fill=white), legend.text=theme_text(size=16),
legend.title=theme_text(size=20))
testPlot + geom_point(aes(colour= groupNum))

As you can see, the text doesn't fit in the white rectangle. I suspect there
is a theme setting I could modify to fix this, but I can't seem to find
which one.

I sincerely thank you for your time and assistance.

Luc
-- 
View this message in context: 
http://n4.nabble.com/ggplot-Problem-with-legend-background-tp961142p961142.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] non-linear regression

2009-12-11 Thread Katharine Mullen

 The problem of estimation of parameters in R is that you have to know the
 value of the initial estimates very accurately, otherwise it does not
 converge.

This was discussed on R-help in the last 2 weeks; see the thread on
'Starting estimates for nls Exponential Fit'.


 The example below could be resolved in Excel, however in  does not converge.
 How to solve the problem?

Can you consider a model with a different functional form or do you need
to fit this exact function?

If you want to minimize log(data) log(model) RSS, then:

tx.br - read.table('tx.br.H.txt',header=F,dec=',')
tx.br - tx.br[,1]
id - 1:100

qx.suav - function(id,A,B,C,D,E,F,G,H,K)
  (A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))

newD - log(tx.br)

HP - nls(newD~log(qx.suav(id,A,B,C,D,E,F,G,H,K)),
  data=data.frame(id=id,newD=newD),
  trace=TRUE,
  nls.control(maxiter=5,warnOnly=TRUE),
  algorithm='port',
  start=list(A=0.000644,B=0.016761290,C=0.10927095582,D=0.00094877,
E=5.949082737,F=24.526811,G=0.46733960,H=1.0970550987,
K=0.771722501657),
  lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))

HP

par(mfrow=c(2,1))
matplot(cbind(fitted(HP), newD),type=l, main=model and fit)

matplot(cbind(exp(fitted(HP)), exp(newD)), type=l,
main=transformed back to original space)

 I made the chart on a logarithmic scale to better visualize the differences.

 Send the data file attached.

 The commands are below:

 tx.br - read.table('c:/tx.br.H.txt',header=F,dec=',')
 tx.br -tx.br[,1]
 id-1:100

 qx.suav - function(id,A,B,C,D,E,F,G,H,K)
   (A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))

 HP - nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),
   data=data.frame(id=id,tx.br=tx.br),
   trace=TRUE,nls.control(maxiter=5,warnOnly=TRUE,minFactor =
 0.1),
  algorithm='port',
  start=list(A=0.000644,B=0.016761290,C=0.10927095582,D=0.00094877,

 E=5.949082737,F=24.526811,G=0.46733960,H=1.0970550987,K=0.771722501657),
   lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))

 HP

 matplot(cbind(log(fitted(HP)), log(tx.br)),type=l)



 - Original Message -
 From: Katharine Mullen k...@few.vu.nl
 To: AneSR citb...@terra.com.br
 Cc: r-help@r-project.org
 Sent: Thursday, December 10, 2009 9:55 PM
 Subject: Re: [R] non-linear regression


  You did not provide the data or a way of generating it.
 
  I would guess that Excel finds the same solution (the same residual sum-of
  squares) as nls but that it uses a weak convergence criterion and/or does
  not give you information regarding why it terminates.
 
  Regarding the step size:  you can set the minimum step size factor via the
  minFactor argument of control.
 
  qx.suav - function(id,A,B,C,D,E,F,G,H,K)
   (A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))
 
  ## make noisy data from model
  id - 1:1000
  tx.br - qx.suav(id,A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,
  E=0.0002127,F=38.5448420,G=0.115,H=1.1109286,
  K=0.382070638)
  set.seed(1)
  tx.br - tx.br + rnorm(length(tx.br),0,.0001)
 
  HP - nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),
   data=data.frame(id=id,tx.br=tx.br),
   trace=TRUE,nls.control(maxiter=5000,warnOnly=TRUE),
   algorithm='port',
   start=list(A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,
 E=0.0002127,F=38.5448420,G=0.115,H=1.1109286,
 K=0.382070638),
   lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))
  matplot(cbind(fitted(HP), tx.br),type=l)
 
  On Thu, 10 Dec 2009, AneSR wrote:
 
 
  I have a non-linear regression with 8 parameters to solve  however it
  does not converge ... easily solves the excel ... including the initial
  estimates used in the R were found in the excel ... Another question is
  how
  to establish the increments of R by the parameters in the search ..
 
 
  qx.suav-function(id,A,B,C,D,E,F,G,H,K){(A^((id+B)^C)+(D*exp(-E*(log(id)-log(F))^2))+(G*H^id)/(1+(K*G*H^id)))}
  HP-nls(tx.br~qx.suav(id,A,B,C,D,E,F,G,H,K),data=data.frame(id=id,tx.br=tx.br),
  trace=TRUE,nls.control(maxiter=5000),algorithm='port',start=list(A=0.0006347,B=0.0453814,C=0.1353538,D=0.1353538,E=0.0002127,F=38.5448420,G=0.115,H=1.1109286,K=0.382070638),lower=list(A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,K=0))
  summary(HP)
 
  How to solve this problem in R?
 
  Ane
  --
  View this message in context:
  http://n4.nabble.com/non-linear-regression-tp959977p959977.html
  Sent from the R help mailing list archive at Nabble.com.
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 


 

Re: [R] Literature analysis

2009-12-11 Thread Schwan
OK Thanks again for the help.

I have tried 

example - read.csv(/PATH/test.cvs)

If i call for the results R is plotting all the data separated by title,
Keyword, author...)

However, I dont know how to tell R that it just should look for e.g.
author,keywords and year and how to plot these for example on x axis the
author and y axis the keywords and on z axis the year?









On Fri, 2009-12-11 at 10:06 -0500, Ista Zahn wrote:
 I think I my original response was bad. And I also realize that I
 don't really understand what you want to do.
 
 Here is what I was thinking:
 
 Format your bibliography as CSV (you can convert common bibliography
 formats to .csv using Tellico or similar software). Then read the
 references into a data frame:
 
 Refs - read.csv(textConnection('Title,Entry Type,Author,Bibtex
 Key,Book 
 Title,Editor,Organization,Publisher,Address,Edition,Pages,Year,ISBN#,Journal,DOI,Month,Number,How
 Published,Chapter,Series,Volume,Cross-Reference,Keywords,URL,Abstract,Notes,ID,Date
 Created,Date Modified
 Unconscious authorship ascription: The effects of success and
 effect-specific information priming on experienced
 authorship,article,Aarts, H.,Aarts2007,,,119–126,2007,,Journal
 of Experimental Social Psychology,,,43,,Lexical Decision;
 unconscious; Perception; presentation of words; effect-specific
 information; experienced authorship; authorship ascription; priming;
 lexical decisions; subliminal perception; Self
 Perception,http://localhost/refbase/Papers/Aarts/Unconscious%20authorship%20ascription:%20The%20effects%20of%20success.pdf,Abstract
 goes here,exported from refbase
 (http://ista.scp.rochester.edu/refbase/show.php?record=14), last
 updated on Tue, 17 Nov 2009 10:23:27 -0500,0,2009-12-11,2009-12-11
 Goal contagion: Perceiving is for pursuing,article,Aarts, H.;
 Gollwitzer, P.; Hassin, R.,Aarts_etal2004,,,23–37,2004,,Journal
 of Personality and Social Psychology,,,87,,Contagion; goal
 contagion; automatic goal adion; Motivation; Perception; implied
 behavioral goals; goal perception; Theories; Automatism; behavioral
 information; goal directedness; Attention; Stimulus Parameters; Goals;
 goal 
 characteristics,http://localhost/refbase/Papers/Aarts/Goal%20contagion:%20Perceiving%20is%20for%20pursuing.pdf,Abstract
 goes here.,exported from refbase
 (http://ista.scp.rochester.edu/refbase/show.php?record=15), last
 updated on Tue, 17 Nov 2009 10:23:27 -0500,1,2009-12-11,2009-12-11'))
 
 closeAllConnections()
 
 (sorry, I know that's going to get all screwed up by word wrapping).
 Next split out the keywords into separate columns, and then combine
 them again into a value column:
 
 library(ggplot2)
 Refs - as.data.frame(cbind(Refs, colsplit(Refs$Keywords, split=; ,
 names=Keyword)))
 Refs - melt(Refs, measure.vars=31:45)
 
 And then that's were I get stuck. I have authors and keywords for each
 publication, but I'm not sure how you want this represented.
 
 -Ista
 
 On Fri, Dec 11, 2009 at 9:04 AM, Schwan s.s.hosse...@utwente.nl wrote:
  Thanks, but how should I put the citation inside a data frame?
 
  data.frame(first txt file, second txt file...)
  plot (what should I insert here) type=p
 
  And how should I load the txt files anyway inside the frame?
 
 
 
 
 
 
  On Fri, 2009-12-11 at 08:37 -0500, Ista Zahn wrote:
  It sounds pretty simple so far. Just put the citation info in a data
  frame, and plot it. I would use ggplot2 for plotting, but it could be
  done in base or lattice too.
 
  On Fri, Dec 11, 2009 at 8:04 AM, Schwan s.s.hosse...@utwente.nl wrote:
   Ok good question I havent explain!
  
   Well,lets keep it simple for the begining. By analyzing the
   keywords(which can also include the authors name) I mean,
  
   1) investigate in which paper the keyword occur and how often
   2) investigate if keywords occur together
  
   X axis can show the paper title (or authors name)
   y axis shows the keywords
  
   if a keyword occurs more often in a paper then the dot on the graph
   changes the color
  
   if keywords occur together then a symbol the same symbol appears.
  
  
  
  
  
  
  
   On Fri, 2009-12-11 at 04:33 -0800, nshephard wrote:
  
  
   Schwan wrote:
   
Thanks for all the comments,
   
and sorry about the unstructured question! I am trying to:
   
1: analyze keywords, names from Authors and year of publication from
citations (with abstracts) i downloaded fron various sites(these
downloads can be converted into .txt files as well)
  
   Sorry to bang the drum but what do you mean by analyse, is it to 
   simply
   count keywords and rank them, investigate which keywords occur together,
   look at trends in keywords by year or something else completely.
  
   Its a very general term (at least for me as I've no knowledge or 
   experience
   of text mining)!
  
   Neil
  
  
   --
   ---
   Hosseiny, MSc. S.S. (Seyed Schwan)
   University of Twente Science and Technology
   

Re: [R] cluster size

2009-12-11 Thread Christian Hennig

Dear Ms Karunambigai,

the kmeans algorithm depends on random initialisation.
There are two basic strategies that can be applied in order to make your 
results reproducible:
1) Fix the random number generator by means of set.seed (see ?set.seed) 
before you run kmeans. The problem with this is that your solution can 
only be reproduced using the same random seed; it technically still is 
random.

2) Specify fixed initial centers, using the centers argument in kmeans.
(Sensible initial centers may be obtained by running hclust using Ward's 
method, obtain the desired number of clusters using cutree and compute the 
centers of the resulting clusters; sorry that I 
don't have the time right now to explain how to do that precisely; the 
help pages and hopefully some understanding of what is going on may help 
you further.)


An alternative strategy that will not absolutely guarantee reproducibility 
but make your results more stable is to use kmeansruns in library fpc, which
is a wrapper that runs kmeans several times and gives you the optimal 
solution. That should reproduce its outcome with higher probability 
(though not precisely 1).
I don't know whether the default value runs=100 is sufficient to give a 
stable solution for your data, but increasing the runs parameter may help.


Cheers,
Christian

On Fri, 11 Dec 2009, karuna m wrote:


hi r-help,
i am doing kmeans clustering in stats. i tried for five clusters clustering 
using:
kcl1 - kmeans(as1[,c(contlife,somlife,agglife,sexlife,
    rellife,hordlife,doutlife,symtlife,washlife,
   chcklife,rptlife,countlife,coltlife,ordlife)], 
5, iter.max = 10, nstart = 1,
     algorithm = Hartigan-Wong)
  table(kcl1$cluster)
every time i am getting five clusters of different sizes like first time with 
cluster sizes
table(kcl1$cluster)
  1   2   3   4   5
140  72 105  98 112
second time with cluster sizes
table(kcl1$cluster)
  1   2   3   4   5
 91 149 106  76 105 and so on.
I wish to know that whether there is any function to get same sizes of clusters 
everytime when we do kmeans clustering.
Thanks in advance.
regards,
Ms.Karunambigai M
PhD Scholar
Dept. of Biostatistics
NIMHANS
Bangalore
India


 The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
[[alternative HTML version deleted]]




*** --- ***
Christian Hennig
University College London, Department of Statistical Science
Gower St., London WC1E 6BT, phone +44 207 679 1698
chr...@stats.ucl.ac.uk, www.homepages.ucl.ac.uk/~ucakche__
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 creat a matrix

2009-12-11 Thread Moohwan Kim
Dear R family

  I am attempting to create a matrix. e.g.,
  0 0 0 0 1
  1 0 0 0 0
  0 1 0 0 0
  0 0 1 0 0
  0 0 0 1 0
  How could I write a R program?
  Later I want to extend it to a N by N case.
  Thanks in advance

  best
  Moohwan

__
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] Please help with a basic function

2009-12-11 Thread Paul Hiemstra

Hi Mark,

This question would probably be better suited for the r-sig-geo mailing 
list. In addition, please read the posting guide and provide a piece of 
code that reproduces the problem.


library(sp)

convert-function(d) {
d-data.frame(d); #convert object to dataframe
d-subset(d,select=c(zinc,x,y)) #select some columns
 d # - add this, or alternatively 'return(d)'
}

data(meuse)
coordinates(meuse) = ~x+y

convert(meuse)

But maybe better, subsetting a SPDF can be done using:

meuse[zinc] # Remains an SPDF
# Returns a data.frame
data.frame(coordinates(meuse), zinc = meuse$zinc)

And some unrequested advice :). To process multiple files, take a look 
at lapply, both for reading and processing.


all_data = lapply(list_of_files, function(file) {
bla = read.table(file)
coordinates(bla) = ~coor.x1 + coor.x2
return(bla)
}
# all data is now a list wit the SPDF's

processed_data = lapply(all_data, function(dat) {
  return(data.frame(coordinates(dat), zinc = dat$zinc))
}

ofcourse you can include the latter lapply stuff inside the first 
'loading' lapply.


all_data = lapply(list_of_files, function(file) {
bla = read.table(file)
bla = subset(bla, select = select=c(time,coords.x1,coords.x2))
coordinates(bla) = ~coor.x1 + coor.x2
return(bla)
}

hope this helps and good luck,

Paul

Mark Na wrote:

Hello,

I am learning how to use functions, but I'm running into a roadblock.

I would like my function to do two things: 1) convert an object to a
dataframe, 2) and then subset the dataframe. Both of these commands work
fine outside the function, but I would like to wrap them in a function so I
can apply the code iteratively to many such objects.

Here's what I wrote, but it doesn't work:

convert-function(d) {
 d-data.frame(d); #convert object to dataframe
 d-subset(d,select=c(time,coords.x1,coords.x2)) #select some columns
}
convert(data) #the problem is that data is the same as it was before
running the function

The objects being processed through my function are SpatialPointsDataFrames
but I'm quite sure that's not my problem, as I can process these outside of
the function (using the above code) ... it's when I try to wrap the code in
a function that it doesn't work.

Thanks, Mark

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



--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul

__
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] memory problem on Suse

2009-12-11 Thread Marc Schwartz

On Dec 11, 2009, at 6:24 AM, Ambrosi Alessandro wrote:



Dear all, I am meeting some problems with  memory allocation. I know  
it is an old issue, I'm sorry.
I looked for a solution in the FAQs and manuals, mails, but without  
finding the working answer.

I really hope you can help me.
For instance, if I try to read micorarray data I get:


mab=ReadAffy(cdfname=hgu133plus2cdf)

Error: cannot allocate vector of size 858.0 Mb




I get similar errors with smaller objects, smaller data sets or  
other procedures

(Error: cannot allocate vector of size 123.0 Mb).
I'm running R with Suse 11.1 Linux OS, on two Xeon processors (8  
cores), 32 GB RAM.
I suppose I have enough resources to manage these objects and data  
files


Any suggestions or hints will be really appreciated!
Many thanks in advance.
Alessandro


Well, you are running into a situation where there is not a contiguous  
chunk of RAM available in the sizes referenced, for allocation to the  
vector.


Presuming that you are running a 64 bit version of SUSE (what does  
'uname -a' show in a system console), you should also check to be sure  
that you are also running a 64 bit version of R. What does:


  .Machine$sizeof.pointer

show?

If it returns 4, then you are running a 32 bit version of R, which  
cannot take advantage of your 64 bit platform. You should install a 64  
bit version of R.


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] how to creat a matrix

2009-12-11 Thread Henrique Dallazuanna
Try this:

N - 5
diag(1, N)[c(N, 1:(N - 1)),]

On Fri, Dec 11, 2009 at 1:47 PM, Moohwan Kim kmhl...@gmail.com wrote:
 Dear R family

  I am attempting to create a matrix. e.g.,
  0 0 0 0 1
  1 0 0 0 0
  0 1 0 0 0
  0 0 1 0 0
  0 0 0 1 0
  How could I write a R program?
  Later I want to extend it to a N by N case.
  Thanks in advance

  best
  Moohwan

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




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

__
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] (no subject)

2009-12-11 Thread Tom Knockinger
Hi, 
i am new to the R-project but until now i have found solutions for every 
problem in toturials, R Wikis and this mailing list, but now i have some 
problems which I can't solve with this knowledge.

I have some data like this:

# sample data
head1 = a;b;c;d;e;f;g;h;i;k;l;m;n;o
data1 = 1;1;1;1;1;1;1;1;1;1;1;1;1;1
data2 = 2;2;2;2;2;2;2;2;2;2;2;2;2;2
data3 = 3;3;3;3;3;3;3;3;3;3;3;3;3;3
datastring = paste(, head1,data1,data2,data3,,sep=\n)

# import operation
res = read.table(textConnection(datastring), header=TRUE, sep = c(;))
closeAllConnections()

# I use these two lines in a for-loop like this: 
#for( j in 1:length(data)) {
#   res[j] = read.table(textConnection(datastring[j]), 
header=TRUE, sep = c(;))
#   closeAllConnections()
#}

I get these strings from a file which contains about 50 to 1000 of them, so I 
can read them all into a list. I am not sure if there is a better way to do 
this, but it works for me. Maybe you have some suggestions for a better 
solution. 

Now after this short introduction to the r-program I use, I have two problems 
with this approach.

1) warnings
i get warnings like unused connection 3 (datastring) closed after some other 
operations from time to time. But all connections should already be closed, and 
I doesn't create new ones.

2) ram usage and program shutdowns
length(data) is usually between 50 to 1000. So it takes some space in ram 
(approx 100-200 mb) which is no problem but I use some analysis code which 
results in about 500-700 mb ram usage, also not a real problem. 
The results are matrixes of (50x14 to 1000x14) so they are small enough to work 
with them afterwards: create plots, or make some more analysis.
So i wrote a function which do the analysis one file after another and keep 
only the results in a list. But after some about 2-4 files my R process uses 
about 1500MB and then the troubles begin. The R console terminates or prints 
the error that no more space can be allocated. So i have to do each file 
separate and save each result in a file and restart R after 2 processed files. 
And do that 3-5 times so that all files are processed, which is a bit anoying. 

I did some research on this problem and i find out that 
-) after I import the data in the same variable the ram usage goes up each time 
about 100-200mb instead of reusing or purging the old data, which should be 
overwritten since they are no longer available after i import a new file.
-) the same occures with the analysis functions which uses much more space and 
also doesn't release the old no longer used variables. But ls() doesn't shows 
them at all.
-) also after I cleared all variables with rm(list=ls(all=TRUE)) the used ram 
space is still the same.

So is there a possibility to get the ram space back? So i can do all the 
analysis in one session and don't have to mess around with additional files?


Thanks for your help

Tom
-- 
Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.!
http://portal.gmx.net/de/go/dsl02

__
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] some problems with ram usage and warnings

2009-12-11 Thread Tom Knockinger
Hi, 
i am new to the R-project but until now i have found solutions for every 
problem in toturials, R Wikis and this mailing list, but now i have some 
problems which I can't solve with this knowledge.

I have some data like this:

# sample data
head1 = a;b;c;d;e;f;g;h;i;k;l;m;n;o
data1 = 1;1;1;1;1;1;1;1;1;1;1;1;1;1
data2 = 2;2;2;2;2;2;2;2;2;2;2;2;2;2
data3 = 3;3;3;3;3;3;3;3;3;3;3;3;3;3
datastring = paste(, head1,data1,data2,data3,,sep=\n)

# import operation
res = read.table(textConnection(datastring), header=TRUE, sep = c(;))
closeAllConnections()

# I use these two lines in a for-loop like this: 
#for( j in 1:length(data)) {
#   res[j] = read.table(textConnection(datastring[j]), 
header=TRUE, sep = c(;))
#   closeAllConnections()
#}

I get these strings from a file which contains about 50 to 1000 of them, so I 
can read them all into a list. I am not sure if there is a better way to do 
this, but it works for me. Maybe you have some suggestions for a better 
solution. 

Now after this short introduction to the r-program I use, I have two problems 
with this approach.

1) warnings
i get warnings like unused connection 3 (datastring) closed after some other 
operations from time to time. But all connections should already be closed, and 
I doesn't create new ones.

2) ram usage and program shutdowns
length(data) is usually between 50 to 1000. So it takes some space in ram 
(approx 100-200 mb) which is no problem but I use some analysis code which 
results in about 500-700 mb ram usage, also not a real problem. 
The results are matrixes of (50x14 to 1000x14) so they are small enough to work 
with them afterwards: create plots, or make some more analysis.
So i wrote a function which do the analysis one file after another and keep 
only the results in a list. But after some about 2-4 files my R process uses 
about 1500MB and then the troubles begin. The R console terminates or prints 
the error that no more space can be allocated. So i have to do each file 
separate and save each result in a file and restart R after 2 processed files. 
And do that 3-5 times so that all files are processed, which is a bit anoying. 

I did some research on this problem and i find out that 
-) after I import the data in the same variable the ram usage goes up each time 
about 100-200mb instead of reusing or purging the old data, which should be 
overwritten since they are no longer available after i import a new file.
-) the same occures with the analysis functions which uses much more space and 
also doesn't release the old no longer used variables. But ls() doesn't shows 
them at all.
-) also after I cleared all variables with rm(list=ls(all=TRUE)) the used ram 
space is still the same.

So is there a possibility to get the ram space back? So i can do all the 
analysis in one session and don't have to mess around with additional files?


Thanks for your help

Tom
-- 
Preisknaller: GMX DSL Flatrate für nur 16,99 Euro/mtl.!
http://portal.gmx.net/de/go/dsl02

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser

__
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 creat a matrix

2009-12-11 Thread Robin Hankin

Hi

try

R library(magic)
R  ashift(diag(5),1)

HTH
rksh



enrique Dallazuanna wrote:

Try this:

N - 5
diag(1, N)[c(N, 1:(N - 1)),]

On Fri, Dec 11, 2009 at 1:47 PM, Moohwan Kim kmhl...@gmail.com wrote:
  

Dear R family

 I am attempting to create a matrix. e.g.,
 0 0 0 0 1
 1 0 0 0 0
 0 1 0 0 0
 0 0 1 0 0
 0 0 0 1 0
 How could I write a R program?
 Later I want to extend it to a N by N case.
 Thanks in advance

 best
 Moohwan

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






  



--
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877

__
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 creat a matrix

2009-12-11 Thread milton ruser
Hi Him.

Did you read the Help/Manual in PDF/A Instroduction to R.PDF?


MyVect-scan()
0 0 0 0 1
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0

MyVect
MyMat-matrix(MyVect, ncol=5, byrow=T)
MyMat

bests
milton



On Fri, Dec 11, 2009 at 10:47 AM, Moohwan Kim kmhl...@gmail.com wrote:

 Dear R family

  I am attempting to create a matrix. e.g.,
  0 0 0 0 1
  1 0 0 0 0
  0 1 0 0 0
  0 0 1 0 0
  0 0 0 1 0
  How could I write a R program?
  Later I want to extend it to a N by N case.
  Thanks in advance

  best
  Moohwan

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


[[alternative HTML version deleted]]

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


[R] obtain intermediate estimate using optim

2009-12-11 Thread Prof. John C Nash


Doing a hessian estimate at each Nelder-Mead iteration is rather like going 
from den Haag
to Delft as a pedestrian walking and swimming via San Francisco. The structure of the 
algorithm means the Hessian estimate is done in addition to the NM work.


While my NM code was used for optim(), I didn't do the interfacing. The 
reporting choices
are reasonably good, but don't necessarily suit your current needs. I'd 
recommend going to
r-forge and installing my updated BFGS code. See
http://r-forge.r-project.org/R/?group_id=395 for a list of the codes -- Rvmmin 
is the one
you want) which is all in R so you can put in output where you choose. It also 
has bounds
constraints, which are quite useful to avoid roaming into unsuitable areas of 
the
parameter space. While Rvmmin works best with analytic gradients, it does OK 
most of the
time with numeric approximations. It keeps an approximate inverse hessian, but 
I would not
assume that bears too much resemblance to the real hessian. Package ucminf uses
essentially the same algorithm (unconstrained only), and the detailed tactics 
seem to be
well-thought out.  However, I don't know how well reporting can be controlled 
(it is R
interfaced to Fortran).

A derivative free method that may be worth a try is bobyqa in the minqa package 
at the
same site as above. This is Mike Powell's code. The output can be set quite 
detailed by
pushing the reporting control (iprint) higher. Again R - Fortran interface 
(thanks to
Kate Mullen).

Ravi Varadhan has several NM versions in R also, but I don't think they are yet 
on r-forge.

If you try any of these, you can help us improve them by reporting 
success/failure off
list. We believe that they are in pretty good shape, but there are always 
interfacing and
tuning issues.

Cheers, JN




Message: 1
Date: Thu, 10 Dec 2009 12:40:17 +0100
From: Lisanne Sanders lisan_sand...@hotmail.com
Subject: [R] obtain intermediate estimate using optim
To: r-help@r-project.org
Message-ID: col110-w27ffa963674aa82fe4bc2395...@phx.gbl
Content-Type: text/plain


Hi,

Currently I am trying to solve a minimization problem using optim as method Nelder-Mead. However, Neldel-Mead needs many iterations until it finally converges. I have set $control.trace and $control.report such that I can see the value of the function at each iteration. I do see that I set the convergence criteria to strict in the sense that the function value does not change much. However, before loosening my convergence criteria, I was wondering how to progamm that I can see the estimates of the true parameters and of the hessian such that I can see whether they do not change much either. Than I can adjust my convergence criteria such that he ends at that point. I do know how to adjust the convergence parameters but I do not know how to obtain intermediate estimates of the parameters. I was wondering whether someone can help me with this. 


Kind regards,

Lisanne Sanders


__
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] Problem with calibrate function

2009-12-11 Thread Frank E Harrell Jr

Rodrigo wrote:

Hi,

I´m trying to use the calibrate function from rms package (made by prof.
Harrell) after fitting a model using cph. But it returns the following error
message:


calibrate(modelo1,B=200,bw=F,u=13)


Using Cox survival estimates at  13 Days
Convergence problems stopping addition
Error in hare(S[, 1], S[, 2], fun(est.surv), maxdim = maxdim, ...) :
 no convergence
 this is serious!

Has anybody experienced the same problem? Can anyone help me?

many thanks,
Rodrigo



Rodrigo,

This is a new feature in rms and there are probably a few warnings I 
need to put in the help file.  How many events are in the dataset used 
to develop your model?  Why did you specify bw=FALSE (which is the 
default)?  Did you use any variable selection when building the model?


Frank

--
Frank E Harrell Jr   Professor and Chair   School of Medicine
 Department of Biostatistics   Vanderbilt University

__
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 could I find the inverse of a matrix?

2009-12-11 Thread Moohwan Kim
Dear R family

I have a following question.
Suppose I have a matrix as follows, for instance:
tau=
0 0 0 0 1
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0

I want to have the inverse of the above matrix and then add some
exponent to it. That is, I want to calculate tau to the (-m). For
example, m=893.

Thanks in advance

Best regards
Moohwan Kim

__
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] memory problem on Suse

2009-12-11 Thread Martin Morgan
Ask on the bioconductpr mailing list, where you will be diirected to  
several solutions for analyzing what I guess are 100's is cel files


http://bioconductor.org

--
Martin Morgan

On Dec 11, 2009, at 8:02 AM, Marc Schwartz marc_schwa...@me.com wrote:


On Dec 11, 2009, at 6:24 AM, Ambrosi Alessandro wrote:



Dear all, I am meeting some problems with  memory allocation. I  
know it is an old issue, I'm sorry.
I looked for a solution in the FAQs and manuals, mails, but without  
finding the working answer.

I really hope you can help me.
For instance, if I try to read micorarray data I get:


mab=ReadAffy(cdfname=hgu133plus2cdf)

Error: cannot allocate vector of size 858.0 Mb




I get similar errors with smaller objects, smaller data sets or  
other procedures

(Error: cannot allocate vector of size 123.0 Mb).
I'm running R with Suse 11.1 Linux OS, on two Xeon processors (8  
cores), 32 GB RAM.
I suppose I have enough resources to manage these objects and data  
files


Any suggestions or hints will be really appreciated!
Many thanks in advance.
Alessandro


Well, you are running into a situation where there is not a  
contiguous chunk of RAM available in the sizes referenced, for  
allocation to the vector.


Presuming that you are running a 64 bit version of SUSE (what does  
'uname -a' show in a system console), you should also check to be  
sure that you are also running a 64 bit version of R. What does:


 .Machine$sizeof.pointer

show?

If it returns 4, then you are running a 32 bit version of R, which  
cannot take advantage of your 64 bit platform. You should install a  
64 bit version of R.


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.


__
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 could I find the inverse of a matrix?

2009-12-11 Thread Steve Lianoglou
Hi Moohwan,

On Dec 11, 2009, at 11:26 AM, Moohwan Kim wrote:

 Dear R family
 
 I have a following question.
 Suppose I have a matrix as follows, for instance:
 tau=
 0 0 0 0 1
 1 0 0 0 0
 0 1 0 0 0
 0 0 1 0 0
 0 0 0 1 0
 
 I want to have the inverse of the above matrix and then add some
 exponent to it. That is, I want to calculate tau to the (-m). For
 example, m=893.

If you *really* want the inverse, use the `solve` function without a second 
parameter:

R tau - c(0, 0, 0, 0, 1,
 1, 0, 0, 0, 0,
 0, 1, 0, 0, 0,
 0, 0, 1, 0, 0,
 0, 0, 0, 1, 0)
R tau - matrix(tau, ncol=5, byrow=TRUE)
R tau %*% solve(tau)
 [,1] [,2] [,3] [,4] [,5]
[1,]10000
[2,]01000
[3,]00100
[4,]00010
[5,]00001

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
The following examples are confusing to me. It is OK, to assigned NULL
to one element in a list. The result is still a list. However, a list
of NULL's are reduced to NULL. I don't understand how this conversion
occurs. Could somebody let me know what is going on?

 X=matrix(1:8, nr=4)
 apply(X,1, function(x) {if(x[[1]]==3){NULL}else{x[[1]]}})
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
NULL

[[4]]
[1] 4

 apply(X,1, function(x) {NULL})
NULL

__
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] Sources for open sourced homework questions for R?

2009-12-11 Thread David Kane
Hi,

I am teaching a one month class in applied statistics and want to
bring my students up to speed in R without devoting much/any lecture
time to R instruction. I think that the best way to do this is to
provide them with a lot of R questions for homework. These questions
would be numerous (there is a lot of material to cover), go from very
simple to somewhat complex, and focus on all the commands and options
that will be useful in applied work. Here are some of my initial
questions:


Q: Load the data from the cars data frame into the local workspace.
A: data(cars)

Q: Find information about the cars data frame.
A: help(cars)

Q: Calculate the dimensions of the data frame.
A: dim(cars)

Q: What are the names of the variables?
A: names(cars)


Needless to say, the questions will become more complex, including the
writing of simple functions. I also want to provide answers to all the
questions that, in theory, could be used in an automated fashion to
check the students work. My current plan is to load these questions
(somehow) into the quiz module in Moodle (http://moodle.org/).

Ideally, I would like this system to be usable by very large classes
and even in the context of distance learning. Student goes to a web
page, logs in and is presented with a page of questions (or a single
question). She figures out the answer in her R session and pastes in
the command (or result) into the answer slot on the webpage and pushes
a button (or does it for ten questions first). The server then
determines which questions she got right and which she got wrong. It
might then provide clues to the ones that she has wrong. Once she is
done, the professor gets a list of her results (how many right, how
many wrong, how many required more than one try and so on).

For now, I am not building that system. (Has anyone already done so?)
Instead, I am just creating the collection of R questions/answers that
might go into such a system. I am aiming for around 1,000 questions.
So: Does anyone know of open sourced collections of R questions like
this which I might use?

Thanks,

Dave Kane
Adjunct Instructor, Williams College

__
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] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu
 Sent: Friday, December 11, 2009 8:44 AM
 To: r-h...@stat.math.ethz.ch
 Subject: [R] Why a list of NULL's are reduced to NULL?
 
 The following examples are confusing to me. It is OK, to assigned NULL
 to one element in a list. The result is still a list. However, a list
 of NULL's are reduced to NULL. I don't understand how this conversion
 occurs. Could somebody let me know what is going on?

The simplification algorithm for reformatting
the output of apply and sapply is handy in the
common case when you know that FUN will return
the same sort of thing each time it it called.
The algorithm is not very useful when FUN may return
objects of various classes or lengths.  sapply has
a simplify=FALSE argument to avoid the simplification
(so it acts like lapply) but apply doesn't.

I suggest you either change your function to always
return one class and length of object or use lapply()
or sapply(simplify=FALSE,...) when you must use a function
with variable output type.  E.g., instead of
   apply(X, 1, function(row){f(row)})
use
   lapply(seq_len(nrow(X)), function(rowIndex){f(X[rowIndex,])})
or
   lapply(split(X, row(X)), function(row){f(row)})

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 
  X=matrix(1:8, nr=4)
  apply(X,1, function(x) {if(x[[1]]==3){NULL}else{x[[1]]}})
 [[1]]
 [1] 1
 
 [[2]]
 [1] 2
 
 [[3]]
 NULL
 
 [[4]]
 [1] 4
 
  apply(X,1, function(x) {NULL})
 NULL
 
 __
 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] Looking for categorization method/module in R

2009-12-11 Thread James Mcininch
All,

I'm relatively new to using R, having used it thus far for some simple
statistics and plotting. However, I'm not new to programming by any
measure.

I've been looking at the various modules available for clustering,
factor analysis, etc. and find that I need advice on which modules I
should be focusing on and their application.

I have a data set comprised of columns of both quantitative and
qualitative / non-numeric attributes. I would like to perform two
operations on this data: identify correlations between attributes,
and cluster the records by attribute.

All of the clustering algorithms that I've looked at so far are based
on numerical distance functions, and it's not clear to me how I'd
apply them to qualitative attributes. It's not appropriate to simple
convert discrete qualitative attributes (e.g., native language) to
numerical values or independent columns with binary values. Is there a
module that provides such an algorithm or that can be adapted to this
purpose?

I can wrap my head around the problem of looking for cross-correlation
between the attributes, but would appreciate any insight in how to
do it most efficiently and present the results.

Thank you.

[[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] SVM regression

2009-12-11 Thread Eleni Christodoulou
Dear R users,

I am trying to apply SVM regression for a set of microarray data. I am using
the function svm() under the package {e1071}. Can anyone tell me what
the *residuals
*value represents? I have some observed values *y_obs* for the parameter
that I want to estimate and I would expect that *svm$residuals = y_obs -
svm$fitted.
*However, this does not happen...Does anyone have any idea on that?

Thanks a lot!
Eleni C.* *

[[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] The correct way to set an element in a list to NULL? (FAQ is not clear)

2009-12-11 Thread Peng Yu
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-set-components-of-a-list-to-NULL_003f

The explanation on this FAQ entry is not clear. It says '... similarly
for named components...'. What I understood was x[i]-list(NULL) is
the same as x$a_name-list(NULL). But, they are not. As the example
below shows, x$a_name-list(NULL) is the same as x[[i]]-list(NULL).

 x=list(a=1:3,b=NULL,c=2:5,d=NULL)
 x
$a
[1] 1 2 3

$b
NULL

$c
[1] 2 3 4 5

$d
NULL

 x[[3]]=list(NULL)
 x
$a
[1] 1 2 3

$b
NULL

$c
$c[[1]]
NULL


$d
NULL

 x$c=list(NULL)
 x
$a
[1] 1 2 3

$b
NULL

$c
$c[[1]]
NULL


$d
NULL


 x[[3]]=7:8
 x
$a
[1] 1 2 3

$b
NULL

$c
[1] 7 8

$d
NULL

 x$c=7:8
 x
$a
[1] 1 2 3

$b
NULL

$c
[1] 7 8

$d
NULL


What seems confusing to me is:
even 'x[i]-list(NULL)' and 'x[[i]]-list(NULL)' are different, why
x[i]-NULL and x[[i]]-NULL are the same?

Shouldn't the meaning of 'x[[i]]-NULL' be defined as the set the i'th
element NULL, rather than deleting the i'th element?

__
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 figure out which the version of split is used?

2009-12-11 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Karl Ove Hufthammer
 Sent: Thursday, December 10, 2009 1:46 AM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] How to figure out which the version of split is used?
 
 On Wed, 9 Dec 2009 19:20:47 -0600 Peng Yu pengyu...@gmail.com wrote:
  Is there a way to figure out which of these variants is actually
  dispatched to when I call split? I know that if the 
 argument is of the
  type data.frame, split.data.frame will be called? Is it the 
 case that
  if the argument is not of type data.frame, Date or POSIXct,
  split.default will be called?
 
 Yes. See ?UseMethod

You can also use trace() to see what actually happens
in test cases.  E.g.,
   invisible(lapply(methods(split),
  function(method)trace(method,
  bquote(cat(Entering, .(method),
  x=, class(x), f=, class(f), \n)
  Tracing function split.data.frame in package base
  Tracing function split.Date in package base
  Tracing function split.default in package base
  Tracing function split.POSIXct in package base
   split(data.frame(x=1:3,y=1:3), f=c(10,10,20))
  Tracing split.data.frame(data.frame(x = 1:3, y = 1:3), f = c(10, 10,
 on entry
  Entering split.data.frame x= data.frame f= numeric
  Tracing split.default(seq_len(nrow(x)), f, drop = drop, ...) on entry
  Entering split.default x= integer f= numeric
  $`10`
x y
  1 1 1
  2 2 2

  $`20`
x y
  3 3 3


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com  

 
 -- 
 Karl Ove Hufthammer
 
 __
 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] SVM regression

2009-12-11 Thread Steve Lianoglou
Hi Eleni,

On Dec 11, 2009, at 12:04 PM, Eleni Christodoulou wrote:

 Dear R users,
 
 I am trying to apply SVM regression for a set of microarray data. I am using
 the function svm() under the package {e1071}. Can anyone tell me what
 the *residuals
 *value represents? I have some observed values *y_obs* for the parameter
 that I want to estimate and I would expect that *svm$residuals = y_obs -
 svm$fitted.
 *However, this does not happen...Does anyone have any idea on that?

This actually is what's happening. The $residuals that are reported in the 
model are against your *scaled* y-vector.

So, with your data:

R m - svm(x,y)
R all(scale(y) - predict(m,x) == m$residuals)
[1] TRUE

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 11:01 AM, William Dunlap wdun...@tibco.com wrote:
 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu
 Sent: Friday, December 11, 2009 8:44 AM
 To: r-h...@stat.math.ethz.ch
 Subject: [R] Why a list of NULL's are reduced to NULL?

 The following examples are confusing to me. It is OK, to assigned NULL
 to one element in a list. The result is still a list. However, a list
 of NULL's are reduced to NULL. I don't understand how this conversion
 occurs. Could somebody let me know what is going on?

 The simplification algorithm for reformatting
 the output of apply and sapply is handy in the
 common case when you know that FUN will return
 the same sort of thing each time it it called.
 The algorithm is not very useful when FUN may return
 objects of various classes or lengths.  sapply has
 a simplify=FALSE argument to avoid the simplification
 (so it acts like lapply) but apply doesn't.

 I suggest you either change your function to always
 return one class and length of object or use lapply()
 or sapply(simplify=FALSE,...) when you must use a function
 with variable output type.  E.g., instead of
   apply(X, 1, function(row){f(row)})
 use
   lapply(seq_len(nrow(X)), function(rowIndex){f(X[rowIndex,])})
 or
   lapply(split(X, row(X)), function(row){f(row)})

Change my function to always returning one class may not always be
possible as I may call a third party R package that is not made by me
and does this kind of wired things of trying to 'simplify'. And I may
not know all the cases where the third party R package 'simplify' the
results, which does not always return the same type. In this case, I
can not be sure the return type is always the same. How do you deal
with this problem?

  X=matrix(1:8, nr=4)
  apply(X,1, function(x) {if(x[[1]]==3){NULL}else{x[[1]]}})
 [[1]]
 [1] 1

 [[2]]
 [1] 2

 [[3]]
 NULL

 [[4]]
 [1] 4

  apply(X,1, function(x) {NULL})
 NULL

 __
 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] shared axes in multipanel plot

2009-12-11 Thread Gabor Grothendieck
Try this using xyplot.zoo in the zoo package.  We define the baseline
and a panel function.   The panel function just performs the default
action to display the graphs and adds the baseline.   The screens
variable is 1,1,2,2,3,3,4,4.  We create a zoo object from dat and use
screens to name the columns according to their group.  Finally we call
xyplot.zoo passing it screens so that the successive columns go in the
indicated panels and also passing the other items.  See ?xyplot.zoo in
zoo and ?xyplot in lattice.

library(zoo)
library(lattice)

baseline - 1:nrow(dat)/nrow(dat)
pnl - function(x, ...) {
panel.plot.default(x, ...)
panel.lines(x, baseline, lwd = 2, col = grey(0.5))
}
nc - ncol(dat)
screens - rep(1:(nc/2), each = 2)
z - zoo(dat)
colnames(z) - paste(Group, screens)
xyplot(z, screens = screens , layout = c(2, 2), col = black, lty =
2, scales = list(y = list(relation = same)), panel = pnl)


On Fri, Dec 11, 2009 at 10:02 AM, Jennifer Young
jennifer.yo...@math.mcmaster.ca wrote:
 Hello

 I've created a function to make a plot with multiple pannels from columns
 of data that are created in a previous function.  In the example below the
 number of columns is 8, giving 4 pannels, but in general it takes data
 with any number of columns and figures out a nice layout.

 The panels all have the same axes, and so I wonder what functions are
 avialable to create axes only on the left and bottom of the whole plot
 rather than each pannel.
 I'd really like a generic way to do this for any number of plots, but was
 even having trouble figuring out how to do it manually for this example;
 How are pannels referred to, in a layout context?
 That is, how do I say,

 if(current.pannel==4) {do stuff}

 Here's a simple version of the code.

 baseline - (1:20)/20    #example data
 dat1 - matrix(baseline,20,8)
 dat - dat1+matrix(rnorm(20*8)/30, 20,8)

 nstrat - ncol(dat)
 rows - ceiling(nstrat/4)
 layout(matrix(1:(rows*2), rows, 2, T))
 par(oma=c(4,4,3,1))
 par(mar=c(1,1,0,1))
 for(i in which(1:nstrat%%2!=0)){
    plot(baseline, type=l, col=grey, lwd=2,
            xlab=, ylab=, ylim=c(0,1), xaxt='n', yaxt='n')
    axis(1, labels=F); axis(2, labels=F)
    points(dat[,i], type=l, lty=2)
    points(dat[,i+1], type=l, lty=2)
 }



 Thank you muchly
 Jennifer Young

 PS: I am a subscriber, but can't for the life of me figure out how to send
 an email while logged in so that the moderators don't have to take the
 time to read it over.  I always get the please wait while we check it
 over email.  Likely I'm being dumb.

 __
 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] The correct way to set an element in a list to NULL? (FAQ is not clear)

2009-12-11 Thread Steve Lianoglou
Hi,

On Dec 11, 2009, at 12:07 PM, Peng Yu wrote:

 http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-set-components-of-a-list-to-NULL_003f
 
 The explanation on this FAQ entry is not clear. It says '... similarly
 for named components...'. What I understood was x[i]-list(NULL) is
 the same as x$a_name-list(NULL). But, they are not.

You're right, x[i] is not the same as x$a_name:

R x - list(a=1:3, b='hello')
R identical(x[1], x$a)
[1] FALSE

R identical(x[1], x['a'])
[1] TRUE

I think that's what it means by similarly for named components. You see, 
x$a_name is really x[[1]], which does the destructive-null-assignment-thing:

R identical(x[[1]], x$a)
[1] TRUE

-steve


 As the example
 below shows, x$a_name-list(NULL) is the same as x[[i]]-list(NULL).
 
 x=list(a=1:3,b=NULL,c=2:5,d=NULL)
 x
 $a
 [1] 1 2 3
 
 $b
 NULL
 
 $c
 [1] 2 3 4 5
 
 $d
 NULL
 
 x[[3]]=list(NULL)
 x
 $a
 [1] 1 2 3
 
 $b
 NULL
 
 $c
 $c[[1]]
 NULL
 
 
 $d
 NULL
 
 x$c=list(NULL)
 x
 $a
 [1] 1 2 3
 
 $b
 NULL
 
 $c
 $c[[1]]
 NULL
 
 
 $d
 NULL
 
 
 x[[3]]=7:8
 x
 $a
 [1] 1 2 3
 
 $b
 NULL
 
 $c
 [1] 7 8
 
 $d
 NULL
 
 x$c=7:8
 x
 $a
 [1] 1 2 3
 
 $b
 NULL
 
 $c
 [1] 7 8
 
 $d
 NULL
 
 
 What seems confusing to me is:
 even 'x[i]-list(NULL)' and 'x[[i]]-list(NULL)' are different, why
 x[i]-NULL and x[[i]]-NULL are the same?
 
 Shouldn't the meaning of 'x[[i]]-NULL' be defined as the set the i'th
 element NULL, rather than deleting the i'th element?
 
 __
 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.

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] The correct way to set an element in a list to NULL? (FAQ is not clear)

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 11:27 AM, Steve Lianoglou
mailinglist.honey...@gmail.com wrote:
 Hi,

 On Dec 11, 2009, at 12:07 PM, Peng Yu wrote:

 http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-set-components-of-a-list-to-NULL_003f

 The explanation on this FAQ entry is not clear. It says '... similarly
 for named components...'. What I understood was x[i]-list(NULL) is
 the same as x$a_name-list(NULL). But, they are not.

 You're right, x[i] is not the same as x$a_name:

 R x - list(a=1:3, b='hello')
 R identical(x[1], x$a)
 [1] FALSE

 R identical(x[1], x['a'])
 [1] TRUE

 I think that's what it means by similarly for named components. You see, 
 x$a_name is really x[[1]], which does the destructive-null-assignment-thing:

 R identical(x[[1]], x$a)
 [1] TRUE

 -steve


 As the example
 below shows, x$a_name-list(NULL) is the same as x[[i]]-list(NULL).

 x=list(a=1:3,b=NULL,c=2:5,d=NULL)
 x
 $a
 [1] 1 2 3

 $b
 NULL

 $c
 [1] 2 3 4 5

 $d
 NULL

 x[[3]]=list(NULL)
 x
 $a
 [1] 1 2 3

 $b
 NULL

 $c
 $c[[1]]
 NULL


 $d
 NULL

 x$c=list(NULL)
 x
 $a
 [1] 1 2 3

 $b
 NULL

 $c
 $c[[1]]
 NULL


 $d
 NULL


 x[[3]]=7:8
 x
 $a
 [1] 1 2 3

 $b
 NULL

 $c
 [1] 7 8

 $d
 NULL

 x$c=7:8
 x
 $a
 [1] 1 2 3

 $b
 NULL

 $c
 [1] 7 8

 $d
 NULL


 What seems confusing to me is:
 even 'x[i]-list(NULL)' and 'x[[i]]-list(NULL)' are different, why
 x[i]-NULL and x[[i]]-NULL are the same?

 Shouldn't the meaning of 'x[[i]]-NULL' be defined as the set the i'th
 element NULL, rather than deleting the i'th element?

Do you have any comments on the above question?

__
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] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread William Dunlap
 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu
 Sent: Friday, December 11, 2009 9:18 AM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] Why a list of NULL's are reduced to NULL?
 
 On Fri, Dec 11, 2009 at 11:01 AM, William Dunlap 
 wdun...@tibco.com wrote:
  -Original Message-
  From: r-help-boun...@r-project.org
  [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu
  Sent: Friday, December 11, 2009 8:44 AM
  To: r-h...@stat.math.ethz.ch
  Subject: [R] Why a list of NULL's are reduced to NULL?
 
  The following examples are confusing to me. It is OK, to 
 assigned NULL
  to one element in a list. The result is still a list. 
 However, a list
  of NULL's are reduced to NULL. I don't understand how this 
 conversion
  occurs. Could somebody let me know what is going on?
 
  The simplification algorithm for reformatting
  the output of apply and sapply is handy in the
  common case when you know that FUN will return
  the same sort of thing each time it it called.
  The algorithm is not very useful when FUN may return
  objects of various classes or lengths.  sapply has
  a simplify=FALSE argument to avoid the simplification
  (so it acts like lapply) but apply doesn't.
 
  I suggest you either change your function to always
  return one class and length of object or use lapply()
  or sapply(simplify=FALSE,...) when you must use a function
  with variable output type.  E.g., instead of
    apply(X, 1, function(row){f(row)})
  use
    lapply(seq_len(nrow(X)), function(rowIndex){f(X[rowIndex,])})
  or
    lapply(split(X, row(X)), function(row){f(row)})
 
 Change my function to always returning one class may not always be
 possible as I may call a third party R package that is not made by me
 and does this kind of wired things of trying to 'simplify'. And I may
 not know all the cases where the third party R package 'simplify' the
 results, which does not always return the same type. In this case, I
 can not be sure the return type is always the same. How do you deal
 with this problem?

I don't understant your constraints.  You say you cannot control
what FUN returns and you cannot control whether apply or lapply
is called.  A reproducible set of examples would help.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
   X=matrix(1:8, nr=4)
   apply(X,1, function(x) {if(x[[1]]==3){NULL}else{x[[1]]}})
  [[1]]
  [1] 1
 
  [[2]]
  [1] 2
 
  [[3]]
  NULL
 
  [[4]]
  [1] 4
 
   apply(X,1, function(x) {NULL})
  NULL
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

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


Re: [R] The correct way to set an element in a list to NULL? (FAQ is not clear)

2009-12-11 Thread Steve Lianoglou

On Dec 11, 2009, at 12:36 PM, Peng Yu wrote:
[snip]

 What seems confusing to me is:
 even 'x[i]-list(NULL)' and 'x[[i]]-list(NULL)' are different, why
 x[i]-NULL and x[[i]]-NULL are the same?
 
 Shouldn't the meaning of 'x[[i]]-NULL' be defined as the set the i'th
 element NULL, rather than deleting the i'th element?
 
 Do you have any comments on the above question?

Sure.

I think it has something to do with how memory is managed and allocated in R.  
You might try to read up on it a bit ... 

In all seriousness tho:

No, I don't really have any comment on that question.

The semantics of what x[i]-list(NULL) vs x[[i]]-list(NULL) seems quite 
reasonable to me ... I'm not sure what that has to do with anything.

I also can't comment on why x[[i]] - NULL deletes the element (instead of 
setting it to NULL, like you want it to) .. it's just the way it is.

That having been said. Once you get it (and I guess it's on the FAQ for a 
reason), then you can figure out how to deal with it.

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 11:43 AM, William Dunlap wdun...@tibco.com wrote:
 -Original Message-
 From: r-help-boun...@r-project.org
 [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu
 Sent: Friday, December 11, 2009 9:18 AM
 To: r-h...@stat.math.ethz.ch
 Subject: Re: [R] Why a list of NULL's are reduced to NULL?

 On Fri, Dec 11, 2009 at 11:01 AM, William Dunlap
 wdun...@tibco.com wrote:
  -Original Message-
  From: r-help-boun...@r-project.org
  [mailto:r-help-boun...@r-project.org] On Behalf Of Peng Yu
  Sent: Friday, December 11, 2009 8:44 AM
  To: r-h...@stat.math.ethz.ch
  Subject: [R] Why a list of NULL's are reduced to NULL?
 
  The following examples are confusing to me. It is OK, to
 assigned NULL
  to one element in a list. The result is still a list.
 However, a list
  of NULL's are reduced to NULL. I don't understand how this
 conversion
  occurs. Could somebody let me know what is going on?
 
  The simplification algorithm for reformatting
  the output of apply and sapply is handy in the
  common case when you know that FUN will return
  the same sort of thing each time it it called.
  The algorithm is not very useful when FUN may return
  objects of various classes or lengths.  sapply has
  a simplify=FALSE argument to avoid the simplification
  (so it acts like lapply) but apply doesn't.
 
  I suggest you either change your function to always
  return one class and length of object or use lapply()
  or sapply(simplify=FALSE,...) when you must use a function
  with variable output type.  E.g., instead of
    apply(X, 1, function(row){f(row)})
  use
    lapply(seq_len(nrow(X)), function(rowIndex){f(X[rowIndex,])})
  or
    lapply(split(X, row(X)), function(row){f(row)})

 Change my function to always returning one class may not always be
 possible as I may call a third party R package that is not made by me
 and does this kind of wired things of trying to 'simplify'. And I may
 not know all the cases where the third party R package 'simplify' the
 results, which does not always return the same type. In this case, I
 can not be sure the return type is always the same. How do you deal
 with this problem?

 I don't understant your constraints.  You say you cannot control
 what FUN returns and you cannot control whether apply or lapply
 is called.  A reproducible set of examples would help.

A very common situation is that the users don't know all the possible
return types of 'some_third_party_function()'. If the users don't know
all the return types, he/she can not make sure the return type of
function(x) {...} be always the same. How do you deal with this case?

apply(X, 1, function(x) {
do something...
some_third_party_function(x)
  }
)

   X=matrix(1:8, nr=4)
   apply(X,1, function(x) {if(x[[1]]==3){NULL}else{x[[1]]}})
  [[1]]
  [1] 1
 
  [[2]]
  [1] 2
 
  [[3]]
  NULL
 
  [[4]]
  [1] 4
 
   apply(X,1, function(x) {NULL})
  NULL
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 

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



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


Re: [R] Sources for open sourced homework questions for R?

2009-12-11 Thread hadley wickham
Hi Dave,

I have a few drills available from http://had.co.nz/stat405 - see the
right hand column, about half way down.  They seem similar in spirit
to what you're thinking of. You might want to look at the Little
Schemer for a similar approach with a different programming language.

However, I'm not sure how pedagogically useful this approach is. If
you break things down too finely, you don't teach the problem solving
skills necessary to attack a new problem. Students will try and solve
the problems as rapidly, using as little of their brain as possible.
I also feel like these small problem fail to invoke any intellectually
curiosity - why the heck should I care that mtcars has 32 observations
and 11 rows?

I'd suggest starting with a big problem that's of interest to the
students - how do we detect spam? What determines the price of a used
car on ebay?  Do soap operas influence baby name trends? Are my
facebook friends representative of the university as a whole? Then
talk about how you might attack the problem in general, before getting
to the concrete tools you'd use in R.

Hadley

On Fri, Dec 11, 2009 at 10:48 AM, David Kane d...@kanecap.com wrote:
 Hi,

 I am teaching a one month class in applied statistics and want to
 bring my students up to speed in R without devoting much/any lecture
 time to R instruction. I think that the best way to do this is to
 provide them with a lot of R questions for homework. These questions
 would be numerous (there is a lot of material to cover), go from very
 simple to somewhat complex, and focus on all the commands and options
 that will be useful in applied work. Here are some of my initial
 questions:

 
 Q: Load the data from the cars data frame into the local workspace.
 A: data(cars)

 Q: Find information about the cars data frame.
 A: help(cars)

 Q: Calculate the dimensions of the data frame.
 A: dim(cars)

 Q: What are the names of the variables?
 A: names(cars)
 

 Needless to say, the questions will become more complex, including the
 writing of simple functions. I also want to provide answers to all the
 questions that, in theory, could be used in an automated fashion to
 check the students work. My current plan is to load these questions
 (somehow) into the quiz module in Moodle (http://moodle.org/).

 Ideally, I would like this system to be usable by very large classes
 and even in the context of distance learning. Student goes to a web
 page, logs in and is presented with a page of questions (or a single
 question). She figures out the answer in her R session and pastes in
 the command (or result) into the answer slot on the webpage and pushes
 a button (or does it for ten questions first). The server then
 determines which questions she got right and which she got wrong. It
 might then provide clues to the ones that she has wrong. Once she is
 done, the professor gets a list of her results (how many right, how
 many wrong, how many required more than one try and so on).

 For now, I am not building that system. (Has anyone already done so?)
 Instead, I am just creating the collection of R questions/answers that
 might go into such a system. I am aiming for around 1,000 questions.
 So: Does anyone know of open sourced collections of R questions like
 this which I might use?

 Thanks,

 Dave Kane
 Adjunct Instructor, Williams College

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




-- 
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] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread hadley wickham
 A very common situation is that the users don't know all the possible
 return types of 'some_third_party_function()'. If the users don't know
 all the return types, he/she can not make sure the return type of
 function(x) {...} be always the same. How do you deal with this case?

It's not that common.  It's pretty bad practice to return different
types from a function depending on the input parameters.  In many
languages this isn't even possible.

The solution is to write a function that takes the output from the
first function, inspects it, and coerces all possibilities to the same
type.

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] confint for glm (general linear model)

2009-12-11 Thread Peter Ehlers

I suspect that you don't know about 'profile' confidence
intervals. If that's true then I can recommend the
discussion in MASS (the book) in section 8.4.
In a nutshell, I don't think that you want to do
a profile confint calculation manually (unless typing
instructions that use the function profile.glm()
counts as 'manual').

 -Peter Ehlers

casperyc wrote:

I think the help page are exactly the same...
I just want to verify the confidence interval manually. That's all I want.

Thanks.

casper



brestat wrote:

This functions are different. I advice you study them:

?confint # profile likelihood
?confint.default # t-distribution

Walmes Zeviani - Brazil



casperyc wrote:

Hi,

I have a glm gives summary as follows,

   Estimate Std. Errorz valuePr(|z|)
(Intercept) -2.03693352 1.449574526 -1.405194 0.159963578
A0.01093048   0.006446256  1.695633 0.089955471
N0.41060119  0.224860819  1.826024 0.067846690
S   -0.20651005  0.067698863 -3.050421 0.002285206

then I use confint(k.glm) to obtain a confidnece interval for the
estimates.


confint(k.glm,level=0.97)

Waiting for profiling to be done...
   1.5 %  98.5 %
(Intercept) -5.471345995  0.94716503
A   -0.002340863  0.02631582
N   -0.037028592  0.95590178
S   -0.365570347 -0.06573675

while reading the help for 'confint', i found something like confint.glm
for general linear model.
I load the MASS package by clicking on the Menu( or otherwise how should
I load the package?)

then I still cant use the confint.glm command, what have I dont wrong?


How do I calculate this confidence interval for glm estimate manually??

for A, I use
0.01093048 + c(-1,1) * 0.006446256 * qt(0.985,df=77)
which is a different interval i got from the confint(k.glm,level=0.97)
above.

To be short, what's the right command to find the confidence interval for
glm estimats?
How do I verify it manully?

Thanks.

casper









--
Peter Ehlers
University of Calgary

__
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] ggplot: Problem with legend background

2009-12-11 Thread hadley wickham
Hi Luc,

You want:

legend.title=theme_text(size=20, hjust = 0)

So the legend title is left aligned, not centred.

Hadley


On Fri, Dec 11, 2009 at 9:26 AM, MUHC_Research
villa...@dms.umontreal.ca wrote:

 Dear R-users,

 I am preparing graphs for an upcoming article using the different functions
 of the ggplot2 package and I've been having problems with the legend
 background. It doesn't seem to scale when the text size is increased. Here's
 the mandatory reproducible example:

 library(ggplot2)
 repFrame - data.frame(A= 1:10, B= rnorm(1:10), groupNum = rep(c(First
 group, Second group),each=5))
 testPlot - ggplot(repFrame, aes(x=A, y = B, group = groupNum)) +
 opts(legend.position=c(0.85,0.3), legend.background =
 theme_rect(fill=white), legend.text=theme_text(size=16),
 legend.title=theme_text(size=20))
 testPlot + geom_point(aes(colour= groupNum))

 As you can see, the text doesn't fit in the white rectangle. I suspect there
 is a theme setting I could modify to fix this, but I can't seem to find
 which one.

 I sincerely thank you for your time and assistance.

 Luc
 --
 View this message in context: 
 http://n4.nabble.com/ggplot-Problem-with-legend-background-tp961142p961142.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 
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] The correct way to set an element in a list to NULL? (FAQ is not clear)

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 11:51 AM, Steve Lianoglou
mailinglist.honey...@gmail.com wrote:

 On Dec 11, 2009, at 12:36 PM, Peng Yu wrote:
 [snip]

 What seems confusing to me is:
 even 'x[i]-list(NULL)' and 'x[[i]]-list(NULL)' are different, why
 x[i]-NULL and x[[i]]-NULL are the same?

 Shouldn't the meaning of 'x[[i]]-NULL' be defined as the set the i'th
 element NULL, rather than deleting the i'th element?

 Do you have any comments on the above question?

 Sure.

 I think it has something to do with how memory is managed and allocated in R. 
  You might try to read up on it a bit ...

Which question do you refer by the first 'it'?

I have been asking a good reference on memory management in R. So far,
no one have given me any useful information. Do you have a good
reference?

 In all seriousness tho:

 No, I don't really have any comment on that question.

 The semantics of what x[i]-list(NULL) vs x[[i]]-list(NULL) seems quite 
 reasonable to me ... I'm not sure what that has to do with anything.

 I also can't comment on why x[[i]] - NULL deletes the element (instead of 
 setting it to NULL, like you want it to) .. it's just the way it is.

The design choice of  x[[i]] - NULL deleting the element instead of
setting it to NULL might increase the complexity of the code. Suppose
that I set the i'th element of x by calling some_function(), which
never return NULL, the following code is perfectly fine.

x[[i]] - some_function()

However, when some_function() does return NULL, the i'th element will
be deleted.

In this case I have to do the following. I will have to use the
following code, when I don't know if some_function() can return NULL,
for the sake of safety. As you can see one line of code has been
expanded to 6 lines.

result=some_function()
if(NULL==result) {
  x[i] - list(NULL)
} else {
  x[[i]] - some_function()
}

For this reason, x[[i]]-NULL should be defined as setting it to NULL.

 That having been said. Once you get it (and I guess it's on the FAQ for a 
 reason), then you can figure out how to deal with it.

 -steve

 --
 Steve Lianoglou
 Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
 Contact Info: http://cbio.mskcc.org/~lianos/contact



__
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] Why a list of NULL's are reduced to NULL?

2009-12-11 Thread Peng Yu
On Fri, Dec 11, 2009 at 12:05 PM, hadley wickham h.wick...@gmail.com wrote:
 A very common situation is that the users don't know all the possible
 return types of 'some_third_party_function()'. If the users don't know
 all the return types, he/she can not make sure the return type of
 function(x) {...} be always the same. How do you deal with this case?

 It's not that common.  It's pretty bad practice to return different
 types from a function depending on the input parameters.  In many
 languages this isn't even possible.

I know this is a bad practice. But R doesn't have a way to forbid such
thing happen. To program defensively, I have to test even uncommon
case, unless it is impossible. When you use a third party software in
your code, do you just ignore the possibility that a function could
return different types?

 The solution is to write a function that takes the output from the
 first function, inspects it, and coerces all possibilities to the same
 type.

How do you figure out all the possibilities?

__
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] Please help with a basic function

2009-12-11 Thread Mark Na
Many thanks for the replies to my call for help this morning. I didn't know
about return() and that helped quite a bit.

Best, Mark

On Fri, Dec 11, 2009 at 10:00 AM, Paul Hiemstra p.hiems...@geo.uu.nlwrote:

 Hi Mark,

 This question would probably be better suited for the r-sig-geo mailing
 list. In addition, please read the posting guide and provide a piece of code
 that reproduces the problem.

 library(sp)


 convert-function(d) {
 d-data.frame(d); #convert object to dataframe
 d-subset(d,select=c(zinc,x,y)) #select some columns
  d # - add this, or alternatively 'return(d)'
 }

 data(meuse)
 coordinates(meuse) = ~x+y

 convert(meuse)

 But maybe better, subsetting a SPDF can be done using:

 meuse[zinc] # Remains an SPDF
 # Returns a data.frame
 data.frame(coordinates(meuse), zinc = meuse$zinc)

 And some unrequested advice :). To process multiple files, take a look at
 lapply, both for reading and processing.

 all_data = lapply(list_of_files, function(file) {
bla = read.table(file)
coordinates(bla) = ~coor.x1 + coor.x2
return(bla)
 }
 # all data is now a list wit the SPDF's

 processed_data = lapply(all_data, function(dat) {
  return(data.frame(coordinates(dat), zinc = dat$zinc))
 }

 ofcourse you can include the latter lapply stuff inside the first 'loading'
 lapply.

 all_data = lapply(list_of_files, function(file) {
bla = read.table(file)
bla = subset(bla, select = select=c(time,coords.x1,coords.x2))
coordinates(bla) = ~coor.x1 + coor.x2
return(bla)
 }

 hope this helps and good luck,

 Paul

 Mark Na wrote:

 Hello,

 I am learning how to use functions, but I'm running into a roadblock.

 I would like my function to do two things: 1) convert an object to a
 dataframe, 2) and then subset the dataframe. Both of these commands work
 fine outside the function, but I would like to wrap them in a function so
 I
 can apply the code iteratively to many such objects.

 Here's what I wrote, but it doesn't work:

 convert-function(d) {
  d-data.frame(d); #convert object to dataframe
  d-subset(d,select=c(time,coords.x1,coords.x2)) #select some columns
 }
 convert(data) #the problem is that data is the same as it was before
 running the function

 The objects being processed through my function are
 SpatialPointsDataFrames
 but I'm quite sure that's not my problem, as I can process these outside
 of
 the function (using the above code) ... it's when I try to wrap the code
 in
 a function that it doesn't work.

 Thanks, Mark

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




 --
 Drs. Paul Hiemstra
 Department of Physical Geography
 Faculty of Geosciences
 University of Utrecht
 Heidelberglaan 2
 P.O. Box 80.115
 3508 TC Utrecht
 Phone:  +3130 274 3113 Mon-Tue
 Phone:  +3130 253 5773 Wed-Fri
 http://intamap.geo.uu.nl/~paul http://intamap.geo.uu.nl/%7Epaul




-- 
Mark Na
University of Saskatchewan
Saskatoon, Canada

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


  1   2   >