Re: [R] [EXT] Re: Initializing vector and matrices

2024-02-29 Thread Eik Vettorazzi

Dear Steven,
I used "sample" just to generate a non-trivial example, you could insert 
your code of generating the real xi at this point :-)


If you want to stick to for-loops for some reasons, something like this 
could work


x<-NULL
for (i in 1:5){
   xi<-1:5
  if (is.null(x)) x<-xi else x<-x+xi
}


cheers

Am 29.02.2024 um 09:23 schrieb Steven Yen:

Hello Eik:

Thanks. I do not need to sample. Essentially, I have a do loop which 
produces 24 vectors of length of some length (say k=300) and 24 matrices 
of 300x300. Then, I simply need to  take the averages of these 24 
vectors and matrices:


x=(x1+x2+...+x24)/k

y=(y1+y2+...+y24)/k

I am just looking for ways to do this in a do loop, which requires 
initialization (to 0's) of x and y. My struggle is not knowning length 
of x until x1 is produced in the first of the loop. Thanks.


Steven

On 2/28/2024 6:22 PM, Eik Vettorazzi wrote:

Hi Steven,
It's not entirely clear what you actually want to achieve in the end.

As soon as you "know" x1, and assuming that the different "xi" do not 
differ in length in the real application, you know the length of the 
target vector.
Instead of the loop, you can use 'Reduce' without having to initialize 
a starting vector.


# generate sample vectors, put them in a list

xi<-lapply(1:5, \(x)sample(5))

# look at xi
xi

# sum over xi
Reduce("+",xi)

this works also for matrices

# generate sample matrices, put them in a list
Xi<-lapply(1:3, \(x)matrix(sample(16), nrow=4))

# look at them
Xi

# sum over Xi
Reduce("+",Xi)

Hope that helps

Eik


Am 28.02.2024 um 09:56 schrieb Steven Yen:
Is there as way to initialize a vector (matrix) with an unknown 
length (dimension)? NULL does not seem to work. The lines below work 
with a vector of length 4 and a matrix of 4 x 4. What if I do not 
know initially the length/dimension of the vector/matrix?


All I want is to add up (accumulate)  the vector and matrix as I go 
through the loop.


Or, are there other ways to accumulate such vectors and matrices?

 > x<-rep(0,4)  # this works but I like to leave the length open
 >  for (i in 1:3){
+  x1<-1:4
+  x<-x+x1
+ }
 > x
[1]  3  6  9 12

 > y = 0*matrix(1:16, nrow = 4, ncol = 4); # this works but I like to 
leave the dimension open

  [,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    0    0
[3,]    0    0    0    0
[4,]    0    0    0    0
 > for (i in 1:3){
+   y1<-matrix(17:32, nrow = 4, ncol = 4)
+   y<-y+y1
+ }
 > y
  [,1] [,2] [,3] [,4]
[1,]   51   63   75   87
[2,]   54   66   78   90
[3,]   57   69   81   93
[4,]   60   72   84   96
 >

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

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




--
Eik Vettorazzi

Universitätsklinikum Hamburg-Eppendorf
Institut für Medizinische Biometrie und Epidemiologie

Christoph-Probst-Weg 1
4. Obergeschoss, Raum 04.1.021.1

20246 Hamburg

Telefon: +49 (0) 40 7410 - 58243
Fax: +49 (0) 40 7410 - 57790

Web: www.uke.de/imbe

Webex: https://webteaching-uke.webex.com/meet/e.vettorazzi


--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Christian Gerloff (Vorsitzender), Joachim Prölß, 
Prof. Dr. Blanche Schwappach-Pignataro, Matthias Waldmann (komm.)
_

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


Re: [R] [EXT] Initializing vector and matrices

2024-02-28 Thread Eik Vettorazzi

Hi Steven,
It's not entirely clear what you actually want to achieve in the end.

As soon as you "know" x1, and assuming that the different "xi" do not 
differ in length in the real application, you know the length of the 
target vector.
Instead of the loop, you can use 'Reduce' without having to initialize a 
starting vector.


# generate sample vectors, put them in a list

xi<-lapply(1:5, \(x)sample(5))

# look at xi
xi

# sum over xi
Reduce("+",xi)

this works also for matrices

# generate sample matrices, put them in a list
Xi<-lapply(1:3, \(x)matrix(sample(16), nrow=4))

# look at them
Xi

# sum over Xi
Reduce("+",Xi)

Hope that helps

Eik


Am 28.02.2024 um 09:56 schrieb Steven Yen:
Is there as way to initialize a vector (matrix) with an unknown length 
(dimension)? NULL does not seem to work. The lines below work with a 
vector of length 4 and a matrix of 4 x 4. What if I do not know 
initially the length/dimension of the vector/matrix?


All I want is to add up (accumulate)  the vector and matrix as I go 
through the loop.


Or, are there other ways to accumulate such vectors and matrices?

 > x<-rep(0,4)  # this works but I like to leave the length open
 >  for (i in 1:3){
+  x1<-1:4
+  x<-x+x1
+ }
 > x
[1]  3  6  9 12

 > y = 0*matrix(1:16, nrow = 4, ncol = 4); # this works but I like to 
leave the dimension open

  [,1] [,2] [,3] [,4]
[1,]    0    0    0    0
[2,]    0    0    0    0
[3,]    0    0    0    0
[4,]    0    0    0    0
 > for (i in 1:3){
+   y1<-matrix(17:32, nrow = 4, ncol = 4)
+   y<-y+y1
+ }
 > y
  [,1] [,2] [,3] [,4]
[1,]   51   63   75   87
[2,]   54   66   78   90
[3,]   57   69   81   93
[4,]   60   72   84   96
 >

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

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


--
Eik Vettorazzi

Universitätsklinikum Hamburg-Eppendorf
Institut für Medizinische Biometrie und Epidemiologie

Christoph-Probst-Weg 1
4. Obergeschoss, Raum 04.1.021.1

20246 Hamburg

Telefon: +49 (0) 40 7410 - 58243
Fax: +49 (0) 40 7410 - 57790

Web: www.uke.de/imbe

Webex: https://webteaching-uke.webex.com/meet/e.vettorazzi


--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Christian Gerloff (Vorsitzender), Joachim Prölß, 
Prof. Dr. Blanche Schwappach-Pignataro, Matthias Waldmann (komm.)
_

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


Re: [R] Decompose df1 into another df2 based on values in df1

2021-05-27 Thread Eik Vettorazzi

A tidyverse-ish solution would be

library(dplyr)
library(tidyr)
library(tibble)

# max cols to split values into
seps<-max(stringr::str_count(unlist(d1),"[/|]"))+1

d1 %>% pivot_longer(S1:S5, names_to="S") %>% 
mutate(value=na_if(value,"w")) %>% separate(value,"[/|]", 
into=LETTERS[1:seps], fill="right") %>% pivot_longer(-S, names_to=NULL, 
values_to="rownames") %>% filter(!is.na(rownames)) %>% 
mutate(index=1L)%>%pivot_wider(names_from=S, values_from=index) %>% 
mutate_all(replace_na,0L) %>% column_to_rownames(var = "rownames")


Best, Eik

Am 26.05.2021 um 23:16 schrieb Adrian Johnson:

Hello,

I am trying to convert a df (given below as d1) into df2 (given below as
res).

  I tried using loops for each row. I cannot get it right.  Moreover the df
is 25 x 500 in dimension and I cannot get it to work.

Could anyone help me here please.

Thanks.
Adrian.

d1 <-
structure(list(S1 = c("a1|a2", "b1|b3", "w"), S2 = c("w", "b1",
"c2"), S3 = c("a2", "b3|b4|b1", "c1|c4"), S4 = c("w", "b4", "c4"
), S5 = c("a2/a3", "w", "w")), class = "data.frame", row.names = c("A",
"B", "C"))

res <-
structure(list(S1 = c(1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L),
 S2 = c(0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L), S3 = c(0L,
 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L), S4 = c(0L, 0L, 0L, 0L,
 0L, 0L, 1L, 0L, 0L, 1L), S5 = c(0L, 1L, 1L, 0L, 0L, 0L, 0L,
 0L, 0L, 0L)), class = "data.frame", row.names = c("a1", "a2",
"a3", "b1", "b2", "b3", "b4", "c1", "c2", "c4"))

[[alternative HTML version deleted]]

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






--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Joachim Prölß, 
Prof. Dr. Blanche Schwappach-Pignataro, Marya Verdel
_

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


Re: [R] geom_ribbon function in ggplot2 package

2018-12-19 Thread Eik Vettorazzi

Hi,
just add +scale_fill_discrete(name=NULL)

Cheers

Am 19.12.2018 um 07:05 schrieb John:

Hi,

When using the geom_ribbon function in gglot2 package, I got the text
"fill" above the legend "A" and "B". How can I get rid of the text "fill"
above the legend?

Thanks!

The code is as follows:


df<-data.frame(x=c(1,2), y=c(1,2), z=c(3,5))

ggplot(df,

aes(1:2))+geom_ribbon(aes(ymin=0,ymax=df[,"y"],fill="A"),alpha=0.5)+geom_ribbon(aes(ymin=0,ymax=df[,"z"],fill="B"),alpha=0.5)

[[alternative HTML version deleted]]

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



--
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Marya Verdel
_

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


Re: [R] system solver in R

2018-11-20 Thread Eik Vettorazzi

How about this:

library(rootSolve)
f1<-function(x)5/((1+x)^1) + 5/((1+x)^2) + 5/((1+x)^3) + 105/((1+x)^4) -105
uniroot.all( f1,c(-1e6,1e6))

[1] -1.9881665  0.0363435

Cheers


Am 20.11.2018 um 13:09 schrieb Engin Yılmaz:

Dea(R)
I try to solve one equation but this program did not give me real roots
for example
yacas("Solve( 5/((1+x)^1) + 5/((1+x)^2) + 5/((1+x)^3) + 105/((1+x)^4) -105
==0, x)")
gave me following results
How can I find real roots?

expression(list(x == complex_cartesian((1/42 - ((1/63 -
((root(7339451281/3087580356,
 2) - 4535/71442)^(1/3) - (4535/71442 + root(7339451281/3087580356,
 2))^(1/3)))/21 - -2/21)/(4 * root(((root(7339451281/3087580356,
 2) - 4535/71442)^(1/3) - (4535/71442 + root(7339451281/3087580356,
 2))^(1/3) - 1/63)^2/4 + 1, 2)))/2 - 1, root(4 *
(((root(7339451281/3087580356,
 2) - 4535/71442)^(1/3) - (4535/71442 + root(7339451281/3087580356,
 2))^(1/3) - 1/63)/2 + root(((root(7339451281/3087580356,
 2) - 4535/71442)^(1/3) - (4535/71442 + root(7339451281/3087580356,
 2))^(1/3) - 1/63)^2/4 + 1, 2)) - (((1/63 -
((root(7339451281/3087580356,
 2) - 4535/71442)^(1/3) - (4535/71442 + root(7339451281/3087580356,
 2))^(1/3)))/21 - -2/21)/(4 * root(((root(7339451281/3087580356,
 2) - 4535/71442)^(1/3) - (4535/71442 + root(7339451281/3087580356,
 2))^(1/3) - 1/63)^2/4 + 1, 2)) - 1/42)^2, 2)/2),...more




Engin Yılmaz , 20 Kas 2018 Sal, 12:53 tarihinde şunu
yazdı:


Thanks a lot!

Berend Hasselman , 20 Kas 2018 Sal, 12:02 tarihinde şunu
yazdı:




R package Ryacas may be what you want.

Berend



On 20 Nov 2018, at 09:42, Engin Yılmaz  wrote:

Dea(R)

Do you know any system solver in R ?

For example, in matlab, is very easy

syms a b c x eqn = a*x^2 + b*x + c == 0; sol = solve(eqn)

How can I  find this type code in R (or directly solver)?

*Since(R)ely*
Engin YILMAZ

   [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide

http://www.R-project.org/posting-guide.html

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





--
*Saygılarımla*
Engin YILMAZ






--
Eik Vettorazzi

Universitätsklinikum Hamburg-Eppendorf
Institut für Medizinische Biometrie und Epidemiologie

Martinistraße 52
Gebäude W 34
20246 Hamburg

Telefon: +49 (0) 40 7410 - 58243
Fax: +49 (0) 40 7410 - 57790

Web: www.uke.de/imbe


--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Marya Verdel
_

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


Re: [R] Reporting binomial logistic regression from R results

2018-11-12 Thread Eik Vettorazzi

Dear Jedi,
please use the source carefully. A and C are not statistically different 
at the 5% level, which can be inferred from glm output. Your last two 
wald.tests don't test what you want to, since your model contains an 
intercept term. You specified contrasts which tests A vs B-A, ie A- 
(B-A)==0 <-> 2*A-B==0 which is not intended I think. Have a look at 
?contr.treatment and re-read your source doc to get an idea what dummy 
coding and indicatr variables are about.


Cheers


Am 12.11.2018 um 02:07 schrieb Frodo Jedi:

Dear list members,
I need some help in understanding whether I am doing correctly a binomial
logistic regression and whether I am interpreting the results in the
correct way. Also I would need an advice regarding the reporting of the
results from the R functions.

I want to report the results of a binomial logistic regression where I want
to assess difference between the 3 levels of a factor (called System) on
the dependent variable (called Response) taking two values, 0 and 1. My
goal is to understand if the effect of the 3 systems (A,B,C) in System
affect differently Response in a significant way. I am basing my analysis
on this URL: https://stats.idre.ucla.edu/r/dae/logit-regression/

This is the result of my analysis:


fit <- glm(Response ~ System, data = scrd, family = "binomial")
summary(fit)


Call:
glm(formula = Response ~ System, family = "binomial", data = scrd)

Deviance Residuals:
 Min   1Q   Median   3Q  Max
-2.8840   0.1775   0.2712   0.2712   0.5008

Coefficients:
  Estimate Std. Error z value Pr(>|z|)
(Intercept)3.2844 0.2825  11.626  < 2e-16 ***
SystemB  -1.2715 0.3379  -3.763 0.000168 ***
SystemC0.8588 0.4990   1.721 0.085266 .
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

 Null deviance: 411.26  on 1023  degrees of freedom
Residual deviance: 376.76  on 1021  degrees of freedom
AIC: 382.76

Number of Fisher Scoring iterations: 6
Following this analysis I perform the wald test in order to understand
whether there is an overall effect of System:

library(aod)


wald.test(b = coef(fit), Sigma = vcov(fit), Terms = 1:3)

Wald test:
--

Chi-squared test:
X2 = 354.6, df = 3, P(> X2) = 0.0
The chi-squared test statistic of 354.6, with 3 degrees of freedom is
associated with a p-value < 0.001 indicating that the overall effect of
System is statistically significant.

Now I check whether there are differences between the coefficients using
again the wald test:

# Here difference between system B and C:


l <- cbind(0, 1, -1)
wald.test(b = coef(fit), Sigma = vcov(fit), L = l)

Wald test:
--

Chi-squared test:
X2 = 22.3, df = 1, P(> X2) = 2.3e-06



# Here difference between system A and C:


l <- cbind(1, 0, -1)
wald.test(b = coef(fit), Sigma = vcov(fit), L = l)

Wald test:
--

Chi-squared test:
X2 = 12.0, df = 1, P(> X2) = 0.00052



# Here difference between system A and B:


l <- cbind(1, -1, 0)
wald.test(b = coef(fit), Sigma = vcov(fit), L = l)

Wald test:
--

Chi-squared test:
X2 = 58.7, df = 1, P(> X2) = 1.8e-14

My understanding is that from this analysis I can state that the three
systems lead to a significantly different Response. Am I right? If so, how
should I report the results of this analysis? What is the correct way?


Thanks in advance

Best wishes

FJ

[[alternative HTML version deleted]]

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



--
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Marya Verdel
_

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


Re: [R] Genuine relative paths with R

2018-10-08 Thread Eik Vettorazzi

Dear Olivier,
you may find the rprojroot package useful, see
https://github.com/r-lib/rprojroot

and a discussion

https://gist.github.com/jennybc/362f52446fe1ebc4c49f#file-2014-10-12_stop-working-directory-insanity-md

Cheers

Am 06.10.2018 um 13:48 schrieb Olivier GIVAUDAN:

Dear R users,

I would like to work with genuine relative paths in R for obvious reasons: if I 
move all my scripts related to some project as a whole to another location of 
my computer or someone else's computer, if want my scripts to continue to run 
seamlessly.

What I mean by "genuine" is that it should not be necessary to hardcode one single 
absolute path (making the code obviously not "portable" - to another place - anymore).

For the time being, I found the following related posts, unfortunately never 
conclusive or even somewhat off-topic:
https://stackoverflow.com/questions/1815606/rscript-determine-path-of-the-executing-script
https://stackoverflow.com/questions/47044068/get-the-path-of-current-script/47045368
http://r.789695.n4.nabble.com/Script-auto-detecting-its-own-path-td2719676.html

So I found 2 workarounds, more or less satisfactory:


   1.  Either create a variable "ScriptPath" in the first lines of each of my R scripts and run a batch 
(or shell, etc.) to replace every single occurrence of "ScriptPath <-" by "ScriptPath <- 
[Absolute path of the R script]" in all the R scripts located in the folder (and possibly subfolders) of the 
batch file.
   2.  Or create an R project file with RStudio and use the package "here" to 
get the absolute path of the R project file and put all the R scripts related to this 
project in the R project directory, as often recommended.

But I am really wondering why R doesn't have (please tell me if I'm wrong) this 
basic feature as many other languages have it (batch, shell, C, LaTeX, SAS with 
macro-variables, etc.)?
Do you know whether the language will have this kind of function in a near 
future? What are the obstacles / what is the reasoning for not having it 
already?

Do you know other workarounds?

Best regards,

Olivier

[[alternative HTML version deleted]]

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



--
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

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


Re: [R] aggregate and list elements of variables in data.frame

2018-06-08 Thread Eik Vettorazzi
Hi,
if you are willing to use dplyr, you can do all in one line of code:

library(dplyr)
df<-data.frame(id=1:10,A=c(123,345,123,678,345,123,789,345,123,789))

df%>%group_by(unique_A=A)%>%summarise(list_id=paste(id,collapse=", "))->r

cheers


Am 06.06.2018 um 10:13 schrieb Massimo Bressan:
> #given the following reproducible and simplified example 
> 
> t<-data.frame(id=1:10,A=c(123,345,123,678,345,123,789,345,123,789)) 
> t 
> 
> #I need to get the following result 
> 
> r<-data.frame(unique_A=c(123, 345, 678, 
> 789),list_id=c('1,3,6,9','2,5,8','4','7,10')) 
> r 
> 
> # i.e. aggregate over the variable "A" and list all elements of the variable 
> "id" satisfying the criteria of having the same corrisponding value of "A" 
> #any help for that? 
> 
> #so far I've just managed to "aggregate" and "count", like: 
> 
> library(sqldf) 
> sqldf('select count(*) as count_id, A as unique_A from t group by A') 
> 
> library(dplyr) 
> t%>%group_by(unique_A=A) %>% summarise(count_id = n()) 
> 
> # thank you 
> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

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


Re: [R] Plot in real unit (1:1)

2018-06-07 Thread Eik Vettorazzi
How about this:

in2mm<-25.4 # scale factor to convert inches to mm

pdf("test.pdf",width=8.3,height=11.7)
pin<-par("pin")
plot(c(0,pin[1]*in2mm),c(0,pin[2]*in2mm), type="n", xaxs="i", yaxs="i")
lines(c(10,10),c(0,10))
text(11,5,"1 cm", adj=0)

lines(c(0,40),c(20,20))
text(20,24,"4 cm")

polygon(c(50,50,70,70),c(50,70,70,50))
text(60,60,"2x2 cm")
dev.off()

cheers

Am 06.06.2018 um 16:00 schrieb Christian Brandstätter:
> Dear List, 
> 
> Is it possible to plot in R in "real" units? I would like to draw a
> plot on A4 paper, where 1 plot unit would be a mm in reality. Is
> something like that possible? I would also like to be able to scale the
> plot in x and y direction. 
> Background: For a project I would have to draw around 65 fast sketches
> of elevation courves. 
> 
> Copied from here, due to no answer: https://stackoverflow.com/questions
> /50606797/plot-in-real-units-mm
> 
> Thank you!
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

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


Re: [R] Problem with regression line

2018-04-18 Thread Eik Vettorazzi
Hi Anne,
I would suggest to change the linear model to lm(BloodPressure~Age), as
this model makes more sense in biological means (you would assume that
age influences pressure, not vice versa) and also obeys the statistical
assumption of weak exogeneity, that age can be measured without error,
at least compared to error-prone bp measures.

Cheers

Am 18.04.2018 um 16:07 schrieb Gerrit Eichner:
> Hi, Anne,
> 
> assign Age and Bloodpressure in the correct order
> to the axes in your call to plot as in:
> 
> plot(y = Age, x = BloodPressure)
> abline(SimpleLinearReg1)
> 
> 
>  Hth  --  Gerrit
> 
> -
> Dr. Gerrit Eichner   Mathematical Institute, Room 212
> gerrit.eich...@math.uni-giessen.de   Justus-Liebig-University Giessen
> Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
> http://www.uni-giessen.de/eichner
> -
> 
> 
> Am 18.04.2018 um 15:26 schrieb CHATTON Anne via R-help:
>> Hello,
>>
>> I am trying to graph a regression line using the followings:
>>
>> Age <- c(39, 47, 45, 47, 65, 46, 67, 42, 67, 56, 64, 56, 59, 34, 42,
>> 48, 45,
>> 17, 20, 19, 36, 50, 39, 21, 44, 53, 63, 29, 25, 69)
>> BloodPressure <- c(144, 220, 138, 145, 162, 142, 170, 124, 158, 154, 162,
>> 150, 140, 110, 128, 130, 135, 114, 116, 124, 136, 142, 120, 120, 160,
>> 158,
>> 144, 130, 125, 175)
>> SimpleLinearReg1=lm(Age ~ BloodPressure)
>> summary(SimpleLinearReg1)
>> eq = paste0("y = ", round(coeff[2],1), "*x ", round(coeff[1],1))
>> plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue",
>> main = eq, xlab = "Age (Year)", ylab = "Blood Pressure (mmHg)")
>> abline(SimpleLinearReg1, col="red")
>> mean(Age)
>> mean(BloodPressure)
>> abline(h=142.53, col="green")
>> abline(v=45.13, col="green")
>>
>> But I cannot get the regression line. Can anybody tell me what's wrong
>> with the codes ? I would appreciate very much. Thanks for any help.
>>
>> Anne
>>
>> [[alternative HTML version deleted]]
>>
>> __________
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

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


Re: [R] Calculate LC50

2018-02-22 Thread Eik Vettorazzi
Have a look at the drc-package.

btw. a linear model does not fit your data very well.

Cheers.


Am 22.02.2018 um 08:20 schrieb AbouEl-Makarim Aboueissa:
> Dear All: good morning
> 
> 
> I need helps with the calculation of the *LC50*  from the data below
> 
> 
> x<-c(0,0.3,0.7,1,4,10)
> y<-c(100,86,65,51.3,19.2,7.4)
> 
> yxreg<-lm(y~x)
> 
> 
> any help will be highly appreciated.
> 
> 
> with many thanks
> abou
> __
> 
> 
> *AbouEl-Makarim Aboueissa, PhD*
> 
> *Professor of Statistics*
> 
> *Department of Mathematics and Statistics*
> *University of Southern Maine*
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

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


Re: [R] outlining (highlighting) pixels in ggplot2

2017-12-20 Thread Eik Vettorazzi
just add

limits=c(-zmax1,zmax1)

to the scale_fill_gradient2-call

hth


Am 20.12.2017 um 18:21 schrieb Morway, Eric:
> I apprecaite the guidance Eik, that works great!  I'm also wondering if
> you have any pointers for how I might stretch the color scale so that
> the max and min values are the same?  Right now, the min is -0.064 and
> the max is something closer to 0.04.  As you can see in what I sent, I
> tried adding:
> 
> zmax1 = max(abs(m1))
> 
> ggplot(..., autoscale = FALSE, zmin = -1 * zmax1, zmax = zmax1) + ...
> 
> to ggplot, but I'm either using the wrong arguments or have not added
> them to the correct spot.  I haven't been able to find the fix for this
> and would very much appreciate any further guidance you can offer for
> this last fix.  

-- 
Eik Vettorazzi

Universitätsklinikum Hamburg-Eppendorf
Institut für Medizinische Biometrie und Epidemiologie

Martinistraße 52
Gebäude W 34
20246 Hamburg

Telefon: +49 (0) 40 7410 - 58243
Fax: +49 (0) 40 7410 - 57790

Web: www.uke.de/imbe


--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

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

Re: [R] outlining (highlighting) pixels in ggplot2

2017-12-20 Thread Eik Vettorazzi
Hi Eric,
you can use an annotate-layer, eg

ind<-which(sig>0,arr.ind = T)
ggplot(m1.melted, aes(x = Month, y = Site, fill = Concentration), autoscale
   = FALSE, zmin = -1 * zmax1, zmax = zmax1) +
  geom_tile() +
  coord_equal() +
  scale_fill_gradient2(low = "darkred",
   mid = "white",
   high = "darkblue",
   midpoint = 0)
+annotate("rect",ymin=ind[,"row"]-.5,ymax=.5+ind[,"row"],
xmin=-.5+ind[,"col"],xmax=.5+ind[,"col"],colour="red", size=.5,
linetype=1, fill=NA)


Cheers

Am 20.12.2017 um 01:32 schrieb Morway, Eric:
> library(ggplot2)
> library(RColorBrewer)
> library(reshape2)
> 
> m1 <- matrix(c(
> -0.0024, -0.0031, -0.0021, -0.0034, -0.0060, -1.00e-02, -8.47e-03, -0.0117,
> -0.0075, -0.0043, -0.0026, -0.0021,
> -0.0015, -0.0076, -0.0032, -0.0105, -0.0107, -2.73e-02, -3.37e-02, -0.0282,
> -0.0149, -0.0070, -0.0046, -0.0039,
> -0.0121, -0.0155, -0.0203, -0.0290, -0.0330, -3.19e-02, -1.74e-02, -0.0103,
> -0.0084, -0.0180, -0.0162, -0.0136,
> -0.0073, -0.0053, -0.0050, -0.0058, -0.0060, -4.38e-03, -2.21e-03, -0.0012,
> -0.0026, -0.0026, -0.0034, -0.0073,
> -0.0027, -0.0031, -0.0054, -0.0069, -0.0071, -6.28e-03, -2.88e-03, -0.0014,
> -0.0031, -0.0037, -0.0030, -0.0027,
> -0.0261, -0.0223, -0.0216, -0.0293, -0.0327, -3.17e-02, -1.77e-02, -0.0084,
> -0.0059, -0.0060, -0.0120, -0.0157,
>  0.0045,  0.0006, -0.0031, -0.0058, -0.0093, -9.20e-03, -6.76e-03,
> -0.0033,  0.0002,  0.0045,  0.0080,  0.0084,
> -0.0021, -0.0018, -0.0020, -0.0046, -0.0080, -2.73e-03,  7.43e-04,  0.0004,
> -0.0010, -0.0017, -0.0022, -0.0024,
> -0.0345, -0.0294, -0.0212, -0.0194, -0.0192, -2.25e-02, -2.05e-02, -0.0163,
> -0.0179, -0.0213, -0.0275, -0.0304,
> -0.0034, -0.0038, -0.0040, -0.0045, -0.0059, -1.89e-03,  6.99e-05, -0.0050,
> -0.0114, -0.0112, -0.0087, -0.0064,
> -0.0051, -0.0061, -0.0052, -0.0035,  0.0012, -7.41e-06, -3.43e-03, -0.0055,
> -0.0020,  0.0016, -0.0024, -0.0069,
> -0.0061, -0.0068, -0.0089, -0.0107, -0.0104, -7.65e-03,  2.43e-03,  0.0008,
> -0.0006, -0.0014, -0.0021, -0.0057,
>  0.0381,  0.0149, -0.0074, -0.0302, -0.0550, -6.40e-02, -5.28e-02, -0.0326,
> -0.0114,  0.0121,  0.0367,  0.0501,
> -0.0075, -0.0096, -0.0123, -0.0200, -0.0288, -2.65e-02, -2.08e-02, -0.0176,
> -0.0146, -0.0067, -0.0038, -0.0029,
> -0.0154, -0.0162, -0.0252, -0.0299, -0.0350, -3.40e-02, -2.51e-02, -0.0172,
> -0.0139, -0.0091, -0.0119, -0.0156),
>   nrow = 15, ncol = 12, byrow=TRUE,
>   dimnames = list(rev(c("TH1", "IN1", "IN3", "GL1", "LH1", "ED9", "TC1",
> "TC2", "TC3", "UT1", "UT3", "UT5", "GC1", "BC1", "WC1")),
>   c(format(seq(as.Date('2000-10-01'),
> as.Date('2001-09-30'), by='month'), "%b"
> 
> # palette definition
> palette <- colorRampPalette(c("darkblue", "blue", "white", "red",
> "darkred"))
> 
> # find max stretch value
> zmax1 = max(abs(m1))
> 
> m1.melted <- melt(m1)
> names(m1.melted) <- c('Site','Month', 'Concentration')
> 
> # Set up an example matrix with binary code for which results (pixels) are
> significant
> set.seed(4004)
> sig <- matrix(round(abs(rnorm(15*12)/3)), nrow = 15, ncol = 12)
> 
> ggplot(m1.melted, aes(x = Month, y = Site, fill = Concentration), autoscale
> = FALSE, zmin = -1 * zmax1, zmax = zmax1) +
>   geom_tile() +
>   coord_equal() +
>   scale_fill_gradient2(low = "darkred",
>mid = "white",
>high = "darkblue",
>midpoint = 0)

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

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

Re: [R] YNT: ggtern and bquote...

2017-12-04 Thread Eik Vettorazzi
t; information by a person other than the intended recipient is unauthorized and 
> may be illegal. In this case, please immediately notify the sender and delete 
> it from your system. Anadolu University does not guarantee the accuracy or 
> completeness of any information included in this message. Therefore, by any 
> means Anadolu University is not responsible for the content of the message, 
> and the transmission, reception, storage, and use of the information. The 
> opinions expressed in this message only belong to the sender of it and may 
> not reflect the opinions of Anadolu University.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistrasse 52
building W 34
20246 Hamburg

Phone: +49 (0) 40 7410 - 58243
Fax:   +49 (0) 40 7410 - 57790
Web: www.uke.de/imbe
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Martina Saurin (komm.)
_

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

Re: [R] unique identifier for number sequence

2015-11-23 Thread Eik Vettorazzi
cumsum(c(x[1],pmax(0,diff(x*x

Am 23.11.2015 um 15:59 schrieb PIKAL Petr:
> Dear all
> 
> I have a vector ones and zeroes like that
> x<-c(rep(0,5), rep(1,5), rep(0,10), rep(1,8))
> 
> and I need to get result like that
> x.i<-c(rep(0,5), rep(1,5), rep(0,10), rep(2,8))
> 
> It means I need an unique identifier for each sequence of ones.
> 
> It probably can be done by rle, cumsum and some fiddling with data but maybe 
> there is some clever way which I overlooked.
> 
> Cheers
> Petr
> 
> 
> 
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou 
> určeny pouze jeho adresátům.
> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
> jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
> svého systému.
> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
> jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
> zpožděním přenosu e-mailu.
> 
> V případě, že je tento e-mail součástí obchodního jednání:
> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, 
> a to z jakéhokoliv důvodu i bez uvedení důvodu.
> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
> Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany 
> příjemce s dodatkem či odchylkou.
> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
> dosažením shody na všech jejích náležitostech.
> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
> žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
> pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu 
> případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je 
> adresátovi či osobě jím zastoupené známá.
> 
> This e-mail and any documents attached to it may be confidential and are 
> intended only for its intended recipients.
> If you received this e-mail by mistake, please immediately inform its sender. 
> Delete the contents of this e-mail with all attachments and its copies from 
> your system.
> If you are not the intended recipient of this e-mail, you are not authorized 
> to use, disseminate, copy or disclose this e-mail in any manner.
> The sender of this e-mail shall not be liable for any possible damage caused 
> by modifications of the e-mail or by delay with transfer of the email.
> 
> In case that this e-mail forms part of business dealings:
> - the sender reserves the right to end negotiations about entering into a 
> contract in any time, for any reason, and without stating any reasoning.
> - if the e-mail contains an offer, the recipient is entitled to immediately 
> accept such offer; The sender of this e-mail (offer) excludes any acceptance 
> of the offer on the part of the recipient containing any amendment or 
> variation.
> - the sender insists on that the respective contract is concluded only upon 
> an express mutual agreement on all its aspects.
> - the sender of this e-mail informs that he/she is not authorized to enter 
> into any contracts on behalf of the company except for cases in which he/she 
> is expressly authorized to do so in writing, and such authorization or power 
> of attorney is submitted to the recipient or the person represented by the 
> recipient, or the existence of such authorization is known to the recipient 
> of the person represented by the recipient.
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

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

Re: [R] doubt with Odds ratio - URGENT HELP NEEDED

2015-09-24 Thread Eik Vettorazzi
>>>
>>>> I can’t get the OR and OR CI :(
>>>>
>>>>
>>>> *DATA:*
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Best,
>>>>
>>>> RO
>>>>
>>>>
>>>>
>>>>
>>>> Atenciosamente,
>>>> Rosa Oliveira
>>>>
>>>> -- 
>>>> 
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Rosa Celeste dos Santos Oliveira,
>>>>
>>>> E-mail:rosit...@gmail.com <http://gmail.com>
>>>> <mailto:rosit...@gmail.com>
>>>> Tlm: +351 939355143
>>>> Linkedin: https://pt.linkedin.com/in/rosacsoliveira
>>>> 
>>>>
>>>> "Many admire, few know"
>>>> Hippocrates
>>>>
>>>>> On 23 Sep 2015, at 12:02, Michael Dewey <li...@dewey.myzen.co.uk
>>>>> <mailto:li...@dewey.myzen.co.uk>
>>>>> <mailto:li...@dewey.myzen.co.uk>> wrote:
>>>>>
>>>>> Dear Rosa
>>>>>
>>>>> It would help if you posted the error messages where they occur so
>>>>> that we can see which of your commands caused which error. However see
>>>>> comment inline below.
>>>>>
>>>>> On 22/09/2015 22:17, Rosa Oliveira wrote:
>>>>>> Dear all,
>>>>>>
>>>>>>
>>>>>> I’m trying to compute Odds ratio and OR confidence interval.
>>>>>>
>>>>>> I’m really naive, sorry for that.
>>>>>>
>>>>>>
>>>>>> I attach my data and my code.
>>>>>>
>>>>>> I’m having lots of errors:
>>>>>>
>>>>>> 1. Error in data.frame(tas1 = tas.data$tas_d2, tas2 =
>>>>>> tas.data$tas_d3, tas3 = tas.data$tas_d4,  :
>>>>>>  arguments imply differing number of rows: 90, 0
>>>>>>
>>>>>
>>>>> At least one of tas_d2, tas_d3, tas_d4 does not exist
>>>>>
>>>>> I suggest fixing that one and hoping the rest go away.
>>>>>
>>>>>> 2. Error in data.frame(tas = c(unlist(tas.data[, -8:-6])), time =
>>>>>> rep(c(0:4),  :
>>>>>>  arguments imply differing number of rows: 630, 450, 0
>>>>>>
>>>>>> 3. Error: object 'tas.data.long' not found
>>>>>>
>>>>>> 4. Error in data.frame(media = c(mean.dead, mean.alive),
>>>>>> standarderror = c(se.dead,  :
>>>>>>  arguments imply differing number of rows: 14, 10
>>>>>>
>>>>>> 5. Error in ggplot(summarytas, aes(x = c(c(1:5), c(1:5)), y = mean,
>>>>>> colour = discharge)) :
>>>>>>  object 'summarytas' not found
>>>>>>
>>>>>> 6. Error in summary(glm(tas.data[, 6] ~ tas.data[, 4], family =
>>>>>> binomial(link = probit))) :
>>>>>>  error in evaluating the argument 'object' in selecting a method for
>>>>>> function 'summary': Error in eval(expr, envir, enclos) : y values
>>>>>> must be 0 <= y <= 1
>>>>>>
>>>>>> 7. Error in wilcox.test.default(pred[obs == 1], pred[obs == 0],
>>>>>> alternative = "great") :
>>>>>>  not enough (finite) 'x' observations
>>>>>> In addition: Warning message:
>>>>>> In is.finite(x) & apply(pred, 1, f) :
>>>>>>  longer object length is not a multiple of shorter object length
>>>>>>
>>>>>>
>>>>>> and off course I’m not getting OR.
>>>>>>
>>>>>> Nonetheless all this errors, I think I have not been able to compute
>>>>>> de code to get OR and OR confidence interval.
>>>>>>
>>>>>>
>>>>>> Can anyone help me please. It’s really urgent.
>>>>>>
>>>>>> PLEASE
>>>>>>
>>>>>> THE CODE:
>>>>>>
>>>>>> the hospital outcome is discharge.
>>>>>>
>>>>>> require(gdata

Re: [R] Help with vectors!

2015-09-09 Thread Eik Vettorazzi
how about this:

match(VAS,unique(VAS))

#or, preserving given order

match(VAS,c("White","Yellow","Green","Black"))

Cheers.

Am 05.09.2015 um 23:14 schrieb Dan D:
> # your data
> VAS<-c("Green","Green","Black","Green","White","Yellow","Yellow","Black","Green","Black")
> 
> # declare the new vector
> New_Vector<-numeric(length(VAS))
> 
> # brute force:
> New_Vector[VAS=="White"]<-1
> New_Vector[VAS=="Yellow"]<-2
> New_Vector[VAS=="Green"]<-3
> New_Vector[VAS=="Black"]<-4
> 
> # a little more subtle
> cols<-c("White","Yellow","Green","Black")
> for (i in 1:length(cols))  New_Vector[VAS==cols[i]]<-i
> 
> # and a general approach (that may give a different indexing, but can be
> used for any array)
> for (i in 1:length(unique(VAS))) New_Vector[VAS==unique(VAS)[i]]<-i
> cbind(1:length(unique(VAS)),unique(VAS)) # a decoding key for the color
> index
> 
> 
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Help-with-vectors-tp4711801p4711895.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

SAVE PAPER - THINK BEFORE PRINTING

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


Re: [R] Logistic Regression with 200K features in R?

2013-12-12 Thread Eik Vettorazzi
it is simply because you can't do a regression with more predictors than
observations.

Cheers.

Am 12.12.2013 09:00, schrieb Romeo Kienzler:
 Dear List,
 
 I'm quite new to R and want to do logistic regression with a 200K
 feature data set (around 150 training examples).
 
 I'm aware that I should use Naive Bayes but I have a more general
 question about the capability of R handling very high dimensional data.
 
 Please consider the following R code where mygenestrain.tab is a 150
 by 20 matrix:
 
 traindata - read.table('mygenestrain.tab');
 mylogit - glm(V1 ~ ., data = traindata, family = binomial);
 
 When executing this code I get the following error:
 
 Error in terms.formula(formula, data = data) :
   allocMatrix: too many elements specified
 Calls: glm ... model.frame - model.frame.default - terms - terms.formula
 Execution halted
 
 Is this because R can't handle 200K features or am I doing something
 completely wrong here?
 
 Thanks a lot for your help!
 
 best Regards,
 
 Romeo
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

Besuchen Sie uns auf: www.uke.de
_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Christian Gerloff (Vertreter des Vorsitzenden), 
Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

SAVE PAPER - THINK BEFORE PRINTING

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


Re: [R] Logistic Regression with 200K features in R?

2013-12-12 Thread Eik Vettorazzi
I thought so (with all the limitations due to collinearity and so on),
but actually there is a limit for the maximum size of an array which is
independent of your memory size and is due to the way arrays are
indexed. You can't create an object with more than 2^31-1 = 2147483647
elements.

https://stat.ethz.ch/pipermail/r-help/2007-June/133238.html

cheers

Am 12.12.2013 12:34, schrieb Romeo Kienzler:
 ok, so 200K predictors an 10M observations would work?
 
 
 On 12/12/2013 12:12 PM, Eik Vettorazzi wrote:
 it is simply because you can't do a regression with more predictors than
 observations.

 Cheers.

 Am 12.12.2013 09:00, schrieb Romeo Kienzler:
 Dear List,

 I'm quite new to R and want to do logistic regression with a 200K
 feature data set (around 150 training examples).

 I'm aware that I should use Naive Bayes but I have a more general
 question about the capability of R handling very high dimensional data.

 Please consider the following R code where mygenestrain.tab is a 150
 by 20 matrix:

 traindata - read.table('mygenestrain.tab');
 mylogit - glm(V1 ~ ., data = traindata, family = binomial);

 When executing this code I get the following error:

 Error in terms.formula(formula, data = data) :
allocMatrix: too many elements specified
 Calls: glm ... model.frame - model.frame.default - terms -
 terms.formula
 Execution halted

 Is this because R can't handle 200K features or am I doing something
 completely wrong here?

 Thanks a lot for your help!

 best Regards,

 Romeo

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

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

Besuchen Sie uns auf: www.uke.de
_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Christian Gerloff (Vertreter des Vorsitzenden), 
Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

SAVE PAPER - THINK BEFORE PRINTING

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


Re: [R] Logistic Regression with 200K features in R?

2013-12-12 Thread Eik Vettorazzi
thanks Duncan for this clarification.
A double precision matrix with 2e11 elements (as the op wanted) would
need about 1.5 TB memory, that's more than a standard (windows 64bit)
computer can handle.

Cheers.

Am 12.12.2013 13:00, schrieb Duncan Murdoch:
 On 13-12-12 6:51 AM, Eik Vettorazzi wrote:
 I thought so (with all the limitations due to collinearity and so on),
 but actually there is a limit for the maximum size of an array which is
 independent of your memory size and is due to the way arrays are
 indexed. You can't create an object with more than 2^31-1 = 2147483647
 elements.

 https://stat.ethz.ch/pipermail/r-help/2007-June/133238.html
 
 That post is from 2007.  The limits were raised considerably when R
 3.0.0 was released, and it is now 2^48 for disk-based operations, 2^52
 for working in memory.
 
 Duncan Murdoch
 
 

 cheers

 Am 12.12.2013 12:34, schrieb Romeo Kienzler:
 ok, so 200K predictors an 10M observations would work?


 On 12/12/2013 12:12 PM, Eik Vettorazzi wrote:
 it is simply because you can't do a regression with more predictors
 than
 observations.

 Cheers.

 Am 12.12.2013 09:00, schrieb Romeo Kienzler:
 Dear List,

 I'm quite new to R and want to do logistic regression with a 200K
 feature data set (around 150 training examples).

 I'm aware that I should use Naive Bayes but I have a more general
 question about the capability of R handling very high dimensional
 data.

 Please consider the following R code where mygenestrain.tab is a 150
 by 20 matrix:

 traindata - read.table('mygenestrain.tab');
 mylogit - glm(V1 ~ ., data = traindata, family = binomial);

 When executing this code I get the following error:

 Error in terms.formula(formula, data = data) :
 allocMatrix: too many elements specified
 Calls: glm ... model.frame - model.frame.default - terms -
 terms.formula
 Execution halted

 Is this because R can't handle 200K features or am I doing something
 completely wrong here?

 Thanks a lot for your help!

 best Regards,

 Romeo

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


 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

Besuchen Sie uns auf: www.uke.de
_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Christian Gerloff (Vertreter des Vorsitzenden), 
Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

SAVE PAPER - THINK BEFORE PRINTING

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


Re: [R] Solving a normal distribution pnorm for q

2013-12-12 Thread Eik Vettorazzi
Assuming r, sd1 and sd2 as known(fixed) components, this works:

X - pnorm(q=q,sd=sd1)*r+pnorm(q=q,sd=sd2)*(1-r)
uniroot(function(x)pnorm(q=x,sd=sd1)*r+pnorm(q=x,sd=sd2)*(1-r)-X,c(-1e6,1e6))


Cheers

Am 12.12.2013 15:58, schrieb Johannes Radinger:
 Thanks for the fast response. Of course I totally overlooked qnorm as I had
 a more complex task in my head.
 
 I wanted to reverse following equation:
 r=0.67
 q=-150
 sd1=100
 sd2=1000
 
 X - pnorm(q=q,sd=sd1)*r+pnorm(q=q,sd=sd2)*(1-r)
 
 Maybe its mathematically really easy, but somehow I don't get it how to do
 reverse and provide X and
 get q especially with the presence of r respectively as weighting factors
 for the two distributions.
 
 /J
 
 
 On Thu, Dec 12, 2013 at 3:09 PM, Dániel Kehl ke...@ktk.pte.hu wrote:
 
 Looks like homework.

 Try ?qnorm
 
 Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ;
 meghatalmaz#243;: Johannes Radinger [johannesradin...@gmail.com]
 Küldve: 2013. december 12. 14:56
 To: R help
 Tárgy: [R] Solving a normal distribution pnorm for q

 Hi,



 I found follwowing example of pnorm here:


 http://www.r-tutor.com/elementary-statistics/probability-distributions/normal-distribution



 Problem

 Assume that the test scores of a college entrance exam fits a normal
 distribution. Furthermore, the mean test score is 72, and the standard
 deviation is 15.2. What is the percentage of students scoring 84 or more in
 the exam?



 Solution

 pnorm(84, mean=72, sd=15.2, lower.tail=FALSE)

 [1] 0.21492



 That is straight forward, however what if I want to know the score the best
 30% students are reaching at least. So I know the solution of pnorm but
 want to know its q. How can that be achieved in R?



 Any suggestions?



 /Johannes

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

-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

Besuchen Sie uns auf: www.uke.de
_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Christian Gerloff (Vertreter des Vorsitzenden), 
Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

SAVE PAPER - THINK BEFORE PRINTING

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


Re: [R] adding tables

2013-12-10 Thread Eik Vettorazzi
How about this:
t2 - table(c(10,11,12,13))
t1 -table(c(1,1,2,4,5))
t12-(rbind(as.data.frame(t1),as.data.frame(t2)))
xtabs(Freq~.,t12)

it works for overlapping tables

t2 - table(c(10,11,12,13,1,2))
t1 -table(c(1,1,2,4,5,11,12))
t12-(rbind(as.data.frame(t1),as.data.frame(t2)))
xtabs(Freq~.,t12)

and it will work for two-dimensional tables as well:

t2 - table(c(10,11,12,13),letters[rep(1:2,each=2)])
t1 -table(c(1,1,2,4,5),letters[rep(c(1,3),length.out=5)])
t12a-(rbind(as.data.frame(t1),as.data.frame(t2)))
xtabs(Freq~.,t12a)

cheers.

Am 10.12.2013 00:59, schrieb Ross Boylan:
 Can anyone recommend a good way to add tables?
 Ideally I would like
 t1 - table(x1)
 t2 - table(x2)
 t1+t2
 
 It t1 and t2 have the same levels this works fine, but I need something
 that will work even if they differ, e.g.,
   t1
 
  1 2 4 5
  2 1 1 1
   t2 - table(c(10, 11, 12, 13))
   t1+t2  # apparently does simple vector addition
 
  1 2 4 5
  3 2 2 2
 whereas I want
 1 2 4 5 10 11 12 13
 2 1 1 1  1  1  1  1
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

Besuchen Sie uns auf: www.uke.de
_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Christian Gerloff (Vertreter des Vorsitzenden), 
Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

SAVE PAPER - THINK BEFORE PRINTING

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


Re: [R] Automatically Remove Aliased Terms from a Model

2013-10-29 Thread Eik Vettorazzi
Hi Thorn,
it is not entirely clear (at least for me) what you want to accomplish.
an easy and fail safe way of extracting used terms in a (g)lm-object is
names(model.frame(l))
if you want to extract terms to finally select a model, have a look at
drop1 and/or MASS::dropterm

Hth

Am 28.10.2013 17:19, schrieb Thaler,Thorn,LAUSANNE,Applied Mathematics:
 Dear all,
 
 I am trying to implement a function which removes aliased terms from a model. 
 The challenge I am facing is that with alias I get the aliased coefficients 
 of the model, which I have to translate into the terms from the model 
 formula. What I have tried so far:
 
 --8--
 d - expand.grid(a = 0:1, b=0:1)
 d$c - (d$a + d$b)  %% 2
 d$y - rnorm(4)
 d - within(d, {a - factor(a); b - factor(b); c - factor(c)})
 l - lm(y ~ a * b + c, d)
 
 removeAliased - function(mod) {
   ## Retrieve all terms in the model
   X - attr(mod$terms, term.label)
   ## Get the aliased coefficients  
   rn - rownames(alias(mod)$Complete)
   ## remove factor levels from coefficient names to retrieve the terms
   regex.base - unique(unlist(lapply(mod$model[, sapply(mod$model, 
 is.factor)], levels)))
   aliased - gsub(paste(regex.base, $, sep = , collapse = |),  , 
 gsub(paste(regex.base, :, sep = , collapse = |), :, rn))
   uF - formula(paste(. ~ ., paste(aliased, collapse = -), sep = -))
   update(mod, uF)
 }
 
 removeAliased(l)
 --8--
 
 This function works in principle, but this workaround with removing the 
 factor levels is just, well, a workaround which could cause problems in some 
 circumstances (when the name of a level matches the end of another variable, 
 when I use a different contrast and R names the coefficients differently etc. 
 - and I am not sure which other cases I am overlooking).
 
 So my question is whether there are some more intelligent ways of doing what 
 I want to achieve? Is there a function to translate a coefficient of a LM 
 back to the term, something like:
 
 termFromCoef(a1) ## a1
 termFromCoef(a1:b1) ## a:b
 
 With this I could simply translate the rownames from alias into the terms 
 needed for the model update.
 
 Thanks for your help.
 
 Kind Regards,
 
 Thorn Thaler 
 NRC Lausanne
 Applied Mathematics
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

Besuchen Sie uns auf: www.uke.de
_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

SAVE PAPER - THINK BEFORE PRINTING

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 can I use a script l (LaTeX \ell) in mathematical annotation of plots?

2013-10-25 Thread Eik Vettorazzi
Hi Byron,
You may have a look at the tikzDevice package, it solves the aesthetic
issue of font mixing.
You can sweave the following example

\documentclass{article}
\usepackage{tikz}
\begin{document}
\SweaveOpts{concordance=TRUE}
\begin{figure}[!h]
\centering
fig1, echo=FALSE, fig=FALSE, results=hide=
library(tikzDevice)
plotfile-simpleEx.tex
tikz(plotfile, width =3.5 , height =3.5)
plot(1, ,type=n)
text(1,1,$\\ell$ within ordinary \\LaTeX text)
dev.off()
@
\input{\Sexpr{plotfile}}
\caption{Test TeX annotation}
\end{figure}
\end{document}

cheers

Am 24.10.2013 18:44, schrieb Byron Dom:
 
 
 
 Thanks. That works for me too.
 
 I had worked that out based on Brian's response to my original post.
 
 If you read thru my response to him in detail, you'll see:
 
 Here are a couple of examples using it that worked:
 plot(1:10,xlab=\u2113)

   plot(1:10,xlab=\u2113(\u2113 + 1))
 
 
 
 
 
 From: Eik Vettorazzi e.vettora...@uke.de
 To: Byron Dom byron_...@yahoo.com; r help r-help@r-project.org 
 Cc: rip...@stats.ox.ac.uk rip...@stats.ox.ac.uk 
 Sent: Thursday, October 24, 2013 2:50 AM
 Subject: Re: [R] How can I use a script l (LaTeX \ell) in mathematical 
 annotation of plots?
 
 
 this works for me:
 
 plot(1,main=\u2113)
 
 cheers
 
 
 Am 24.10.2013 01:39, schrieb Byron Dom:


 Original post: On 13/10/2013 18:53, Byron Dom wrote:

 Due to convention a script l - $$\ell$$ (LaTeX \ell) is used to 
 represent a certain quantity in something I'm working on. I'm 
 unable to figure out how to use it in R. It's not included in the 
 list on ?plotmath.

 Can anyone tell me how to use it?  Its unicode is U+2113. This 
 page has a list of various encodings of it: 

   http://www.fileformat.info/info/unicode/char/2113/encoding.htm.  
 Is there a way to include it by using one of these encodings somehow?

 -

 On 13/10/2013 22:06 Prof Brian Ripley responded:

 What do you want to do with it?  plotmath is about plotting, but you
 have not otherwise mentioned that, let alone the device on which you 
 want to plot.

 Read the help for plotmath: on some plot devices, just use \u2113.  It 
 is not AFAICS in the Adobe symbol encoding.

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

 -

 My response:

 Thanks I worked out how to do it based on your mention of u2113.
 See below.

 I'm sorry if my information wasn't complete enough. I assumed that 
 what I said, combined with the subject (How can I use a script l 
 (LaTeX \ell) in
   mathematical annotation of plots?) would have been 
 enough.

 I just wanted to be able to do this on the default device, which 
 displays plots within the R session window. I have a simple path 
 to go from there to .png form, which I include in LaTeX documents
 and for other purposes. I am using R version 3.0.1 in Windows 7, 
 for which I believe the default plot device is windows.

 An example of the kind of thing I wanted to do is to include 
 ylab = expression(hat(gamma)) (which is equivalent to the LaTex 
 \hat{\gamma}}) among the base-graphics plot() arguments. That 
 works. In LaTeX a script l is produced with \ell, but 
 something like ylab = expression(ell) doesn't work in R. 
 I wanted to be able to do the equivalent of that, but to obtain ℓ.

 Here are a couple of examples using it that worked:
 plot(1:10,xlab=\u2113)

   plot(1:10,xlab=\u2113(\u2113 + 1))
 The only (slight) problem with this is the minor aesthetic issue 

 that the ℓ one gets this way is in an obviously different font 

 from what one gets using the LaTeX \lambda command/symbol.

 Strangely, earlier, when I tried 
 plot(1:10,xlab=expression(symbol(\u2113)))
 it did the same thing as 
 plot(1:10,xlab=expression(lambda))
 So I got a lower-case greek lambda - λ, rather than ℓ
 (script l).

 When I used the unicode representation for lowercase 
 lambda - λ - as follows

   plot(1:10,xlab=expression(symbol(\u03bb)))
 I got this for an x-axis label: Y+03BB. On the other hand,
 the following did work
 plot(1:10,xlab=\u03bb), 
 giving me an x-axis label of lambda - λ.
 [[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.

 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

Besuchen Sie uns auf: www.uke.de

Re: [R] How can I use a script l (LaTeX \ell) in mathematical annotation of plots?

2013-10-24 Thread Eik Vettorazzi
this works for me:

plot(1,main=\u2113)

cheers

Am 24.10.2013 01:39, schrieb Byron Dom:
 
 
 Original post: On 13/10/2013 18:53, Byron Dom wrote:
 
 Due to convention a script l - $$\ell$$ (LaTeX \ell) is used to 
 represent a certain quantity in something I'm working on. I'm 
 unable to figure out how to use it in R. It's not included in the 
 list on ?plotmath.

 Can anyone tell me how to use it?  Its unicode is U+2113. This 
 page has a list of various encodings of it: 

  http://www.fileformat.info/info/unicode/char/2113/encoding.htm.  
 Is there a way to include it by using one of these encodings somehow?
 
 -
 
 On 13/10/2013 22:06 Prof Brian Ripley responded:
 
 What do you want to do with it?  plotmath is about plotting, but you
 have not otherwise mentioned that, let alone the device on which you 
 want to plot.

 Read the help for plotmath: on some plot devices, just use \u2113.  It 
 is not AFAICS in the Adobe symbol encoding.

 -- 
 Brian D. Ripley,  ripley at stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel: 
  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595
 
 -
 
 My response:
 
 Thanks I worked out how to do it based on your mention of u2113.
 See below.
 
 I'm sorry if my information wasn't complete enough. I assumed that 
 what I said, combined with the subject (How can I use a script l 
 (LaTeX \ell) in
  mathematical annotation of plots?) would have been 
 enough.
 
 I just wanted to be able to do this on the default device, which 
 displays plots within the R session window. I have a simple path 
 to go from there to .png form, which I include in LaTeX documents
 and for other purposes. I am using R version 3.0.1 in Windows 7, 
 for which I believe the default plot device is windows.
 
 An example of the kind of thing I wanted to do is to include 
 ylab = expression(hat(gamma)) (which is equivalent to the LaTex 
 \hat{\gamma}}) among the base-graphics plot() arguments. That 
 works. In LaTeX a script l is produced with \ell, but 
 something like ylab = expression(ell) doesn't work in R. 
 I wanted to be able to do the equivalent of that, but to obtain ℓ.
 
 Here are a couple of examples using it that worked:
plot(1:10,xlab=\u2113)
   
  plot(1:10,xlab=\u2113(\u2113 + 1))
 The only (slight) problem with this is the minor aesthetic issue 
 
 that the ℓ one gets this way is in an obviously different font 
 
 from what one gets using the LaTeX \lambda command/symbol.
 
 Strangely, earlier, when I tried 
plot(1:10,xlab=expression(symbol(\u2113)))
 it did the same thing as 
plot(1:10,xlab=expression(lambda))
 So I got a lower-case greek lambda - λ, rather than ℓ
 (script l).
 
 When I used the unicode representation for lowercase 
 lambda - λ - as follows
   
  plot(1:10,xlab=expression(symbol(\u03bb)))
 I got this for an x-axis label: Y+03BB. On the other hand,
 the following did work
plot(1:10,xlab=\u03bb), 
 giving me an x-axis label of lambda - λ.
   [[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.
 

-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--

Besuchen Sie uns auf: www.uke.de
_

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg
Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Joachim Prölß, Rainer Schoppik
_

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


Re: [R] Jul 26, 2013; 12:34am

2013-07-29 Thread Eik Vettorazzi
Dear Frank,
you can use grconvertY and grconvertX to convert from user coordinates
to inches etc and vice versa.
E.g.

lines(rep(.25*1500,2),grconvertY(grconvertY(par(usr)[3],user,inches)+c(0,.1),from=inches,to=user))

should produce a tick of 0.1 inches height, regardless of the actual
plot height.

Hope this helps.

Am 26.07.2013 13:57, schrieb Frank Harrell:
 Thanks Rich and Jim and apologies for omitting the line
 
 x - c(285, 43.75, 94, 150, 214, 375, 270, 350, 41.5, 210, 30, 37.6,
 281, 101, 210)
 
 But the fundamental problem remains that vertical spacing is not correct
 unless I waste a lot of image space at the top.
 
 Frank
 
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] measuring distances between colours?

2013-05-30 Thread Eik Vettorazzi
Hi John,
i would propose a one-liner for the hexcode transformation:

hex2dec-function(hexnums)sapply(strtoi(hexnums,16L),function(x)x%/%256^(2:0)%%256)

#instead of
hexnumerals - 0:15
names(hexnumerals) - c(0:9, LETTERS[1:6])
hex2decimal - function(hexnums){
hexnums - strsplit(hexnums, )
decimals - matrix(0, 3, length(hexnums))
decimals[1, ] - sapply(hexnums, function(x)
 sum(hexnumerals[x[1:2]] * c(16, 1)))
decimals[2, ] - sapply(hexnums, function(x)
 sum(hexnumerals[x[3:4]] * c(16, 1)))
decimals[3, ] - sapply(hexnums, function(x)
 sum(hexnumerals[x[5:6]] * c(16, 1)))
decimals
}
#some tests
cols-c(AA, 002200, 99, 00, BB00BB, 00)
cols-sub(^#,,toupper(cols))
#actually 'toupper' is not needed for hex2dec

#check results
hex2decimal(cols)
hex2dec(cols)

#it is not only shorter ocde, but even faster.

cols.test-sprintf(%06X,sample(0:(256^3),10))
system.time(hex2decimal(cols.test))
#   User  System verstrichen
#   3.540.003.61
system.time(hex2dec(cols.test))
#   User  System verstrichen
#   0.530.000.53

cheers.

Am 30.05.2013 14:13, schrieb John Fox:
 Dear r-helpers,
 
 I'm interested in locating the named colour that's closest to an arbitrary 
 RGB colour. The best that I've been able to come up is the following, which 
 uses HSV colours for the comparison:
 
 r2c - function(){
 hexnumerals - 0:15
 names(hexnumerals) - c(0:9, LETTERS[1:6])
 hex2decimal - function(hexnums){
 hexnums - strsplit(hexnums, )
 decimals - matrix(0, 3, length(hexnums))
 decimals[1, ] - sapply(hexnums, function(x)   
  sum(hexnumerals[x[1:2]] * c(16, 1)))
 decimals[2, ] - sapply(hexnums, function(x) 
  sum(hexnumerals[x[3:4]] * c(16, 1)))
 decimals[3, ] - sapply(hexnums, function(x) 
  sum(hexnumerals[x[5:6]] * c(16, 1)))
 decimals
 }
 colors - colors()
 hsv - rgb2hsv(col2rgb(colors))
 function(cols){
 cols - sub(^#, , toupper(cols))
 dec.cols - rgb2hsv(hex2decimal(cols))
 colors[apply(dec.cols, 2, function(dec.col) 
 which.min(colSums((hsv - dec.col)^2)))]
 }
 }
 
 rgb2col - r2c()
 
 I've programmed this with a closure so that hsv gets computed only once.
 
 Examples:
 
 rgb2col(c(AA, 002200, 99, 00, BB00BB, #00))
 [1] darkred   darkgreen blue4 darkgreen magenta3  darkgreen
 rgb2col(c(00, #00))
 [1] darkgoldenrod cyan4  
 
 Some of these colour matches, e.g., #00 - darkgreen seem poor to me. 
 Even if the approach is sound, I'd like to be able to detect that there is no 
 sufficiently close match in the vector of named colours. That is, can I 
 establish a maximum acceptable distance in the HSV (or some other) colour 
 space?
 
 I vaguely recall a paper or discussion concerning colour representation in R 
 but can't locate it.
 
 Any suggestions would be appreciated.
 
 John
 
 
 John Fox
 Sen. William McMaster Prof. of Social Statistics
 Department of Sociology
 McMaster University
 Hamilton, Ontario, Canada
 http://socserv.mcmaster.ca/jfox/
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Prof. Dr. Dr. Uwe 
Koch-Gromus, Astrid Lurati (Kommissarisch), Joachim Prölß, Matthias Waldmann 
(Kommissarisch)

Bitte erwägen Sie, ob diese Mail ausgedruckt werden muss - der Umwelt zuliebe.

Please consider whether this mail must be printed - please think of the 
environment.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 call an object given a string?

2013-04-29 Thread Eik Vettorazzi
Hi Rui,
how about this

sapply(ls(),get)

cheers

Am 29.04.2013 13:07, schrieb Rui Esteves:
 Hello,
 
 This is very basic and very frustrating.
 
 Suppose this:
 A=5
 B=5
 C=10
 
 ls()
 A
 B
 C
 
 I would like this
 xpto()
 5
 5
 10
 
 How can I do xpto()?
 
 Thanks
 Rui
 
   [[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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] all.vars for nested expressions

2013-04-29 Thread Eik Vettorazzi
Hi Felix,
I thought, this could be an easy task for substitute, and the following
works as expected:

all.vars(substitute(expression(tp/a),list(a=expression(fn+tp
# [1] tp fn

But (of course)
all.vars(substitute(sen,list(a=a)))
does not yield the desired result, and I can't figure out, how to set up
as.name, bquote, eval, deparse etc to do the task properly.

Instead, my approach is a recursive call to all.vars

xall.help-function(x){
  #check if there is an object with name x
  if(exists(x)) lapply(all.vars(get(x)),xall.help) else x}

xall.vars-function(x){
   if (!is.character(x)) x-paste(substitute(x))
   #for convenience put in a single vecotr
   #xall.help returns a 'parsed tree'
   unique(unlist(xall.help(x)))
  }

#example
fn-expression(n1+n2)
a - expression(fn+tp)
sen - expression(tp/a)

xall.vars(sen)
# [1] tp n1 n2

cheers.

Am 29.04.2013 13:33, schrieb flxms:
 Dear R fellows,
  
 Assume I define
 
 a - expression(fn+tp)
 sen - expression(tp/a)
 
 Now I'd like to know, which variables are necessary for calculating sen
 
 all.vars(sen)
 
 This results in a vector c(tp,a). But I'd like all.vars to evaluate the
 sen-object down to the ground level, which would result in a vector
 c(tp,fn) (because a was defined as fn+tp). In other words, I'd like
 all.vars to expand the a-object (and all other downstream objects). I am
 looking for a solution, that works with much more levels. This is just a
 very simple example.
 
 I'd appreciate any suggestions how to do that very much!
 Thanks in advance,
 
 Felix
 
   [[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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] Frequency Block Chart

2013-04-23 Thread Eik Vettorazzi
Hi Angelo,
you might have a look at this
http://lmdvr.r-forge.r-project.org/figures/figures.html?chapter=06;figure=06_15;theme=stdBW;code=right

Cheers

Am 23.04.2013 12:42, schrieb Angelo Scozzarella Tiscali:
 Hi, friends.
 I'd like to illustrate the relationship between two categorical variables 
 with a block chart (a three-dimensional bar chart) with the height of the 
 blocks being proportional to the frequencies.
 
 Is there a way to do it with R?
 
 Thanks in advance
 
 Angelo
   [[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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 search a list that contains multiple dissimilar vectors?

2013-03-28 Thread Eik Vettorazzi
Hi Eric,
something like the following might me a starter

(index-lapply(alist,function(x)which(x==x.search)))

cheers.

Am 28.03.2013 08:40, schrieb Eric Rupley:
 
 Dear All,
 
 This is a simple question, but I'm stumped about the simplest way to search a 
 list object such as the following:
 
 This randomish snippet:
 
 n - c(round(runif(round(runif(1,1,10),0),1,10),0))
 alist - new(list)
 for (i in seq_along(n)) {
   alist[[i]] - c(round(runif(round(runif(1,1,10),0),1,10),0))
 }
 names(alist) - sample(letters[1:length(n)])
 rm(n);c(alist)
 
 
 ...produces something like this:
 
 $d
 [1] 4
 
 $b
 [1] 3 5 3
 
 $a
 [1]  2  5  7  3 10  3  4  9  9
 
 $c
 [1]  6  3  7  4  5 10  8 10  3
 
 My question is how does one search the list for a given value, in a most 
 compressed set of commands, in order two return two separate indices: a) the 
 index of the list element(s) containing the value, and b) the index of the 
 matching value(s) within the vector.
 
 Right now, I'm writing cumbersome loops to iterate though the elements, but 
 there must be a simple, effective method to which I have not found a 
 reference.
 
 Many thanks in advance, and apologies if I have overlooked a reference 
 passage.  
 Best,
 Eric
 
 --
  Eric Rupley
  University of Michigan, Museum of Anthropology
  1109 Geddes Ave, Rm. 4013
  Ann Arbor, MI 48109-1079
  
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] urgent: question concerning data manipulation

2013-03-04 Thread Eik Vettorazzi
There’s more than one way to skin a cat, here is another

mm-model.matrix(~personId+law+0,testdata)
merge(testdata,aggregate(mm[,-1],list(personId=mm[,personId]),max))

cheers

Am 04.03.2013 16:44, schrieb David Studer:
 Hello everyone!
 
 Does anyone of you know how I could solve the following problem.
 I guess, it is not a very difficult question, but I simply lack of the
 right idea:
 
 I have a dataset containing data of convictions. This dataset contains 4
 columns:
 - personId: individual number that identifies the offender
 - law: law which has been violated
 - article: article which has been violated
 
 # Testdata:
 personId-c(1,1,2,2,2,2,2,3,4,4)
 law-c(SVG, SVG, StGB, StGB, SVG, AuG, StGB, SVG, StGB,
 AuG)
 article-c(10, 10, 123, 122, 10, 40, 126, 10, 111, 40)
 testdata-data.frame(personId, law, article)
 
 Now I'd like to create three additional dummy-coded columns for each law
 (SVG, StGB, AuG).
 For each offender (all offenders have the same personId) it should be
 checked, whether there are
 any violations against the three laws. If there are any violations against
 SVG (for example), then
 in all rows of this offender the column SVG should have the value 1
 (otherwise 0).
 
 For example offender 2 has once violated against law SVG therefore his
 four entries should have
 the value 1 at the column SVG.
 
 I hope you can understand my problem. I'd really appreciate any hints and
 solutions!
 
 Thank you!
 David
 
   [[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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] Problems with line types in plots saved as PDF files

2013-02-20 Thread Eik Vettorazzi
Hi Ian,
besides encouraging alternative pdf viewers, you just could thin out
your interpolation grid, such as
b = seq(-10, 10, 0.02) #instead of 0.0002
and everything goes fine even with AcroRead XI.

Cheers

Am 20.02.2013 01:09, schrieb Ian Renner:
 Hi,
 
 I am trying to save a plot as a PDF with different line types. In the example 
 below, R displays the plot correctly with 2 curves in solid lines, 2 curves 
 in dashed lines and 1 curve as a dotted line. However, when I save the image 
 as PDF (as attached), the dashed lines become solid. This also happens if I 
 use the pdf command directly (by removing the # symbols).
 
 Is there any way around this? Saving the image as a JPEG or PNG file works 
 fine but the image quality is not desirable.
 
 b.hat = 6
 a.1 = -12
 a.2 = 0
 a.3 = 200
 
 b = seq(-10, 10, 0.0002)
 l = a.1*(b - b.hat)^2 + a.2*(b - b.hat) + a.3
 
 lambda = 20
 
 p = -lambda*abs(b)
 
 pen.like = l + p
 
 y.min = 3*min(p)
 y.max = max(c(l, p, pen.like))
 
 #pdf(file = TestPlot.pdf, 6, 6)
 #{
 plot(b, l, type = l, ylim = c(y.min, y.max), lwd = 2, xlab = 
 expression(beta), ylab = , col = green, yaxt = n, xaxt = n)
 points(b, p, type = l, lty = dotted, lwd = 2, col = red)
 points(b, pen.like, type = l, lwd = 2, lty = dashed, col = green)
 
 axis(1, at = c(0))
 axis(2, at = c(0))
 
 lambda.hat = which.max(pen.like)
 lambda.glm = which(b == b.hat)
 
 points(b[lambda.glm], l[lambda.glm], pch = 16, cex = 1.5)
 points(b[lambda.hat], l[lambda.hat], pch = 17, cex = 1.5)
 
 b.hat = -3
 a.1 = -1.5
 a.2 = 0
 a.3 = 120
 
 l = a.1*(b - b.hat)^2 + a.2*(b - b.hat) + a.3
 
 pen.like = l + p
 
 points(b, l, type = l, lwd = 2, col = blue)
 points(b, pen.like, type = l, lwd = 2, lty = dashed, col = blue)
 
 lambda.hat = which.max(pen.like)
 lambda.glm = which(b == b.hat)
 
 points(b[lambda.glm], l[lambda.glm], pch = 16, cex = 1.5)
 points(b[lambda.hat], l[lambda.hat], pch = 17, cex = 1.5)
 
 abline(h = 0)
 abline(v = 0)
 
 #}
 
 #dev.off()
 
 
 Thanks,
 
 Ian
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] subsetting data file by intoducing a second file

2013-02-12 Thread Eik Vettorazzi
Hi Ozgul,
the interesting part is the select parameter in subset:

subset(bg,select=c_bg[,1])


cheers

Am 12.02.2013 15:29, schrieb Ozgul Inceoglu:
 Hello,
 
 I have a very data matrix and I have a file which has the names that I need 
 to subset. However I cannot manage to subset the main file. ANy idea?
 
 bg - read.table (file.choose(), header=T, row.names)
 bg
   Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 
 Otu00131 Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 
 Otu00209 Otu00218
 Gi20Jun11  0.0012170 0.0012170 0.0000 
0 0.00121700000 0.0012170 
 0.001217
 Gi40Jun11  0.000 0.000 0.0000 
0 0.0000000 0.000 
 0.00
 Gi425Jun11 0.000 0.000 0.0000 
0 0.0000000 0.000 
 0.00
 Gi45Jun11  0.000 0.000 0.00151300 
0 0.0000000 0.000 
 0.00
 Gi475Jun11 0.000 0.000 0.0000 
0 0.0000000 0.000 
 0.00
 Gi50Jun11  0.000 0.000 0.0000 
0 0.0000000 0.000 
 0.00
 ...
 #second file which has the names that I want to subset
 c_bg
   [,1] 
   [1,] Otu0128
   [2,] Otu0218
   [3,] Otu0034
   [4,] Otu0257
   [5,] Otu0212
   [6,] Otu0279
   [7,] Otu0318
   [8,] Otu0266
   [9,] Otu0056
 ...
 #by using the c_bg name file, I would like to subset bg file
 
 g1-subset(bg,colnames(bg) %in% (c_bg))
 
 # this returns me the all the column names in bg file.
 
 Thank you,
 Ö
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] how to draw confidence interval lines of a fitted curve of polynominal regression

2013-02-07 Thread Eik Vettorazzi
Hi Elaine
you can do all at one go using the ggplot2-package

library(ggplot2)
qplot(age,weight)+ geom_smooth(method=lm,formula=y~poly(x,2))

Have a look at ?geom_smooth when you want to incooperate customized
model predictions

cheers.

Am 07.02.2013 02:31, schrieb Elaine Kuo:
 Hello,
 
 I drew a plot of weight and height of people and fitted it with a
 polynominal regression x^2.
 (using curve())
 
 Now I would like to draw the confidence interval line for the fitted curve.
 Please kindly advise the code for the purpose.
 Thank you.
 
 Elaine
 
   [[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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] weighing proportion of rowSums in dataframe

2013-02-06 Thread Eik Vettorazzi
Hi Alain,
here is a one-liner for a df without the rowSum column

df-data.frame(id=c(x01,x02,x03,x04,x05,x06),a=c(1,2,NA,4,5,6),b=c(2,4,6,8,10,NA),c=c(NA,3,9,12,NA,NA))

(df$wSum-apply(sweep(df[,-1],1,rowSums(df[,-1],na.rm=T),/),1,function(x)sum(x*w,na.rm=T)))

hth.

Am 06.02.2013 14:17, schrieb D. Alain:
 Dear R-List, 
 
 
 I am sure there must be a very simple way to do this - I just do not know 
 how...
 This is what I want to do: 
 
 
 #my dataframe
 
 df-data.frame(id=c(x01,x02,x03,x04,x05,x06),a=c(1,2,NA,4,5,6),b=c(2,4,6,8,10,NA),c=c(NA,3,9,12,NA,NA),sum=c(3,9,15,24,15,6))
 
ida b c   sum
 1 x01  1 2NA   3
 2 x02  2 4 3  9
 3 x03 NA  6 9 15
 4 x04  4 81224
 5 x05  510   NA  15
 6 x06  6   NA  NA   6
 
 
 #my weights
 w-c(10.5,9,12.8)
 
 #now I want to calculate the proportion of the rowsum = sum of every other 
 number in the row, that is df[1,2]/df[1,5], df[1,3]/df[1,5], ...
 
 
 #e.g. 
 
 
 df.prop
 
 
id a b   c  sum 
 1 x01  0.33 0.66 NA3
 2 x02  0.22 0.44 0.33 9
 3 x03 NA   0.4   0.6   15
 4 x04  0.16 0.33 0.524
 5 x05  0.33 0.66 NA   15
 6 x06  1   NA NA   6
 
 #and then calculate a rowsum, were each column is weighed by its associated 
 factor in the vector w, i.e. all entries in column df$a should be weighed 
 by the factor 10.5, df$b by 9 and df$c by 12.8 and then summed up to a 
 weighed rowsum (wrowsum=10.5*0.33+9*0.66).
 
 Any suggestions how to achieve this in a simple way with dataframes that have 
 9000 rows and 44 columns (so I cannot do this row by row) - sorry, if this is 
 to easy a question.
 
 Thank you very much in advance!
 
 Best wishes
 
 Alain
   [[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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] Omitting repeated occurrence in a string

2013-02-06 Thread Eik Vettorazzi
Hi Christopher,
what is the rule to omit ah which is also repeated in Text?
The following might be a start:

Text - ahsgdvasgAbcabcsdahj
#finds first repetion of substrings of length 2 or more, here ah
gsub((?i)([a-z]{2,})(.*)\\1,\\1\\2,Text,perl=T)
#finds all repetions of substrings of length 3 or more, here Abc
gsub((?i)([a-z]{3,})(.*)\\1,\\1\\2,Text,perl=T)
#finds only subsequent repetions of substrings of length 2 or more
gsub((?i)([a-z]{2,})\\1,\\1,Text,perl=T)

hth.

Am 06.02.2013 17:46, schrieb Christofer Bogaso:
 Hello again,
 
 I was looking for some way on How to delete repeated appearance in a
 String. Let say I have following string:
 
 Text - ahsgdvasgAbcabcsdahj
 
 Here you see Abc appears twice. But I want to keep only 1
 occurrence. Therefore I need that:
 
 Text_result - ahsgdvasgAbcsdahj (i.e. the first one).
 
 Can somebody help me if it is possible using some R function?
 
 Thanks and regards,
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] merge 2 data.frames

2013-02-06 Thread Eik Vettorazzi
Hi Mat,
just have a look at ?rbind

cheers.

Am 06.02.2013 15:55, schrieb Mat:
 Hello together,
 
 i have probably a easy question, but how can i sum 2 data.frames among each
 other.
 I have 2 data.frames which look like this one:
 
 Cu.No.  place  level
 1 123London  A
 2111 Paris   B
 
 Cu.No.  place  level
 1 333Berlin  C
 2444 MadridA
 
 and now i want this data in the same data.frame. like this one:
 
 Cu.No.  place  level
 1 123London  A
 2111 Paris   B
 3 333Berlin  C
 4444 MadridA
 
 how can i do this.
 
 Thanks.
 
 Mat
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/merge-2-data-frames-tp4657702.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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] reshape help

2013-02-04 Thread Eik Vettorazzi
Hi Robert,
how about this?

tmp-read.table(text=ID   Dx
Anausea
Adiabetes
Akidney_failure
Aheart_attack
Afever
Bfever
Bpneumonia
Bheart_attack
Bnausea
Bcough
Ckidney_failure
Cnausea
Cfoot_pain,header=T)

data.frame(cbind(ID=levels(tmp$ID),(table(tmp$ID,tmp$Dx

hth.

Am 04.02.2013 09:16, schrieb Robert Strother:
 Dear R users -
 
 I have a list of patient identifiers and diagnoses from inpatient
 admissions.  I would like to reorganize the list, presently in a long
 format to a wide format in reshape, but in the absence of a time element,
 I am uncertain how to do this - any help greatly appreciated.
 
 ID   Dx
 Anausea
 Adiabetes
 Akidney failure
 Aheart attack
 Afever
 Bfever
 Bpneumonia
 Bheart attack
 Bnausea
 Bcough
 Ckidney failure
 Cnausea
 Cfoot pain
 
 I want this to be
 IDnausea  diabetes  kidney_failure  heart_attack  fever  pneumonia
 A  11 1   1  1
 0
 B  00 0   1  1
 1
 
 
 R. Matthew Strother, MD
 Clinical Pharmacology
 Medical Oncology
 
   [[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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] R plot like candlestick

2013-01-29 Thread Eik Vettorazzi
Hi Denis,
there is no if, only how in R ;)

how about this:

rmail2-read.table(textConnection(item, min, int_1, int_2, max
a, 2.5, 3, 4, 5.5
b, 2, 3.5, 4, 4.5
c, 3.5, 4, 4.5, 5),header=T,sep=,)
with(rmail2,symbols(item, (int_1+ int_2)/2, boxplots=cbind(.25,
int_2-int_1,
int_1-min,max-int_2,0),inches=F,ylim=range(rmail2[,-1]),xaxt=n,ylab=))
axis(1,seq_along(rmail2$item),labels=rmail2$item)

hth.

Am 28.01.2013 22:26, schrieb Denis Francisci:
 Hi all,
 I'm new on this list so I greet all.
 My question is: does exist in R a plot similar to candlestick plot but
 not based on xts (time series)? I have to plot a range of 4 value: for
 every item I have min value, max value and 2 intermediate values. I
 would like plot this like a candlestick, i.e. with a box between 2
 intermediate values and 1 segment between box and min value and a
 segment between box and max value. Candlestick plot is provided by
 quantmod package, but it is very specific for financial purpose and it
 uses time series for x axis. I need a simpler method for plotting my
 data that are stored in a table like this:
 
 item, min, int_1, int_2, max
 a, 2.5, 3, 4, 5.5
 b, 2, 3.5, 4, 4.5
 c, 3.5, 4, 4.5, 5
 .
 
 Does anyone know if there is an R-plot for this purpose?
 Thank you very much,
 
 D.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] a confidence interval from an ANOVA model

2013-01-21 Thread Eik Vettorazzi
Hi Erin,
how about this:

dta-read.table(textConnection(trt resp
A 23
A 28
A 37
A 30
B 37
B 44
B 31
B 35
C 42
C 47
C 52
C 38),header=T)

summary(ano-aov(resp~trt,dta))
ano0-update(ano,.~.+0)
confint(ano0)
# and the corresponding means are
coef(ano0)

# or use the effects package
library(effects)
summary(allEffects(ano))

hth.

Am 20.01.2013 03:11, schrieb Erin Hodgess:
 Dear R People:
 I have a data set with trt and resp:
 trt resp
 A 23
 A 28
 A 37
 A 30
 B 37
 B 44
 B 31
 B 35
 C 42
 C 47
 C 52
 C 38
 
 And I did read.table, constructed an aov object and ran the summary on
 the aov object.  I also ran the TukeyHSD function.  All is well so
 far.
 My question is:  is there a way to put together a confidence interval
 from the aov object on a particular mean, please?  It seems like there
 should be.
 
 Thanks,
 Have a great night/day,
 Sincerely,
 Erin
 
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

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


Re: [R] Hello R User

2012-12-14 Thread Eik Vettorazzi
Hi Bibek,
how about this?

dta-read.table(textConnection(ID  Time
1   3
1   6
1   7
1   10
1   16
2   12
2   18
2   19
2   25
2   28
2   30),header=T)

dta$delta-with(dta,ave(Time,ID,FUN=function(x)c(0,diff(x
dta

hth.

Am 14.12.2012 16:51, schrieb bibek sharma:
 Hello R User,
 In the sample data given below, time is recorded for each id
 subsequently. For the analysis, for each id, I would like to set 1st
 recorded time to zero and thereafter find the difference from previous
 time. I.e. for ID==1, I would like to see Time=0,3,1,3,6. This needs
 to be implemented to big data set.
 Any suggestions are much appreciated!
 Thanks,
 Bibek
 
 IDTime
 1 3
 1 6
 1 7
 1 10
 1 16
 2 12
 2 18
 2 19
 2 25
 2 28
 2 30
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


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


Re: [R] error in IF condition with factor evaluation

2012-11-23 Thread Eik Vettorazzi
Hi Edoardo,
there is a difference between comparisons and assignments, both
semantically as well as in R syntax: == vs = or -, latter being
more obvious an assignment.
This is the source of your error.
But to change the labels of a factor object, it is easier to do sth like

at-factor(1:5,labels=letters[1:5])
at
levels(at)[3]-xyz
at   #check

hth



Am 23.11.2012 10:42, schrieb edoardo baldoni:
 Cam anyone tell me why the condition x[i] == DISCONECTED looks like
 producing an NA instead of TRUE/FALSE
 
 I would like to rename DISCONNECTED those factors inside the variable
 dataset$STATUS.x that are named DISCONECTED
 
 thank you
 
 
 summary(dataset$STATUS.x)
  ACTIVE DISCONECTED PENDING   SUSPENDED  TERMINATED
  158869  16918130288565   47233
NA's
   6
 class(dataset$STATUS.x)
 [1] factor

 fff = function(x) {
 + for (i in 1:length(x)){
 + if (x[i] == DISCONECTED) {
 + x[i] == DISCONNECTED
 + } else x[i] == x[i]
 + }
 + return(x)
 + }

 r = fff(dataset$STATUS.x)
 Error in if (x[i] == DISCONECTED) { :
   missing value where TRUE/FALSE needed
 
   [[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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790
--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Martin Zeitz (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 can I improve an ugly, dumb hack

2012-09-06 Thread Eik Vettorazzi
Hi Bert,
maybe I'm missing the point, but

dd-cbind(d,m)

does 1, 2 and 3 as desired:

n - data.frame(nx=letters[7:9], ny = 7:9)
str(cbind(d,m,n))

t-letters[7:9]
str(cbind(d,t))

cheers.


Am 06.09.2012 18:03, schrieb Bert Gunter:
 Hi Folks:
 
 Here's the situation:
 
 m - cbind(x=letters[1:3], y = letters[4:6])
 m
  x   y
 [1,] a d
 [2,] b e
 [3,] c f
 
 ## m is a 2 column character matrix
 
 d - data.frame(a=1:3,b=4:6)
 d$c - m
 d
   a b c.x c.y
 1 1 4   a   d
 2 2 5   b   e
 3 3 6   c   f
 
 ## But please note (as was remarked in a thread here a couple of months ago)
 ncol(d)
 [1] 3
 
 ## d is a ** 3 ** column data frame
 
 Now what I wish to do is programmatically convert d to a 4 column
 frame with names c(a,b,x,y). Of course:
 
 1. The column classes/modes must be preserved (character going to
 factor and numeric remaining numeric).
 
 2. I assume that I do not know a priori which of d's
 components/columns are matrices and which are vectors.
 
 3. There may be many more columns which are vectors or matrix than
 just the three in this little example.
 
 I can easily and sensibly accomplish these 3 tasks, but the problem is
 that I run afoul of data frame column naming procedures in doing so,
 about which the data.frame Help page says rather enigmatically:
 
 How the names of the data frame are created is complex, and the rest
 of this paragraph is only the basic story. Indeed!
 (This, of course, is shorthand for Go look at the source if you want
 to know! )
 
 Anyway, AFAICT from the Help, any simple approach to conversion
 using data.frame results in c.x and c.y for the names of the last
 two columns. I **can** get what I want by explicitly constructing the
 vector of names via the following ugly hack; my question is, can it be
 improved?
 
 dd - do.call(data.frame,d)
 
 dd
   a b c.x c.y
 1 1 4   a   d
 2 2 5   b   e
 3 3 6   c   f
 
 ncol(dd)
 [1] 4
 
 cnames - sapply(d,colnames)
 cnames
 $a
 NULL
 
 $b
 NULL
 
 $c
 [1] x y
 
 
  names(dd) -  unlist(ifelse(sapply(cnames,is.null),names(d),cnames))
   ##Yuck!
 
 dd
   a b x y
 1 1 4 a d
 2 2 5 b e
 3 3 6 c f
 
 Cheers to all,
 Bert
 
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] define subset argument for function lm as variable?

2012-08-21 Thread Eik Vettorazzi
Hi Rainer,
I got an error while replicating your data.frame construction.

But this worked for me

ctl = c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt = c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
dat - data.frame( group = gl(2,10,20, labels=c(Ctl,Trt)),
 weight = c(ctl, trt)
 )
lm(weight ~ group, data=dat, subset=trt0)

Cheers

Am 21.08.2012 17:11, schrieb Rainer M Krug:
 On 21/08/12 16:57, Bert Gunter wrote:
 ?? I do not groc what you mean. ... subset == subs would work fine in
 your lm call. So unless someone else does get it, you may need to
 elaborate.
 
 OK - here is an example:
 
 dat - data.frame(
  ctl = c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14),
  trt = c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69),
  group = gl(2,10,20, labels=c(Ctl,Trt)),
  weight = c(ctl, trt)
  )
 lm(weight ~ group, data=dat, subset=trt0)
 
 subst - trt0 ### here I get the obvious error: Error: object 'trt' not
 found
 
 # I want to use:
 
 lm(weight ~ group, data=dat, subset=subst)
 
 

 In general, ?substitute, ?bquote, and ?quote are useful to avoid
 immediate evaluation of calls, but I don't know if that's relevant to
 what you want here.
 
 Looks promising from the help, but I don't get it to work.
 
 Rainer
 

 -- Bert

 On Tue, Aug 21, 2012 at 7:44 AM, Rainer M Krug r.m.k...@gmail.com
 wrote:
 Hi

 I want to do a series of linear models, and would like to define the
 input
 arguments for lm() as variables. I managed easily to define the formula
 arguments in a variable, but I also would like to have the subset in a
 variable. My reasoning is, that I have the subset in the results object.

 So I wiould like to add a line like:

 subs - dead==FALSE  recTreat==FALSE

 which obviously does not work as the expression is evaluated
 immediately. Is
 is it possible to do what I want to do here, or do I have to go back
 to use

 dat - subset(dat, dead==FALSE  recTreat==FALSE)

 ?



 dat - loadSPECIES(SPECIES)
 feff - height~pHarv*year   # fixed effect in the model
 reff - ~year|plant # random effect in the model,
 where
 year is the
 dat.lme - lme(
   fixed = feff,   # fixed effect
 in the
 model
   data  = dat,
   random = reff,  # random effect
 in the
 model
   correlation = corAR1(form=~year|plant), #
   subset = dead==FALSE  recTreat==FALSE, #
   na.action = na.omit
   )
 dat.lm - lm(
  formula =  feff,  # fixed effect in the model
  data = dat,
  subset = dead==FALSE  recTreat==FALSE,
  na.action = na.omit
  )

 Thanks,

 Rainer

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

 Centre of Excellence for Invasion Biology
 Stellenbosch University
 South Africa

 Tel :   +33 - (0)9 53 10 27 44
 Cell:   +33 - (0)6 85 62 59 98
 Fax :   +33 - (0)9 58 10 27 44

 Fax (D):+49 - (0)3 21 21 25 22 44

 email:  rai...@krugs.de

 Skype:  RMkrug

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



 
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] define subset argument for function lm as variable?

2012-08-21 Thread Eik Vettorazzi
Josh's solution should be fine.

just one more note,
trt0 may not work as intended since trt is a factor in your example.
Just check
subset(dat,trt0)
wich is just 'dat'.



Am 21.08.2012 17:41, schrieb Rainer M Krug:
 On 21/08/12 17:35, Eik Vettorazzi wrote:
 Hi Rainer,
 I got an error while replicating your data.frame construction.

 But this worked for me

 ctl = c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
 trt = c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
 dat - data.frame( group = gl(2,10,20, labels=c(Ctl,Trt)),
   weight = c(ctl, trt)
   )
 
 Sorry  - to much garbage in my workspace left.
 
 Just add:
 
 rm(ctl)
 rm(trt)
 
 after the definition
 
 lm(weight ~ group, data=dat, subset=trt0)
 
 this obviously works, but I would like to have:
 
 subst - trt0
 lm(weight ~ group, data=dat, subset=subst)
 
 Sorry about this,
 
 Rainer
 
 

 Cheers

 Am 21.08.2012 17:11, schrieb Rainer M Krug:
 On 21/08/12 16:57, Bert Gunter wrote:
 ?? I do not groc what you mean. ... subset == subs would work fine in
 your lm call. So unless someone else does get it, you may need to
 elaborate.

 OK - here is an example:

 dat - data.frame(
   ctl = c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14),
   trt = c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69),
   group = gl(2,10,20, labels=c(Ctl,Trt)),
   weight = c(ctl, trt)
   )
 lm(weight ~ group, data=dat, subset=trt0)

 subst - trt0 ### here I get the obvious error: Error: object 'trt' not
 found

 # I want to use:

 lm(weight ~ group, data=dat, subset=subst)



 In general, ?substitute, ?bquote, and ?quote are useful to avoid
 immediate evaluation of calls, but I don't know if that's relevant to
 what you want here.

 Looks promising from the help, but I don't get it to work.

 Rainer


 -- Bert

 On Tue, Aug 21, 2012 at 7:44 AM, Rainer M Krug r.m.k...@gmail.com
 wrote:
 Hi

 I want to do a series of linear models, and would like to define the
 input
 arguments for lm() as variables. I managed easily to define the
 formula
 arguments in a variable, but I also would like to have the subset
 in a
 variable. My reasoning is, that I have the subset in the results
 object.

 So I wiould like to add a line like:

 subs - dead==FALSE  recTreat==FALSE

 which obviously does not work as the expression is evaluated
 immediately. Is
 is it possible to do what I want to do here, or do I have to go back
 to use

 dat - subset(dat, dead==FALSE  recTreat==FALSE)

 ?



 dat - loadSPECIES(SPECIES)
 feff - height~pHarv*year   # fixed effect in the model
 reff - ~year|plant # random effect in the model,
 where
 year is the
 dat.lme - lme(
fixed = feff,   # fixed effect
 in the
 model
data  = dat,
random = reff,  # random effect
 in the
 model
correlation = corAR1(form=~year|plant), #
subset = dead==FALSE  recTreat==FALSE, #
na.action = na.omit
)
 dat.lm - lm(
   formula =  feff,  # fixed effect in the
 model
   data = dat,
   subset = dead==FALSE  recTreat==FALSE,
   na.action = na.omit
   )

 Thanks,

 Rainer

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

 Centre of Excellence for Invasion Biology
 Stellenbosch University
 South Africa

 Tel :   +33 - (0)9 53 10 27 44
 Cell:   +33 - (0)6 85 62 59 98
 Fax :   +33 - (0)9 58 10 27 44

 Fax (D):+49 - (0)3 21 21 25 22 44

 email:  rai...@krugs.de

 Skype:  RMkrug

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







 
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] Chopping a vector up into smaller vectors

2012-08-02 Thread Eik Vettorazzi
Hi Stephen,
how about this:

chop-function(x,counts){
 stopifnot(sum(counts)==length(x))
 split(9:1,unlist(mapply(rep,seq_along(counts),counts)))
}
chop(9:1,c(3,2,4))

cheers

Am 02.08.2012 12:29, schrieb Stephen Eglen:
 Anyone got a neat way to chop a vector up into smaller subvectors?
 This is what I have now, which seems inelegant:
 
 chop - function(v, counts) {
   stopifnot(sum(counts)==length(v))
   end - cumsum(counts)
   beg - c(1, 1+end[-length(end)])
   begend - cbind(beg, end)
   apply(begend, 1, function(x) v[x[1]:x[2]])
 }
   
 
 chop(9:1, c(3,2,4))
 [[1]]
 [1] 9 8 7
 
 [[2]]
 [1] 6 5
 
 [[3]]
 [1] 4 3 2 1
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Polygon shaded area

2012-08-02 Thread Eik Vettorazzi
Hi Jose,
how about this

example(polygon)

I think the second one is pretty much what you want.

cheers.

Am 02.08.2012 14:33, schrieb Jose Narillos de Santos:
 Hi all,
 
 I have two vectors (columns) called efinal and efinal 2.
 
 I want to plot them on the same plot and draw a shaded area beween the
 two lines using function polygon
 
 I have tried all but I don ´t understand the polygon area, can you help me
 with examples?
 
 plot(efinal,type=l,ylim=range(min(efinal2),
 max(efinal)),ylab=,main=plot)
 
 par(new=T)
 plot(efinal2,type=l,ylim=range(min(efinal2), max(efinal)),ylab=)
 
 The efinal are two temporal series I attach?
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Polygon shaded area

2012-08-02 Thread Eik Vettorazzi
Hi Jose,
this should work (but I think you need a deeper understanding, what
plot(efinal) does, see ?plot):

plot(efinal,ylim=range(c(efinal,efinal2)),type=n,ylab=)
xv-seq_along(efinal)
polygon(c(xv,rev(xv)),c(efinal,rev(efinal2)),col=red)

cheers

Am 02.08.2012 16:36, schrieb Jose Narillos de Santos:
 Hi I attach my function. No error message (it seems a line appears but
 nothing similar to examples(polygon))
 
 
 
 2012/8/2 Eik Vettorazzi e.vettora...@uke.de mailto:e.vettora...@uke.de
 
 Hi Jose,
 how about this
 
 example(polygon)
 
 I think the second one is pretty much what you want.
 
 cheers.
 
 Am 02.08.2012 14:33, schrieb Jose Narillos de Santos:
  Hi all,
 
  I have two vectors (columns) called efinal and efinal 2.
 
  I want to plot them on the same plot and draw a shaded area
 beween the
  two lines using function polygon
 
  I have tried all but I don ´t understand the polygon area, can you
 help me
  with examples?
 
  plot(efinal,type=l,ylim=range(min(efinal2),
  max(efinal)),ylab=,main=plot)
 
  par(new=T)
  plot(efinal2,type=l,ylim=range(min(efinal2), max(efinal)),ylab=)
 
  The efinal are two temporal series I attach?
 
 
 
  __
  R-help@r-project.org mailto:R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 
 --
 Eik Vettorazzi
 
 Department of Medical Biometry and Epidemiology
 University Medical Center Hamburg-Eppendorf
 
 Martinistr. 52
 20246 Hamburg
 
 T ++49/40/7410-58243 tel:%2B%2B49%2F40%2F7410-58243
 F ++49/40/7410-57790 tel:%2B%2B49%2F40%2F7410-57790
 
 --
 Pflichtangaben gemäß Gesetz über elektronische Handelsregister und
 Genossenschaftsregister sowie das Unternehmensregister (EHUG):
 
 Universitätsklinikum Hamburg-Eppendorf; Körperschaft des
 öffentlichen Rechts; Gerichtsstand: Hamburg
 
 Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des
 Vorsitzenden), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr.
 Uwe Koch-Gromus
 
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread Eik Vettorazzi
I still try to figure out, what you are finally asking for, but maybe

res-sapply(list4,function(x)max(x[[1]]$coconut))
names(res)-c(mango, banana, pineapple)
res
max(res)

is worth a try?

Especially i did not get the point of doing something like
x[which.max(x)] because this is in any case just max(x)

if you would like to plug in different functions or want to select
different columns,

fun-max # or min, median etc
sapply(lapply(list4,[[,1),fun)

could be a start, where lapply(list4,[[,1) extracts the first object
in each sublist - which is in your case a data.frame with just one
column ('coconut'), where 'fun' can be applied to. So to address
'coconut' explicitly, just nest this lapply approach:

sapply(lapply(lapply(list4,[[,1),[[,coconut),fun)
#or use an anonymous extractor function
sapply(lapply(list4,function(x)x[[1]][[coconut]]),fun)

cheers

Am 02.08.2012 16:09, schrieb gail:
 Hi,
 
 my dataset is the result of the function density on another set of data.
 It refers to that data in its variable call, though since all the results
 are actually reproduced (except that I've removed all rows bar 10), I am not
 sure why R still needs it. But I've understood now why your code doesn't
 work on my data: your sublists are still just dataframes, whereas my
 sublists contain all sorts of vectors (2 numerical vectors and 5 other
 things). I've changed your data to make it look a bit more like mine, and
 you'll see that the code doesn't work. 
 
 mango - list(data.frame(coconut=1:6), y=c(4,5,3,2,1,8),
 bw=c(4,18,12,3,4,9), nn=paste0(a,1:6))
 banana - list(data.frame(coconut=c(1,2,18,16,15)), y=c(4,5,9,2,1),
 bw=c(4,18,22,3,4), nn=paste0(a,1:5))
 pineapple - list(data.frame(coconut=c(4,6,9)), y=c(8,24,12),
 bw=c(14,31,36), nn=paste0(a,1:3))
 list4 - list(mango, banana, pineapple)
 
 b - list()
 
  for(i in 1:3){
  b[[i]] - list()
  b[[i]] - lapply (list4[[i]]$coconut, FUN=function(x) x[which.max(x)])
  }
 
 b
 summary( b)
 
 What I want to end up with is the following:
 
coconut
 mango   6
 banana 18
 pineapple   9
 (that's for the individual sublists)
 
 and 
coconut
 18
 (that's for the list as a whole).
 
 Hope this is becoming a bit clearer ...
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/apply-function-over-same-column-of-all-objects-in-a-list-tp4638681p4638876.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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] apply function over same column of all objects in a list

2012-08-02 Thread Eik Vettorazzi
Hi Arun,
if you name the data.frame in the list, e.g.
mango - list( y=c(4,5,3,2,1,8), bw=c(4,18,12,3,4,9),
nn=paste0(a,1:6),target=data.frame(coconut=1:6))
banana - list(target=data.frame(coconut=c(1,2,18,16,15)), y=c(4,5,9,2,1),
bw=c(4,18,22,3,4), nn=paste0(a,1:5))
pineapple - list(target=data.frame(coconut=c(4,6,9)), y=c(8,24,12),
bw=c(14,31,36), nn=paste0(a,1:3))
list6-list(mango,banana,pineapple)

then
sapply(lapply(list5,[[,target),max)

still works.

Regards

Am 02.08.2012 20:21, schrieb arun kirshna [via R]:
 Hi Elk,
 
 I tried to test with another case where coconut is in different position in
 the sublist.
 mango - list( y=c(4,5,3,2,1,8), bw=c(4,18,12,3,4,9),
 nn=paste0(a,1:6),data.frame(coconut=1:6))
 banana - list(data.frame(coconut=c(1,2,18,16,15)), y=c(4,5,9,2,1),
 bw=c(4,18,22,3,4), nn=paste0(a,1:5))
 pineapple - list(data.frame(coconut=c(4,6,9)), y=c(8,24,12),
 bw=c(14,31,36), nn=paste0(a,1:3)) 
 list5-list(mango,banana,pineapple)
 #Your code
 fun-max # or min, median etc
 sapply(lapply(list5,[[,1),fun) 
 [1]  8 18  9
 # Here, first number should be 6, instead it did the max of y from mango.
 #Then, I tried second solution of yours
 sapply(lapply(lapply(list5,[[,1),[[,coconut),fun) 
 #Error in FUN(X[[1L]], ...) : subscript out of bounds
 #Third solution
  sapply(lapply(list5,function(x)x[[1]][[coconut]]),fun)
 #Error in x[[1]][[coconut]] : subscript out of bounds
 
 #I tried with another way to come up with the result (not as elegant)
 b3-do.call(c,list5)
 names(b3)[4]-mango
  names(b3)[5]-banana
  names(b3)[9]-pineapple
  b4-data.frame(key=names(b3),value=unlist(lapply(b3,FUN=function(x)
 max(x
  key1-c(mango,banana,pineapple)
  b5-subset(b4, b4$key%in% key1)
  b5
 #key value
 #4 mango 6
 #5banana18
 #9 pineapple 9
 b6-within(b5,{value-as.numeric(as.character(value))})
 max(b6$value)
 #[1] 18
 A.K.
 
 
 
 
 
 
 __
 If you reply to this email, your message will be added to the discussion 
 below:
 http://r.789695.n4.nabble.com/apply-function-over-same-column-of-all-objects-in-a-list-tp4638681p4638926.html
 This email was sent by arun kirshna (via Nabble)
 
   [[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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] help with a regression problem

2012-08-01 Thread Eik Vettorazzi
Hi,
maybe working with a data.frame in long format is an option - then you
can use e.g. lmList and so on up to mixed models, depending on your
final goals of analyses (e.g. check for differential slopes).

vmat-matrix(c(X1,X2,X3,X4,Y1,Y2,Y3,Y4),nrow=2,byrow=T)
aa.l-reshape(aa,idvar=ID,direction=long,varying=vmat,v.names=c(X,Y))
library(nlme)
(ll-lmList(Y~X|ID,aa.l,na.action=na.omit))
summary(ll)

cheers.

Am 01.08.2012 15:06, schrieb R Heberto Ghezzo, Dr:
 Hello,
 I have a big data frame where consecutive time dates and corresponding 
 observed values for each subject (ID) are on a line. I want to compute the 
 linear slope for each subject. I would like to use apply but I do
 not know how to express the corresponding function. An example using a loop 
 follows 
 #
 # create dummy data set There are missing values
  a - c(1,2,3,4, 1,1,1,1, 2,2,3,3, 3,4,NA,4, 5,5,5,5,
 2.1,2.2,2.3,2.4, 2.3,2.4,2.6,2.6, 2.5,2.6,2.9,3,
 2.6,NA,3.2,4)
 a - matrix(a, nr=4)
 aa - as.data.frame(a)
 names(aa) - c(ID,X1,X2,X3,X4,Y1,Y2,Y3,Y4)
 #
 #  I want the regression coefficientes of the Y on the X for each ID
 #
 sl - rep(NA,4)
 for(i in 1:4) {
   x1 - a[i,2:5]
   y1 - a[i,6:9]
   sl[i] - lm(y1 ~ x1)$coef[2]
 }
 sl
 #
 #   I would like to use apply on the data.frame aa but with which function?
 #
 sl - apply(aa,1,FUN) # FUN = ??
 #
 Thanks for any help
 
 R.Heberto Ghezzo Ph.D.
 Montreal - 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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Optimize a function with Discrete inputs

2012-08-01 Thread Eik Vettorazzi
Hi,
not sure if that is what you are looking for, but have a look at

cmb-t(combn(c(0,3,5,8),2))   #get all pairs of combinations
cbind(cmb,apply(cmb,1,diff))  #for each pair, get the difference

cheers


Am 01.08.2012 12:29, schrieb loyolite270:
 Hi
 
 I need to optimize the below function:
 
 a=function(x){
  A=x[1]
  B=x[2]
  C=B-A
 return(C)
 }
 
 I need to optimize the above function such that x can be any combination of
 these number (0,3,5,8) of vector length 2
 (i.e) x can be (3,0), (5,0), (8,0), (3,5), (3,8), (5,8), .. etc
 
 can someone please help me solve this problem ?
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Optimize-a-function-with-Discrete-inputs-tp4638644.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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Variables in a Tabular form. easily saved in a txt file

2012-07-26 Thread Eik Vettorazzi
Hi Alex,

sprintf with left alignment might be a start:

cat(sprintf(%-7s| %-12d|
%-5d,paste(City,1:3,sep=),(12345)%/%10^c(1:3),c(2,5,54433)),sep=\n)
#cat has also a file option, see ?cat.

but acutally your given output doesn't look like a conventional table
but much more like this:
cat(sprintf(paste(%-7s| %-,12:14,d|
%-5d,sep=),paste(City,1:3,sep=),(12345)%/%10^c(1:3),c(2,5,54433)),sep=\n)

cheers.

Am 26.07.2012 13:29, schrieb Alaios:
 Dear all,
 I would like to save few variable-names with their values in a tabular form, 
 with that I mean
 
 that files can be printed easily in R in a tabular form and also saved in a 
 ascii file that when one opens it see also the variables in a nice tabular 
 format.
 
 IS that possible? Below a small example of how should look results in R and 
 in a txt file.
 
 
 
 
 
 
  Postal Code | Superb
 City1   |   2134  |  2
 City2   |   254|  5
 City3   |   12  |  54433
 
 
 
 I am ok if you can give me some hard coded example to try. 
 
 
 
 Regards
 Alex
   [[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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] package memisc: recode examples

2012-07-24 Thread Eik Vettorazzi
Hi Marion,
the Hmisc package has also a function called recode, maybe you loaded
this package after memisc so the memisc version was masked (you should
have got a warning message about that). Or perhaps you wrote you own
recode function?

Try

find(recode,mode=function)

to see all search list entries.

You can access the desired function regardless of the place in the
search path by
memisc::recode(...)


hth.

Am 24.07.2012 13:53, schrieb Marion Wenty:
 Dear people,
 
 Yesterday I looked at the recode command in the memisc package and ran the
 following example stated in the manual:
 
 x - as.item(sample(1:6,20,replace=TRUE),
  labels=c( a=1,
b=2,
c=3,
d=4,
e=5,
f=6))
 
 print(x)
 f - as.factor(x)
 f
 recode(f,
   A=c(a,b),
   B=c(c,d),otherwise=copy
   )
 
 I also used this command for my dataset and it work - I didn't get an error
 message.
 
 Today I have tried several times running this example, also with my
 dataset, and always got the same error message (in German):
 
 Fehler in recode(f, A = c(a, b), B = c(c, d), otherwise = copy) :
   unbenutzte(s) Argument(e) (A = c(a, b), B = c(c, d), otherwise =
 copy)
 
 (Error in recode ...
   unused argument(s) ...)
 
 I also couldn't find anything in the internet. I don't understand why this
 is not working anymore. Does anyone know what the problem is?
 
 Thank you very much for your help in advance!
 
 Marion
 
   [[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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Maintaining Column names while writing csv file.

2012-07-19 Thread Eik Vettorazzi
Hi Vincy,
have you checked

names(df2)

and

names(df_new)

because by default 'data.frame' checks the column names to ensure that
they are syntactically valid variable names and 1w and 2w aren't, so an
X is prepended (see ?data.frame and ?make.names).

compare
tst.fail-data.frame(a=1:3,1a=1:3,1b=1:3)
names(tst.fail)

#and
tst-data.frame(a=1:3,1a=1:3,1b=1:3,check.names = F)
names(tst)

this works for me:

tst2-data.frame(a=1:3,w1=4:6,w3=4:6)
write.csv(merge(tst,tst2),file=testr.csv)


hth.

Am 19.07.2012 08:55, schrieb Vincy Pyne:
 Dear R helpers,
 
 I have one trivial problem while writing an output file in csv format.
 
 I have two dataframes say df1 and df2 which I am reading from two different 
 csv files. 
 
 df1 has column names as date, r1, r2, r3 while the dataframe df2 has column 
 names as date, 1w, 2w. 
 
 (the dates in both the date frames are identical also no of elements in each 
 column are equal say = 10).
 
 I merge these dataframes as
 
 df_new = merge(df1, df2, by = date, all = T) 
 
 So my new data frame has columns as 
 
 date, r1, r2, r3, 1w, 2w
 
 However, if I try to write this new dataframe as a csv file as
 
 write.csv(data.frame(df_new), 'df_new.csv', row.names = FALSE)
 
 The file gets written, but when I open the csv file, the column names 
 displayed are as
 
 date, r1, r2, r3, X1w, X2w
 
 My original output file has about 200 columns so it is not possible to write 
 column names individually. Also, I can't change the column names since I am 
 receiving these files from external source and need to maintain the column 
 names.
 
 Kindly guide
 
 
 Regards
 
 Vincy
 
 
   [[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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Finding the last value before a certain date

2012-07-19 Thread Eik Vettorazzi
Hi Robert,
how about this (assuming your data.frame is ordered by date):

tmp-read.table(textConnection(datey
1 2010-09-27 1356
2 2010-10-04 1968
3 2010-10-11 2602
4 2010-10-17 3116
5 2010-10-24 3496
6 2010-10-31 3958),header=T,colClasses=c(date=Date))
tmp[max(which(tmp$dateas.Date(2010-10-06))),y]

hth.

Am 19.07.2012 09:42, schrieb Robert Latest:
 Hello all,
 
 I have a dataframe that looks like this:
 
 head(df)
 datey
 1 2010-09-27 1356
 2 2010-10-04 1968
 3 2010-10-11 2602
 4 2010-10-17 3116
 5 2010-10-24 3496
 6 2010-10-31 3958
 
 I need a function that, given any date, returns the y value
 corresponding to the given date or the last day before the given date.
 
 Example:
 
 Input: as.Date(2010-10-06). Output: 1968 (because the last value is
 from 2010-10-04)
 
 I've been tinkering with this for an hour now, without success. I
 think the solution is either surprisingly complicated or surprisingly
 simple.
 
 Thanks,
 robert
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] problem with using apply for dataframe

2012-07-19 Thread Eik Vettorazzi
Hi Marion,
as stated in the help file ?apply coerces a data.frame object into an
array. Since an array has only one type of data, this coercion turns all
your variables into strings (because this data type can hold all
information given without loss).

If it happens that your data.frame consists only of numeric variables,
then this type suffices for the array as well, and things like sum or
mean can be applied row/columnwise.

btw:

apply(mydataframe,2,function(x)sum(x))

doesn't work either (for the same reason).

Cheers

Am 19.07.2012 11:48, schrieb Marion Wenty:
 Dear people,
 
 I am including an example of a dataframe:
 
 mydataframe-data.frame(X=c(1:4),total_bill=c(16.99,10.34,21.01,23.68),tip=c(1.01,1.66,3.50,3.31),sex=c(Male,Male,Male,Female))
 
 When I use the sapply function getting the information about the factors
 works:
 
 sapply(mydataframe,function(x)is.factor(x))
 
  X total_billtipsex
  FALSE  FALSE  FALSE   TRUE
 
 
 But if I use the apply function it doesn't work:
 
 apply(mydataframe,2,function(x)is.factor(x))
 
  X total_billtipsex
  FALSE  FALSE  FALSE  FALSE
 
 
 I don't understand why, because I have used the apply function for
 dataframes before e.g. using sum(x) instead of is.factor(x) and it did work.
 
 Could anyone help me with this?
 
 Thank you very much for your help in advance!
 
 Marion
 
   [[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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] duplicate data between two data frames according to row names

2012-07-18 Thread Eik Vettorazzi
Hi Jeff,
looks like a job for ?rbind and ?merge

merge(rbind(DF1,DF2),DF3)


hth

Am 18.07.2012 10:21, schrieb jeff6868:
 Hi everybody.
 
 I'll first explain my problem and what I'm trying to do. 
 Admit this example:
 I'm working on 5 different weather stations.
 I have first in one file 3 of these 5 weather stations, containing their
 data. Here's an example of this file:
 
 DF1 - data.frame(station=c(ST001,ST004,ST005),data=c(5,2,8))
 
 And my two other stations in this other data.frame:
 
 DF2 - data.frame(station=c(ST002,ST003),data=c(3,7))
 
 I would like to add geographical coordinates of these weather stations
 inside these two data.frames, according to the number of the weather
 station.
 
 All of my geographical coordinates for each of the 5 weather stations are
 inside another data frame:
 
 DF3 -
 data.frame(station=c(ST001,ST002,ST003,ST004,ST005),lat=c(40,41,42,43,44),lon=c(1,2,3,4,5))
 
 My question is: how can I put automatically these geographical coordinates
 inside my first 2 data frames, according to the number of the weather
 station?
 
 For this example, the first two data frames DF1 and DF2 should become:
 
 DF1 -
 data.frame(station=c(ST001,ST004,ST005),lat=c(40,43,44),lon=c(1,4,5),data=c(5,2,8))
 and
 DF2 -
 data.frame(station=c(ST002,ST003),lat=c(41,42),lon=c(2,3),data=c(3,7))
 
 I need to automatize this method because my real dataset contains 70 weather
 stations, and each file contains other (or same sometimes) stations , but
 each station can be found in the list of the coordinates file (DF3).
 
 Is there any way or any function able to do this kind of thing?
 
 Thank you very much!
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/duplicate-data-between-two-data-frames-according-to-row-names-tp4636845.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.
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] contour

2012-07-18 Thread Eik Vettorazzi
Hi Akhil,
in addition to Rui's post, here is a solution using lattice graphics.

tmp-read.table(textConnection(x1 x2 x3
0   12
0   21
0   35
1   14
1   22
1   33),header=T)

library(lattice)
contourplot(x3~x1*x2,tmp)

hth.

Am 18.07.2012 11:23, schrieb Akhil dua:
 Hello Everyone
 
 I have the data long format and I want to draw the contour plot with it
 
 x1 x2 x3
 0   12
 0   21
 0   35
 1   14
 1   22
 1   33
 
 
 when I am using contour(x1,x2,x3,col=heat.colors) or fill.contour
 its giving me an error that increasing x and y expected
 
 
 So please tell me what is the right function to draw contour when the data
 is not ordered and you cant order it.
 
   [[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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 create table with file link in Rd File

2012-07-17 Thread Eik Vettorazzi
Hi,
I think \tabular does what you want, see
see http://cran.r-project.org/doc/manuals/R-exts.html#Lists-and-tables

hth.

Am 17.07.2012 14:45, schrieb purushothaman:
 Hi,
 
 i need to create table like this
 
 ---
 module name  class namefunction name  
 
 fun description
 ---
 CSV Functions CSVoperations   http://readcsv.hml Read csv used to
 read input csv file
 
 
 
 Thanks
 B.Purushothaman
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/how-to-create-table-with-file-link-in-Rd-File-tp4636740p4636742.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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] I need to get function name from R file

2012-07-11 Thread Eik Vettorazzi
Hi,
how about this:

sandbox-new.env()
sys.source(test.R,envir=sandbox)

#all objects defined in test.r
(tstf-ls(env=sandbox))

#just the functions
tstf[sapply(tstf, function(n) exists(n, envir = sandbox, mode =
function, inherits = FALSE))]

hth

Eik

Am 11.07.2012 15:22, schrieb purushothaman:
 Hi,
 
 i need to get functions name from R file
 
 example
 
 test.R file having 2 functions like
 
 add-function()
 {
 a+b
 }
 sub-function()
 {
 a-b
 }
 
 how to get function name from test.R file
 
 i need output is functions are add,sub.
 
 Thanks
 B.Purushothaman
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/I-need-to-get-function-name-from-R-file-tp4636136.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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Import single variables from SPSS

2012-07-05 Thread Eik Vettorazzi
Hi Marion,
package memisc does what you want, just have a look at ?importers.

Hth
Eik

Am 05.07.2012 15:05, schrieb Marion Wenty:
 Dear all,
 I have got a very big SPSS dataframe and I would like to just import one or
 a few variables (the dataframe has got a lot of colums).
 I used the package foreign but I couldn't find anything in there for my
 problem.
 Thank you very much for your help in advance.
 Marion
 
   [[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.
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] inverse binomial in R

2012-06-19 Thread Eik Vettorazzi
Hi Anna,
you are at the upper end of the support of the respective binomial
distribution when asking for invbinomial(n,n,p). The probability of
seeing n or less successes in n trials is 1, regardless of the
underlying success rate. It cannot be less, so asking for
invbinomial(50,50, 0.6) makes no sense at all - neither does the result
of stata.

You may insert some exception handling in the function by throwing a
warning or error, when this special case occurs - or even return 0 to
cope the erroneous stata result.

cheers

Am 19.06.2012 11:39, schrieb anna freni sterrantino:
 
 
 Hi Duncan and Rlist,
 I've notice a different behaviour in the invbinomial
 you suggest me and invbinomial in stata.
 
 invbinomial(50,50, 0.4)
 Error in uniroot(function(x) pbinom(k, n, x) - p, c(0, 1)) : 
   f() values at end points not of opposite sign
 invbinomial(50,50, 0.6)
 Error in uniroot(function(x) pbinom(k, n, x) - p, c(0, 1)) : 
   f() values at end points not of opposite sign
 
 while stata
 gen p3=invbinomial(50,50, 0.4)
 
 . display p3
 0
 
 
 
 
 . gen p4=invbinomial(50,50, 0.6)
 
 . display p4
 0
 
 Thanks
 Cheers 
 
 Anna
 
 
 
  Da: Duncan Murdoch murdoch.dun...@gmail.com
 
 Cc: Rcran help r-help@r-project.org 
 Inviato: Giovedì 31 Maggio 2012 15:32
 Oggetto: Re: [R] inverse binomial  in R
 
 On 12-05-31 9:10 AM, anna freni sterrantino wrote:
 Hello!
 I'm having some trouble
 trying to replicate in R a Stata function

invbinomial(n,k,p)
  Domain n: 1 to 1e+17
  Domain k: 0 to n - 1
  Domain p: 0 to 1 (exclusive)
  Range:0 to 1
  Description:  returns the inverse of the cumulative binomial; i.e., 
 it
returns the probability of success on one trial 
 such
that the probability of observing floor(k) or 
 fewer
successes in floor(n) trials is p.

 I've found some hints on the web like
 http://rwiki.sciviews.org/doku.php?id=guides:tutorials:regression:table

 I tried to replicate using qbinom
 the results obtained in

 invbinomial(10,5, 0.5)
 .54830584

 but with no success.
 
 I don't think base R has a function like that, though some contributed 
 package probably does.  If you're writing it yourself you'd need to use 
 uniroot or some other solver, e.g
 
 invbinomial - function(n, k, p) {
uniroot(function(x) pbinom(5, 10, x) - p, c(0, 1))
 }
   [[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.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Day or Month difference between dates???

2012-06-01 Thread Eik Vettorazzi
Hi Tammy,
I suspect that the first 4 digits compose the year, so with

Year_Month-c(2010*100+9:11,2011*100+1:2)
#check composition
Year_Month

ym-(Year_Month%/%100*12+Year_Month%%100)
ym-ym[1]

should give the difference in months.

Differences in Days are a bit trickier, since not all months have an
equal number of days. Something like

xd-as.Date(paste(Year_Month%/%100,Year_Month%%100,01,sep=-))
xd-xd[1]

deals with that.

Cheers


Am 01.06.2012 13:31, schrieb Tammy Ma:
 
 HI, R-Users:
 
 I got a questions. have been struggling so long time
 
 I have this data:
 
 m1$Year_Month
   201009 201010 201011 201101 201102
 min(m1$Year_Month)
   201009
 
 I want to calculate the following two answers, how do I program it?
 
 difference in Month?
  [1] 0 1 2 4 5 
 
 difference in Days?
  0  31  61 
 
 Thank you in advance!!!
 
 Tammy
 
   [[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.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] \Sexpr{}

2012-04-02 Thread Eik Vettorazzi
Hi Hua,
try

options(SweaveSyntax=SweaveSyntaxNoweb)

before sweaving your file (see A.14 in the FAQ section of the manual).
In most cases R2HTML interferes with Sweave, causing your problem


hth.

Am 02.04.2012 15:12, schrieb Liang, Hua:
 Did anyone know whether the problem  it doesn't evaluate \Sexpr{} in Sweave 
 has been fixed? I checked r help page and realized it was asked a couple of 
 years ago. But I didn't find solutions.
 
 Thanks for your help in advance!
 
 Hua
 
 
   [[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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Test Normality

2012-03-28 Thread Eik Vettorazzi
Hi Sindy,
you might try Snows penultimate normality test from the TeachingDemos
package. But read the help file carefully.

http://www.inside-r.org/packages/cran/TeachingDemos/docs/SnowsPenultimateNormalityTest

cheers.

Am 28.03.2012 02:32, schrieb Sindy Carolina Lizarazo:
 Good Night
 
 I made different test to check normality and multinormality in my dataset,
 but I don´t know which test is better.
 
 To verify univariate normality I checked: shapiro.test, cvm.test, ad.test,
 lillie.test, sf.test or jaque.bera.test and
 To verify multivariate normal distribution  I use mardia, mvShapiro.Test,
 mvsf, mshapiro.test, mvnorm.e.
 
 I have a dataset with almost 1000 data and 9 variables, in both cases the
 result is non-normality. For this reason, I transformed data with bcPower
 function and I want to check normality again.
 
 I really appreciate your help.
 Thanks.
 
   [[alternative HTML version deleted]]
 
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] plot points using circles filled half in red and half in blue.

2012-03-28 Thread Eik Vettorazzi
Hi Alan,
on an UTF-8 locale you can use \u25D6 and \u25D7, but you have to plot
group a=4 twice.

On Windows in a non-utf locale you can use a special Windows font:

windowsFonts(wdg2=windowsFont(Wingdings 2))

plot(0:1,0:1)
strh-strheight(x)/2.02
points(x = 0.5, y = 0.75+strh/2,pch=¼,family=wdg2,col=red)
points(x = 0.5, y = 0.75-strh/2,pch=½,family=wdg2,col=green)

strw-strwidth(º)
points(.4-strw/2,.7,pch=º,family=wdg2,col=red)
points(.4+strw/2,.7,pch=»,family=wdg2,col=green)

Cheers

Am 28.03.2012 04:49, schrieb alan:
 I want to plot many points and want to use circles. The filling color
 depends on variable a. if a=1, then not fill
 if a=2 then fill with red, if a=3 then fill with blue, if a=4, fill
 half with red and half with blue. Can anyone tell me how to plot the
 case a=4? Thanks a lot
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] What are the color's name in heat.color(5)

2012-03-28 Thread Eik Vettorazzi
Hi,
just one more note, col2rgb works for color codes as well:

(HC.m - col2rgb(heat.colors(5)))

and to convert named colors to color codes, something like

tabl-apply(col2rgb(colors()),2,function(x)do.call(rgb,c(as.list(x),alpha=255,maxColorValue=255)))
names(tabl)-colors()
tabl

should work.

cheers

Am 28.03.2012 15:51, schrieb David Winsemius:
 
 On Mar 28, 2012, at 9:08 AM, Kevin Wright wrote:
 
 They have hex RGB values instead of names:

 R heat.colors(5)
 
 [1] #FFFF #FF5500FF #FFAA00FF #00FF #80FF

 Kevin
 
 The first one is the same as 'red' as can be seen by parsing the RGB
 values above:
 
 col2rgb(red)
   [,1]
 red255
 green0
 blue 0
 
 HC.m  matrix( c( strtoi( substr(heat.colors(5), 2,3), 16L),
 strtoi(substr(heat.colors(5), 4,5), 16L), strtoi(substr(heat.colors(5),
 6,7), 16L) ), nrow=3, byrow=TRUE)
 HC.m
  [,1] [,2] [,3] [,4] [,5]
 [1,]  255  255  255  255  255
 [2,]0   85  170  255  255
 [3,]0000  128
 
 One of the others 'yellow' is also in named colors:
 
 which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
 c(HC.m[,2]))) )
 integer(0)
 which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
 c(HC.m[,3]))) )
 integer(0)
 which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
 c(HC.m[,1]))) )
 [1] 552 553
 which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
 c(HC.m[,4]))) )
 [1] 652 653
 which( apply(col2rgb(colors()) , 2 , function(x) all( x ==
 c(HC.m[,5]))) )
 integer(0)
 
 colors()[552: 553]
 [1] red  red1
 
 colors()[652:653]
 [1] yellow  yellow1
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] SPSS R-Menu for Ordinal Factor Analysis

2012-03-26 Thread Eik Vettorazzi
Hi Till,
you need a plug-in for SPSS to run R, which is bound to a fixed R
version. SPSS 19 uses R2.10 and SPSS 20 uses R2.12 (both not up-to-date
R versions). So you have to download this plugin (after registering on
IBM Support) for your spss version and the according R version - or
start with a brand new R2.14 ;)
Cheers.


Am 26.03.2012 13:32, schrieb Till Below:
 Dear all,
 
 I am trying to conduct an enhanced version of factor analysis with a
 SPSS interface that allows to use R. This approach has been suggested in
 the recent article:
 
 Basto, M. and J.M. Pereira  An SPSS R-Menu for Ordinal Factor Analysis.
 Journal of Statistical Software 46, pp. 1-29.
 
 My variables are ordinal-type and the tool of Basto allows to run
 polychoric correlations in the SPSS environment with the R essentials
 ans Plugin.
 
 I used R 2.10 version for spss 20 (I only have access to spss 20). I
 loaded the required packages. When running the factor analysis in spss
 with the plugin I receive the error message posted below. Aparently, the
 tool of Basto runs only with spss 19. Since the packages and the plugin
 are installed I think it must be a problem of the spss version.
 
 Could someone suggest me a solution for the problem? I am not familiar
 with R, and so I would prefer to run the factor analysis in spss. Is
 there any possebility to run it with spss V. 20?
 
 Best regards and compliments for your work,
 
 Till Below (PhD student, Humboldt Universität zu Berlin, Germany)
 
 
 SPSS output with error message:
 
 GET
   FILE='C:\X.
 DATASET NAME DatenSet1 WINDOW=FRONT.
 DATASET ACTIVATE DatenSet1.
 SAVE OUTFILE='C:\XX
  /COMPRESSED.
 *Mário Basto, José Manuel Pereira, IPCA
 *Required: SPSS 19 and R Integration Plugin
 *R Packages required: psych, polycor, GPArotation, nFactors, corpcor, ICS.
 set printback off.
 
 
 
 
 
 
 
 
 
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Best way to compute the difference between two levels of a factor ?

2012-03-21 Thread Eik Vettorazzi
Hi Sylvain,

assuming your data frame is ordered by ID and TIME, how about this
aggregate(cbind(X,Y)~ID,data, function(x)(x[2]-x[1]))

#or doing this for all but the first 2 columns of data:
aggregate(data[,-(1:2)],by=list(data$ID), function(x)(x[2]-x[1]))

cheers.

Am 21.03.2012 09:48, schrieb wphantomfr:
 Dear R-help Members,
 
 
 I am wondering if anyone think of the optimal way of computing for
 several numeric variable the difference between 2 levels of a factor.
 
 
 To be clear let's generate a simple data frame with 2 numeric variables 
 collected for different subjects (ID) and 2 levels of a TIME factor
 (time of evaluation)
 
 data=data.frame(ID=c(AA,AA,BB,BB,CC,CC),TIME=c(T1,T2,T1,T2,T1,T2),X=rnorm(6,10,2.3),Y=rnorm(6,12,1.9))
 
 
   ID TIME X Y
 1 AA   T1  9.959540 11.140529
 2 AA   T2 12.949522  9.896559
 3 BB   T1  9.039486 13.469104
 4 BB   T2 10.056392 14.632169
 5 CC   T1  8.706590 14.939197
 6 CC   T2 10.799296 10.747609
 
 I want to compute for each subject and each variable (X, Y, ...) the
 difference between T2 and T1.
 
 Until today I do it by reshaping my dataframe to the wide format (the
 columns are then ID, X.T1, X.T2, Y.T1,Y.T2) and then  compute the
 difference between successive  columns one by one :
 data$Xdiff=data$X.T2-data$X.T1
 data$Ydiff=data$Y.T2-data$Y.T1
 ...
 
 but this way is probably not optimal if the difference has to be
 computed for a large number of variables.
 
 How will you handle it ?
 
 
 Thanks in advance
 
 Sylvain Clément
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] constant function

2012-03-07 Thread Eik Vettorazzi
Hi Chris,
how about this:

constant-function(x) rep(7,length(x))
curve(constant,-1000,100)

cheers.

Am 07.03.2012 06:41, schrieb Chris Waggoner:
 Is it possible to define a constant function (for example the zero function) 
 in R?
 
 I found the following unsatisfying hack to create the seven function:
 
 constant - stepfun( x = -100:100,   y = rep(7,   201)  )
 
 
 This is mathematically unsatisfying because the domain is artificially 
 restricted to [-100,100] rather than (-Inf,Inf).
 
 Additionally, unless I use pch=n there are ugly dots on the plot (and again 
 this feels hackish).
 
 
 Any suggestions on what else to do?
 
 
 
 Thanks in advance.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Aggregate with Function List ?

2012-02-24 Thread Eik Vettorazzi
Hi Michael,
something like the following might be a starting point for aggregating
data using arbitrary lists of functions:

(it is lacking a method for data.frame objects)

maggregate-function(...)UseMethod(maggregate)
maggregate.default-function(x, FUN, ...){
 tmp-lapply(FUN,function(fct)aggregate(x,FUN=fct,...))
 names(tmp)-sapply(substitute(FUN), deparse)[-1]
 r2-data.frame(tmp[[1]][,1],sapply(tmp,[,-1))
 names(r2)[1]-names(tmp[[1]])[1]
 r2
}
maggregate.formula-function(formula, data, FUN, ..., subset, na.action
= na.omit){

tmp-lapply(FUN,function(fct)aggregate(formula,data,fct,...,na.action =
na.action))
 names(tmp)-sapply(substitute(FUN), deparse)[-1]
 r2-data.frame(tmp[[1]][,1],sapply(tmp,[,-1))
 names(r2)[1]-names(tmp[[1]])[1]
 r2
 }
#using formula method
maggregate(Sepal.Length~Species,data=iris,FUN=c(mean,median,sd))
maggregate(Sepal.Length~Species,data=iris,FUN=list(mean,quantile))

#check if parameters are passed to quantile
maggregate(Sepal.Length~Species,iris,FUN=list(mean,quantile),probs=c(.25,.5,.75))


maggregate(iris$Sepal.Length,by=list(iris$Species),FUN=list(mean,quantile))


Cheers

Am 23.02.2012 19:41, schrieb Michael Karol:
 R Experts
 
  
 
   I wish to tabulate into one data frame statistics summarizing
 concentration data.   The summary is to include mean, standard
 deviation, median, min and max.  I wish to have summaries by Dose, Day
 and Time.   I can do this by calling aggregate once for each of the
 statistics (mean, standard deviation, median, min and max) and then
 execute 4 merges to merging the 5 data frames into one.  (Example
 aggregate code for mean only is shown below.)  
 
   Can someone show me the coding to do this as one command, rather than
 5 calls to aggregate and 4 merges.  In other words, in essence, I'd like
 to present to FUN = a list of functions, so all the summary stats come
 back in one data frame.  Your assistance is appreciated.  Thank you.
 
  
 
 MeansByDoseDayTime - aggregate(as.double(DF$Concentration), by =
 list(DF$Dose, DF$Day, DF$Time), FUN = mean, trim = 0, na.rm = T,
 weights=NULL)
 
  
 
  
 
 Regards, 
 
 Michael
 
 
   [[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.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Loop

2012-02-22 Thread Eik Vettorazzi
Hi Florian,

'yet that doesn't work' is an improper question on this list, see the
posting guide.
Besides that, something like
set-vector(mode = list, length = 10)
for (i in 1:10){
   set[[i]] - complete(imp,i)}

or saving some typing

set-lapply(1:10,function(i)complete(imp,i))

should work.

cheers

Am 22.02.2012 11:32, schrieb Florian Weiler:
 Dear all,
 
 I have a (probably very basic) question. I am imputing data with the mice
 package, using 10 chains. I can then write out the 10 final values of the
 chains simply by
 
 name1 - complete(imp, 1)
   :
   :
 name10 - complete(imp,10)
 
 Not a big deal, I just wanted to do that in a little loop as follows:
 
 for (i in 1:10){
   set[i] - complete(imp,i)}
 
 Yet that doesn't work, I also tried other things like:
 for (i in 1:10){
   set[[i]] - complete(imp,i)}
 
 Again, no success. It only saves a couple of lines of code, but there must
 be an easy solution, right?
 Thanks,
 Florian
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Loop-tp4409865p4409865.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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 substitute in nested function calls

2012-02-21 Thread Eik Vettorazzi
Hi Sebastian,
how about this:

mycurve - function (expr) {
do.call(curve,list(substitute(expr),-100,100))
}

mycurve(x^2)
mycurve(sin(x/20))
mycurve(x+x^2-x^3)

cheers

Am 21.02.2012 06:28, schrieb Sebastian Kranz:
 Dear List members,
 
 I really, like the feature that one can call R functions with 
 mathematical expressions, e.g.
 
 curve(x^2, 0, 1)
 
 
 I wonder, how I can construct in a simple way a function like
 
 mycurve = function (expr) {...}
 
 such that that a call
 
 mycurve(x^2)
 
 has the same effect as the call
 
 curve(x^2, -100,100)
 
 Below is some code that works, but it seems much to complicated: it 
 first substitutes and deparses the expression, creates a string with the 
 new function call and then parses and evaluates the string again. Does 
 anybody know a simpler, more elegant solution?
 
 mycurve = function(expr) {
# The following attempt does not work
# curve(substitute(expr),-100,100)
 
# Transform original expression to a string
org.expr = deparse(substitute(expr))
# Construct a string, parse it and evaluates it
eval(parse(text=paste(curve(,org.expr,,-100,100),sep=)))
 }
 mycurve(x^2)
 
 Best regards,
 Sebastian
 
   [[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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Run function several times changing only one argument - without a loop

2012-02-20 Thread Eik Vettorazzi
Hi Marion,
you can either use any of the *apply-functions or vectorize your
function (which internally uses mapply):

par(las=1)
par(mar=c(5,13,4,2))
barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F)

#using sapply
invisible(sapply((1:9)*10,function(x)axis(2,pos=x,tick=T, tcl=F,
labels=F,col=white)))

#using Vectorize
barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F)
vaxis-Vectorize(axis,pos)
invisible(vaxis(2,pos=(1:9)*10, tick=T, tcl=F, labels=F,col=white))

Cheers!

Am 20.02.2012 11:04, schrieb Marion Wenty:
 Dear people,
 
 I created a plot which looks like this:
 
 Ee1-matrix(c(88,86,74,62,41),ncol=5)
 colnames(Ee1)-c(Lehrer,Lehrerinnen,Klassenkollegen,Klassenkolleginnen,Geschwister)
 par(las=1)
 par(mar=c(5,13,4,2))
 barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F)
 axis(2,pos=10, tick=T, tcl=F, labels=F,col=white)
 axis(2,pos=20, tick=T, tcl=F, labels=F,col=white)
 axis(2,pos=30, tick=T, tcl=F, labels=F,col=white)
 axis(2,pos=40, tick=T, tcl=F, labels=F,col=white)
 axis(2,pos=50, tick=T, tcl=F, labels=F,col=white)
 axis(2,pos=60, tick=T, tcl=F, labels=F,col=white)
 axis(2,pos=70, tick=T, tcl=F, labels=F,col=white)
 axis(2,pos=80, tick=T, tcl=F, labels=F,col=white)
 axis(2,pos=90, tick=T, tcl=F, labels=F,col=white)
 
 Now I would like to shorten the whole thing - namely use only one step to
 create the 9 axes without having to use a loop.
 
 In general, I would be interested if there is a way to use a function
 several times changing only one argument, without having to use a loop.
 
 Does anyone know how to do that.
 
 Marion
 
   [[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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Toggle cASE

2011-12-05 Thread Eik Vettorazzi
Hi Antonio,
how about this:

txt2 - useRs may fly into JFK or laGuardia
chartr(a-zA-Z, A-Za-z, txt2)


Cheers.

Am 05.12.2011 08:11, schrieb Tonio:
 Hello R-help list,
  
 I am looking for way to toggle the case of the characters like a flip-flop; 
 that is from ''Hello'' to hELLO or vice versa.
  
 I know that there are a number of functions like casefold, tolower, toupper, 
 etc. but these functions change the case in an uniform way.
  
 Thanks in advance,
  
 Antonio Rivero Ostoic
  
  
  
  
 Antonio Rivero Ostoic
 PhD Student, Department of Leadership and Strategy
 From 1 Jul until 31 Dec 2011
 Tel.+61 3 8344 4300
 Fax +61 3 9347 6618
 Email   j...@sdu.dk
 Addr.   The University of Melbourne, Victoria 3010  Australia
 -
 UNIVERSITY OF SOUTHERN DENMARK
 Sdr. Stationsvej 28 · DK-4200   Slagelse · Denmark · Tel. +45 6550 1000 ·
 www.sdu.dk
 
   [[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.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] query for xlim/ylim of current plot

2011-10-31 Thread Eik Vettorazzi
Hi Lukas,
does
par(usr)
help?

Cheers.

Am 31.10.2011 11:34, schrieb eldor ado:
 der R-listers,
 
 does anyone of you know whether there is a function which returns the
 xlim/ylim ranges of the current plot (i would like to use coordinates
 to place some text via a function, regardless of the x/y lims of the
 plot).
 
 best regards,
 lukas kohl
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] textplot in layout

2011-10-25 Thread Eik Vettorazzi
Hi Ben,
maybe mtext is of more help here?

par(mar=c(7,3,3,3))
plot(year,rate,main='main',sub='sub')
mtext('test',cex=1,side=1,line=5)
box()

cheers

Am 25.10.2011 15:26, schrieb Ben quant:
 Hello,
 
 Someone (Erik) recently posted about putting text on a plot. That thread
 didn't help. I'd like to put text directly below the 'sub' text (with no
 gap). The code below is the best I can do. Note the large undesirable gap
 between 'sub' and 'test'. I'd like the word 'test' to be just below the top
 box() boarder (directly below 'sub').
 
 year - c(2000 ,   2001  ,  2002  ,  2003 ,   2004)
 rate - c(9.34 ,   8.50  ,  7.62  ,  6.93  ,  6.60)
 op - par(no.readonly = TRUE)
 on.exit(par(op))
 layout(matrix(c(1,2), 2, 1, byrow = TRUE),heights=c(8,1))
 par(mar=c(5,3,3,3))
 plot(year,rate,main='main',sub='sub')
 library(gplots)
 par(mar=c(0,0,0,0),new=F)
 textplot('test',valign='top',cex=1)
 box()
 
 Note: I'd rather solve it with textplot. If not, my next stop is
 grid.text(). Also, the text I am plotting with textplot is much longer so a
 multiple line text plot would solve my next issue (of which I have not
 looked into yet). Lastly, layout is not necessary. I just used it because I
 thought it would do what I wanted.
 
 Thanks,
 
 Ben
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Plotting text?

2011-10-24 Thread Eik Vettorazzi
Hi Kevin,
this should be read as halign=center - so is it a typo just in your
mail or in your program as well?

apart from that, the rules at the bottom lines of every post on this
list also apply here: what have you tried and what went wrong?

Cheers

Am 24.10.2011 14:48, schrieb Kevin Burton:
 Thank you. This works pretty well. I am having some trouble with the text on
 the left-hand side getting cut off. I have tried haling=center  with not
 luck. How can I make the text seem wider than it really is to avoid the
 truncation. It is only a few characters but still it is annoying. Thank you.
 
 -Original Message-
 From: Eik Vettorazzi [mailto:e.vettora...@uke.de] 
 Sent: Saturday, October 22, 2011 7:06 AM
 To: rkevinbur...@charter.net
 Cc: r-help@r-project.org
 Subject: Re: [R] Plotting text?
 
 Hi Kevin,
 have a look at ?textplot from the gplots-package.
 
 cheers
 
 Am 22.10.2011 02:26, schrieb rkevinbur...@charter.net:

 I noticed that the text() command adds text to a plot. Is there a way 
 to either make the plot blank or add text to a blank sheet. I would 
 like to plot a page that contains just text, no plot lines, labels, etc.

 Suggestions?

 Kevin

  [[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.
 
 
 --
 Eik Vettorazzi
 Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum
 Hamburg-Eppendorf
 
 Martinistr. 52
 20246 Hamburg
 
 T ++49/40/7410-58243
 F ++49/40/7410-57790
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] splitting a string into words preserving blanks (using regex)

2011-10-24 Thread Eik Vettorazzi
Hi Mark,
here is a way using gsub to insert a split marker and strsplit.

strsplit(gsub(([[:alnum:]]+),|\\1|,c( somewords to split ))[[1]]

cheers

Am 24.10.2011 15:46, schrieb Mark Heckmann:
 I would like to split a string into words at its blanks but also to preserve 
 all blanks.
 
 Example:
   c( somewords to split ) 
 should become
   c( , some,,  words,  , to ,  , split,  )
 
 I was not able to achieve this via strsplit() .
 But I am not familiar with regular expressions.
 Is there an easy way to do that using e.g. regex and strsplit?
 
 Thanks
 Mark
 –––
 Mark Heckmann
 Blog: www.markheckmann.de
 R-Blog: http://ryouready.wordpress.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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Plotting text?

2011-10-22 Thread Eik Vettorazzi
Hi Kevin,
have a look at ?textplot from the gplots-package.

cheers

Am 22.10.2011 02:26, schrieb rkevinbur...@charter.net:
 
 I noticed that the text() command adds text to a plot. Is there a way to 
 either make the plot blank or add text to a blank sheet. I would like 
 to plot a page that contains just text, no plot lines, labels, etc.
 
 Suggestions?
 
 Kevin
 
   [[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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] How to remove all objects except the sequence

2011-10-20 Thread Eik Vettorazzi
Hi Sergio,
how about this:

rm(list=setdiff(ls(),z))

cheers.

Am 20.10.2011 11:00, schrieb Sergio René Araujo Enciso:
 Dear All:
 
 I would like to know if there is plausible way to say to R to remove all
 elements in the memory but the sequence. I have a code which makes a loop,
 and what I want is after the programme has performed all the operation over
 every ith element, to remove all the objects, expect the sequence
 parameter. I included the option rm(list=ls(all=TRUE)), but obviously that
 removes the sequence as well.  I know that I can give the names of the
 objects to remove, but instead of doing so I would like to tell R remove all
 but the sequence. Is there a way for doing so? The reason for removing all
 the objects after each operation is saving some memory, as the operation I
 am doing involves some bootstrapping, after the loop reaches a certain ith
 element, the operations start to be really slow. So I want to faster the
 loop by removing the objects and free memory after every operation.
 Below is my code:
 
 setwd(C:\\Dokumente und Einstellung\\.)
 library(tsDyn)
 
 z-(1:1000)### sequence parameter
 sink(prueba.txt)
 for (i in seq(z))
 {
 P1-read.csv(2R_EQ_P_R1.csv)
 P2-read.csv(2R_EQ_P_R2.csv)
 c-data.frame(P1[i],P2[i])
 c.t-ts(c)*-1
 try(print(z[i]))
 try(SeoTest-TVECM.SeoTest(c.t, lag=1, beta=1, trim=0.1, nboot=100))
 try(summary(SeoTest))
 rm(list=ls(all=TRUE)) ### Here I want to erase all but z
 }
 
 best,
 
 Sergio René
 
   [[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.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] how to plot two surfaces with lattice::wireframe

2011-10-14 Thread Eik Vettorazzi
Hi Carl,
I have no idea what z or f(z) are, but maybe outer will help you:

wireframe(outer(seq(0,5,length.out=50),seq(2,4,length.out=40),function(x,y)sin(x*y)))

cheers.

Am 13.10.2011 23:37, schrieb Carl Witthoft:
 Hi all,
 I'd like to plot the Real and Imaginary parts of some f(z) as two
 different surfaces in wireframe (the row/column axes are the real and
 imag axes).  I know I can do it by, roughly speaking, something like
 
 plotz - expand.grid(x={range of Re(z)}, y={range of Im(z), groups=1:2)
 plotz$func-c(Re(f(z),Im(f(z))
 wireframe(func~x*y,data=plotz,groups=groups)
 
 But that seems like a clunky way to go, especially if I happen to have
 started out with a nice matrix of the f(z) values.
 
 So, is there some simpler way to write the formula in wireframe?  I
 envision, for a matrix of complex values zmat,  pseudocode:
 
 wireframe(c(Re(zmat),Im(zmat), groups=1:2)
 
  -- and yes, I'm fully aware that without a connection between the
 'groups' variable and zmat, this won't work as written.
 
 All suggestions (including read the help file for {some lattice func I
 didn't know about} ) greatfully accepted.
 
 Carl


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Remove specific rows in a matrix/data.frame

2011-10-13 Thread Eik Vettorazzi
Hi Syrvn,
how about this
dtf-read.table(textConnection(Letter Number
a 1
a 1
b 1
b 0
c 0
c 1
d 0
d 0),header=T)
aggregate(Number~Letter,data=dtf,max)

cheers.

Am 13.10.2011 18:42, schrieb syrvn:
 Hi,
 
 
 imagine the following matrix/data.frame
 
 Letter Number
 a 1
 a 1
 b 1
 b 0
 c 0
 c 1
 d 0
 d 0 
 
 If the numbers for two identical letters are also identical then I want to
 remove either the first or the
 second row of that letter. If for a letter the numbers are 1 and 0 I want to
 remove the row with the 0.
 
 That means if the code works I would and up with the following
 matrix/data.frame
 
 Letter Number
 a 1
 b 1
 c 1
 d 1
 
 
 Many thanks,
 Syrvn
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902149.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.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Remove specific rows in a matrix/data.frame

2011-10-13 Thread Eik Vettorazzi
Hi,
just put it in the formula:

aggregate(Number ~ Letter+Test,data=dtf,max)

cheers

Am 13.10.2011 19:30, schrieb syrvn:
 Hello again,
 
   
 dtf-read.table(textConnection(Letter Test Number 
   a b 1 
   a b 1 
   b b 1 
   b b 0 
   c b 0 
   c b 1 
   d b 0 
   d b 0),header=T) 
 aggregate(Number ~ Letter,data=dtf,max)
 
 how can I adjust this solution that the results also includes Test?
 
 I tried:
 
 aggregate(Number ~ Letter,data=dtf,max,by=list(Letter, Test, Number))
 
 But it breaks with the following error message:
 
 Error in aggregate.data.frame(mf[1L], mf[-1L], FUN = FUN, ...) : 
   arguments must have same length
 
 
 
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902286.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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

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


Re: [R] Parallel processing for R loop

2011-10-12 Thread Eik Vettorazzi
Hi Sandeep,
still missing an answer? Perhaps you cross check your post with the
rules of the posting guide and find what is missing at all here.

Anyway, depending on your OS, package multicore, snow/snowfall
may fit your needs - but you have to re-formulate your loop using
adequate multicore *apply-functions.

hth

Am 11.10.2011 14:13, schrieb Sandeep Patil:
 I have an R script that consists of a for loop
 that repeats a process for many different files.
 
 
 I want to process this parallely on machine with
 multiple cores, is there any package for it ?
 
 Thanks


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 test if two C statistics are significantly different?

2011-10-11 Thread Eik Vettorazzi
Hi Yujie,
there is still a lot of work in progress, I think. As
http://faculty.washington.edu/heagerty/Software/SurvROC/RisksetROC/risksetROCdiscuss.pdf

states: [...] for inference and variance estimation, we now suggest
bootstrapping [...].
Recently I catched a glimpse on roc.test from the pROC package, they
implemented, amongst others, a bootstrap algorithm - maybe this is a
start for your own work?

Hth.

Am 10.10.2011 21:35, schrieb Yujie Wang:
 Hey all,
 
 In order to test if a marker is a risk factor, I built two models (using cox
 proportional hazard model). One model included this marker, and the other is
 not.
 
 Then, I use R package risksetROC to test how much predictive value did the
 marker add to this model. I get two C statistics by analyzing the linear
 predictors of the two models into this package.
 
 The qustion is How to test if two C statistics are significantly different?
 
 Your help will be greatly appreciated!
 
 Yujie
 
   [[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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] need help on read.spss

2011-10-11 Thread Eik Vettorazzi
Hi,
if you specify to.data.frame=T, then use.missings is implictly set to
T as well, which causes different results for (user-defined) missing values.

cheers.

Am 11.10.2011 12:07, schrieb Smart Guy:
 Hi,
   I have one doubt about one of the parameter of 'read.spss()' from
 'foreign' package.
 Here is the syntax :-
 
 read.spss ( file,
 use.value.labels = TRUE,
 to.data.frame = FALSE,
 max.value.labels = Inf,
 trim.factor.names = FALSE,
 trim_values = TRUE,
 reencode = NA,
 use.missings = to.data.frame )
 
 
 In above syntax when I pass *'to.data.frame= FALSE*' it gives me missing
 values from SPSS file (that I try to read using read.spss() ). But when I
 pass '*to.data.frame = TRUE*' then its not giving me missing values. And
 need to get missing values.
 
 According to read.spss() documentation
 
 *to.data.frame :  return a data frame?*
 
 I am curious to know, if we pass *'to.data.frame = TRUE*' , is it going to
 cause some issue or effect something? I didn't understand the read.spss()
 documentation correctly.
 Please explain.
 
 Thanks in Advance
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] anova.rq {quantreg) - Why do different level of nesting changes the P values?!

2011-10-06 Thread Eik Vettorazzi
Hi Tal,
you are comparing different things. The Details-section of ?anova.qr
states test the hypothesis that smaller models are adequate relative to
the largest specified model. So in your first anova you compare fit2
with fit1 and fit0, in your second attempt fit1 with fit0, so you have
different base-models to compare with, and consequently different
p-values.

hth.

Am 06.10.2011 10:05, schrieb Tal Galili:
 Hello dear R help members.
 
 I am trying to understand the anova.rq, and I am finding something which I
 can not explain (is it a bug?!):
 
 The example is for when we have 3 nested models.  I run the anova once on
 the two models, and again on the three models.  I expect that the p.value
 for the comparison of model 1 and model 2 would remain the same, whether or
 not I add a third model to be compared with.
 However, the P values change, and I do not understand why.
 
 Here is an example code (following with it's input):
 
 data(barro)
 fit0 - rq(y.net ~  lgdp2 + fse2 , data = barro)
 fit1 - rq(y.net ~  lgdp2 + fse2 + gedy2 , data = barro)
 fit2 - rq(y.net ~  lgdp2 + fse2 + gedy2 + Iy2 , data = barro)
 anova(fit0,fit1,fit2, R = 1000)
 anova(fit0,fit1, R = 1000)
 
 
 Output:
 
 data(barro)
 fit0 - rq(y.net ~  lgdp2 + fse2 , data = barro)
 fit1 - rq(y.net ~  lgdp2 + fse2 + gedy2 , data = barro)
 fit2 - rq(y.net ~  lgdp2 + fse2 + gedy2 + Iy2 , data = barro)
 anova(fit0,fit1,fit2, R = 1000)
 Quantile Regression Analysis of Deviance Table
 
 Model 1: y.net ~ lgdp2 + fse2 + gedy2 + Iy2
 Model 2: y.net ~ lgdp2 + fse2 + gedy2
 Model 3: y.net ~ lgdp2 + fse2
   Df Resid Df F valuePr(F)
 1  1  156  29.494 2.110e-07 ***
 2  2  156  18.194 7.901e-08 ***
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 anova(fit0,fit1, R = 1000)
 Quantile Regression Analysis of Deviance Table
 
 Model 1: y.net ~ lgdp2 + fse2 + gedy2
 Model 2: y.net ~ lgdp2 + fse2
   Df Resid Df F value  Pr(F)
 1  1  157  3.9532 0.04852 *
 ---
 Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 sessionInfo()
 R version 2.13.1 (2011-07-08)
 Platform: i386-pc-mingw32/i386 (32-bit)
 
 locale:
 [1] LC_COLLATE=Hebrew_Israel.1255  LC_CTYPE=Hebrew_Israel.1255
 [3] LC_MONETARY=Hebrew_Israel.1255 LC_NUMERIC=C
 [5] LC_TIME=Hebrew_Israel.1255
 
 attached base packages:
 [1] splines   stats graphics  grDevices utils datasets  methods
 base
 
 other attached packages:
  [1] rms_3.3-1Hmisc_3.8-3
  survival_2.36-9
  [4] colorspace_1.1-0 quantreg_4.71SparseM_0.89
 
  [7] PerformanceAnalytics_1.0.3.2 xts_0.8-2zoo_1.7-4
 
 [10] reporttools_1.0.6xtable_1.5-6
 
 loaded via a namespace (and not attached):
 [1] cluster_1.14.0  grid_2.13.1 lattice_0.19-33 tools_2.13.1
 
 
 
 
 
 
 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 --
 
   [[alternative HTML version deleted]]
 
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] converting commas to points

2011-10-06 Thread Eik Vettorazzi
Hi Anna,
have a look at ?write.csv2, which deals with the Excel conventions for
CSV in German locale.

cheers


Am 06.10.2011 17:39, schrieb Anna Lee:
 Hello everyone!
 
 I work with a german excell version which uses commas instead of
 points for seperating decimal places. R work with points so in order
 to be able to save my excell tables without changing the commas to
 points, whenever I load a table I type in: read.table(..., dec = ,)
 only R puts the points into the wron places. For excample excell has a
 cell with the number: 0,09 so what R does, it writes the number as 0.9
 which is wrong and makes my calculations become useless.
 
 Does anyone know this problem? Maby I made a mistake somewhere?
 
 I would be glad about your answers!
 
 Cheers, Anna
 


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] help with regexp

2011-10-05 Thread Eik Vettorazzi
Hi Jannis,
just use the backreferences in gsub, see ?gsub, - replacement

test - c('filename_1_def.pdf', 'filename_2_abc.pdf')
gsub(.*_([A-z]+)\\.pdf, \\1, test)

hth.

Am 05.10.2011 13:56, schrieb Jannis:
 Dear list memebers, 
 
 
 I am stuck with using regular expressions.
 
 
 Imagine I have a vector of character strings like:
 
 test - c('filename_1_def.pdf', 'filename_2_abc.pdf')
 
 How could I use regexpressions to extract only the 'def'/'abc' parts of these 
 strings?
 
 
 Some try from my side yielded no results:
 
 testresults - grep('(?=filename_[[:digit:]]_).{1,3}(?=.pdf)', perl = TRUE, 
 value = TRUE)
 
 Somehow I seem to miss some important concept here. Until now I always used 
 nested sub expressions like:
 
 testresults - sub('.pdf$', '', sub('^filename_[[:digit:]]_', '' , test))
 
 
 but this tends to become cumbersome and I was wondering whether there is a 
 more elegant way to do this?
 
 
 
 Thanks for any help
 
 Jannis
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] unload a library while testing?

2011-10-05 Thread Eik Vettorazzi
Hi Rainer,
for better or worse unlibrary actually is done by detach in R,
?detach
#first example

cheers

Am 05.10.2011 15:04, schrieb Rainer M Krug:
 Hi
 
 I am testing a package, and after I make changes, I have to close R and open
 R again to load the new version (same version number) of the package I am
 working on. So my question:
 
 is there a function which removes a package, i.e
 
 library(myPackage)
 
 Package is loaded
 unlibrary(myPackage)
 
 package is not loaded any more
 
 Thanks,
 
 Rainer
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. 
Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] String manipulation with regexpr, got to be a better way

2011-09-30 Thread Eik Vettorazzi
Hi Chris,
why not using routines for dates
dates - c(09/10/2003, 10/22/2005)
format(strptime(dates,format=%m/%d/%Y),%Y)

or take just the last 4 chars from dates
gsub(.*([0-9]{4})$,\\1,dates)

cheers

Am 29.09.2011 16:23, schrieb Chris Conner:
 Help-Rs,
  
 I'm doing some string manipulation in a file where I converted a string date 
 in mm/dd/ format and returned the date .
  
 I've used regexpr (hat tip to Gabor G for a very nice earlier post on this 
 function) in steps (I've un-nested the code and provided it and an example of 
 what I did below.  My question is: is there a more efficient way to do this.  
 Specifically is there a way to use regexpr or some other string function to 
 return not the first instance, but the 2nd (or for that matter 3rd, 4th or 
 5th instance) of a certain string?
  
  #first find the first occurence of / and create a variable for this 
 firstslash - unlist(regexpr(/, dates, fixed = TRUE)) #then use frist/ to 
 cut the string field into an intermediate variable e.g., from 1/1/2008 to 
 1/2008. step1 - substr( dates,  (firstslash + 1), nchar(dates) ) #then 
 repeat steps 1 and 2...there's got to be a better way step2 - 
 unlist(regexpr(/, step1, fixed = TRUE)) #then use step2 to cut string into 
 final product e.g., from 1/2008 to 2008. final - substring(step1,step2 + 1, 
 nchar(step1) )
  
 Thx!
 C
   [[alternative HTML version deleted]]
 
 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Plotting Lines Through multiple groups

2011-09-28 Thread Eik Vettorazzi
Hi Clara,
are there repeated measures of an animal on the same day?
Otherwise I did not get the point of the level of aggregation.

Using lattice you can do sth like
xyplot(Cort~Day,groups=Animal,type=c(p,a),data=df)

but with your given data this just connects the raw points

hth.

Am 28.09.2011 08:03, schrieb clara_eco:
 Hi I have data in the following format
 Cort Day Animal
 230  1
 273  1
 240  2
 271  2
 342  2
 303  2
 244  2
 200  3
 241  3
 282  3
 344  3
 etc.
 It is measured across time(day) however no every individual is measured the
 same number of times.  All I want to do is plot the Raw data and then run a
 line connecting the data points of each individual animal, for the example
 above there would be three lines as there are three animals.
 I've tried, gplots, lattice and car but I'm not really figuring it out, any
 help would be greatly appreciated!
 
 Thanks 
 Clara
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Plotting-Lines-Through-multiple-groups-tp3850099p3850099.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.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Problem with predict and lines in plotting binomial glm

2011-09-21 Thread Eik Vettorazzi
Hi Anina,
predict.glm returns predicted probabilities, when used with
type=response, so you have to either scale the probs to the number of
trials for any x or you plot probs from start:

par(mfcol=c(1,2))
plot(x, successes)
lines(x, (successes+failures)*predict(glm1, type= response), lwd=2)
plot(x, successes/(successes+failures))
lines(x, predict(glm1, type= response), lwd=2)

If you use predict with new data, please name the rows accordingly, when
you actually want to use them:

newdf - data.frame(seq(min(x), max(x), length=20))
#you would expect 20 predictions, but *surprise* you get
length(predict(glm2, type=response, newdata= newdf)) #52!
newdf - data.frame(x=seq(min(x), max(x), length=20))
length(predict(glm2, type=response, newdata= newdf)) #ok

And you should use the appropriate x in lines as well:

plot(x,successes/(successes+failures))
lines(newdf$x, predict(glm2, type=response, newdata= newdf),col=red)

Cheers

Am 21.09.2011 09:55, schrieb Heystek, A, Me 15418...@sun.ac.za:
 Problems with predict and lines in plotting binomial glm
 Dear R-helpers
 
 I have found quite a lot of tips on how to work with glm through this mailing 
 list, but still have a problem that I can't solve.
 I have got a data set of which the x-variable is count data and the 
 y-variable is proportional data, and I want to know what the relationship 
 between the variables are.
 The data was overdispersed (the residual deviance is much larger than the 
 residual degrees of freedom) therefore I am using the quasibinomial family, 
 thus the y-variable is a matrix of successes and failures (20 trials for 
 every sample, thus each y-variable row counts up to 20).
 
 x - c(1200, 1200, 1200, 1200, 1200, 1200, 1200, 1200, 1800, 1800, 1800, 
 1800, 1800, 1800, 1800, 1800, 1800, 2400, 2400, 2400, 2400, 2400, 2400, 2400, 
 3000, 3000, 3600, 3600, 3600, 3600, 4200, 4200, 4800, 4800, 5400, 6600, 6600, 
 7200, 7800, 7800, 8400, 8400, 8400, 9000, 9600, 10200, 13200, 18000, 20400, 
 24000, 25200, 36600)
 successes - c(6, 16, 11, 14, 11, 16, 13, 13, 14, 16, 12, 12, 11, 15, 12, 9, 
 7, 7, 17, 15, 13, 9, 9, 12, 14, 8, 9, 16, 7, 9, 14, 11, 8, 8, 13, 6, 16, 11, 
 9, 7, 9, 8, 4, 14, 7, 3, 3, 9, 12, 8, 4, 6)
 failures - c(14, 4, 9, 6, 9, 4, 7, 7, 6, 4, 8, 8, 9, 5, 8, 11, 13, 13, 3, 5, 
 7, 11, 11, 8, 6, 12, 11, 4, 13, 11, 6, 9, 12, 12, 7, 14, 4, 9, 11, 13, 11, 
 12, 16, 6, 13, 17, 17, 11, 8, 12, 16, 14)
 y - cbind(successes, failures)
 data - data.frame(y, x)
 
 glm1 - glm(y ~ x, family= quasibinomial, data= data)
 glm2 - glm(y ~ log(x), family=quasibinomial, data= data) # residual 
 deviance is lower with log transformed x-value
 plot(x, successes)
 lines(x, predict(glm1, type= response), lwd=2)
 
 
 
 
 Firstly, because of the skewed distribution of the x variable I am not sure 
 whether it should be log transformed or not.  When I do log transform it, the 
 residual deviance and the p-value for the slope is lower.
 Either way, the lines command does not plot any line and neither does it give 
 any error messages.  On some of my other data it plots a line way below all 
 the data points.  From what I can gather, the predict function as it is now 
 uses the fitted values because no newdata argument is specified. I want the 
 line to be predicted from the same x-values.  I tried two ways of adding the 
 newdata argument:
 
 ## a data.frame using the original x-values
 lines(x, predict(glm2, type= response, newdata= as.data.frame(x)))
 ##  or a data.frame with values (the same length as y) from the range of x 
 values
 newdf - data.frame(seq(min(x), max(x), length=52))
 lines(x, predict(glm2, type=response, newdata= newdf))
 
 Only the second option plotted a line once, but then I could never get it to 
 do the same again on a new plot even though I used the same variables and 
 same code.
 
 
 Thank you very much for your time and patient
 Anina Heystek
 
 BSc Honours student
 Department of Botany and Zoology
 University of Stellenbosch, Stellenbosch, South Africa
 15418...@sun.ac.za
 
 
 
   [[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.


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

__
R-help@r-project.org mailing list
https

Re: [R] pasting elements of one character vector together

2011-09-20 Thread Eik Vettorazzi
Hi marion,
just transpose the matrix:
mm-matrix(LETTERS[1:20],nrow=5)
paste(t(mm),collapse=)
or - if you want the result seperated by rows

apply(mm,1,paste,collapse=)

cheers

Am 20.09.2011 11:55, schrieb Marion Wenty:
 I have another question concerning the paste command:
 
 now instead of a vector I would like to paste the elements of a matrix
 together, which works in the same:
 
 Mypastedmatrix - paste(Mymatrix,collapse=)
 
 My problem now is that the program does this BY COLUMN, but I would like to
 have the elements pasted together BY ROW.
 
 Could anybody help me with this?
 
 Marion
 
 2011/9/19 Marion Wenty marion.we...@gmail.com
 
 hello michael and dimitris,
 yes, this was it!
 now i understand this collapse-argument.
 thank you very much.
 marion


 2011/9/19 Dimitris Rizopoulos d.rizopou...@erasmusmc.nl

 Try this:

 object - c(Hello, World)
 paste(object, collapse =  )


 I hope it helps.

 Best,
 Dimitris




 On 9/19/2011 3:58 PM, Marion Wenty wrote:

 hello,

 i am familiar with the paste command with which i can paste for exaple:

 object- Hello
 paste(object,World)

 now i would like to be able to paste all the elements of the same vector
 together e.g:

 object- c(Hello,World)

 getting as a result also:

 Hello World.

 Does anyone know the solution to this problem?

 Thank you very much in advance.

 Marion

[[alternative HTML version deleted]]

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


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

 Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
 Tel: +31/(0)10/7043478
 Fax: +31/(0)10/7043014
 Web: 
 http://www.erasmusmc.nl/**biostatistiek/http://www.erasmusmc.nl/biostatistiek/



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


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Possible or not possible: serif axis labels with plotmath [but everything else sans serif]?

2011-09-19 Thread Eik Vettorazzi
Hi Jan Marius,
using the tikzDevice-package, nearly everything is possible (at least,
all what can be done in LaTeX).

cheers

Am 19.09.2011 11:58, schrieb Hofert Jan Marius:
 Dear expeRts,
 
 I it possible to have serif labels in the following plot?
 
 x - 1:10
 y - x
 plot(x, y, type=b, xlab=expression(x[1]), ylab=expression(x[2]))
 
 I know that one can use pdf(, family=serif), but then also the axis tick 
 marks 
 are printed in serif font. Apart from the fact that it may not look nice, I'm 
 just interested if one can have serif axis labels but everything else in sans 
 serif
 (default).
 
 Cheers,
 
 Marius
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Possible or not possible: serif axis labels with plotmath [but everything else sans serif]?

2011-09-19 Thread Eik Vettorazzi
Hi Jan Marius,
I had a lot of positive experience with tkiz, but yes, handling large
datasets can push it to the limits.

Anyway, in your case, isn't it as simple as

plot(x, y, type=b,xlab=,ylab=)
title(xlab=expression(x[1]), ylab=expression(x[2]),family=serif)

cheers

Am 19.09.2011 14:51, schrieb Hofert Jan Marius:
 Dear Eik,
 
 although possible in this case, tikzDevice is certainly not a general 
 solution to all kinds of problems :-) I used it for quite some time before I 
 gave up: I had a simple bar plot, the bars being black. This already caused 
 errors like TeX capacity exceeded ... and I obtained these a lot. In fact, 
 enlarging the TeX capacity (not trivial but possible) did not solve these 
 issues. That's why I gave up on this package [although, clearly, the idea of 
 full TeX support is totally appealing -- that's why I looked at the package 
 in the first place].
 
 Cheers,
 
 Marius
 
 On 2011-09-19, at 14:38 , Eik Vettorazzi wrote:
 
 Hi Jan Marius,
 using the tikzDevice-package, nearly everything is possible (at least,
 all what can be done in LaTeX).

 cheers

 Am 19.09.2011 11:58, schrieb Hofert Jan Marius:
 Dear expeRts,

 I it possible to have serif labels in the following plot?

 x - 1:10
 y - x
 plot(x, y, type=b, xlab=expression(x[1]), ylab=expression(x[2]))

 I know that one can use pdf(, family=serif), but then also the axis tick 
 marks 
 are printed in serif font. Apart from the fact that it may not look nice, 
 I'm 
 just interested if one can have serif axis labels but everything else in 
 sans serif
 (default).

 Cheers,

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


 -- 
 Eik Vettorazzi
 Institut für Medizinische Biometrie und Epidemiologie
 Universitätsklinikum Hamburg-Eppendorf

 Martinistr. 52
 20246 Hamburg

 T ++49/40/7410-58243
 F ++49/40/7410-57790

 --
 Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
 Genossenschaftsregister sowie das Unternehmensregister (EHUG):

 Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen 
 Rechts; Gerichtsstand: Hamburg

 Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander 
 Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

 
 ETH Zurich
 Dr. Marius Hofert
 RiskLab, Department of Mathematics
 HG E 65.2
 Rämistrasse 101
 8092 Zurich
 Switzerland
 
 Phone +41 44 632 2423
 marius.hof...@math.ethz.ch
 http://www.math.ethz.ch/~hofertj
 


-- 
Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


Re: [R] Replace a for loop with a function

2011-09-19 Thread Eik Vettorazzi
Hi Iris,
maybe I misinterpret this, but I think in the end it all comes down to
sample(1:3,50,prob=c(0.5,0.15,0.35),replace=T))

cheers

Am 19.09.2011 17:16, schrieb Eekhout, I.:
 Hi all, 
 
 I would like to replace the for loop in the code below with a function
 to improve the speed and to make the script more efficient. 
 The loop creates a vector of integers (x) with the probability of f for
 each integer.
 The length of f is variable, but sums to 1. 
 I tried to use a function with optional arguments which did not work.
 
 Here is the code:
 
 f - data.matrix(c(0.5,0.15,0.35))
 u - runif(50) 
 x - data.matrix(rep(1, n)) 
 fc - 0
   for(i in 1:length(f))   {
   fc - fc + f[i] 
   cf - ifelse(ufc,1,0)
   x - x + cf
   }
 x
 
 Can anyone help me with this translation?
 Thanks in advance, 
 
 Iris
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


-- 
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

--
Pflichtangaben gemäß Gesetz über elektronische Handelsregister und 
Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; 
Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Jörg F. Debatin (Vorsitzender), Dr. Alexander 
Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

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


  1   2   3   >