[R] including Sweave tangled code in '.Rnw' document

2008-11-30 Thread Kyle Matoba
Hello List,

I have been using Sweave for my homework this last quarter and have been
very impressed at how much time and effort it saves me.  I, however, have
run up against a problem which I have not been able to solve using any of
the Sweave/LaTeX tricks I know.  I work through my homework one problem at a
time, typesetting equations and writing R code, etc. and occasionally use
'Stangle()' from within R to extract the code if I need to pin down a
problem or experiment interactively.  I would like to be able to include
this resultant code in a verbatim environment in my final TeX'ed up document
as an appendix so that the grader can look it over, etc.  I could implement
this in any number of ways using linux tools, but would like to know if
there is a clean way to do so using LaTeX or Sweave so that the latest
version of the code is included in my homework each time I run 'R CMD Sweave
HW4.Rnw; pdflatex HW4.tex'.

e.g I envision something such as:

\begin{document}
fig3, echo=false, results=hide, fig=true, eps=F=
plot(runif(1000))
@

TA here is my code:

% some manner of Sweave/LaTeX macro to include the R code tangled out of
this '.Rnw' document
% in this case it would just be 'plot(runif(1000))', perhaps manually
enclosed in a verbatim environment

\end{document}
I am running R-2.6.2 on Ubuntu Hardy Heron.


Thanks for all your help with Sweave.  I think it is a fantastic tool.

Kyle

[[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] function for simultaneous confidence interval of regression coefficients

2008-11-30 Thread Kyle Matoba
List,

Would someone be so kind as to point me to a function that will calculate
simultaneous confidence intervals of regression coefficients based upon
their distribution as (under the assumption of normal errors, with
\mathbf{X} as the design matrix):

$\hat{\mathbf{\beta}} \sim N(\mathbf{\beta},
\sigma^2(\mathbf{X}^T\mathbf{X})^{-1})$.


'confint' calculates individual coefficients so far as I can tell, but I
need simultaneous CIs based on the confidence ellipse/ F distribution.
Inverting the ellipse gives this equation:

\mathbf{\hat{\beta}} \pm
\sqrt{\mathrm{diag}(s^2(\mathbf{X}^T\mathbf{X})^{-1}) \times p \times F_{p,
n-p, .95}}

Thanks, and sorry for such a dumb question.  Either I am not searching for
the right thing or this hasn't already been addressed in the lists (perhaps
because it is so easy).

Kyle

[[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] Drawing a tree in R

2008-11-30 Thread peterdc


Severin Hacker wrote:
 
 Hi,
 
 I've been trying to make use of the dendrogram class to plot a tree.
 However, my attempts have failed so far because I'm not sure how to build
 up the nested list. (where do I have to store the nodes?). The tree I want
 to be drawn is like this: in the form (node, left child,right child)
 (root,(n1,1,(n2,2,3)),4) 
 
 If it is not easily possible to draw a tree with the help of the
 dendrogram class I'm open to any other method to draw a tree in R!!
 
 Thanks!
 
 -Severin
 
 

Severin,

Check out the R package ape for plotting phylogenetic trees.  

require(ape)
foo - read.tree(text = (root,(n1,1,(n2,2,3)),4);)
plot(foo)

HTH

Peter 
-- 
View this message in context: 
http://www.nabble.com/Drawing-a-tree-in-R-tp20711698p20749736.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] about body-

2008-11-30 Thread ronggui
In  body(fun, envir = environment(fun)) - value,  value can be an
expression or a list of R expressions.

But it seems that value must be length-1 list (if it is a list), is it right?
 f2 - function(x) {}
 body(f2) - list(quote(x- x^5),quote(return(y)))
Error in as.function.default(c(formals(fun), value), envir) :
  invalid formal argument list for function


I want to construct a function by computing, what I do at this moment
is as follows:

 f - function(x) {}
 body(f)[[2]] - quote(x- x^5)
 body(f)[[3]] - quote(return(y))

Is there a better way to do this?

Thanks

-- 
HUANG Ronggui, Wincent
Tel: (00852) 3442 3832
PhD Candidate, City University of Hong Kong
http://ronggui.huang.googlepages.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] including Sweave tangled code in '.Rnw' document

2008-11-30 Thread Berwin A Turlach
G'day Kyle,

On Sat, 29 Nov 2008 11:11:37 -0800
Kyle Matoba [EMAIL PROTECTED] wrote:

 I have been using Sweave for my homework this last quarter [...] but
 would like to know if there is a clean way to do so using LaTeX or
 Sweave so that the latest version of the code is included in my
 homework each time I run 'R CMD Sweave HW4.Rnw; pdflatex HW4.tex'.
 
 e.g I envision something such as:

A file HW4.Rnw such as the following seem to do what you want:

++ start HW4.Rnw ++
\documentclass[a4paper,11pt]{article}

\usepackage{listings}

\begin{document}

fig3, echo=FALSE, results=hide, fig=TRUE, eps=FALSE=
plot(runif(1000))
@

=
mean(runif(1000))  
@   

TA here is my code:

% some manner of Sweave/LaTeX macro to include the R code tangled out
% of this '.Rnw' document in this case it would just be
% 'plot(runif(1000))', perhaps manually enclosed in a verbatim
% environment 

echo=FALSE, results=hide,split=TRUE=
Stangle(file=HW4.Rnw, output=XYZ.R, annotate=FALSE)
@ 


\lstinputlisting[emptylines=0]{XYZ.R}


\end{document}
++ end HW4.Rnw 

If the last Stangle command should be included in the listing, remove
the split=TRUE option.  And the file= argument to Stangle would
have to be correctly set for each .Rnw file; did not find a way to
automate this.  


 I am running R-2.6.2 on Ubuntu Hardy Heron.

R 2.6.2 is quite old by now, the current version is R 2.8.0.  When you
upgrade, be aware of:

o   The default for 'stylepath' in Sweave's (default) RweaveLatex
driver is now FALSE rather than TRUE if
SWEAVE_STYLEPATH_DEFAULT is unset : see ?RweaveLatex.
To support this, tools::texi2dvi adds the R 'texmf' directory
to the input search path.

which could mean that the way you process .Rnw file might no longer
work. 

HTH.

Cheers,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability+65 6516 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: [EMAIL PROTECTED]
Singapore 117546http://www.stat.nus.edu.sg/~statba

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] simple question with table()

2008-11-30 Thread Simone Gabbriellini

Dear List,

my problem should be easy to fix, but I couldn't find a solution by  
myself...


In my survey, there is a question with 14 possible answers. None of  
the respondents choose the 13th answer, so when I table() the results,  
R says:


1   2   3   4   5   6   7   8   9   10  
11  12  14
31  52  7   21  40  7   8   2   28  2   
2   1   17

13 is missing... anyone knows how to tell table() that there are 14  
modalities in the answers? I tried with


responseName 
=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14)


but all I have is:

error in table
all the arguments must have the same length

thank you,
Simone

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


Re: [R] simple question with table()

2008-11-30 Thread Berwin A Turlach
G'day Simone,

On Sun, 30 Nov 2008 11:05:13 +0100
Simone Gabbriellini [EMAIL PROTECTED] wrote:

 my problem should be easy to fix, but I couldn't find a solution by  
 myself...
 
 In my survey, there is a question with 14 possible answers. None of  
 the respondents choose the 13th answer, so when I table() the
 results, R says:
[...]
 13 is missing... anyone knows how to tell table() that there are 14  
 modalities in the answers?

The easiest way is probably to turn your data into a factor with the
appropriate set of levels:

R dat - sample(c(1:12,14), 100, replace=TRUE)
R table(factor(dat, levels=min(dat):max(dat)))

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 
 9  5  4  7  7 11  8 10  9  8  6 11  0  5 

that was once the solution of one of my colleagues and I find it
somewhat nicer than the one I came up with:

R rng - min(dat):max(dat)
R res - colSums(outer(dat, min(dat):max(dat), ==))
R names(res) - rng
R res
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 
 9  5  4  7  7 11  8 10  9  8  6 11  0  5 
 
HTH.

Best wishes,

Berwin

=== Full address =
Berwin A TurlachTel.: +65 6516 4416 (secr)
Dept of Statistics and Applied Probability+65 6516 6650 (self)
Faculty of Science  FAX : +65 6872 3919   
National University of Singapore 
6 Science Drive 2, Blk S16, Level 7  e-mail: [EMAIL PROTECTED]
Singapore 117546http://www.stat.nus.edu.sg/~statba

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


Re: [R] simple question with table()

2008-11-30 Thread Chuck Cleland
On 11/30/2008 5:05 AM, Simone Gabbriellini wrote:
 Dear List,
 
 my problem should be easy to fix, but I couldn't find a solution by
 myself...
 
 In my survey, there is a question with 14 possible answers. None of the
 respondents choose the 13th answer, so when I table() the results, R says:
 
 12345678910111214
 3152721407822822117
 
 13 is missing... anyone knows how to tell table() that there are 14
 modalities in the answers? I tried with
 
 responseName=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
 
 
 but all I have is:
 
 error in table
 all the arguments must have the same length

  Make the responses to the question a factor and set the levels of the
factor to include all 14 possible answers.  For example:

 table(factor(rep(c('1','2'), each=7), levels=c('1','2','3')))

1 2 3
7 7 0

?factor

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

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

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


Re: [R] simple question with table()

2008-11-30 Thread Jorge Ivan Velez
Dear Simone,
Try this:

x=c(1,1,2,3,4,3,2,2,2,1,2,3,4,4,3)
table(factor(x,levels=1:5))
1 2 3 4 5
3 5 4 3 0

HTH,

Jorge



On Sun, Nov 30, 2008 at 5:05 AM, Simone Gabbriellini 
[EMAIL PROTECTED] wrote:

 Dear List,

 my problem should be easy to fix, but I couldn't find a solution by
 myself...

 In my survey, there is a question with 14 possible answers. None of the
 respondents choose the 13th answer, so when I table() the results, R says:

 1   2   3   4   5   6   7   8   9   10
  11  12  14
 31  52  7   21  40  7   8   2   28  2
 2   1   17

 13 is missing... anyone knows how to tell table() that there are 14
 modalities in the answers? I tried with


 responseName=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14)

 but all I have is:

 error in table
 all the arguments must have the same length

 thank you,
 Simone

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


[[alternative HTML version deleted]]

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


Re: [R] simple question with table()

2008-11-30 Thread Dimitris Rizopoulos

you have to use a factor, e.g.,

x - sample((1:14)[-13], 100, TRUE)
f - factor(x, levels = 1:14)
table(f)


I hope it helps.

Best,
Dimitris


Simone Gabbriellini wrote:

Dear List,

my problem should be easy to fix, but I couldn't find a solution by 
myself...


In my survey, there is a question with 14 possible answers. None of the 
respondents choose the 13th answer, so when I table() the results, R says:


12345678910111214
3152721407822822117

13 is missing... anyone knows how to tell table() that there are 14 
modalities in the answers? I tried with


responseName=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14) 



but all I have is:

error in table
all the arguments must have the same length

thank you,
Simone

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

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



--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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: unbalanced repeated measures

2008-11-30 Thread Peter Dalgaard

Sumitrajit Dhar wrote:

Hi folks,

I am trying to figure out how run a repeated measures ANOVA on the  
following data set.


subject trial frequency dplvl
1  FSI052A A 1NA
2  FSI052B B 1NA
3  FSI053A A 1NA

..



Both frequency and trial are factorized.

  is.factor(trial)
[1] TRUE
  is.factor(frequency)
[1] TRUE
  levels(frequency)
[1] 1 2 3 4 6

I know that I should be using 'lme' rather than aov, but

  summary(aov(dplvl~trial*frequency+Error(subject/ 
(trial*frequency)),data=tenB))


Error: subject
 Df Sum Sq Mean Sq F value Pr(F)
trial1   7.157.15  0.2566 0.6203
frequency1  40.84   40.84  1.4657 0.2461
trial:frequency  1   0.030.03  0.0013 0.9723
Residuals   14 390.11   27.86

Error: subject:frequency
 Df  Sum Sq Mean Sq F value   Pr(F)
frequency1 183.893 183.893  11.925 0.003271 **
trial:frequency  1  16.393  16.393   1.063 0.317866
Residuals   16 246.738  15.421
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Error: Within
   Df Sum Sq Mean Sq F value Pr(F)
Residuals 35 269.137.69

What I do not understand is why I am getting df=1 for frequency when  
there are 5 levels of that factor.


Is tenB$frequency also a factor? The prototypical error would be to have 
modified only a copy of it.


By the way, with that amount of NA in the response, you are not going to 
undertand aov output in any case...


(and what happened with the subject:trial stratum???)

--
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] barplot labels

2008-11-30 Thread Simone Gabbriellini

Dear List,

is it possible to plot vertical labels under vertical bars? for  
vertical labels I mean to rotate 90 degrees horizontal labels


I suppose yes, because if excel can do this, R should do it twice  
better...


thank you,
Simone

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fwd: simple question with table()

2008-11-30 Thread simone gabbriellini
Dear ALL,

thank you for this sunday morning help! It works great!

all the best,
Simone

Il giorno 30/nov/08, alle ore 11:22, Jorge Ivan Velez ha scritto:


 Dear Simone,

 Try this:

 x=c(1,1,2,3,4,3,2,2,2,1,2,3,4,4,3)
 table(factor(x,levels=1:5))
 1 2 3 4 5
 3 5 4 3 0

 HTH,

 Jorge



 On Sun, Nov 30, 2008 at 5:05 AM, Simone Gabbriellini [EMAIL PROTECTED] 
  wrote:
 Dear List,

 my problem should be easy to fix, but I couldn't find a solution by  
 myself...

 In my survey, there is a question with 14 possible answers. None of  
 the respondents choose the 13th answer, so when I table() the  
 results, R says:

 1   2   3   4   5   6   7   8
 9   10  11  12  14
 31  52  7   21  40  7   8   2
 28  2   2   1   17

 13 is missing... anyone knows how to tell table() that there are 14  
 modalities in the answers? I tried with

 responseName 
 =c(1,2,3,4,5,6,7,8,9,10,11,12,13,14)

 but all I have is:

 error in table
 all the arguments must have the same length

 thank you,
 Simone

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



dott. Simone Gabbriellini - PhD Student
Department of Social Sciences
University of Pisa
[EMAIL PROTECTED]





[[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] barplot labels

2008-11-30 Thread Jorge Ivan Velez
Hi Simone,

Yes. Take a look at the las argument in ?par. Here is an example with
barplot:

barplot(table(factor(x,levels=1:5)),names.arg=c('First','Second','Third','Forth','Fifth'),las=2)


HTH,

Jorge


On Sun, Nov 30, 2008 at 5:33 AM, Simone Gabbriellini 
[EMAIL PROTECTED] wrote:

 Dear List,

 is it possible to plot vertical labels under vertical bars? for vertical
 labels I mean to rotate 90 degrees horizontal labels

 I suppose yes, because if excel can do this, R should do it twice better...

 thank you,
 Simone

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


[[alternative HTML version deleted]]

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


[R] about centralization

2008-11-30 Thread Weijia You
Hi all,

Is there anyone who ever used igraph to calculate the index of
centralization ?
I tried my best but can't find it in igraph.

The brief introduction to centralization can be found here , and I think
it's an important index for measuring the centrality on the aggregated
level.(http://faculty.ucr.edu/~hanneman/nettext/C10_Centrality.html)

Thank you for any comments and suggestions.

Best wishes!

Weijia

[[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] about body-

2008-11-30 Thread Gabor Grothendieck
Its also possible to build up a string:

 f - function(x) {}
 body(f) - parse(text = { x - x^5; return(x) })
 f
function (x)
{
x - x^5
return(x)
}


On Sun, Nov 30, 2008 at 4:15 AM, ronggui [EMAIL PROTECTED] wrote:
 In  body(fun, envir = environment(fun)) - value,  value can be an
 expression or a list of R expressions.

 But it seems that value must be length-1 list (if it is a list), is it right?
 f2 - function(x) {}
 body(f2) - list(quote(x- x^5),quote(return(y)))
 Error in as.function.default(c(formals(fun), value), envir) :
  invalid formal argument list for function


 I want to construct a function by computing, what I do at this moment
 is as follows:

  f - function(x) {}
 body(f)[[2]] - quote(x- x^5)
 body(f)[[3]] - quote(return(y))

 Is there a better way to do this?

 Thanks

 --
 HUANG Ronggui, Wincent
 Tel: (00852) 3442 3832
 PhD Candidate, City University of Hong Kong
 http://ronggui.huang.googlepages.com/

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


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


Re: [R] including Sweave tangled code in '.Rnw' document

2008-11-30 Thread Ista Zahn
You could achieve this from the LaTeX side of things using the
attachfile package:
http://www.ctan.org/tex-archive/macros/latex/contrib/attachfile/

I use this package to attach data files and R code to pdf's generated
with Sweave + pdflatex, so that the entire analysis can be reproduced
from a single document.

-Ista
 -- Forwarded message --
 From: Kyle Matoba [EMAIL PROTECTED]
 To: r-help@r-project.org
 Date: Sat, 29 Nov 2008 11:11:37 -0800
 Subject: [R] including Sweave tangled code in '.Rnw' document
 Hello List,

 I have been using Sweave for my homework this last quarter and have been
 very impressed at how much time and effort it saves me.  I, however, have
 run up against a problem which I have not been able to solve using any of
 the Sweave/LaTeX tricks I know.  I work through my homework one problem at a
 time, typesetting equations and writing R code, etc. and occasionally use
 'Stangle()' from within R to extract the code if I need to pin down a
 problem or experiment interactively.  I would like to be able to include
 this resultant code in a verbatim environment in my final TeX'ed up document
 as an appendix so that the grader can look it over, etc.  I could implement
 this in any number of ways using linux tools, but would like to know if
 there is a clean way to do so using LaTeX or Sweave so that the latest
 version of the code is included in my homework each time I run 'R CMD Sweave
 HW4.Rnw; pdflatex HW4.tex'.

 e.g I envision something such as:

 \begin{document}
 fig3, echo=false, results=hide, fig=true, eps=F=
 plot(runif(1000))
 @

 TA here is my code:

 % some manner of Sweave/LaTeX macro to include the R code tangled out of
 this '.Rnw' document
 % in this case it would just be 'plot(runif(1000))', perhaps manually
 enclosed in a verbatim environment

 \end{document}
 I am running R-2.6.2 on Ubuntu Hardy Heron.


 Thanks for all your help with Sweave.  I think it is a fantastic tool.

 Kyle


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Snow and multi-processing

2008-11-30 Thread Blanchette, Marco
I think I found a solution. I do not like to use global variable by fear of 
unpredictable side-effects but, I think that in this case I don't have to much 
chance.

Here is a mock function that pushes the content of a variable evaluated within 
a function to the nodes on the cluster, do some computation on the nodes using 
that variable and then return the result after cleaning up the newly created 
global variable.

Let me know what you people think:

aTest - function(x,n.nodes=2){
  library(snow)

  #initialize a cluster
  makeCluster(rep('locahost',n.nodes),type='SOCK')

  #create a global variable
  y - x

  #export the variable to the cluster
  clusterExport(cl,'y')

  #do some computation on the cluster
  c - clusterEvalQ(cl,y+2)

  #remove the variable from the global environment
  rm(y, envir=.GlobalEnv)

  #stop the cluster
  stopCluster(cl)

  #exit and return the computation
  return(c)
}


On 11/29/08 6:59 PM, Marco Blanchette [EMAIL PROTECTED] wrote:

Dear R gurus,

I have a very embarrassingly parallelizable job that I am trying to speed up 
with snow on our local cluster. Basically, I am doing ~50,000 t.test for a 
series of micro-array experiments, one gene at a time. Thus, I can easily 
spread the load across multiple processors and nodes.

So, I have a master list object that tells me what rows to pick up for each 
genes to do the t.test from series of microarray experiments containing 
~500,000 rows and x columns per experiments.

While trying to optimize my function using parLapply(), I quickly realized that 
I was not gaining any speed because every time a test was done on one of the 
item in the list, the 500,000 line by x column matrix had to be shipped along 
with the item in the list and the traffic time was actually longer than the 
computing time.

However, if I export the 500,000 object first across the spawned processes as 
in this mock script

cl - makeCluster(nnodes,method)
mArrayData - getData(experiments)
clusterExport(cl, 'mArrayData')

Results - parLapply(cl, theMapList, function(x) t.testFnc(x))

With a function that define the mArrayData argument as a default parameter as in

t.testFnc - function(probeList, array=mArrayData){
x - array[probeList$A,]
y - array[probeList$B,]
 res - doSomeTest(x,y)
return(res)
}

Using this strategy, I was able to gain full advantage of my cluster and reduce 
the analysis time by the number of nodes I have in our cluster. The large data 
matrix was resident in each processes and didn't have to travel on the network 
every time a item from the list was pass to the function t.testFnc()

However, I quickly realized that this works (the call to clusterExport() ) only 
when I run the script one line at a time. When the process is enclosed in a 
function, the object mArrayData is not exported, presumably because it's not a 
global object from the Master process.

So, what is the alternative to push the content of an object to the slaves? The 
documentation in the snow package is a bit light and I couldn't find good 
example out there. I don't want to have the function getData() evaluated on 
each nodes because the argument to that functions are humongous and that would 
cause way too much traffic on the network. I want the result of the function 
getData(), the object mArrayData, propagated to the cluster only once and be 
available to downstream functions.

Hope this is clear and that a solution will be possible.

Many thanks

Marco

--
Marco Blanchette, Ph.D.
Assistant Investigator
Stowers Institute for Medical Research
1000 East 50th St.

Kansas City, MO 64110

Tel: 816-926-4071
Cell: 816-726-8419
Fax: 816-926-2018

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


--
Marco Blanchette, Ph.D.
Assistant Investigator
Stowers Institute for Medical Research
1000 East 50th St.

Kansas City, MO 64110

Tel: 816-926-4071
Cell: 816-726-8419
Fax: 816-926-2018

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


Re: [R] about centralization

2008-11-30 Thread Gábor Csárdi
Weijia, centralization was not included in igraph, because really, it
takes only writing a one line function to do it. But it is on our TODO
list and will be included soon.

E.g. for degree see the thread that starts here:
http://lists.gnu.org/archive/html/igraph-help/2008-11/msg00064.html

You can do it similarly for other measures, but first you need to find
out which structure is the most centralized for a given measure. E.g.
for degree it is the star graph, but not for eigenvector centrality.
Probably this is written in the classic Wasserman-Faust book.

Best,
Gabor

On Sun, Nov 30, 2008 at 1:37 PM, Weijia You [EMAIL PROTECTED] wrote:
 Hi all,

 Is there anyone who ever used igraph to calculate the index of
 centralization ?
 I tried my best but can't find it in igraph.

 The brief introduction to centralization can be found here , and I think
 it's an important index for measuring the centrality on the aggregated
 level.(http://faculty.ucr.edu/~hanneman/nettext/C10_Centrality.html)

 Thank you for any comments and suggestions.

 Best wishes!

 Weijia

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




-- 
Gabor Csardi [EMAIL PROTECTED] UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] including Sweave tangled code in '.Rnw' document

2008-11-30 Thread Vincent Goulet

Kyle,

In addition to listings already mentioned by Berwin, you may find  
useful the answers package. This is what I use to create assignments/ 
exams/exercise sets with solutions all in one file.


HTH

Vincent

---
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

Le sam. 29 nov. à 14:11, Kyle Matoba a écrit :


Hello List,

I have been using Sweave for my homework this last quarter and have  
been
very impressed at how much time and effort it saves me.  I, however,  
have
run up against a problem which I have not been able to solve using  
any of
the Sweave/LaTeX tricks I know.  I work through my homework one  
problem at a
time, typesetting equations and writing R code, etc. and  
occasionally use

'Stangle()' from within R to extract the code if I need to pin down a
problem or experiment interactively.  I would like to be able to  
include
this resultant code in a verbatim environment in my final TeX'ed up  
document
as an appendix so that the grader can look it over, etc.  I could  
implement
this in any number of ways using linux tools, but would like to know  
if

there is a clean way to do so using LaTeX or Sweave so that the latest
version of the code is included in my homework each time I run 'R  
CMD Sweave

HW4.Rnw; pdflatex HW4.tex'.

e.g I envision something such as:

\begin{document}
fig3, echo=false, results=hide, fig=true, eps=F=
plot(runif(1000))
@

TA here is my code:

% some manner of Sweave/LaTeX macro to include the R code tangled  
out of

this '.Rnw' document
% in this case it would just be 'plot(runif(1000))', perhaps manually
enclosed in a verbatim environment

\end{document}
I am running R-2.6.2 on Ubuntu Hardy Heron.


Thanks for all your help with Sweave.  I think it is a fantastic tool.

Kyle

[[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] about centralization

2008-11-30 Thread Simone Gabbriellini

Weijia,

if you only need degree centralization, Gabor suggests me those lines  
of code and they work great:


## undirected graph
centralization-(sum(max(degree(g))-degree(g)))/(vcount(g)-1)/ 
(vcount(g)-2


## directed graph
centralization-(sum(max(degree(g))-degree(g)))/(2*vcount(g)-1)/ 
(vcount(g)-2


hope it helps,
Simone


Il giorno 30/nov/08, alle ore 17:05, Gábor Csárdi ha scritto:


Weijia, centralization was not included in igraph, because really, it
takes only writing a one line function to do it. But it is on our TODO
list and will be included soon.

E.g. for degree see the thread that starts here:
http://lists.gnu.org/archive/html/igraph-help/2008-11/msg00064.html

You can do it similarly for other measures, but first you need to find
out which structure is the most centralized for a given measure. E.g.
for degree it is the star graph, but not for eigenvector centrality.
Probably this is written in the classic Wasserman-Faust book.

Best,
Gabor

On Sun, Nov 30, 2008 at 1:37 PM, Weijia You [EMAIL PROTECTED]  
wrote:

Hi all,

Is there anyone who ever used igraph to calculate the index of
centralization ?
I tried my best but can't find it in igraph.

The brief introduction to centralization can be found here , and  
I think
it's an important index for measuring the centrality on the  
aggregated

level.(http://faculty.ucr.edu/~hanneman/nettext/C10_Centrality.html)

Thank you for any comments and suggestions.

Best wishes!

Weijia

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





--
Gabor Csardi [EMAIL PROTECTED] UNIL DGM

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] using wc-w (unix) in R on cluster

2008-11-30 Thread Juliet Hannah
This command

rows - as.numeric(system(paste(wc -l  /path/myFile.txt,sep=), TRUE))

works when used directly in R and when I put it inside a shell script
and submit it to the cluster.

This command

columns - as.numeric(system(paste(head -1  /path/myFile.txt | wc
-w,sep=), TRUE))

works when used in R, however is not working when I submit it.

I am using these commands to count the number of rows and columns on a
large file.

Any suggestions?

Thanks,

Juliet

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 input a string without quote

2008-11-30 Thread Carl Witthoft

From: Yihui Xie xieyihui_at_gmail.com
Date: Sun, 30 Nov 2008 15:32:35 +0800

Wow, you are so lazy... But sometimes R is just designed for lazy guys... 


Yeah, well, laziness is the mother of  creativity :-) .
But seriously: I know far too many engineers who  plug madly away for 
hours/days on end, where I would just stop, take a breath, figure out a 
method or mini-algorithm, and get the job done quick and easy.  That's 
what R is for.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] grouping similar column values into a single row

2008-11-30 Thread T Joshi
Hi,
I have a following situation with data:
col1   col2
mir-1 aaa
mir-1 abc
mir-1 aac
mir-2 abb
mir-2 aaa
mir-3 cag
mir-3 ccc
mir-3 aaa

I want to have  output in this format:
col1 col2
mir-1 aaa, abc, aac
mir-2 abb, aaa
mir-3 cag,ccc,aaa


I have sorted column 1 so that the grouping could be possible. I could
have done the same with mysql using a simple query, but I am not sure
how I can do it in R. Please suggest me possible way.

Thanks,
Joshi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 input a string without quote

2008-11-30 Thread hadley wickham
On Sun, Nov 30, 2008 at 11:38 AM, Carl Witthoft [EMAIL PROTECTED] wrote:
 From: Yihui Xie xieyihui_at_gmail.com
 Date: Sun, 30 Nov 2008 15:32:35 +0800

 Wow, you are so lazy... But sometimes R is just designed for lazy guys... 


 Yeah, well, laziness is the mother of  creativity :-) .
 But seriously: I know far too many engineers who  plug madly away for
 hours/days on end, where I would just stop, take a breath, figure out a
 method or mini-algorithm, and get the job done quick and easy.  That's what
 R is for.

We will encourage you to develop the three great virtues of a
programmer:  laziness, impatience, and hubris.
Larry Wall, Programming Perl

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] grouping similar column values into a single row

2008-11-30 Thread Gabor Grothendieck
See ?tapply

 tapply(paste(DF$col2), DF$col1, c)
$`mir-1`
[1] aaa abc aac

$`mir-2`
[1] abb aaa

$`mir-3`
[1] cag ccc aaa

 # or
 t(t(tapply(paste(DF$col2), DF$col1, paste, collapse =  )))
  [,1]
mir-1 aaa abc aac
mir-2 abb aaa
mir-3 cag ccc aaa

 # or
 t(do.call(cbind, tapply(paste(DF$col2), DF$col1, ts)))
  [,1]  [,2]  [,3]
mir-1 aaa abc aac
mir-2 abb aaa NA
mir-3 cag ccc aaa


On Sun, Nov 30, 2008 at 1:08 PM, T Joshi [EMAIL PROTECTED] wrote:
 Hi,
 I have a following situation with data:
 col1   col2
 mir-1 aaa
 mir-1 abc
 mir-1 aac
 mir-2 abb
 mir-2 aaa
 mir-3 cag
 mir-3 ccc
 mir-3 aaa

 I want to have  output in this format:
 col1 col2
 mir-1 aaa, abc, aac
 mir-2 abb, aaa
 mir-3 cag,ccc,aaa


 I have sorted column 1 so that the grouping could be possible. I could
 have done the same with mysql using a simple query, but I am not sure
 how I can do it in R. Please suggest me possible way.

 Thanks,
 Joshi

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Regex: workaround for variable length negative lookbehind

2008-11-30 Thread Stefan Th. Gries
Hi all

I have the following regular expression problem: I want to find
complete elements of a vector that end in a repeated character but
where the repetition doesn't make up the whole word. That is, for the
vector vec:

vec-c(, baaa, bbaa, bbba, baamm, aa)

I would like to get
baaa
bbaa
baamm

From tools where negative lookbehind can involve variable lengths, one
would think this would work:

grep((?!(?:\\1|^))(.)\\1{1,}$, vec, perl=T)

But then R doesn't like it that much ... I also know I can get it like this:

whole.word.rep - grep(^(.)\\1{1,}$, vec, perl=T) # 1 6
rep.at.end - grep((.)\\1{1,}$, vec, perl=T) # 1 2 3 5 6
setdiff(rep.at.end, whole.word.rep) # 2 3 5

But is there a one-line grep thingy to do this?

Thx for any pointers,
STG

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Graphics for proportion within factor

2008-11-30 Thread Rob James
  BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }I
am looking to draw what I hoped was a simple plot of proportion WITHIN
a strata, save % males by site. I seem to be able to get proportion of
males, by
 site, where the proportion is across the whole dataset, but not the
proportion within each site.
 thanks in advance,
 Rob
 
[[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] using survey weights for correlations

2008-11-30 Thread Steve Powell
Dear list,
I have a data file which includes, alongside various variables representing 
questionnaire scores, a variable for survey weights computed as the number of 
observations in the sample drawn from that group divided by the number of 
observations in the population in the group. I need to calculate a covariance 
matrix of the questionnaire scores for use in sem. How do I apply the weights?
Thanks in advance,
Steve Powell

www.promente.org

proMENTE social research

Krančevićeva 35
71000 Sarajevo

skype stevepowell99
mob. +387 61 215 997
tel. +387 33 556 865
fax. +387 33 556 866

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Regex: workaround for variable length negative lookbehind

2008-11-30 Thread Stefan Evert




Hi Stefan! :-)

From tools where negative lookbehind can involve variable lengths,  
one

would think this would work:

grep((?!(?:\\1|^))(.)\\1{1,}$, vec, perl=T)

But then R doesn't like it that much ...


It's really the PCRE library that doesn't like your regexp, not R.   
The problem is that negative behind is only possible with a fixed- 
length expression, and since \1 may hold an arbitrary string, the PCRE  
library can't be sure it's just a single character.  I'm also  
surprised that you're allowed to use \1 before defining it.


But is there a one-line grep thingy to do this?


Can't think of a one-liner, but a three-line solution you can easily  
enough wrap in a small function:


vec-c(, baaa, bbaa, bbba, baamm, aa)
idx.1 - grep((.)\\1$, vec)
idx.2 - grep(^(.)\\1*$, vec)
vec[setdiff(idx.1, idx.2)]

Cheers,
Stefan



--
The wonders of Googleology (episode 1)

from collectibles to cars
84,700,000 -- Google
9,443,672 -- Google N-grams (Web 1T5)
1 -- ukWaC

[ [EMAIL PROTECTED] | http://purl.org/stefan.evert ]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] function for simultaneous confidence interval of regression coefficients

2008-11-30 Thread Kingsford Jones
see
?coef  # extract the estimates
?vcov  #  extract their covariance matrix
?qf  # get the F quantile of interest

Also, you may be interested in

?car::ellipse
?ellipse::ellipse.lm
?gmodels::glht.test

hth,

Kingsford Jones


On Sat, Nov 29, 2008 at 4:30 PM, Kyle Matoba [EMAIL PROTECTED] wrote:
 List,

 Would someone be so kind as to point me to a function that will calculate
 simultaneous confidence intervals of regression coefficients based upon
 their distribution as (under the assumption of normal errors, with
 \mathbf{X} as the design matrix):

 $\hat{\mathbf{\beta}} \sim N(\mathbf{\beta},
 \sigma^2(\mathbf{X}^T\mathbf{X})^{-1})$.


 'confint' calculates individual coefficients so far as I can tell, but I
 need simultaneous CIs based on the confidence ellipse/ F distribution.
 Inverting the ellipse gives this equation:

 \mathbf{\hat{\beta}} \pm
 \sqrt{\mathrm{diag}(s^2(\mathbf{X}^T\mathbf{X})^{-1}) \times p \times F_{p,
 n-p, .95}}

 Thanks, and sorry for such a dumb question.  Either I am not searching for
 the right thing or this hasn't already been addressed in the lists (perhaps
 because it is so easy).

 Kyle

[[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] Randomization of a two-way ANOVA?

2008-11-30 Thread Joe Ratster

Hello list,

I wish to perform a randomization test on the F-statistics of a 2 way ANOVA
but have not been able to find out how to do so - is there a package  /
function that can perform this that I am unaware of? 

FactorA has 6 levels (0,1,2,3,4,5) whereas FactorB has 3 (1,2,3). A sample:

Resp.   FactorA FactorB
2   0   2
3   1   2
1   2   2
0   3   2
0   4   2
0   5   2
4   0   1
6   1   1
1   2   1
0   3   1
1   4   1
0   5   1
2   0   2
3   1   2
1   2   2
2   3   2
1   4   2
0   5   2
3   0   1
3   1   1
1   2   1
0   3   1
0   4   1
7   1   3
2   2   3
0   3   3
1   4   3
0   5   3
1   0   3

Also, is the F-statistic an appropriate test-statistic for the randomization
test when it is computed using non-normal data?

Any insight into this issue would be much appreciated.
Thanks.

-- 
View this message in context: 
http://www.nabble.com/Randomization-of-a-two-way-ANOVA--tp20761769p20761769.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] Regex: workaround for variable length negative lookbehind

2008-11-30 Thread Gabor Grothendieck
Try this:

 vec - c(, baaa, bbaa, bbba, baamm, aa)

 grep(^(?!(.)\\1{1,}$).*(.)\\2{1,}$, vec, perl = TRUE)
[1] 2 3 5

The (?...) succeeds only if the string is not all the same
character and since that consumes no characters it
restarts at the beginning to match anything followed
by repeated characters to the end.

On Sun, Nov 30, 2008 at 2:33 PM, Stefan Th. Gries [EMAIL PROTECTED] wrote:
 Hi all

 I have the following regular expression problem: I want to find
 complete elements of a vector that end in a repeated character but
 where the repetition doesn't make up the whole word. That is, for the
 vector vec:

 vec-c(, baaa, bbaa, bbba, baamm, aa)

 I would like to get
 baaa
 bbaa
 baamm

 From tools where negative lookbehind can involve variable lengths, one
 would think this would work:

 grep((?!(?:\\1|^))(.)\\1{1,}$, vec, perl=T)

 But then R doesn't like it that much ... I also know I can get it like this:

 whole.word.rep - grep(^(.)\\1{1,}$, vec, perl=T) # 1 6
 rep.at.end - grep((.)\\1{1,}$, vec, perl=T) # 1 2 3 5 6
 setdiff(rep.at.end, whole.word.rep) # 2 3 5

 But is there a one-line grep thingy to do this?

 Thx for any pointers,
 STG

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


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


[R] how to select cases based on value of one or more variables

2008-11-30 Thread Simone Gabbriellini

dear list,

I have read a spss file with read.spss()

now I have a list with all my variable stored as vectors.

is it possible to selec cases based on the value of one or more  
variables?


thank you,
Simone

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Regex: workaround for variable length negative lookbehind

2008-11-30 Thread Gabor Grothendieck
Here is a very slight further simplification, i.e. we can drop the final {1,}

 grep(^(?!(.)\\1{1,}$).*(.)\\2$, vec, perl = TRUE)
[1] 2 3 5


On Sun, Nov 30, 2008 at 3:26 PM, Gabor Grothendieck
[EMAIL PROTECTED] wrote:
 Try this:

 vec - c(, baaa, bbaa, bbba, baamm, aa)

 grep(^(?!(.)\\1{1,}$).*(.)\\2{1,}$, vec, perl = TRUE)
 [1] 2 3 5

 The (?...) succeeds only if the string is not all the same
 character and since that consumes no characters it
 restarts at the beginning to match anything followed
 by repeated characters to the end.

 On Sun, Nov 30, 2008 at 2:33 PM, Stefan Th. Gries [EMAIL PROTECTED] wrote:
 Hi all

 I have the following regular expression problem: I want to find
 complete elements of a vector that end in a repeated character but
 where the repetition doesn't make up the whole word. That is, for the
 vector vec:

 vec-c(, baaa, bbaa, bbba, baamm, aa)

 I would like to get
 baaa
 bbaa
 baamm

 From tools where negative lookbehind can involve variable lengths, one
 would think this would work:

 grep((?!(?:\\1|^))(.)\\1{1,}$, vec, perl=T)

 But then R doesn't like it that much ... I also know I can get it like this:

 whole.word.rep - grep(^(.)\\1{1,}$, vec, perl=T) # 1 6
 rep.at.end - grep((.)\\1{1,}$, vec, perl=T) # 1 2 3 5 6
 setdiff(rep.at.end, whole.word.rep) # 2 3 5

 But is there a one-line grep thingy to do this?

 Thx for any pointers,
 STG

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 select cases based on value of one or more variables

2008-11-30 Thread David Winsemius


?subset

On Nov 30, 2008, at 3:36 PM, Simone Gabbriellini wrote:


dear list,

I have read a spss file with read.spss()

now I have a list with all my variable stored as vectors.

is it possible to selec cases based on the value of one or more  
variables?


thank you,
Simone

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 select cases based on value of one or more variables

2008-11-30 Thread Don MacQueen

It is.

For example, if you have a variable stored as a vector named x, and 
another variable stored as aa vector named y, you can select cases 
of y where x is greater than 3 by using


  y[x3]

However, you're going to have to provide more information in order to 
get a better answer than that (see the posting guide, link included 
with every post to r-help). In particular, I'm guessing that the 
answer you really want looks somewhat different than my example -- 
but this depends on the exact structure of what read.spss() produces.


I'd also suggest reading some of the documentation available from the 
R website (CRAN), notably, An Introduction to R.


-Don

At 9:36 PM +0100 11/30/08, Simone Gabbriellini wrote:

dear list,

I have read a spss file with read.spss()

now I have a list with all my variable stored as vectors.

is it possible to selec cases based on the value of one or more variables?

thank you,
Simone

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



--
-
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Graphics for proportion within factor

2008-11-30 Thread David Winsemius
You could see whether the stacked barchart in Sarkar's website meets  
your needs:


http://lmdvr.r-forge.r-project.org/figures/figures.html
See figure 4.5

also look at:
?prop.table

Description
This is really sweep(x, margin, margin.table(x, margin), /) for  
newbies 



--
David Winsemius

On Nov 30, 2008, at 2:36 PM, Rob James wrote:


 BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }I
am looking to draw what I hoped was a simple plot of proportion WITHIN
a strata, save % males by site. I seem to be able to get proportion of
males, by
site, where the proportion is across the whole dataset, but not the
proportion within each site.
thanks in advance,
Rob

[[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] Regex: workaround for variable length negative lookbehind

2008-11-30 Thread Stefan Evert

But is there a one-line grep thingy to do this?


Can't think of a one-liner, but a three-line solution you can easily  
enough wrap in a small function:


vec-c(, baaa, bbaa, bbba, baamm, aa)
idx.1 - grep((.)\\1$, vec)
idx.2 - grep(^(.)\\1*$, vec)
vec[setdiff(idx.1, idx.2)]


Oops, my bad, that solution was in Stefan's original mail already.  I  
got his example mixed up with some other text and thought he was  
talking about something different.


Still, I think it's better to write a few lines of R code than to  
abuse regular expressions to do something they were never intended to  
do.  How do other people on this list feel about that issue?


Sorry again, and next time I'll trink a cup of coffee _before_ I post!
Stefan

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


Re: [R] using survey weights for correlations

2008-11-30 Thread John Fox
Dear Steve,

You can use svyvar() in the svy package to compute a covariance matrix that 
properly reflects the weights (and other details of the sampling design), and 
from this, using cov2cor(), a correlation matrix (if you want that too). You 
should get consistent estimates from sem() in the sem package (assuming that's 
what you were planning to use), but standard errors and statistical tests won't 
be right. You should be able to get valid inferences by bootstrapping, making 
proper allowance for the weights in resampling.

I hope this helps,
 John

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


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
 Behalf Of Steve Powell
 Sent: November-30-08 2:41 PM
 To: R-Help
 Subject: [R] using survey weights for correlations
 
 Dear list,
 I have a data file which includes, alongside various variables representing
 questionnaire scores, a variable for survey weights computed as the number of
 observations in the sample drawn from that group divided by the number of
 observations in the population in the group. I need to calculate a covariance
 matrix of the questionnaire scores for use in sem. How do I apply the
 weights?
 Thanks in advance,
 Steve Powell
 
 www.promente.org
 
 proMENTE social research
 
 Krančevićeva 35
 71000 Sarajevo
 
 skype stevepowell99
 mob. +387 61 215 997
 tel. +387 33 556 865
 fax. +387 33 556 866
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] selectively importing functions etc. from files

2008-11-30 Thread Faheem Mitha


Hi Charles,

Thanks for the reply.

On Sun, 30 Nov 2008, Charles C. Berry wrote:


On Sat, 29 Nov 2008, Faheem Mitha wrote:



Hi,

If I want to import the contents of a R file into another one, I can do

source(foo.R)

However, this imports everything from foo.R, including all functions 
and global variables. Is there a way of selectively importing 
individual functions etc., in a similar fashion to Python's


from foo import bar



There are probably a lot of ways to skin this cat.

But you might want to explain why you want to do this in the first 
place.


It may turn out that the problem you wish to solve is better addressed 
by placing your objects in a package that is attached far down the 
search list.


Well, I just want to be able to selectively import specific functions from 
files, so I can control what has been imported. One minor advantage of 
this (there are many) is that it makes it difficult to accidentally 
overwrite objects of the same name with each other. This is quite standard 
practice across languages to avoid polluting the global namespace. And of 
course, I'd like to do this as simply as possible.



A simple way to do what you say you want:

Use

source(foo.R, local=TRUE)

from within a function. Then either assign( ..., envir=.GlobalEnv ) 
selected objects or attach( list( ) ) them.


Not sure I follow this. I want to import into the global namespace. Why 
would I import from within a function? You mean first import locally into 
some function and then selectively export to the global namespace?


Another way is to use parse, as.character.srcref, and friends to avoid 
evaluating each of the objects, then eval() selected expressions in the 
desired environment.


And this one even less. Can you give a simple example?
 Regards, Faheem.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 select cases based on value of one or more variables

2008-11-30 Thread Simone Gabbriellini

sorry for my bad presentation...

read.spss gives me this:

 students
$Auno
  [1]  6  1  2  2  1  3  4  2  4  2  4  4  1  1 NA  1  4  2  1  1  1   
5  4
 [24]  2  1  2  1  2  1  4  4  1  1  1  2  1  6  1  1  1  1  1  2  1   
2  1
 [47]  2  2  1  4  2  4  3  1  1  1  1  3  2  1  4  4  4  4  2  4  1   
2  4
 [70]  1  3  4  5  2  4  3  5  5  4  2  1  1  1  1  4  5  2  4  4  1   
4  2
 [93]  1  2  3  3  2  1  2  2  2  1  1  1  3  5  5  5  2 NA  2  1 NA   
5  2
[116]  1  4  2 NA  1  4  5  2  3  1  1  1  1  4  2  1  1  3  2  4  2   
4  2
[139]  1  4  1  2  4  1  2  3  2  1  1  2  4  4  3  4  1  1  3  2  1   
1  2
[162]  1  2  5  5  5  1  4  3  2  3  3  2  1  1  5  1  2  1  1  2  1   
2  1
[185]  1  2  1  1  1  1  3  4  2  1  4  2  4  1  4  2  1  1  1  2  1   
4  1

[208]  5  1  1  4  4  2  1  1  5  4  1  1  5  5  4  1  4

$Sex
  [1] 2 1 2 1 2 2 2 2 1 2 1 1 2 1 0 2 2 2 2 2 2 2 2 1 2 2 1 2 2 1 2 2  
2 1
 [35] 2 2 2 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2  
1 2
 [69] 2 1 2 1 2 1 2 2 2 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 1 2 1 2 2 2 2 2  
2 2
[103] 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 0 2 2 2 1 2 2 1 2 1 2 2 1 1 2 1  
2 1
[137] 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 1 1  
2 2
[171] 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 1 2 2 1 1 1 1 1 2 0 2 2 1 2 1  
2 2

[205] 1 2 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2



I would like to filter - or subset - the dataset for $Sex = 1 (in this  
case means male...),  for example...


thanks anyway,
Simone



Il giorno 30/nov/08, alle ore 21:49, Don MacQueen ha scritto:


It is.

For example, if you have a variable stored as a vector named x,  
and another variable stored as aa vector named y, you can select  
cases of y where x is greater than 3 by using


 y[x3]

However, you're going to have to provide more information in order  
to get a better answer than that (see the posting guide, link  
included with every post to r-help). In particular, I'm guessing  
that the answer you really want looks somewhat different than my  
example -- but this depends on the exact structure of what  
read.spss() produces.


I'd also suggest reading some of the documentation available from  
the R website (CRAN), notably, An Introduction to R.


-Don

At 9:36 PM +0100 11/30/08, Simone Gabbriellini wrote:

dear list,

I have read a spss file with read.spss()

now I have a list with all my variable stored as vectors.

is it possible to selec cases based on the value of one or more  
variables?


thank you,
Simone

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

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



--
-
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
[EMAIL PROTECTED]
-


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 select cases based on value of one or more variables

2008-11-30 Thread Kingsford Jones
It's generally easier to work with data frames, so read your data with

students - read.spss(yourFile, to.data.frame=TRUE)


Then subset will work as expected:

subset(students, Sex == 1)


If you would rather keep the data as a list you could do something like

lapply(students, function(x) x[students$Sex == 1])

hth,

Kingsford Jones



On Sun, Nov 30, 2008 at 2:15 PM, Simone Gabbriellini
[EMAIL PROTECTED] wrote:
 sorry for my bad presentation...

 read.spss gives me this:

 students
 $Auno
  [1]  6  1  2  2  1  3  4  2  4  2  4  4  1  1 NA  1  4  2  1  1  1  5  4
  [24]  2  1  2  1  2  1  4  4  1  1  1  2  1  6  1  1  1  1  1  2  1  2  1
  [47]  2  2  1  4  2  4  3  1  1  1  1  3  2  1  4  4  4  4  2  4  1  2  4
  [70]  1  3  4  5  2  4  3  5  5  4  2  1  1  1  1  4  5  2  4  4  1  4  2
  [93]  1  2  3  3  2  1  2  2  2  1  1  1  3  5  5  5  2 NA  2  1 NA  5  2
 [116]  1  4  2 NA  1  4  5  2  3  1  1  1  1  4  2  1  1  3  2  4  2  4  2
 [139]  1  4  1  2  4  1  2  3  2  1  1  2  4  4  3  4  1  1  3  2  1  1  2
 [162]  1  2  5  5  5  1  4  3  2  3  3  2  1  1  5  1  2  1  1  2  1  2  1
 [185]  1  2  1  1  1  1  3  4  2  1  4  2  4  1  4  2  1  1  1  2  1  4  1
 [208]  5  1  1  4  4  2  1  1  5  4  1  1  5  5  4  1  4

 $Sex
  [1] 2 1 2 1 2 2 2 2 1 2 1 1 2 1 0 2 2 2 2 2 2 2 2 1 2 2 1 2 2 1 2 2 2 1
  [35] 2 2 2 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 2 2 2 2 2 1 2
  [69] 2 1 2 1 2 1 2 2 2 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 1 2 1 2 2 2 2 2 2 2
 [103] 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 0 2 2 2 1 2 2 1 2 1 2 2 1 1 2 1 2 1
 [137] 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2
 [171] 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 1 2 2 1 1 1 1 1 2 0 2 2 1 2 1 2 2
 [205] 1 2 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2

 

 I would like to filter - or subset - the dataset for $Sex = 1 (in this case
 means male...),  for example...

 thanks anyway,
 Simone



 Il giorno 30/nov/08, alle ore 21:49, Don MacQueen ha scritto:

 It is.

 For example, if you have a variable stored as a vector named x, and
 another variable stored as aa vector named y, you can select cases of y
 where x is greater than 3 by using

  y[x3]

 However, you're going to have to provide more information in order to get
 a better answer than that (see the posting guide, link included with every
 post to r-help). In particular, I'm guessing that the answer you really want
 looks somewhat different than my example -- but this depends on the exact
 structure of what read.spss() produces.

 I'd also suggest reading some of the documentation available from the R
 website (CRAN), notably, An Introduction to R.

 -Don

 At 9:36 PM +0100 11/30/08, Simone Gabbriellini wrote:

 dear list,

 I have read a spss file with read.spss()

 now I have a list with all my variable stored as vectors.

 is it possible to selec cases based on the value of one or more
 variables?

 thank you,
 Simone

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


 --
 -
 Don MacQueen
 Lawrence Livermore National Laboratory
 Livermore, CA, USA
 925-423-1062
 [EMAIL PROTECTED]
 -

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 select cases based on value of one or more variables

2008-11-30 Thread Simone Gabbriellini

yes it's THE solution!

thank you very much,
Simone


Il giorno 30/nov/08, alle ore 22:42, Kingsford Jones ha scritto:


It's generally easier to work with data frames, so read your data with

students - read.spss(yourFile, to.data.frame=TRUE)


Then subset will work as expected:

subset(students, Sex == 1)


If you would rather keep the data as a list you could do something  
like


lapply(students, function(x) x[students$Sex == 1])

hth,

Kingsford Jones



On Sun, Nov 30, 2008 at 2:15 PM, Simone Gabbriellini
[EMAIL PROTECTED] wrote:

sorry for my bad presentation...

read.spss gives me this:


students

$Auno
[1]  6  1  2  2  1  3  4  2  4  2  4  4  1  1 NA  1  4  2  1  1  1   
5  4
[24]  2  1  2  1  2  1  4  4  1  1  1  2  1  6  1  1  1  1  1  2   
1  2  1
[47]  2  2  1  4  2  4  3  1  1  1  1  3  2  1  4  4  4  4  2  4   
1  2  4
[70]  1  3  4  5  2  4  3  5  5  4  2  1  1  1  1  4  5  2  4  4   
1  4  2
[93]  1  2  3  3  2  1  2  2  2  1  1  1  3  5  5  5  2 NA  2  1  
NA  5  2
[116]  1  4  2 NA  1  4  5  2  3  1  1  1  1  4  2  1  1  3  2  4   
2  4  2
[139]  1  4  1  2  4  1  2  3  2  1  1  2  4  4  3  4  1  1  3  2   
1  1  2
[162]  1  2  5  5  5  1  4  3  2  3  3  2  1  1  5  1  2  1  1  2   
1  2  1
[185]  1  2  1  1  1  1  3  4  2  1  4  2  4  1  4  2  1  1  1  2   
1  4  1

[208]  5  1  1  4  4  2  1  1  5  4  1  1  5  5  4  1  4

$Sex
[1] 2 1 2 1 2 2 2 2 1 2 1 1 2 1 0 2 2 2 2 2 2 2 2 1 2 2 1 2 2 1 2 2  
2 1
[35] 2 2 2 1 1 2 2 2 2 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 2 2 2 2  
2 1 2
[69] 2 1 2 1 2 1 2 2 2 2 2 2 1 2 2 2 1 2 2 2 1 1 1 2 1 2 1 2 2 2 2  
2 2 2
[103] 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 0 2 2 2 1 2 2 1 2 1 2 2 1 1 2  
1 2 1
[137] 2 1 2 1 1 1 1 1 1 2 1 1 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 1  
1 2 2
[171] 2 2 2 2 2 1 1 1 1 2 2 2 2 2 2 2 2 1 2 2 1 1 1 1 1 2 0 2 2 1 2  
1 2 2

[205] 1 2 2 2 2 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2



I would like to filter - or subset - the dataset for $Sex = 1 (in  
this case

means male...),  for example...

thanks anyway,
Simone



Il giorno 30/nov/08, alle ore 21:49, Don MacQueen ha scritto:


It is.

For example, if you have a variable stored as a vector named x,  
and
another variable stored as aa vector named y, you can select  
cases of y

where x is greater than 3 by using

y[x3]

However, you're going to have to provide more information in order  
to get
a better answer than that (see the posting guide, link included  
with every
post to r-help). In particular, I'm guessing that the answer you  
really want
looks somewhat different than my example -- but this depends on  
the exact

structure of what read.spss() produces.

I'd also suggest reading some of the documentation available from  
the R

website (CRAN), notably, An Introduction to R.

-Don

At 9:36 PM +0100 11/30/08, Simone Gabbriellini wrote:


dear list,

I have read a spss file with read.spss()

now I have a list with all my variable stored as vectors.

is it possible to selec cases based on the value of one or more
variables?

thank you,
Simone

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



--
-
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
[EMAIL PROTECTED]
-


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] including Sweave tangled code in '.Rnw' document

2008-11-30 Thread Kyle Matoba
Vincent, Ista, Berwin:

Thank you all for your help.  It is great that a student like myself can
receive help from Professors and experts such as yourselves.

To the list, I found Berwin's solution to work excellently, though I chose
to change the font of the included text, e.g.

\texttt{  \lstinputlisting[emptylines=0]{XYZ.R} }

Ista's suggestion also seems excellent, though I am required to submit a
paper copy of the work and Ista's is a bit easier to manage with this goal
in mind.

Vincent's comment is also quite appropriate, unfortunately I have enough
trouble with LaTeX as it is and the problem has been solved to my
satisfaction I have chosen to put off exploration of this package for
another day.

Best,

Kyle





On Sun, Nov 30, 2008 at 8:42 AM, Vincent Goulet 
[EMAIL PROTECTED] wrote:

 Kyle,

 In addition to listings already mentioned by Berwin, you may find useful
 the answers package. This is what I use to create
 assignments/exams/exercise sets with solutions all in one file.

 HTH

 Vincent

 ---
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec
  [EMAIL PROTECTED]   http://vgoulet.act.ulaval.ca

 Le sam. 29 nov. à 14:11, Kyle Matoba a écrit :

  Hello List,

 I have been using Sweave for my homework this last quarter and have been
 very impressed at how much time and effort it saves me.  I, however, have
 run up against a problem which I have not been able to solve using any of
 the Sweave/LaTeX tricks I know.  I work through my homework one problem at
 a
 time, typesetting equations and writing R code, etc. and occasionally use
 'Stangle()' from within R to extract the code if I need to pin down a
 problem or experiment interactively.  I would like to be able to include
 this resultant code in a verbatim environment in my final TeX'ed up
 document
 as an appendix so that the grader can look it over, etc.  I could
 implement
 this in any number of ways using linux tools, but would like to know if
 there is a clean way to do so using LaTeX or Sweave so that the latest
 version of the code is included in my homework each time I run 'R CMD
 Sweave
 HW4.Rnw; pdflatex HW4.tex'.

 e.g I envision something such as:

 \begin{document}
 fig3, echo=false, results=hide, fig=true, eps=F=
 plot(runif(1000))
 @

 TA here is my code:

 % some manner of Sweave/LaTeX macro to include the R code tangled out of
 this '.Rnw' document
 % in this case it would just be 'plot(runif(1000))', perhaps manually
 enclosed in a verbatim environment

 \end{document}
 I am running R-2.6.2 on Ubuntu Hardy Heron.


 Thanks for all your help with Sweave.  I think it is a fantastic tool.

 Kyle

[[alternative HTML version deleted]]

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







[[alternative HTML version deleted]]

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


[R] controlling the number of times a script is repeated in a loop

2008-11-30 Thread Salas, Andria Kay
I am running a large for loop and at the end of each iteration a matrix is 
produced.  The program changes the columns in the matrix, and each time a 
column is added the name of that column is y.  All original columns have no 
column name.  Due to the nature of the program, all original columns will 
eventually be replaced with new columns each with the column name y. It is at 
this point that I want the program to stop running the for loop (right now I 
just have it running for 20 iterations resulting in a matrix with a mix of old 
and new columns).  I was thinking maybe I could do something with an if else 
statement and the command colnames.  For example:

If(colnames all are y) (stop) else (run the program again)

Not entirely sure how to go about this though, or if I am even on the right 
track.  Maybe I need to get rid of the master for loop as perhaps for loops are 
more constraining in the number of times the program is run?  The number of 
runs to get all original columns replaced with new ones will never be the same 
(I plan on running this several times, with time steps ending when all original 
columns are replaced.  Perhaps at the end of each time step I can set column 
names to have no column names (so from ys to nothing), allowing me to use 
this method for each time step)...

I know it is always helpful to have some code to work with, but it seems 
impractical to send the whole program as one part if it I am still working on 
and would probably just create more confusion.  Hopefully someone might be able 
to offer a few suggestions...I can try to come up with a toy program to send 
along but I am not good enough in R yet to do this quickly!

Thank you for all the help and I am sorry if this question is perhaps a bit 
confusing!  If I have not made my problem and what I hope to do clear, please 
let me know.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] selectively importing functions etc. from files

2008-11-30 Thread Charles C. Berry

On Sun, 30 Nov 2008, Faheem Mitha wrote:



Hi Charles,

Thanks for the reply.

On Sun, 30 Nov 2008, Charles C. Berry wrote:


 On Sat, 29 Nov 2008, Faheem Mitha wrote:

 
  Hi,
 
  If I want to import the contents of a R file into another one, I can do
 
  source(foo.R)
 
  However, this imports everything from foo.R, including all functions and 
  global variables. Is there a way of selectively importing individual 
  functions etc., in a similar fashion to Python's
 
  from foo import bar



 There are probably a lot of ways to skin this cat.

 But you might want to explain why you want to do this in the first place.



 It may turn out that the problem you wish to solve is better addressed by
 placing your objects in a package that is attached far down the search
 list.


Well, I just want to be able to selectively import specific functions from 
files, so I can control what has been imported. One minor advantage of this 
(there are many) is that it makes it difficult to accidentally overwrite 
objects of the same name with each other. This is quite standard practice 
across languages to avoid polluting the global namespace. And of course, I'd 
like to do this as simply as possible.


Right. And if you put all the objects in a package and do this:

## if you want to mask as little as possible, use
library(mypkg, pos = package:base)

you will achieve this. You can also set

LazyLoad: yes

in the DESCRIPTION file. Then if you want to 'promote' functions to 
the .GlobalEnv, you can do


foo - mypkg:::foo

Come to think of it, if the functions are all made local to the mypkg 
namespace, then they will only mask funcitons further down the search() 
list if they are called by other functions in mypkg.





 A simple way to do what you say you want:

 Use

  source(foo.R, local=TRUE)

 from within a function. Then either assign( ..., envir=.GlobalEnv )
 selected objects or attach( list( ) ) them.


Not sure I follow this. I want to import into the global namespace. Why would 
I import from within a function? You mean first import locally into some 
function and then selectively export to the global namespace?


Exactly. The objects that are not assign()ed or attach()ed will 
'disappear'.





 Another way is to use parse, as.character.srcref, and friends to avoid
 evaluating each of the objects, then eval() selected expressions in the
 desired environment.


And this one even less. Can you give a simple example?


OK. parse a file with two functions in it. Find one of the function 
expressions and evaluate it:



cat(foo - function(x) x+1;bar - function(x) x*2,file=foobar.R)
foobar.expr - parse(foobar.R)
ls()

[1] foobar.expr

grep(foo -,sapply(attr(foobar.expr,'srcref'),function(x) as.character(x)))

[1] 1
eval(foobar.expr[[ 1 ]]) 
ls()

[1] foo foobar.expr

foo

function(x) x+1

---

Another way to achieve what you want is to put source of each function in 
its own file in a single directory. Then


source(file.path(pkgpath,foo.R))

will load the single function in pkgpath/foo.R

HTH,

Chuck



 Regards, Faheem.

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




Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] minor edit WAS: Re: selectively importing functions etc. from files

2008-11-30 Thread Charles C. Berry

On Sun, 30 Nov 2008, Charles C. Berry wrote:


On Sun, 30 Nov 2008, Faheem Mitha wrote:



[much deleted]

I missed a '\n ' in my previous post. It should have read:


 eval(foobar.expr[[ 1 ]])
ls()
[1] foo foobar.expr

 foo

function(x) x+1




Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

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


[R] Rserve and creating a list of lists

2008-11-30 Thread Saptarshi Guha
Hello,
I have some code which generates lattice objects. The function  
recieves serialized forms of the lattice objects which it then  
unserializes and then adds to an ArrayListREXP.

REXPRaw rser = new REXPRaw( target );  //target contains the raw  
serialized forms of lattice objects
rconn.assign(temp,rser);
REXP ret = rconn.eval(invisible(unserialize(temp))); (1)
rexpArr.add(ret);
RList rlist = new RList(rexpArr);
REXPList rl = new REXPList(rlist);

The problem is when I do an assign

rconn.assign(finalresult,rl);

whence I get
*** REXPFactory unable to interpret  
[EMAIL PROTECTED] *
** REXPFactory unable to interpret  
[EMAIL PROTECTED]
*** REXPFactory unable to interpret  
[EMAIL PROTECTED]
*** REXPFactory unable to interpret  
[EMAIL PROTECTED]
*** REXPFactory unable to interpret  
[EMAIL PROTECTED] *
** REXPFactory unable to interpret  
[EMAIL PROTECTED]


How can I in general,force the unserialize to return a list?
Saptarshi Guha | [EMAIL PROTECTED] | http://www.stat.purdue.edu/~sguha
Marijuana is nature's way of saying, Hi!.


[[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] controlling the number of times a script is repeated in a loop

2008-11-30 Thread hadley wickham
On Sun, Nov 30, 2008 at 12:21 PM, Salas, Andria Kay [EMAIL PROTECTED] wrote:
 I am running a large for loop and at the end of each iteration a matrix is 
 produced.  The program changes the columns in the matrix, and each time a 
 column is added the name of that column is y.  All original columns have no 
 column name.  Due to the nature of the program, all original columns will 
 eventually be replaced with new columns each with the column name y. It is 
 at this point that I want the program to stop running the for loop (right now 
 I just have it running for 20 iterations resulting in a matrix with a mix of 
 old and new columns).  I was thinking maybe I could do something with an if 
 else statement and the command colnames.  For example:

 If(colnames all are y) (stop) else (run the program again)

Have a look at ?while :

while(!(colnames all are y)) { run the program again }

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] Rserve and creating a list of lists

2008-11-30 Thread Saptarshi Guha
Hello,
With reference to the problem below, I have narrowed it down to  
trellis objects containing language objects , e.g a trellis object has  
a list element called $prepanel.default which is a function.
The same happens if assign the result of an 'dist' call since it  
contains as one of its attributes the calling function (as a language).
The error returned by Rserve (latest version) is Error: unsupported  
type 0
So if the result of an eval is a language block, then it can't be  
assigned?
Is there a work around this?
Regards
Saptarshi
R.version = 2.8


 On Nov 30, 2008, at 5:53 PM, Saptarshi Guha wrote:

 Hello,
  I have some code which generates lattice objects. The function  
 recieves serialized forms of the lattice objects which it then  
 unserializes and then adds to an ArrayListREXP.
  
  REXPRaw rser = new REXPRaw( target );  //target contains the raw  
 serialized forms of lattice objects
  rconn.assign(temp,rser);
  REXP ret = rconn.eval(invisible(unserialize(temp))); (1)
  rexpArr.add(ret);
  RList rlist = new RList(rexpArr);
  REXPList rl = new REXPList(rlist);

  The problem is when I do an assign

  rconn.assign(finalresult,rl);

  whence I get
  *** REXPFactory unable to interpret  
 [EMAIL PROTECTED] *
  ** REXPFactory unable to interpret  
 [EMAIL PROTECTED]
  *** REXPFactory unable to interpret  
 [EMAIL PROTECTED]
  *** REXPFactory unable to interpret  
 [EMAIL PROTECTED]
  *** REXPFactory unable to interpret  
 [EMAIL PROTECTED] *
  ** REXPFactory unable to interpret  
 [EMAIL PROTECTED]


  How can I in general,force the unserialize to return a list?
 Saptarshi Guha | [EMAIL PROTECTED] | http://www.stat.purdue.edu/~sguha
 Marijuana is nature's way of saying, Hi!.





Saptarshi Guha | [EMAIL PROTECTED] | http://www.stat.purdue.edu/~sguha
An adequate bootstrap is a contradiction in terms.


[[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] chron and R 2.8

2008-11-30 Thread stephen sefick
Yes
chron 2.3-25
zoo 1.5-4
R 2.8
Mac OS X 10.5.5

Gabor I don't know how to start up another verison of R on the mac.  I
will figure this out, and get back to you (I can then test both of
them side by side).

other fast installation (version numbers from description files in R
2.7.2 directory)
chron 2.3-24
zoo 1.5-4
Mac OS X 10.5.5

thanks

Stephen

On Sat, Nov 29, 2008 at 10:19 AM, Gabor Grothendieck
[EMAIL PROTECTED] wrote:
 Are you using the same version of chron both times?

 On Sat, Nov 29, 2008 at 10:05 AM, stephen sefick [EMAIL PROTECTED] wrote:
 has anyone had problems with the upgrade to R 2.8 and chron date
 classes.  I have a large zoo object that has a chron index, and it is
 taking 5x or so longer to do the same calculation as with 2.7 if it
 doesn't fail.  I will provide anything necessary I am not entirely
 sure what ya'll would need if anything to try and reproduce the
 behavior.  I am using the package StreamMetabolism.
 thanks

 --
 Stephen Sefick

 Let's not spend our time and resources thinking about things that are
 so little or so large that all they really do for us is puff us up and
 make us feel like gods.  We are mammals, and have not exhausted the
 annoying little problems of being mammals.

-K. Mullis

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





-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] chron and R 2.8

2008-11-30 Thread Gabor Grothendieck
To run the old version of chron that you have under 2.7.2
into 2.8.0, on 2.7.2 issue the command (note initial dot):

.libPaths()

Suppose you find that the library that contains chron in
2.7.2 is /a/b.

Then on 2.8.0 ensure that you don't have chron on the search path

search()

and if you do detach it:

detach(package:chron)
search() # should no longer be there

Then run this where ... is the library that the old version of chron
is in under 2.7.2.

library(chron, lib = ...)

To run the new version of chron detach the old version and just use:

library(chron)


On Sun, Nov 30, 2008 at 9:14 PM, stephen sefick [EMAIL PROTECTED] wrote:
 Yes
 chron 2.3-25
 zoo 1.5-4
 R 2.8
 Mac OS X 10.5.5

 Gabor I don't know how to start up another verison of R on the mac.  I
 will figure this out, and get back to you (I can then test both of
 them side by side).

 other fast installation (version numbers from description files in R
 2.7.2 directory)
 chron 2.3-24
 zoo 1.5-4
 Mac OS X 10.5.5

 thanks

 Stephen

 On Sat, Nov 29, 2008 at 10:19 AM, Gabor Grothendieck
 [EMAIL PROTECTED] wrote:
 Are you using the same version of chron both times?

 On Sat, Nov 29, 2008 at 10:05 AM, stephen sefick [EMAIL PROTECTED] wrote:
 has anyone had problems with the upgrade to R 2.8 and chron date
 classes.  I have a large zoo object that has a chron index, and it is
 taking 5x or so longer to do the same calculation as with 2.7 if it
 doesn't fail.  I will provide anything necessary I am not entirely
 sure what ya'll would need if anything to try and reproduce the
 behavior.  I am using the package StreamMetabolism.
 thanks

 --
 Stephen Sefick

 Let's not spend our time and resources thinking about things that are
 so little or so large that all they really do for us is puff us up and
 make us feel like gods.  We are mammals, and have not exhausted the
 annoying little problems of being mammals.

-K. Mullis

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





 --
 Stephen Sefick

 Let's not spend our time and resources thinking about things that are
 so little or so large that all they really do for us is puff us up and
 make us feel like gods.  We are mammals, and have not exhausted the
 annoying little problems of being mammals.

-K. Mullis


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Randomization of a two-way ANOVA?

2008-11-30 Thread Mike Lawrence
The code below may not be the most optimized, but it should do the trick.
I've implemented the permutation test, which by some nomenclatures is
distinguished from the randomization test in that the latter is exhaustive
while the former is not.

I'm eager to hear the views of the list on whether the permutation test
fares when you use a parametric stat like the F as the focal statistic. I
know that David Howell introduction to the test employs the F (
http://www.uvm.edu/~dhowell/StatPages/Resampling/Resampling.html). I
personally think that in cases of known violation of normality and/or
homogeneity of variance, it seems odd to incorporate MSerror into the focal
statistic. I look forward to the list educating me if this view turns out to
be uninformed.

#make sure the factors are treated as such
FactorA = factor(FactorA)
FactorB = factor(FactorB)

#get the observed Fs
obs.aov = aov(Resp~FactorA*FactorB)
obs.mainA.F = summary(obs.aov)[[1]]$F[1]
obs.mainB.F = summary(obs.aov)[[1]]$F[2]
obs.AbyB.F = summary(obs.aov)[[1]]$F[3]

#prepare for the permutation loop
perms = 1e4
perm.mainA.F = rep(NA,perms)
perm.mainB.F = rep(NA,perms)
perm.AbyB.F = rep(NA,perms)

#run the permutation loop
for(i in 1:perms){
Randomized.Resp = Resp[order(runif(length(Resp)))]
perm.aov = aov(Randomized.Resp~FactorA*FactorB)
perm.mainA.F[i] = summary(perm.aov)[[1]]$F[1]
perm.mainB.F[i] = summary(perm.aov)[[1]]$F[2]
perm.AbyB.F[i] = summary(perm.aov)[[1]]$F[3]
}

#compute the p-values
p.mainA = mean(perm.mainA.Fobs.mainA.F)
p.mainB = mean(perm.mainB.Fobs.mainB.F)
p.AbyB = mean(perm.AbyB.Fobs.AbyB.F)

#print the p-values
print(p.mainA)
print(p.mainB)
print(p.AbyB)




-- 
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University
www.thatmike.com

Looking to arrange a meeting? Do so at:
http://www.timetomeet.info/with/mike/

~ Certainty is folly... I think. ~

[[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] Examples of advanced data visualization

2008-11-30 Thread Duncan Temple Lang



Hans W. Borchers wrote:

Dear R-help,

I am looking for ideas and presentations of new and advanced data visualization
methods. As an example of what I am searching for, the 'Many Eyes' pages at

http://manyeyes.alphaworks.ibm.com/manyeyes/

may provide a good paradigm. I would be interested even if it will not be easy
to implement such examples in R, e.g. because of the interactive nature of these
graphical displays.




A few days before your mail, I started putting together some
examples of using R and SVG/ECMAScript and R and 
Flash/Flex/MXML/ActionScript.


There are some examples of R graphics that provide interactivity in 
various forms and ways at


   http://www.omegahat.org/SVGAnnoation/tests/examples.html

(Most examples will work with Firefox, Opera is the most
comprehensive browser however for these examples.)

The Flex examples will take more time.


 D.



Please answer to my e-mail address. In case enough interesting material comes
up, I will enter a summary here.

Hans Werner Borchers
ABB Corporate Research

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


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


[R] How to make a banner table.

2008-11-30 Thread Andrew Choens
I have a dataframe with the following variables:

idnum   areagender  raceetc.

I would like to make a table that looks like

areagender  race
M  FB W A
1   4  53 5 1
2   6  74 6 3

etc.

Basically, I want to make a single broad table with a number of sub-set
tables. I have tried:

cbind(table(area, gender), table(area, race))

But, when I do this, I lose the labels gender / race. This makes it a
lot harder to understand my factor labels. when I use cbind, I get this:

M  F B W A
1 4  5 3 5 1
2 6  7 4 6 3

Although, it is technically correct, I really want to keep my factor
labels. I also tried this with xtabs and get the same results. Any
ideas? I saw a relatively recent thread asking a similar question, but
the proposed solution did not work for me, so I thought I would ask the
questions again.

If I am missing someting terribly obvious, I apologize.

thanks.


-- 
Insert something humorous here.  :-)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Examples of advanced data visualization

2008-11-30 Thread Duncan Temple Lang


Sorry for the need for a second mail, but the URL missed a 't'

  http://www.omegahat.org/SVGAnnotation/tests/examples.html

 ^

Duncan Temple Lang wrote:



Hans W. Borchers wrote:

Dear R-help,

I am looking for ideas and presentations of new and advanced data 
visualization
methods. As an example of what I am searching for, the 'Many Eyes' 
pages at


http://manyeyes.alphaworks.ibm.com/manyeyes/

may provide a good paradigm. I would be interested even if it will not 
be easy
to implement such examples in R, e.g. because of the interactive 
nature of these

graphical displays.




A few days before your mail, I started putting together some
examples of using R and SVG/ECMAScript and R and 
Flash/Flex/MXML/ActionScript.


There are some examples of R graphics that provide interactivity in 
various forms and ways at


   http://www.omegahat.org/SVGAnnoation/tests/examples.html

(Most examples will work with Firefox, Opera is the most
comprehensive browser however for these examples.)

The Flex examples will take more time.


 D.


Please answer to my e-mail address. In case enough interesting 
material comes

up, I will enter a summary here.

Hans Werner Borchers
ABB Corporate Research

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] explaining a model with rcs() terms

2008-11-30 Thread David Winsemius


On Nov 30, 2008, at 10:23 PM, Dylan Beaudette wrote:


Hi, I am using the rcs() function in the Design library to model
non-linearity that is not well characterized by an otherwise
mechanistic function. I am able to make the model 'available' to
others through the excellent nomogram() function and the set of tables
that it can create. However, I would like to present the model in an
'expanded' format-- probably what rcspline.restate() or latex.Design()
produce on a model fit object.

Here is how the model was fit:

fit.ols - ols( log(k) ~ (rcs(activity) * (log(conc) + sar)) +
(rcs(sand) * (log(conc) + sar)), data=sm.clean, x=TRUE, y=TRUE)

Here is how I am accessing the 'expanded' format of the model  
structure:


options(digits=3)
latex(fit.ols, file='fit_rcs.tex')

The output contains several notation elements that I am not familiar  
with:


1. x_{+}  -- it seems that this represent a term that should be set
to 0, when x is 0?


It is set to zero when the term inside the cubic is less than zero.  
See pages 20-21 of Harrell's book where the basis functions are  
described and illustrated.


i.e.  the entire expression   −453(activity −  
0.842)_{+}^{3}  = 0 when

'activity' = 0 ??


 whenever (activity − 0.842)  0





2. the '!x' found in :

+log(conc) [ −0.0118sand + 9.58
! ×
!10−6 (sand − 11.6)


My guess is that this is 9.58 x 10^-6


− 0.000128(sand − 37.5)
+0.00045(sand − 47.2)
− 0.000350(sand − 51)
+ 1.86
! ×
!10−5 (sand − 69.8) ]


I don't see anything like that in Harrell's text and I am wondering if  
a different character is getting rendering incorrectly. The only time  
you see it is when the exponent is below -4.







 what exactly does that mean?


An image version of the equation in question is attached.

Any input would be greatly appreciated!

Cheers,

Dylan
complex_equation.png__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 input a string without quote

2008-11-30 Thread Jinsong Zhao

Wow, you are so lazy... But sometimes R is just designed for lazy guys...

##
f = function(a) {
s = substitute(a)
as.character(s)
}
##


f(a = asdf)

[1] asdf

f(qwer)

[1] qwer


Regards,
Yihui
--
Yihui Xie [EMAIL PROTECTED]
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China



Thanks!

However,
 f(012345)
[1] 12345
 f(0123-X)
[1] -   123 X


I hope to get:
012345
0-123-X




On Sat, Nov 29, 2008 at 10:59 PM, Gabor Grothendieck
[EMAIL PROTECTED] wrote:

This works if you type it in from the R console:


s - readline()

this is my string


s

[1] this is my string




Thanks! readline() works for my situation.

Regards,
Jinsong

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 make a banner table.

2008-11-30 Thread Charles C. Berry

On Sun, 30 Nov 2008, Andrew Choens wrote:


I have a dataframe with the following variables:

idnum   areagender  raceetc.

I would like to make a table that looks like

areagender  race
M  FB W A
1   4  53 5 1
2   6  74 6 3

etc.

Basically, I want to make a single broad table with a number of sub-set
tables. I have tried:


Well you are asked to provide commented, minimal, self-contained, 
reproducible code, and I see nothing here I can reproduce.


But here is a start:


tab1 - xtabs(~agegp+tobgp,esoph)
tab2 - xtabs(~agegp+alcgp,esoph)
cat(paste(capture.output(tab1),capture.output(tab2),'\n'))

   tobgpalcgp
 agegp   0-9g/day 10-19 20-29 30+ agegp   0-39g/day 40-79 80-119 120+
   25-344 4 3   4   25-34 4 4  34
   35-444 4 4   3   35-44 4 4  43
   45-544 4 4   4   45-54 4 4  44
   55-644 4 4   4   55-64 4 4  44
   65-744 4 4   3   65-74 4 3  44
   75+  4 4 1   2   75+   3 4  22


It is left as an exercise to figure out how to redo the first line to move 
'alcgp' over '  0-3' and how to delete the redundant 'agegp; column. See


?nchar
?substring

and maybe

?sprintf

for some pointers.

HTH,

Chuck




cbind(table(area, gender), table(area, race))

But, when I do this, I lose the labels gender / race. This makes it a
lot harder to understand my factor labels. when I use cbind, I get this:

M  F B W A
1 4  5 3 5 1
2 6  7 4 6 3

Although, it is technically correct, I really want to keep my factor
labels. I also tried this with xtabs and get the same results. Any
ideas? I saw a relatively recent thread asking a similar question, but
the proposed solution did not work for me, so I thought I would ask the
questions again.

If I am missing someting terribly obvious, I apologize.

thanks.


--
Insert something humorous here.  :-)

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



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Attempting to get a STELLA model into R

2008-11-30 Thread Gibson, Tyler F
To whomever may be of help,

I am a student in a graduate modeling class at the University of North Carolina 
at Wilmington. I am trying to get a STELLA model converted into R. I am in the 
process of trying to 're-write' the script into R, but I seem to be missing 
pieces (i.e. parm values) that are keeping me from being able to replicate this 
model into R. Does anyone have an idea of a possible solution to my problem? 
Are there conversion programs or packages available that can convert STELLA 
models into R format?

Thank you very much for you time, and I hope to hear back from you soon.

-Tyler Gibson

[EMAIL PROTECTED]
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] factanal question

2008-11-30 Thread Don McNeil
Dear R users:
I'm wondering if it's possible to get the residual correlation matrix when 
using factanal.
Since factanal assumes that the errors are normally distributed and independent 
(provided the factor model fits the data) this would be useful. Of course you 
would need to submit the data to the function to get the residuals (not just 
their correlation matrix), but it should be possible to get the residual 
correlation matrix if only the data correlation matrix is provided.
Don McNeil

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] AIC function and Step function

2008-11-30 Thread Dana77

 Thanks for kind help from Steven and Christos last time.  Now I got new
problem regarding the codes for calculating the weights (w) in AIC ()
function. 
The original code is as below:
  getAnywhere(logLik.lm)
function (object, REML = FALSE, ...) 
  {
res - object$residuals
p - object$rank
N - length(res)
if (is.null(w - object$weights)) {
w - rep.int(1, N)
}else {
excl - w == 0
if (any(excl)) {
res - res[!excl]
N - length(res)
w - w[!excl]
}
}

 Now my question is, if I use lm() function to fit a multiple linear
regression model, such as mod.fit-lm(formula = Y~ X1 + X2 + X3, data =
set1), what code could I use to extract the weights (w) out? or how to
calculate the weights(w) shown in above codes? Thanks for your time and kind
help!

Dana



Steven McKinney wrote:
 
 Hi Dana,
 
 Many thanks to Christos Hatzis who sent
 me an offline response, pointing out the
 new functions that make this much
 easier than my last suggestions:
 methods() and getAnywhere()
 
 methods(extractAIC)
 [1] extractAIC.aov* extractAIC.coxph*   extractAIC.glm*
 extractAIC.lm*  extractAIC.negbin* 
 [6] extractAIC.survreg*
 
Non-visible functions are asterisked
 getAnywhere(extractAIC.coxph)
 A single object matching ‘extractAIC.coxph’ was found
 It was found in the following places
   registered S3 method for extractAIC from namespace stats
   namespace:stats
 with value
 
 function (fit, scale, k = 2, ...) 
 {
 edf - length(fit$coef)
 loglik - fit$loglik[length(fit$loglik)]
 c(edf, -2 * loglik + k * edf)
 }
 environment: namespace:stats
 
 
 Thank you Christos.
 
 
 That said, one of the advantages of getting
 the source code is that it has comments that
 are stripped out when the code is sourced into R
 
 e.g. from the command line
 
 getAnywhere(AIC.default)
 A single object matching ‘AIC.default’ was found
 It was found in the following places
   registered S3 method for AIC from namespace stats
   namespace:stats
 with value
 
 function (object, ..., k = 2) 
 {
 ll - if (stats4 %in% loadedNamespaces()) 
 stats4:::logLik
 else logLik
 if (length(list(...))) {
 object - list(object, ...)
 val - lapply(object, ll)
 val - as.data.frame(t(sapply(val, function(el) c(attr(el, 
 df), AIC(el, k = k)
 names(val) - c(df, AIC)
 Call - match.call()
 Call$k - NULL
 row.names(val) - as.character(Call[-1])
 val
 }
 else AIC(ll(object), k = k)
 }
 environment: namespace:stats
 
From the source file
 
 
 #  File src/library/stats/R/AIC.R
 #  Part of the R package, http://www.R-project.org
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
 #  the Free Software Foundation; either version 2 of the License, or
 #  (at your option) any later version.
 #
 #  This program is distributed in the hope that it will be useful,
 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #  GNU General Public License for more details.
 #
 #  A copy of the GNU General Public License is available at
 #  http://www.r-project.org/Licenses/
 
  Return the object's value of the Akaike Information Criterion
  (or An Inf.. Crit..)
 
 AIC - function(object, ..., k = 2) UseMethod(AIC)
 
 ## AIC for logLik objects
 AIC.logLik - function(object, ..., k = 2)
 -2 * c(object) + k * attr(object, df)
 
 AIC.default - function(object, ..., k = 2)
 {
 ## AIC for various fitted objects --- any for which there's a logLik()
 method:
 ll - if(stats4 %in% loadedNamespaces()) stats4:::logLik else logLik
 if(length(list(...))) {# several objects: produce data.frame
   object - list(object, ...)
   val - lapply(object, ll)
   val - as.data.frame(t(sapply(val,
 function(el)
 c(attr(el, df), AIC(el, k = k)
   names(val) - c(df, AIC)
 Call - match.call()
 Call$k - NULL
   row.names(val) - as.character(Call[-1])
   val
 } else AIC(ll(object), k = k)
 }
 
 
 
 Steven McKinney
 
 Statistician
 Molecular Oncology and Breast Cancer Program
 British Columbia Cancer Research Centre
 
 email: smckinney +at+ bccrc +dot+ ca
 
 tel: 604-675-8000 x7561
 
 BCCRC
 Molecular Oncology
 675 West 10th Ave, Floor 4
 Vancouver B.C. 
 V5Z 1L3
 Canada
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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://www.nabble.com/AIC-function-and-Step-function-tp20728043p20764062.html
Sent from the R help mailing 

Re: [R] Regex: workaround for variable length negative lookbehind

2008-11-30 Thread Wacek Kusnierczyk
Gabor Grothendieck wrote:
 Try this:

   
 vec - c(, baaa, bbaa, bbba, baamm, aa)
 

   
 grep(^(?!(.)\\1{1,}$).*(.)\\2{1,}$, vec, perl = TRUE)
 

or even

grep(^(?!(.)\\1+$).*(.)\\2+$, vec, perl = TRUE)


vQ

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


Re: [R] AIC function and Step function

2008-11-30 Thread Kingsford Jones
On Sun, Nov 30, 2008 at 5:05 PM, Dana77 [EMAIL PROTECTED] wrote:

  Thanks for kind help from Steven and Christos last time.  Now I got new
 problem regarding the codes for calculating the weights (w) in AIC ()
 function.
 The original code is as below:
   getAnywhere(logLik.lm)
 function (object, REML = FALSE, ...)
  {
res - object$residuals
p - object$rank
N - length(res)
if (is.null(w - object$weights)) {
w - rep.int(1, N)
}else {
excl - w == 0
if (any(excl)) {
res - res[!excl]
N - length(res)
w - w[!excl]
}
}

  Now my question is, if I use lm() function to fit a multiple linear
 regression model, such as mod.fit-lm(formula = Y~ X1 + X2 + X3, data =
 set1), what code could I use to extract the weights (w) out? or how to
 calculate the weights(w) shown in above codes?


mod.fit won't have weights because you didn't specify any through the
weights argument to lm.  If you had, you could extract them using the
same technique used in the above code:  w - mod.fit$weights

hth,

Kingsford Jones






 Thanks for your time and kind
 help!

 Dana



 Steven McKinney wrote:

 Hi Dana,

 Many thanks to Christos Hatzis who sent
 me an offline response, pointing out the
 new functions that make this much
 easier than my last suggestions:
 methods() and getAnywhere()

 methods(extractAIC)
 [1] extractAIC.aov* extractAIC.coxph*   extractAIC.glm*
 extractAIC.lm*  extractAIC.negbin*
 [6] extractAIC.survreg*

Non-visible functions are asterisked
 getAnywhere(extractAIC.coxph)
 A single object matching 'extractAIC.coxph' was found
 It was found in the following places
   registered S3 method for extractAIC from namespace stats
   namespace:stats
 with value

 function (fit, scale, k = 2, ...)
 {
 edf - length(fit$coef)
 loglik - fit$loglik[length(fit$loglik)]
 c(edf, -2 * loglik + k * edf)
 }
 environment: namespace:stats


 Thank you Christos.


 That said, one of the advantages of getting
 the source code is that it has comments that
 are stripped out when the code is sourced into R

 e.g. from the command line

 getAnywhere(AIC.default)
 A single object matching 'AIC.default' was found
 It was found in the following places
   registered S3 method for AIC from namespace stats
   namespace:stats
 with value

 function (object, ..., k = 2)
 {
 ll - if (stats4 %in% loadedNamespaces())
 stats4:::logLik
 else logLik
 if (length(list(...))) {
 object - list(object, ...)
 val - lapply(object, ll)
 val - as.data.frame(t(sapply(val, function(el) c(attr(el,
 df), AIC(el, k = k)
 names(val) - c(df, AIC)
 Call - match.call()
 Call$k - NULL
 row.names(val) - as.character(Call[-1])
 val
 }
 else AIC(ll(object), k = k)
 }
 environment: namespace:stats

From the source file


 #  File src/library/stats/R/AIC.R
 #  Part of the R package, http://www.R-project.org
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
 #  the Free Software Foundation; either version 2 of the License, or
 #  (at your option) any later version.
 #
 #  This program is distributed in the hope that it will be useful,
 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #  GNU General Public License for more details.
 #
 #  A copy of the GNU General Public License is available at
 #  http://www.r-project.org/Licenses/

  Return the object's value of the Akaike Information Criterion
  (or An Inf.. Crit..)

 AIC - function(object, ..., k = 2) UseMethod(AIC)

 ## AIC for logLik objects
 AIC.logLik - function(object, ..., k = 2)
 -2 * c(object) + k * attr(object, df)

 AIC.default - function(object, ..., k = 2)
 {
 ## AIC for various fitted objects --- any for which there's a logLik()
 method:
 ll - if(stats4 %in% loadedNamespaces()) stats4:::logLik else logLik
 if(length(list(...))) {# several objects: produce data.frame
   object - list(object, ...)
   val - lapply(object, ll)
   val - as.data.frame(t(sapply(val,
 function(el)
 c(attr(el, df), AIC(el, k = k)
   names(val) - c(df, AIC)
 Call - match.call()
 Call$k - NULL
   row.names(val) - as.character(Call[-1])
   val
 } else AIC(ll(object), k = k)
 }



 Steven McKinney

 Statistician
 Molecular Oncology and Breast Cancer Program
 British Columbia Cancer Research Centre

 email: smckinney +at+ bccrc +dot+ ca

 tel: 604-675-8000 x7561

 BCCRC
 Molecular Oncology
 675 West 10th Ave, Floor 4
 Vancouver B.C.
 V5Z 1L3
 Canada

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

Re: [R] Examples of advanced data visualization

2008-11-30 Thread Dieter Menne



Hans W. Borchers-4 wrote:
 
 Tom Backer Johnsen backer at psych.uib.no writes:
 
 I am also wondering if the R Wiki would be a better place to publish
 summaries
 on topics discussed here. On the mailing list, summaries are forgotten
 within
 one or two months time, only to be retrieved in specific searches.
 

I have tried this once with a subject I found interesting and buried under
too many quotes of previous mails:

http://wiki.r-project.org/rwiki/doku.php?id=guides:lmer-tests

Since the the reaction was mainly negative and legalese (you should ask
permission to quote other people) that I will never try this again.

Dieter

-- 
View this message in context: 
http://www.nabble.com/Examples-of-advanced-data-visualization-tp20736795p20767389.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.