Re: [R] Puzzled by results from base::rank()

2023-08-11 Thread Gerrit Eichner

Dear Chris,

the members of the triplet would be ranked 4, 5 and 6 (in your example), 
so the *mean of their ranks* is correctly 5.


For any set of k tied values the ranks of its elements are averaged (and 
assigned to each of its k members).


 Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 215
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 11.08.2023 um 09:54 schrieb Chris Evans via R-help:
I understand that the default ties.method is "average".  Here is what I 
get, expanding a bit on the help page example. Running R 4.3.1 on Ubuntu 
22.04.2.


 > x2 <- c(3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5)
 > rank(x2)
  [1]  4.5  1.5  6.0  1.5  8.0 11.0  3.0 10.0  8.0  4.5  8.0

OK so the ties, each of with two members, are ranked to their mean.

So now I turn one tie from a twin to a triplet:

 > x3 <- c(x2, 3)
 > rank(x3)
  [1]  5.0  1.5  7.0  1.5  9.0 12.0  3.0 11.0  9.0  5.0  9.0  5.0
 > sprintf("%4.3f", rank(x3))
  [1] "5.000"  "1.500"  "7.000"  "1.500"  "9.000"  "12.000" "3.000" 
"11.000"

  [9] "9.000"  "5.000"  "9.000"  "5.000"

The doublet is still given the mean of the values but the triplet is 
rounded up.  What am I missing here?!


TIA,

Chris



__
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] Get data from a list of data frames

2022-12-15 Thread Gerrit Eichner

Hello, Stefano,

maybe the following example contains what you want to achieve:

Station1 <- data.frame(sensor = c("thermometer", "raingauge", 
"snowgauge", "anemometer"),

   code = c(2583, 1478, 3178, NA))
Station2 <- data.frame(sensor = c("thermometer", "raingauge", 
"snowgauge", "anemometer"),

   code = c(2584, 1479, 3179, 4453))
Station3 <- data.frame(sensor = c("thermometer", "raingauge", 
"snowgauge", "anemometer"),

   code = c(2584, 1479, 3179, 4453))
Station4 <- data.frame(sensor = rev(c("thermometer", "raingauge", 
"snowgauge", "anemometer")),

   code = c(2584, 1479, 3179, 4453))
Station5 <- data.frame(sensor = c("raingauge", "snowgauge", 
"thermometer", "anemometer"),

   code = c(2584, 1479, 3179, 4453))

Total <- list("Station1"=Station1, "Station2"=Station2,
  Station3 = Station3, Station4 = Station4,
  Station5 = Station5)

select.stat <- paste0("Station", c(1, 4, 5))
select.sens <- "thermometer"

sapply(Total[select.stat], function(x, sens)
  x$code[x$sensor == sens], sens = select.sens)



 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 15.12.2022 um 14:52 schrieb Stefano Sofia:

Dear R-list users,

I have a list of n data frames built as follows:


Station1 <- data.frame(sensor = c("thermometer", "raingauge", "snowgauge", 
"anemometer"), code = c(2583, 1478, 3178, NA))
Station2 <- data.frame(sensor = c("thermometer", "raingauge", "snowgauge", 
"anemometer"), code = c(2584, 1479, 3179, 4453))


Total <- list("Station1"=Station1, "Station2"=Station2, ...)

I would need to have a vector with the sensor codes of the thermometers of some 
stations, let's say of Station1, Station2 and Station5 (i.e. c(2583, 2584, 
2587)).
I tried with lapply, but I have not been able to get what I need.
Could you please help me?

Thank you

Stefano



  (oo)
--oOO--( )--OOo--
Stefano Sofia PhD
Civil Protection - Marche Region - Italy
Meteo Section
Snow Section
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona (AN)
Uff: +39 071 806 7743
E-mail: stefano.so...@regione.marche.it
---Oo-oO



AVVISO IMPORTANTE: Questo messaggio di posta elettronica pu� contenere 
informazioni confidenziali, pertanto � destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
� il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si � ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dell'art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessit� ed 
urgenza, la risposta al presente messaggio di posta elettronica pu� essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
received this message in error, please forward it to the sender and delete it 
completely from your computer system.

--

Questo messaggio  stato analizzato da Libraesva ESG ed  risultato non infetto.

This message was scanned by Libraesva ESG and is believed to be clean.


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


__
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] How to create density ellipses with R

2022-01-14 Thread Gerrit Eichner

Hi Paul,

take a look at base R's function contour (and the Examples section
of its help page), and follow maybe the hints under "See also".

 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 14.01.2022 um 16:12 schrieb Paul Bernal:

Dear R friends,

Happy new year to you all. Not quite sure if this is the proper place to
ask about this, so I apologize if it is not, and if it isn´t, maybe you can
point me to the right place.

I would like to know if there is any R package that allows me to produce
density ellipses. Searching through the net, I came across a package called
ellipse, but I'm not sure if this is the one I should use.

Any help and/or guidance will be greatly appreciated.

Best regards,

Paul

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


__
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] Replacing certain rows with values from a different column

2021-08-10 Thread Gerrit Eichner

Hi, James,

if I understand you correctly, maybe,

with(firstdf,
  ifelse(Province %in% seconddf$Country,
 Province,
 Country)
)

does what you want?

 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 10.08.2021 um 12:58 schrieb James Milks via R-help:

I have two columns in a larger data set that list countries in one column and, 
in some cases, individual provinces within a country or oversea territories in 
another. I have country population in a second data set that I’m planning to 
use to calculate per capita rates in the first data set. My issue: I need to 
match my two data sets. Here are some examples:

First data set:

Province <- c("Australian Capital Territory", "New South Wales", "Northern Territory", "Queensland", "South Australia", "Tasmania", 
"Victoria", "Western Australia", "", "", "", "Faroe Islands", "Greenland")

Country <- c("Australia", "Australia", "Australia", "Australia", "Australia", "Australia", "Australia", "Australia", 
"Austria", "Azerbaijan", "Denmark", "Denmark", "Denmark")

firstdf <- data.frame(Province, Country)

Second data set:

Country <- c("Australia", "Austria", "Azerbaijan", "Denmark", "Faroe Islands", 
"Greenland")

seconddf <- data.frame(Country)

In this example, I need to aggregate sum Australia while keeping Faroe Islands 
and Greenland separate from Denmark. What I’d like to do is create a column 
that looks like this:

firstdf$nation <- c("Australia", "Australia", "Australia", "Australia", "Australia", "Australia", "Australia", 
"Australia", "Austria", "Azerbaijan", "Denmark", “Faroe Islands", “Greenland”)

Is there a way to do this or am I stuck doing this by hand?

Thanks for any help on this vexing issue.

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



__
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] Plotting Coxph model with an interaction.

2021-05-20 Thread Gerrit Eichner

Hi, John,

it should work the same way as without interaction (but make sure
to use the fitted object "coxfit", not just "fit" in our call of
survfit, and note that age*rx already expands to age + rx + age:rx
so that age + rx is redundant in your formula):

coxfit <- coxph(Surv(futime, fustat) ~ age+rx+age*rx, data = ovarian)
plot(survfit(coxfit, newdata=data.frame(age=60,rx=2)))

Or do I missunderstand your question?

 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 20.05.2021 um 21:15 schrieb Bert Gunter:

Perhaps this might be useful:

https://rpubs.com/tf_peterson/interactionplotDemo

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Thu, May 20, 2021 at 10:29 AM Sorkin, John 
wrote:


Colleagues,

I hope someone can tell me how to plot a cox model that contains an
interaction term.

I know that plot(survfit(. . . . )) can be used to plot a Cox model, i.e..
coxfit <- coxph(Surv(futime, fustat) ~ age+rx, data = ovarian)
plot(survfit(fit, newdata=data.frame(age=60,rx=2)))

but I don't know how to plot a cox model with an interaction, i.e.

coxfit <- coxph(Surv(futime, fustat) ~ age+rx+age*rx, data = ovarian)
plot(survfit(fit, newdata=data.frame(???)))

Thank you,
John

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and
Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


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



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



__
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] Group by and duplicate a value/dplyr

2021-05-11 Thread Gerrit Eichner

Hello, Elahe,

you were, of course, supposed to insert my suggested
code-snippet into you code and test it therein ...

 Regards  --  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 11.05.2021 um 13:40 schrieb Elahe chalabi:

Hello Gerit

mutate(MinValue = min(Value[Value != 0]) )  or  mutate(MinValue = 
sort(unique(Value))[2]) only mutates one value which is 100, it doesnt mutate 
minimum Value != 0 per group by element








On Tuesday, May 11, 2021, 01:26:49 PM GMT+2, Gerrit Eichner 
 wrote:





Homework?

Try maybe

mutate(MinValue = min(Value[Value != 0]) )

or

mutate(MinValue = sort(unique(Value))[2])

   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 11.05.2021 um 13:11 schrieb Elahe chalabi via R-help:

Hi all,

I have the following data frame


dput(df)
       structure(list(Department = c("A", "A", "A", "A", "A", "A", "A",
"A", "B", "B", "B", "B", "B", "B", "B", "B"), Class = c(1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), Value = c(0L,
100L, 800L, 800L, 0L, 300L, 1200L, 1200L, 0L, 0L, 400L, 400L,
200L, 800L, 1200L, 1200L)), class = "data.frame", row.names = c(NA,
-16L))


I would like to group by "Department" and "Class" and repeat the minimum value of 
"Valule" excluding zeros or get the second minimum value. The desired output is:


       dput(df)
       structure(list(Department = c("A", "A", "A", "A", "A", "A", "A",
"A", "B", "B", "B", "B", "B", "B", "B", "B"), Class = c(1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), Value = c(0L,
100L, 800L, 800L, 0L, 300L, 1200L, 1200L, 0L, 0L, 400L, 400L,
200L, 800L, 1200L, 1200L), MinValue = c(100L, 100L, 100L, 100L,
300L, 300L, 300L, 300L, 400L, 400L, 400L, 400L, 200L, 200L, 200L,
200L)), class = "data.frame", row.names = c(NA, -16L))

 
how should I change the following dplyr to give me the desired output?



      df <-
     df %>%
     group_by(Department,Class) %>%
     mutate(MinValue=min(Value) )


Thanks for any help.
Elahe




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



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



__
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] Group by and duplicate a value/dplyr

2021-05-11 Thread Gerrit Eichner

Homework?

Try maybe

mutate(MinValue = min(Value[Value != 0]) )

or

mutate(MinValue = sort(unique(Value))[2])

 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 11.05.2021 um 13:11 schrieb Elahe chalabi via R-help:

Hi all,

I have the following data frame


dput(df)
     structure(list(Department = c("A", "A", "A", "A", "A", "A", "A",
"A", "B", "B", "B", "B", "B", "B", "B", "B"), Class = c(1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), Value = c(0L,
100L, 800L, 800L, 0L, 300L, 1200L, 1200L, 0L, 0L, 400L, 400L,
200L, 800L, 1200L, 1200L)), class = "data.frame", row.names = c(NA,
-16L))


I would like to group by "Department" and "Class" and repeat the minimum value of 
"Valule" excluding zeros or get the second minimum value. The desired output is:


     dput(df)
     structure(list(Department = c("A", "A", "A", "A", "A", "A", "A",
"A", "B", "B", "B", "B", "B", "B", "B", "B"), Class = c(1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), Value = c(0L,
100L, 800L, 800L, 0L, 300L, 1200L, 1200L, 0L, 0L, 400L, 400L,
200L, 800L, 1200L, 1200L), MinValue = c(100L, 100L, 100L, 100L,
300L, 300L, 300L, 300L, 400L, 400L, 400L, 400L, 200L, 200L, 200L,
200L)), class = "data.frame", row.names = c(NA, -16L))


how should I change the following dplyr to give me the desired output?



    df <-
   df %>%
   group_by(Department,Class) %>%
   mutate(MinValue=min(Value) )


Thanks for any help.
Elahe

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



__
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] cox.zph

2021-03-31 Thread Gerrit Eichner

Yes. :-)

 Best regards  --  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 31.03.2021 um 21:29 schrieb Sorkin, John:

Colleagues,

I would like to make certain that my understanding of the tabular output 
produced by cox.zph is correct.

Am I correct that the NULL hypothesis being tested is that the hazard is 
proportional in time?  Therefor a non-significant result indicates that we 
don't have evidence that the proportional hazards assumption is incorrect and 
we can assume that the hazard is proportional. A significant result indicates 
that we have evidence that the proportional hazards assumption is violated.

Thank you,
John

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


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



__
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] Calculating column differences

2021-03-24 Thread Gerrit Eichner

Dear Jeff,

read diff's help page, and you'll find out
what is wrong with your expectation.

What do think diff(df$Score) should give for
the first element in df$Score??

 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 24.03.2021 um 17:48 schrieb Jeff Reichman:

r-help forum

  


I'm trying to calculate the diff between two rows and them mutate the
difference into a new column. I'm using the diff function but not giving me
what I want.

  


df <- data.frame(ID=1:5,Score=4*2:6)

  


What a want  where

   ID Score  diff

1  1 8  8

2  212 4

3  316 4

4  420 4

5  524 4

  


What I am getting

   ID Score  diff

1  1 8  NA

2  212 4

3  316 4

4  420 4

5  524 4

  


Jeff

  



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



__
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] Color in stripchart

2021-03-10 Thread Gerrit Eichner

Dear Robin,

if you study stripchart's code (graphics:::stripchart) carefully
you will find out that the elements of the vector provided to the
col-argument (and the pch-argument as well) are selected by iterating
along the groups (in your case year). I don't seen easy solution for
your problem using stripchart, but you may want to look at the
examples of function beeswarm in package beeswarm.

 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 10.03.2021 um 14:08 schrieb Dr. Robin Haunschild:

Dear fellow R users,

I'd like to color individual points in a stripchart. This works well as
long as I have only a single value per y axis category:

df <- data.frame(year = seq(2011, 2018), value = seq(10,80, 10))
df$color <- 'black'
df[df$value<33,]$color <- 'blue'
df[df$value>66,]$color <- 'red'
stripchart(df$value ~ df$year, pch=18, col=df$color, method='stack')

When I use multiple values per y axis category, all points in a specific
y axis category have the same color:

set.seed(20210310)
years <- sample(x=seq(2011, 2018), size = 365*8, replace = TRUE)
values <- sample(x=seq(0,100), size = 365*8, replace = TRUE)
df <- data.frame(year = years, value = values)
df$color <- 'black'
df[df$value<33,]$color <- 'blue'
df[df$value>66,]$color <- 'red'
stripchart(df$value ~ df$year, pch=18, col=df$color, method='stack')

I'd expect to see all points with a value below 33 in blue color, all
points with a value above 66 in red color, and the remaining points in
black color.

I can use a black stripchart plot as basis and plot blue and red points
over the black ones, but I do not get the stacking right:

stripchart(df$value ~ df$year, pch=18, method='stack')
points(df[df$color=='blue',]$value, df[df$color=='blue',]$year-2010,
type='p', pch=18, col='blue')
points(df[df$color=='red',]$value, df[df$color=='red',]$year-2010,
type='p', pch=18, col='red')

Am I somehow misusing the stripchart function?


Best regards,

Robin


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



__
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] Fwd: Concatenation?

2021-02-18 Thread Gerrit Eichner

Right, Bert, but not if X is "only"  matrix. ;-)

> X <- cbind(X1 = letters[1:3],
   X2 = 5:7,
   X3 = LETTERS[1:3]
)
> do.call(paste0, X)
Fehler in do.call(paste0, X) : das zweite Argument muss eine Liste sein

(Sorry, but my system is German. :-))

But, of course, then, e.g.,

do.call(paste0, data.frame(X))

would work.

 Best  --  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.02.2021 um 17:08 schrieb Bert Gunter:

Inline comment below.
Cheers,
Bert

Bert Gunter

"
or, if stored as columns of a matrix or data frame X, e.g.,


##

apply(X, 1, paste0)

##
"
No. paste() is vectorized. apply() can be avoided:

df  <- data.frame(X1 = letters[1:3],

                  X2 = 5:7,
                  X3 = LETTERS[1:3]
)

df

   X1 X2 X3
1  a  5  A
2  b  6  B
3  c  7  C


do.call(paste0, df)

[1] "a5A" "b6B" "c7C"



   Hth  --  Gerrit

---------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de
<mailto:gerrit.eich...@math.uni-giessen.de> 
  Justus-Liebig-University Giessen

Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/eichner
<http://www.uni-giessen.de/eichner>
-

Am 17.02.2021 um 22:09 schrieb Parkhurst, David:
 > If I have a vector of site abbreviations and a vector of depths
in those water bodies, is there a simple way in R to combine them to
make a third vector?
 > Examples:
 >
 > site  depth           desired
 > MU    0               MU0
 > MU    1               MU1
 > MU    2               MU2
 > MC    0               MC0
 > MC    1               MC1
 > MC    2               MC2
 >
 > The dataset has many more lines than this.  I can see how to do
this with lots of if statements, but does R have magic that can make
it happen easily?  I guess this would be called concatenation.
 >
 > __
 > R-help@r-project.org <mailto:R-help@r-project.org> mailing list
-- To UNSUBSCRIBE and more, see
 > https://stat.ethz.ch/mailman/listinfo/r-help
<https://stat.ethz.ch/mailman/listinfo/r-help>
 > PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
<http://www.R-project.org/posting-guide.html>
 > and provide commented, minimal, self-contained, reproducible code.
 >

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



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


[R] Fwd: Concatenation?

2021-02-18 Thread Gerrit Eichner

[I forgot to keep it on the list.]

 Weitergeleitete Nachricht 
Betreff: Re: [R] Concatenation?
Datum: Wed, 17 Feb 2021 22:14:13 +0100
Von: Gerrit Eichner 
Organisation: JLU Gießen
An: Parkhurst, David 

Hi David,

checkout, e. g., base-R's

paste0(site, depth)

or, if stored as columns of a matrix or data frame X, e.g.,

apply(X, 1, paste0)

or, e.g., tidyr's

unite.

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 17.02.2021 um 22:09 schrieb Parkhurst, David:

If I have a vector of site abbreviations and a vector of depths in those water 
bodies, is there a simple way in R to combine them to make a third vector?
Examples:

sitedepth   desired
MU  0   MU0
MU  1   MU1
MU  2   MU2
MC  0   MC0
MC  1   MC1
MC  2   MC2

The dataset has many more lines than this.  I can see how to do this with lots 
of if statements, but does R have magic that can make it happen easily?  I 
guess this would be called concatenation.

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



__
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] [effects] Wrong xlevels in effects plot for mixed effects model when multiline = TRUE

2020-11-09 Thread Gerrit Eichner

Dear John,

thank you for prompt reply and your hints. The problem is that our
lmer model is much more complicated and has several interaction
terms:

Mass ~ Sex + I(YoE - 1996) + I(PAI/0.1 - 16) + I(gProt/10 - 6.2) +
I(Age/10 - 7.2) + I((Age/10 - 7.2)^2) + Diuretics +
Sex:I(PAI/0.1 - 16) + Sex:I(gProt/10 - 6.2) +
Sex:I(Age/10 - 7.2) + Sex:I((Age/10 - 7.2)^2) +
I(YoE - 1996):I(Age/10 - 7.2) + I(PAI/0.1 - 16):I(Age/10 - 7.2) +
I(gProt/10 - 6.2):I(Age/10 - 7.2) +
(I(Age/10 - 7.2) + I((Age/10 - 7.2)^2) | ID)

so that allEffects is quite efficient, and since I want to place
several interaction terms with Age in one figure with Age on the
horizontal axis the argument x.var = "Age" in plot would be very
helpful. :-)

Further hints using the above complex model: The following works well:
eff <- Effect(c("gProt", "Age"), m,
  xlevels = list(gProt = 1:6 * 30, Age = 60:100))
plot(eff, lines=list(multiline=TRUE), x.var = "Age")

But this fails (note that Age is missing in xlevels):
eff <- Effect(c("gProt", "Age"), m, xlevels = list(gProt = 1:6 * 30))
plot(eff, lines=list(multiline=TRUE), x.var = "Age")


And that just led me to a solutution also for allEffects: Specifying
Age in xlevels for allEffects (although it seems unnecessary when
x.var = "Age" is used in plot) produces the correct graphical
output! :-)

Thank you very much for your support and the brilliant effects
package in general! :-)

 Best regards  --  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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 09.11.2020 um 19:51 schrieb John Fox:

Dear Gerrit,

This looks like a bug in plot.eff(), which I haven't yet tracked down, 
but the following should give you what you want:


eff <- Effect(c("gProt", "Age"), m, xlevels = list(gProt = 1:6 * 30, 
Age=60:100))

plot(eff, lines=list(multiline=TRUE))

or

eff <- predictorEffect("Age", m, xlevels = list(gProt = 1:6 * 30))
plot(eff, lines=list(multiline=TRUE))

A couple of comments on your code, unrelated to the bug in plot.eff():

You don't need allEffects() because there's only one high-order fixed 
effect in the model, I(gProt/10 - 6.2):I(Age/10 - 7.2) (i.e., the 
interaction of gProt with Age).


x.var isn't intended as an argument for plot() with allEffects() because 
there generally isn't a common horizontal axis for all of the high-order 
effect plots.


Finally, thank you for the bug report. Barring unforeseen difficulties, 
we'll fix the bug in due course.


I hope this helps,
  John

John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
web: https://socialsciences.mcmaster.ca/jfox/

On 2020-11-09 8:06 a.m., Gerrit Eichner wrote:

Dear list members,

I observe a strange/wrong graphical output when I set the xlevels
in (e. g.) allEffects for an lmer model and plot the effects with
multiline = TRUE. I have compiled a reprex for which you need the
lmer model and the environment in which the model was fitted. They
are contained in the zip file at
https://jlubox.uni-giessen.de/dl/fiSzTCc3bW8z2npZvPpqG1xr/m-and-G1.zip
After unpacking the following should work:

m <- readRDS("m.rds")   # The lmer-model.
G1 <- readRDS("G1.rds") # Environment in which the model
  # was fitted; needed by alaEffects.
summary(m) # Just to see the model.

library(effects)
aE <- allEffects(m, xlevels = list(gProt = 1:6 * 30))
  # Non-default values for xlevels.

plot(aE)  # Fine.
plot(aE, x.var = "Age")   # Fine.
plot(aE, lines = list(multiline = TRUE))  # Fine.

plot(aE, lines = list(multiline = TRUE),
   x.var = "Age")    # Nonsense.


Anybody any idea about the reason, my mistake, or a
workaround? Thx for any hint!

   Regards  --  Gerrit


PS:
  > sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] effects_4.2-0 carData_3.0-4

loaded via a namespace (and not attached):
   [1] Rcpp_1.0.5   lattice_0.20-41  MASS_7.3-53  grid_4.0.2 
DBI_1.1.0
   [6] nlme_3.1-149 survey_4.0   estimability_1.3 minqa_1.2.4 
nloptr_1.2.2.2
[11] Matrix_1.2-1

[R] [effects] Wrong xlevels in effects plot for mixed effects model when multiline = TRUE

2020-11-09 Thread Gerrit Eichner

Dear list members,

I observe a strange/wrong graphical output when I set the xlevels
in (e. g.) allEffects for an lmer model and plot the effects with
multiline = TRUE. I have compiled a reprex for which you need the
lmer model and the environment in which the model was fitted. They
are contained in the zip file at
https://jlubox.uni-giessen.de/dl/fiSzTCc3bW8z2npZvPpqG1xr/m-and-G1.zip
After unpacking the following should work:

m <- readRDS("m.rds")   # The lmer-model.
G1 <- readRDS("G1.rds") # Environment in which the model
 # was fitted; needed by alaEffects.
summary(m) # Just to see the model.

library(effects)
aE <- allEffects(m, xlevels = list(gProt = 1:6 * 30))
 # Non-default values for xlevels.

plot(aE)  # Fine.
plot(aE, x.var = "Age")   # Fine.
plot(aE, lines = list(multiline = TRUE))  # Fine.

plot(aE, lines = list(multiline = TRUE),
  x.var = "Age")# Nonsense.


Anybody any idea about the reason, my mistake, or a
workaround? Thx for any hint!

  Regards  --  Gerrit


PS:
 > sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] effects_4.2-0 carData_3.0-4

loaded via a namespace (and not attached):
  [1] Rcpp_1.0.5   lattice_0.20-41  MASS_7.3-53  grid_4.0.2 
DBI_1.1.0
  [6] nlme_3.1-149 survey_4.0   estimability_1.3 minqa_1.2.4 
nloptr_1.2.2.2
[11] Matrix_1.2-18boot_1.3-25  splines_4.0.2statmod_1.4.34 
lme4_1.1-23
[16] tools_4.0.2  survival_3.2-3   yaml_2.2.1   compiler_4.0.2 
colorspace_1.4-1

[21] mitools_2.4  insight_0.9.5nnet_7.3-14

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

__
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] how to generate this kind of graph

2020-07-22 Thread Gerrit Eichner

Hi, John,

look for the package beeswarm.

 Regards  --  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 22.07.2020 um 07:23 schrieb array chip via R-help:


Hello everyone,

I saw this scatterplots from a paper and thought it looked very nice:

https://drive.google.com/file/d/1V7F1gq-J_GIFDOrJs00hwGyXUqCZ_xwa/view?usp=sharing

It was similar to stripchart() with 'jitter' method, but it has a special 
pattern of aligning points which made it look nicer than standard stripchart().

Does anyone know if there is a package in R that can do this kind of plots?

Thanks,

John

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



__
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] nearest lower and higher integers to a multiple of another integer

2020-04-06 Thread Gerrit Eichner

Hi Stefano,

maybe floor(x / n) * n and ceiling(x / n) * n does what you want?

 Best regards  --  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 06.04.2020 um 10:29 schrieb Stefano Sofia:

Dear R list members,
given an integer x, I would need to find the nearest lower and higher integers 
(xmin and xmax) to a multiple of another integer n.

Example: if x is -2 and n is 4, xmin becomes -4 and xmax is 0.

I tried to manage it with simple "if" statements, but this is not efficient at 
all.
Could please somebody help me to find an easy way to implement it?

Thank you for your attention and your help
Stefano Sofia

  (oo)
--oOO--( )--OOo
Stefano Sofia PhD
Civil Protection - Marche Region
Meteo Section
Snow Section
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona
Uff: 071 806 7743
E-mail: stefano.so...@regione.marche.it
---Oo-oO



AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere 
informazioni confidenziali, pertanto è destinato solo a persone autorizzate 
alla ricezione. I messaggi di posta elettronica per i client di Regione Marche 
possono contenere informazioni confidenziali e con privilegi legali. Se non si 
è il destinatario specificato, non leggere, copiare, inoltrare o archiviare 
questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al 
mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi 
dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed 
urgenza, la risposta al presente messaggio di posta elettronica può essere 
visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by 
persons entitled to receive the confidential information it may contain. E-mail 
messages to clients of Regione Marche may contain information that is 
confidential and legally privileged. Please do not read, copy, forward, or 
store this message unless you are an intended recipient of it. If you have 
received this message in error, please forward it to the sender and delete it 
completely from your computer system.

--
Questo messaggio  stato analizzato da Libra ESVA ed  risultato non infetto.
This message was scanned by Libra ESVA and is believed to be clean.


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



__
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] how to find number of unique rows for combination of r columns

2019-11-08 Thread Gerrit Eichner

It seems as if dt is not a (base R) data frame but a
data table. I assume, you will have to transform dt
into a data frame (maybe with as.data.frame) to be
able to apply unique in the suggested way. However,
I am not familiar with data tables. Perhaps somebody
else can provide a more profound guess.

 Regards  --  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 08.11.2019 um 16:02 schrieb Ana Marija:

I tried it but I got this error:

udt <- unique(dt[c("chr", "pos", "gene_id")])

Error in `[.data.table`(dt, c("chr", "pos", "gene_id")) :
   When i is a data.table (or character vector), the columns to join by
must be specified using 'on=' argument (see ?data.table), by keying x
(i.e. sorted, and, marked as sorted, see ?setkey), or by sharing
column names between x and i (i.e., a natural join). Keyed joins might
have further speed benefits on very large data due to x being sorted
in RAM.

On Fri, Nov 8, 2019 at 8:58 AM Gerrit Eichner
 wrote:


Hi, Ana,

doesn't

udt <- unique(dt[c("chr", "pos", "gene_id")])
nrow(udt)

get close to what you want?

   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 08.11.2019 um 15:38 schrieb Ana Marija:

Hello,

I have a data frame like this:


head(dt,20)

   chrpos gene_id pval_nominal  pval_ret   wl  wr
   1: chr1  54490 ENSG02272320.6084950 0.7837780 31.62278 21.2838
   2: chr1  58814 ENSG02272320.2952110 0.8975820 31.62278 21.2838
   3: chr1  60351 ENSG02272320.4397880 0.8679590 31.62278 21.2838
   4: chr1  61920 ENSG02272320.3195280 0.6018090 31.62278 21.2838
   5: chr1  63671 ENSG02272320.2377390 0.9880390 31.62278 21.2838
   6: chr1  64931 ENSG02272320.2766790 0.9070370 31.62278 21.2838
   7: chr1  81587 ENSG02272320.6057930 0.6167630 31.62278 21.2838
   8: chr1 115746 ENSG02272320.4078770 0.7799110 31.62278 21.2838
   9: chr1 135203 ENSG02272320.4078770 0.9299130 31.62278 21.2838
10: chr1 138593 ENSG02272320.8464560 0.5696060 31.62278 21.2838

it is very big,

dim(dt)

[1] 737191228

To count number of unique rows for all 3 columns: chr, pos and gene_id
I could just join those 3 columns and than count. But how would I find
unique number of rows for these 4 columns without joining them?

Thanks
Ana

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



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


__
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] how to find number of unique rows for combination of r columns

2019-11-08 Thread Gerrit Eichner

Hi, Ana,

doesn't

udt <- unique(dt[c("chr", "pos", "gene_id")])
nrow(udt)

get close to what you want?

 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 08.11.2019 um 15:38 schrieb Ana Marija:

Hello,

I have a data frame like this:


head(dt,20)

  chrpos gene_id pval_nominal  pval_ret   wl  wr
  1: chr1  54490 ENSG02272320.6084950 0.7837780 31.62278 21.2838
  2: chr1  58814 ENSG02272320.2952110 0.8975820 31.62278 21.2838
  3: chr1  60351 ENSG02272320.4397880 0.8679590 31.62278 21.2838
  4: chr1  61920 ENSG02272320.3195280 0.6018090 31.62278 21.2838
  5: chr1  63671 ENSG02272320.2377390 0.9880390 31.62278 21.2838
  6: chr1  64931 ENSG02272320.2766790 0.9070370 31.62278 21.2838
  7: chr1  81587 ENSG02272320.6057930 0.6167630 31.62278 21.2838
  8: chr1 115746 ENSG02272320.4078770 0.7799110 31.62278 21.2838
  9: chr1 135203 ENSG02272320.4078770 0.9299130 31.62278 21.2838
10: chr1 138593 ENSG02272320.8464560 0.5696060 31.62278 21.2838

it is very big,

dim(dt)

[1] 737191228

To count number of unique rows for all 3 columns: chr, pos and gene_id
I could just join those 3 columns and than count. But how would I find
unique number of rows for these 4 columns without joining them?

Thanks
Ana

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



__
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] [effects] allEffects does not accept integer value for xlevels

2019-09-05 Thread Gerrit Eichner

Dear John,

thank you for the quick response and fix! Sorry, that I didn't
detect the bug earlier, but everything had run smoothly sofar. ;-)
(I am aware of predictorEffects. I have in fact switched to it
recently. Excellent functionality; thx a lot for it! Actually,
experimenting with its ...levels arguments lead me to the
respective attempts with allEffects out of curiosity.)

Dear Rolf,

my conjecture was not about a "problem with using [[...]] to
*extract* entries from vectors", but about assigning a value to a
list component of an object which is not a list. I was referring
to xlevels[[name]] <- levs where xlevels is an integer. (But that
doesn't matter anymore because my conjecture pointed to the wrong
function anyway.)

 Best regards  --  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 05.09.2019 um 00:32 schrieb Fox, John:

Dear Rolf,

Thanks for trying to help. The bug wasn't in AnalyzeModel().

There was a bug in Effect.lm(), Effect.multinom(), and Effect.polr() in how xlevels=n (e.g., 
xlevels=4) was handled, now fixed in the development version of the effects package on R-Forge, 
from which it can be installed via install.packages("effects", 
repos="http://R-Forge.R-project.org";). Despite my implication to the contrary, xlevels=n 
works properly in predictorEffect() in the version of effects currently on CRAN.

I'll wait for a decent interval before updating effects again on CRAN.

Best,
  John


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rolf
Turner
Sent: Wednesday, September 4, 2019 5:39 PM
To: Fox, John 
Cc: r-help@r-project.org; sa...@umn.edu
Subject: Re: [R] [effects] allEffects does not accept integer value for
xlevels


I'm obviously not understanding something here, but it seems to me that
the conjecture


It appears to me that the cause is buried in effects:::Analyze.model

in or close to the the lines

if (is.numeric(xlevels) & length(xlevels) == 1L) {
 levs <- xlevels
 for (name in focal.predictors) xlevels[[name]] <- levs
}



where xlevels -- while not being a list in this case -- is
subscripted by xlevels[[name]].


is not correct.  There is no problem with using [[...]] to extract entries
from vectors.  E.g.:

x <- 1:3
names(x) <- c("mung","gorp","clyde")
x[["gorp"]]

produces

[1] 2

cheers,

Rolf

On 5/09/19 2:19 AM, Fox, John wrote:

Dear Gerrit,

Yes, that appears to be a bug in Effect() -- too bad that it wasn't

discovered earlier because a new version of the package was submitted
yesterday, but thank you for the bug report.


We'll fix the bug, but until then a work-around is to specify the
number of levels for each numeric predictor, as in

allEffects(mod.cowles, xlevels=list(neuroticism=4, extraversion=4))

I used 4 levels here to verify that this works correctly, since 5 is the

default.


As well, although unrelated to this bug, you might take a look at

predictorEffects(), which we recommend in preference to allEffects().


Best,
   John

--
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: socialsciences.mcmaster.ca/jfox/




-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
Gerrit Eichner
Sent: Wednesday, September 4, 2019 9:25 AM
To: r-help@r-project.org
Subject: [R] [effects] allEffects does not accept integer value for
xlevels

Dear list,

citing from allEffects' help page (of package effects 4.1-2):
"If xlevels=n is an integer, then each numeric predictor is
represented by n equally spaced values rounded to 'nice' numbers."


However, adapting the first example from allEffects' help page throws
an an error:

mod.cowles <- glm(volunteer ~ sex + neuroticism*extraversion,
 data=Cowles, family=binomial)
allEffects(mod.cowles,
xlevels=5) Error in xlevels[[name]] : subscript out of bounds


It appears to me that the cause is buried in effects:::Analyze.model

in or close to the the lines

if (is.numeric(xlevels) & length(xlevels) == 1L) {
 levs <- xlevels
 for (name in focal.predictors) xlevels[[name]] <- levs
}



where xlevels -- while not being a list in this case -- is
subscripted by xlevels[[name]].

Is anyone aware of a workaround (without having to specify all
numeric predictors of the used model explicitly in a list and giving
it to xlevels when calling allEffects), and without having to write
my own Analyze.model function? ;-)


Thx in advanc

[R] [effects] allEffects does not accept integer value for xlevels

2019-09-04 Thread Gerrit Eichner

Dear list,

citing from allEffects' help page (of package effects 4.1-2):
"If xlevels=n is an integer, then each numeric predictor is
represented by n equally spaced values rounded to 'nice' numbers."


However, adapting the first example from allEffects' help
page throws an an error:

mod.cowles <- glm(volunteer ~ sex + neuroticism*extraversion,
  data=Cowles, family=binomial)
allEffects(mod.cowles, xlevels=5)
Error in xlevels[[name]] : subscript out of bounds


It appears to me that the cause is buried in
effects:::Analyze.model

in or close to the the lines

if (is.numeric(xlevels) & length(xlevels) == 1L) {
  levs <- xlevels
  for (name in focal.predictors) xlevels[[name]] <- levs
 }



where xlevels -- while not being a list in this case -- is
subscripted by xlevels[[name]].

Is anyone aware of a workaround (without having to specify all
numeric predictors of the used model explicitly in a list and
giving it to xlevels when calling allEffects), and without
having to write my own Analyze.model function? ;-)


 Thx in advance and best regards  --  Gerrit



PS:  sessionInfo()

R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

Random number generation:
 RNG: Mersenne-Twister
 Normal:  Inversion
 Sample:  Rounding

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] effects_4.1-2 carData_3.0-2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2lattice_0.20-38   MASS_7.3-51.4 grid_3.6.1 

 [5] DBI_1.0.0 nlme_3.1-141  survey_3.36 
estimability_1.3
 [9] minqa_1.2.4   nloptr_1.2.1  Matrix_1.2-17 boot_1.3-23 


[13] splines_3.6.1 lme4_1.1-21.9001  survival_2.44-1.1 compiler_3.6.1
[17] colorspace_1.4-1  mitools_2.4   nnet_7.3-12


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

__
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] Partition a vector into select groups with fixed length

2019-08-18 Thread Gerrit Eichner

Hi, Christofer,

try something along

len <- 5
split(Vec, rep(seq(ceiling(length(Vec)/len)), each = len))

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 18.08.2019 um 20:01 schrieb Christofer Bogaso:

Hi,

Let say I have a vector as below

Vec = LETTERS

Now I want to break this vector into groups of the same length of 5.

So,
1st group consists - "A" "B" "C" "D" "E"
2nd group - "F" "G" "H" "I" "J"

and so on..
last group will consist only the leftover elements

I have a very large initial vector, so looking for some efficient way
to achieve the same. Any pointer will be highly appreciated.

Thanks for your time.

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



__
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] Integer Sample with Mean Dependent on Size

2019-08-01 Thread Gerrit Eichner

n_1 + ... + n_N = 2(N-1) is requested for integers n_i >= 1.

What about c(rep(2, N-2), 1, 1))?

but I'm afraid that this was not what you really wanted. ;-)
However, you didn't say if your sample should be random. :-)

 Best regards  --  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 01.08.2019 um 12:27 schrieb Lorenzo Isella:

Dear All,
I cannot unfortunately provide any R code, otherwise I would not need to 
post this in the first place.
I need to generate a sample of N positive non-zero integers such that 
their mean is *exactly* 2(N-1)/N, i.e. the mean depends on the length of 
the sample.
For a start, we can assume that every integer in my sample can assume 
only the values 1, 2 and 3.

Any suggestion is appreciated.
Cheers

Lorenzo

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


__
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] Fwd: How to retain the NA as a value for splitting a dataframe

2019-05-23 Thread Gerrit Eichner

Hello, Jun,

try

split(df, f = factor(df$C, exclude = NULL))

For more info see ?factor, of course.

 Regards  --  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 24.05.2019 um 06:40 schrieb Jun Shen:

Dear list,

Say I have a data frame with NA in the variable which I want to use as a
sorting variable for splitting the data frame.

df <- data.frame(A=1:10, B=c(rep(99,5), rep(100,5)), C=c(rep(NA,3),
rep(1,3), rep(2,4)))

split(df, f=df[c('C')], drop=FALSE), I got the output as follows. I was
hoping to retain the part of the df where C=NA. drop=FALSE doesn't seem to
take effect here. Appreciate any comments. Thanks.

$`1`
   A   B C
4 4  99 1
5 5  99 1
6 6 100 1

$`2`
 A   B C
7   7 100 2
8   8 100 2
9   9 100 2
10 10 100 2


Jun

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



__
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] Diff'ing 2 strings

2019-01-10 Thread Gerrit Eichner

Don't you mean ?Rdiff ?

 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 10.01.2019 um 08:35 schrieb Martin Møller Skarbiniks Pedersen:

On Sat, Jan 5, 2019, 14:58 Sebastien Bihorel <
sebastien.biho...@cognigencorp.com wrote:


Hi,

Does R include an equivalent of the linux diff command?



yes.
?rdiff

/martin

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



__
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] summary function does not work with Westfall correction in multcomp with 27 comparisons

2018-11-08 Thread Gerrit Eichner

Dear Rich,

w/o the original data we can actually only guess, but I think you
may haven't been patient enough to let summary.glht finish its
job. Have you tried to increase the number of contrasts, i.e.
comparisons, step by step to see how the computational burden and
hence the required computing time increases?

Internally, a lot effort goes into the computation of probabilities
and/or quantiles of multivariate normal or t distributions, and in
your setting they *are* high-dimensional. For more reliable and
elaborate details you may have to consult the cited references in
?summary.glht, or wait/hope for a more knowledgeable list member to
"jump in".

 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 08.11.2018 um 18:10 schrieb Friedman, Richard A.:

Dear List.

I ran multcomp with 27 comaprisons. The glht command returned an mcp object,
but the summary command with the Westfall correction ddi not give a summary.
When I ran the same dataset with 4 comparisons I got p-values. When I sued a 
summary with
univariate or Bonferroni’s method with all 27 comarisons I got p-values. But 
all 27 did not
work for Wesrfall. Please advise.
Here is a record of my session with 27 comparisons and Westfall:

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

   Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[R.app GUI 1.70 (7543) x86_64-apple-darwin15.6.0]

[History restored from /Users/friedman/.Rapp.history]

objc[31790]: Class FIFinderSyncExtensionHost is implemented in both 
/System/Library/PrivateFrameworks/FinderKit.framework/Versions/A/FinderKit 
(0x7fff9c2b7c90) and 
/System/Library/PrivateFrameworks/FileProvider.framework/OverrideBundles/FinderSyncCollaborationFileProviderOverride.bundle/Contents/MacOS/FinderSyncCollaborationFileProviderOverride
 (0x119bf8cd8). One of the two will be used. Which one is undefined.

library(multcomp)

Loading required package: mvtnorm
Loading required package: survival
Loading required package: TH.data
Loading required package: MASS

Attaching package: ‘TH.data’

The following object is masked from ‘package:MASS’:

 geyser


tumor<-read.table("a8_1wayall_input.txt",sep="\t",header=T)
class(tumor)

[1] "data.frame"

dim(tumor)

[1] 309   2

tumor[1,]

  condition  log2vol
1 aa.vector.4w 7.297375


model<-lm(log2vol~condition,data=tumor)
summary(model)


Call:
lm(formula = log2vol ~ condition, data = tumor)

Residuals:
Min 1Q Median 3QMax
-7.997 -2.414  0.291  2.164  8.059

Coefficients:
  Estimate Std. Error t value Pr(>|t|)
(Intercept)   4.587760.60457   7.588  4.3e-13 ***
conditionab.vector.6w 1.398180.85499   1.635 0.103054
conditionac.vector.8w 2.890850.85499   3.381 0.000820 ***
conditionba.dnmt1kd.4w   -2.674910.84733  -3.157 0.001760 **
conditionbb.dnmt1kd.6w   -1.433900.84733  -1.692 0.091654 .
conditionbc.dnmt1kd.8w   -0.471880.84733  -0.557 0.578020
conditionca.dnmt3bkd.4w  -3.153250.89139  -3.537 0.000469 ***
conditioncb.dnmt3bkd.6w  -2.173340.89139  -2.438 0.015355 *
conditioncc.dnmt3bkd.8w  -1.501870.89139  -1.685 0.093078 .
conditionda.dnmt1kdhrad9.4w   1.081531.08991   0.992 0.321863
conditiondb.dnmt1kdhrad9.6w   2.383831.08991   2.187 0.029517 *
conditiondc.dnmt1kdhrad9.8w   3.539901.08991   3.248 0.001297 **
conditionea.dnmt3bkdhrad9.4w  0.027951.06049   0.026 0.978991
conditioneb.dnmt3bkdhrad9.6w  1.340371.06049   1.264 0.207263
conditionec.dnmt3bkdhrad9.8w  3.409551.06049   3.215 0.001449 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.141 on 294 degrees of freedom
Multiple R-squared:  0.3155, Adjusted R-squared:  0.2829
F-statistic: 9.678 on 14 and 294 DF,  p-value: < 2.2e-16


model.mc<-glht(model,linfct=mcp(condition=c("ab.vector.6w-aa.vector.4w=

Re: [R] verInd= and HorInd= arguments to pairs() function

2018-06-08 Thread Gerrit Eichner

Am 08.06.2018 um 12:02 schrieb Martin Maechler:

Martin Maechler
 on Fri, 8 Jun 2018 11:13:24 +0200 writes:


[..]

 >> Thank you, Chris, for the report and
 >> Gerrit for your proposed fix !!
 >>
 >> It looks good to me,  but I will test some more (also with
 >> 'row1attop=FALSE')  before committing the bug fix.

 > and there, another change was needed:  Instead of your

 > for (j in if (row1attop) verInd else rev(verInd))
 >for (i in horInd) {

 > we do now need

 > for(j in verInd)
 >for(i in if(row1attop) horInd else rev(horInd)) {

 > and the difference is of course only relevant for the
 > non-default  'row1attop = FALSE'

 > (which some graphic experts argue to be clearly *better* than the 
default,
 > as only in that case,  the upper and lower triangles of the
 > matrix are nicely "mirrors of each other", and that is also
 > the reason why  lattice::splom()  uses the equivalent of
 > 'row1attop=FALSE')

 > I will commit the change to R-devel today - and intend to port
 > to R-patched in time to make it into the upcoming R 3.5.1.

Well, as I find, there are more bugs there, if you are using
'horInd' and 'verInd' creatively:

In a nice pairs(), the axis ticks (and their labels (numbers))
are always "on the outside" of the scatterplot matrix, and
nicely alternating.  This is not the case unfortunately, when using
  horInd or verInd which are *not* of the form p1:p2 (p1 <= p2)

==> even more changes are needed to make these cases "nice",


Well, the *shown* axis ticks and labels do nicely alternate if
(hor|ver)Ind = p1:p2 (p1 <= p2) is fulfilled, but not all of
the axis ticks and labels, which one *might* wish to see, are
currently drawn anyway ... I would consider changes which "heal"
this as more interesting than solving this problem in full
generality, i.e., in cases of creative use of (hor|ver)Ind.
However, I don't think it's urgent, at all.



or  should we *require* horInd and verInd to be of that form??

This would not be back-compatible, but than such cases have been
"wrong" really in all versions of R anyway, *and*  at least be
reordering the matrix/data.frame columns, the restriction of

 (hor|ver)Ind =  p1:p2 (p1 <= p2)

would seem acceptable, would it ?



I could live very well with that requirement (while breaking
back-compatibility), because from my point of view a "creative"
use of 'horInd' and 'verInd' violating (hor|ver)Ind = p1:p2
(p1 <= p2) won't occur often.

On the other hand, why forcing (hor|ver)Ind = p1:p2 (p1 <= p2)?
If people violated it "they get what they deserve". ;-)

Btw, 'horInd' and 'verInd' sort of exchange their meaning if
row1attop = FALSE, but I this can be explained by the "work flow":
First, (hor|ver)Ind are used to select the respective rows and
columns from the full paris-plot, and then, row1attop is used
when the results are drawn. I think this is sensible.

 Regards  --  Gerrit

__
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] verInd= and HorInd= arguments to pairs() function

2018-06-07 Thread Gerrit Eichner

Hi, Chris,

had the same problem (and first thought it was my fault), but there
seems to be a typo in the code of pairs.default. Below is a workaround.
Look for two comments (starting with #) in the code to see what I
have changed to make it work at least the way I'd expect it in one of
your examples.

 Hth --  Gerrit


mypairs <- function (x, labels, panel = points, ...,
horInd = 1:nc, verInd = 1:nc,
lower.panel = panel, upper.panel = panel, diag.panel = NULL,
text.panel = textPanel, label.pos = 0.5 + has.diag/3, line.main = 3,
cex.labels = NULL, font.labels = 1, row1attop = TRUE, gap = 1,
log = "") {
if (doText <- missing(text.panel) || is.function(text.panel))
textPanel <- function(x = 0.5, y = 0.5, txt, cex, font) text(x,
y, txt, cex = cex, font = font)
localAxis <- function(side, x, y, xpd, bg, col = NULL, main,
oma, ...) {
xpd <- NA
if (side%%2L == 1L && xl[j])
xpd <- FALSE
if (side%%2L == 0L && yl[i])
xpd <- FALSE
if (side%%2L == 1L)
Axis(x, side = side, xpd = xpd, ...)
else Axis(y, side = side, xpd = xpd, ...)
}
localPlot <- function(..., main, oma, font.main, cex.main) plot(...)
localLowerPanel <- function(..., main, oma, font.main, cex.main) 
lower.panel(...)
localUpperPanel <- function(..., main, oma, font.main, cex.main) 
upper.panel(...)
localDiagPanel <- function(..., main, oma, font.main, cex.main) 
diag.panel(...)

dots <- list(...)
nmdots <- names(dots)
if (!is.matrix(x)) {
x <- as.data.frame(x)
for (i in seq_along(names(x))) {
if (is.factor(x[[i]]) || is.logical(x[[i]]))
x[[i]] <- as.numeric(x[[i]])
if (!is.numeric(unclass(x[[i]])))
stop("non-numeric argument to 'pairs'")
}
}
else if (!is.numeric(x))
stop("non-numeric argument to 'pairs'")
panel <- match.fun(panel)
if ((has.lower <- !is.null(lower.panel)) && !missing(lower.panel))
lower.panel <- match.fun(lower.panel)
if ((has.upper <- !is.null(upper.panel)) && !missing(upper.panel))
upper.panel <- match.fun(upper.panel)
if ((has.diag <- !is.null(diag.panel)) && !missing(diag.panel))
diag.panel <- match.fun(diag.panel)
if (row1attop) {
tmp <- lower.panel
lower.panel <- upper.panel
upper.panel <- tmp
tmp <- has.lower
has.lower <- has.upper
has.upper <- tmp
}
nc <- ncol(x)
if (nc < 2L)
stop("only one column in the argument to 'pairs'")
if (!all(horInd >= 1L && horInd <= nc))
stop("invalid argument 'horInd'")
if (!all(verInd >= 1L && verInd <= nc))
stop("invalid argument 'verInd'")
if (doText) {
if (missing(labels)) {
labels <- colnames(x)
if (is.null(labels))
labels <- paste("var", 1L:nc)
}
else if (is.null(labels))
doText <- FALSE
}
oma <- if ("oma" %in% nmdots)
dots$oma
main <- if ("main" %in% nmdots)
dots$main
if (is.null(oma))
oma <- c(4, 4, if (!is.null(main)) 6 else 4, 4)
opar <- par(mfcol = c(length(horInd), length(verInd)),
# Changed from mfrow to mfcol
mar = rep.int(gap/2, 4), oma = oma)
on.exit(par(opar))
dev.hold()
on.exit(dev.flush(), add = TRUE)
xl <- yl <- logical(nc)
if (is.numeric(log))
xl[log] <- yl[log] <- TRUE
else {
xl[] <- grepl("x", log)
yl[] <- grepl("y", log)
}
for (j in if (row1attop) verInd else rev(verInd))
 for (i in horInd) {
# Exchanged i and j. (i used to be in
# the outer and j in the inner loop!)
l <- paste0(ifelse(xl[j], "x", ""), ifelse(yl[i], "y", ""))
localPlot(x[, j], x[, i], xlab = "", ylab = "", axes = FALSE,
type = "n", ..., log = l)
if (i == j || (i < j && has.lower) || (i > j && has.upper)) {
box()
if (i == 1 && (!(j%%2L) || !has.upper || !has.lower))
localAxis(1L + 2L * row1attop, x[, j], x[, i],
  ...)
if (i == nc && (j%%2L || !has.upper || !has.lower))
localAxis(3L - 2L * row1attop, x[, j], x[, i],
  ...)
if (j == 1 && (!(i%%2L) || !has.upper || !has.lower))
localAxis(2L, x[, j], x[, i], ...)
if (j == nc && (i%%2L || !has.upper || !has.lower))
localAxis(4L, x[, j], x[, i], ...)
mfg <- par("mfg")
if (i == j) {
if (has.diag)
  localDiagPanel(as.vector(x[, i]), ...)
if (doText) {
  par(usr = c(0, 1, 0, 1))
  if (is.null(cex.labels)) {
l.wid <- strwidth(labels, "user")
cex.labels <- max(0.8, min(2, 0.9/max(l.wid)))
  }
  xlp <- if (xl[i]

Re: [R] Manipulation of data.frame into an array

2018-05-24 Thread Gerrit Eichner

Why not use as.matrix(Imp) in this case?

 Regards  --  Gerrit

Am 24.05.2018 um 17:04 schrieb Bert Gunter:

This is one of those instances where a less superficial knowledge of R's
technical details comes in really handy.

What you need to do is convert the data frame to a single (numeric) vector
for, e.g. a matrix() call. This can be easily done by noting that a data
frame is also a list and using do.call():

## imp is the data frame:

do.call(c,imp)

  X11  X12  X13  X14  X15  X16  X17  X18  X19 X110 X111 X112 X113 X114
12121212121212
X115 X116  X21  X22  X23  X24  X25  X26  X27  X28  X29 X210 X211 X212
12010111010101
X213 X214 X215 X216   Y1   Y2   Y3   Y4   Y5   Y6   Y7   Y8   Y9  Y10
11011234567812
  Y11  Y12  Y13  Y14  Y15  Y16
345678

So, e.g. for a 3 column matrix:


matrix(do.call(c,imp), ncol=3)

   [,1] [,2] [,3]
  [1,]101
  [2,]212
  [3,]103
  [4,]214
  [5,]115
  [6,]216
  [7,]107
  [8,]218
  [9,]101
[10,]212
[11,]103
[12,]214
[13,]115
[14,]216
[15,]107
[16,]218

Cheers,
Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

On Thu, May 24, 2018 at 7:46 AM, Ioanna Ioannou  wrote:


Hello everyone,


  I want to transform a data.frame into an array (lets call it mydata),
where: mydata[[1]] is the first imputed dataset...and for each mydata[[d]],
the first p columns are covariates X, and the last one is the outcome Y.


Lets assume a simple data.frame:


Imputed = data.frame( X1 = c(1,2,1,2,1,2,1,2, 1,2,1,2,1,2,1,2),

   X2 = c(0,1,0,1,1,1,0,1,
0,1,0,1,1,1,0,1),

Y   =
c(1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8))

The first 8 have been obtained by the first imputation and the later 8 by
the 2nd.


Can you help me please?


Best,

ioanna

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



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



__
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] Wired result when I convert from Character to Numeric

2018-05-23 Thread Gerrit Eichner

Hi, Christofer,

try

print(as.numeric(x), digits = 10) # or another number of digits

to increase the printed(!) precision.

 Hth  --  Gerrit

Am 23.05.2018 um 12:42 schrieb Christofer Bogaso:

Hi,

Below is my simple result in R


x = "1282553.821000"
as.numeric(x)

[1] 1282554

Any idea where all numbers in the decimal places (ie 8, 2, 1) are gone?

Thanks,

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



__
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] Further questions

2018-04-20 Thread Gerrit Eichner

Hello, Anne,

just a few quick hints because I need to run.

First, try to format you R-code in emails like this
with adequate line breaks.

Second, if you boil down your problem to the crucial point
(and not just pack an email with very specific code) more
people may be more willing to respond.

Third, just to be sure: This list is not for home work.

Two more remarks see inline below.

 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 20.04.2018 um 10:32 schrieb CHATTON Anne via R-help:

Hi R folks,
In my previous post I forgot to mention that I was new to R. I was
really grateful for your quick help. I have two further questions:
1) In the graph of a regression line I would like to show one specific residual yi obs - 
yi pred (let's take the person whose residual is 76). How do I add a bracket to this 
vertical distance and name it? I'am getting stuck after the "textxy" function.
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)
mean(Age)
mean(BloodPressure)
SimpleLinearReg1 <- lm(BloodPressure ~ Age)
summary(SimpleLinearReg1)
coeff <-coefficients(SimpleLinearReg1)
coeff
eq <- as.formula(
   paste0("y ~ ", round(coefficients(SimpleLinearReg1)[1],2), "",
 paste(sprintf(" %+.2f*%s ",
   coefficients(SimpleLinearReg1)[-1],
   names(coefficients(SimpleLinearReg1)[-1])),
   collapse="")))
eq <- paste0("y = ", round(coeff[2],1), "x + ", round(coeff[1],1))
plot(Age, BloodPressure, pch = 16, cex = 1.3, col = "blue",
main = "Graphe de la relation entre l'âge et la pression artérielle",
xlab = "Age (année)", ylab = "Pression artérielle (mmHg)")
abline(SimpleLinearReg1, col="red")
res <- signif(residuals(SimpleLinearReg1), 2)
pre <- predict(SimpleLinearReg1)
segments(Age, BloodPressure, Age, pre, col="red")
library(calibrate)
textxy(Age, BloodPressure, res, cex=0.7)


I don't understand what mean by "to add a bracket", but why
don't you just place a "name" next to the vertical line at
residual # 76 using the function text?


 2)


2) I also need your help plotting a hyperplan for a multiple
regression and here I am really stuck...


This is a bit more complicated. Learn, e.g., about function persp
or search for "plot regression surface with r" and find, e.g.,
https://stackoverflow.com/questions/7863906/plot-regression-surface#7864088 
as the first hit.




inc <- c(25000, 28000, 17500, 3, 25000, 32000, 3, 29000, 26000, 4)
age <- c(60, 36, 21, 35, 33, 43, 29, 45, 41, 48)
educ <- c(12, 12, 13, 16, 16, 12, 13, 15, 15, 20)
MultLinearReg1 <- lm(inc ~ age + educ)
summary(MultLinearReg1)

Thank you so much!

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



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




--

 Best regards  --  Gerrit
 Best regards  --  Gerrit Eichner
 Hth  --  Gerrit
 Viele Grüße  --  Gerrit
 Viele Grüße  --  Gerrit Eichner
 Viele Grüße  --  GE
 Freundliche Grüße  --  Gerrit Eichner
 Freundliche Grüße  --  GE
 Grüße  --  Gerrit
 Grüße  --  Gerrit Eichner
 Grüße  --  GE
 Gruß  --  G

-
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

__
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] effects & lme4: error since original dataframenotfoundWASeffects: error when original data frame is missing

2018-01-18 Thread Gerrit Eichner

Thanks, John,

for your hint! (Unfortunately, I was not aware of this vignette,
but I am glad that I seem to habe been on the right track.)

Indeed very helpful, in particular of course, the warning regarding
the danger of overwriting already existing objects. That danger might
be reduced by pre-checking the intended name and if neccessary
changing it (somehow ...) automatically. (Have to think about that ...)

 Best regards  --  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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 17.01.2018 um 15:55 schrieb Fox, John:

Dear Gerrit,

This issue is discussed in a vignette in the car package (both for functions in the car and effects 
packages): vignette("embedding", package="car") . The solution suggested there 
is the essentially the one that you used.

I hope this helps,
  John

-
John Fox, Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: socialsciences.mcmaster.ca/jfox/



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Gerrit
Eichner
Sent: Wednesday, January 17, 2018 9:50 AM
To: r-help@r-project.org
Subject: Re: [R] effects & lme4: error since original data frame
notfoundWASeffects: error when original data frame is missing

Third "hi" in this regard and for the archives:

I found a (maybe "dirty") workaround which at least does what I need by
creating a copy of the required data frame in the .GlobalEnv by means of
assign:

foo <- function() {
assign("X", sleepstudy, pos = 1)
fm <- lmer(Reaction ~ Days + (Days | Subject), data = X)
Effect("Days", fm)
}


   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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
---------

Am 17.01.2018 um 15:02 schrieb Gerrit Eichner:

Hi, again,

I have to modify my query since my first (too simple) example doesn't
reflect my actual problem. Second try:

When asking Effect() inside a function to compute an effect of an
lmer-fit which uses a data frame local to the body of the function, as
in the following example (simplifying my actual application), I get
the "Error in is.data.frame(data) :
object 'X' not found":

  > foo <- function() {
+  X <- sleepstudy
+  fm <- lmer(Reaction ~ Days + (Days | Subject), data = X)
+  Effect("Days", fm)
+ }

  > foo()

Error in is.data.frame(data) : object 'X' not found


With lm-objects there is no problem:

  > foo2 <- function() {
+   X <- sleepstudy
+   fm <- lm(Reaction ~ Days, data = X)
+   Effect("Days", fm)
+ }

  > foo2()



Any idea how to work around this problem?
Once again, thx in advance!

   Regards  --  Gerrit

PS: > sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8
x64 (build 9200)

Matrix products: default

locale:
[1]

LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252 [3]

LC_MONETARY=German_Germany.1252 LC_NUMERIC=C [5]
LC_TIME=German_Germany.1252

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

other attached packages:
[1] effects_4.0-0   carData_3.0-0   lme4_1.1-14 Matrix_1.2-11
car_2.1-5 [6] lattice_0.20-35

loaded via a namespace (and not attached):
   [1] Rcpp_0.12.13   MASS_7.3-47    grid_3.4.2
MatrixModels_0.4-1
   [5] nlme_3.1-131   survey_3.32-1  SparseM_1.77 minqa_1.2.4
   [9] nloptr_1.0.4   splines_3.4.2  tools_3.4.2
survival_2.41-3 [13] pbkrtest_0.4-7 yaml_2.1.14
parallel_3.4.2 compiler_3.4.2 [17] colorspace_1.3-2   mgcv_1.8-22
nnet_7.3-12 quantreg_5.33

-
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
Fax: +49-(0)641-99-32109    http://www.uni-giessen.de/eichner
-

Am 17.01.2018 um 10:55 schrieb Gerrit Eichner:

Hello, everyody,

when asking, e.g., Effect() to compute the effects of a fitted, e.g.,
linear model after having deleted the data frame fro

Re: [R] effects & lme4: error since original data frame notfoundWASeffects: error when original data frame is missing

2018-01-17 Thread Gerrit Eichner

Third "hi" in this regard and for the archives:

I found a (maybe "dirty") workaround which at least does what I need
by creating a copy of the required data frame in the .GlobalEnv by
means of assign:

foo <- function() {
  assign("X", sleepstudy, pos = 1)
  fm <- lmer(Reaction ~ Days + (Days | Subject), data = X)
  Effect("Days", fm)
}


 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-----

Am 17.01.2018 um 15:02 schrieb Gerrit Eichner:

Hi, again,

I have to modify my query since my first (too simple)
example doesn't reflect my actual problem. Second try:

When asking Effect() inside a function to compute an effect
of an lmer-fit which uses a data frame local to the body of
the function, as in the following example (simplifying my
actual application), I get the "Error in is.data.frame(data) :
object 'X' not found":

 > foo <- function() {
+  X <- sleepstudy
+  fm <- lmer(Reaction ~ Days + (Days | Subject), data = X)
+  Effect("Days", fm)
+ }

 > foo()

Error in is.data.frame(data) : object 'X' not found


With lm-objects there is no problem:

 > foo2 <- function() {
+   X <- sleepstudy
+   fm <- lm(Reaction ~ Days, data = X)
+   Effect("Days", fm)
+ }

 > foo2()



Any idea how to work around this problem?
Once again, thx in advance!

  Regards  --  Gerrit

PS: > sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] effects_4.0-0   carData_3.0-0   lme4_1.1-14 Matrix_1.2-11 car_2.1-5
[6] lattice_0.20-35

loaded via a namespace (and not attached):
  [1] Rcpp_0.12.13   MASS_7.3-47    grid_3.4.2 MatrixModels_0.4-1
  [5] nlme_3.1-131   survey_3.32-1  SparseM_1.77 minqa_1.2.4
  [9] nloptr_1.0.4   splines_3.4.2  tools_3.4.2 survival_2.41-3
[13] pbkrtest_0.4-7 yaml_2.1.14    parallel_3.4.2 compiler_3.4.2
[17] colorspace_1.3-2   mgcv_1.8-22    nnet_7.3-12 quantreg_5.33

-
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
Fax: +49-(0)641-99-32109    http://www.uni-giessen.de/eichner
-

Am 17.01.2018 um 10:55 schrieb Gerrit Eichner:

Hello, everyody,

when asking, e.g., Effect() to compute the effects of a fitted,
e.g., linear model after having deleted the data frame from the
workspace for which the model was obtained an error is reported:

 > myair <- airquality
 > fm <- lm(Ozone ~ Temp, data = myair)
 > rm(myair)
 > Effect("Temp", fm)
Error in eval(model$call$data, envir) : object 'myair' not found

Has anybody a better "workaround" for this than, e.g., explicitly
saving the fitted model object fm together with its original
environment or just the data needed frame (maybe in a list like
fm.plus.origdata <- list(fm, myair = myair)) to be able to restore
the original environemt (or at least the needed opriginal data
frame) of the time when fm was created?

Thx for any hint!

  Regards  --  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
Fax: +49-(0)641-99-32109    http://www.uni-giessen.de/eichner

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


__
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, reproduci

Re: [R] effects & lme4: error since original data frame not found WASeffects: error when original data frame is missing

2018-01-17 Thread Gerrit Eichner

Hi, again,

I have to modify my query since my first (too simple)
example doesn't reflect my actual problem. Second try:

When asking Effect() inside a function to compute an effect
of an lmer-fit which uses a data frame local to the body of
the function, as in the following example (simplifying my
actual application), I get the "Error in is.data.frame(data) :
object 'X' not found":

> foo <- function() {
+  X <- sleepstudy
+  fm <- lmer(Reaction ~ Days + (Days | Subject), data = X)
+  Effect("Days", fm)
+ }

> foo()

Error in is.data.frame(data) : object 'X' not found


With lm-objects there is no problem:

> foo2 <- function() {
+   X <- sleepstudy
+   fm <- lm(Reaction ~ Days, data = X)
+   Effect("Days", fm)
+ }

> foo2()



Any idea how to work around this problem?
Once again, thx in advance!

 Regards  --  Gerrit

PS: > sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] effects_4.0-0   carData_3.0-0   lme4_1.1-14 Matrix_1.2-11 
car_2.1-5

[6] lattice_0.20-35

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13   MASS_7.3-47grid_3.4.2 
MatrixModels_0.4-1
 [5] nlme_3.1-131   survey_3.32-1  SparseM_1.77 
minqa_1.2.4
 [9] nloptr_1.0.4   splines_3.4.2  tools_3.4.2 
survival_2.41-3
[13] pbkrtest_0.4-7 yaml_2.1.14parallel_3.4.2 
compiler_3.4.2
[17] colorspace_1.3-2   mgcv_1.8-22nnet_7.3-12 
quantreg_5.33


-
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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
---------

Am 17.01.2018 um 10:55 schrieb Gerrit Eichner:

Hello, everyody,

when asking, e.g., Effect() to compute the effects of a fitted,
e.g., linear model after having deleted the data frame from the
workspace for which the model was obtained an error is reported:

 > myair <- airquality
 > fm <- lm(Ozone ~ Temp, data = myair)
 > rm(myair)
 > Effect("Temp", fm)
Error in eval(model$call$data, envir) : object 'myair' not found

Has anybody a better "workaround" for this than, e.g., explicitly
saving the fitted model object fm together with its original
environment or just the data needed frame (maybe in a list like
fm.plus.origdata <- list(fm, myair = myair)) to be able to restore
the original environemt (or at least the needed opriginal data
frame) of the time when fm was created?

Thx for any hint!

  Regards  --  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
Fax: +49-(0)641-99-32109    http://www.uni-giessen.de/eichner

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


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

[R] effects: error when original data frame is missing

2018-01-17 Thread Gerrit Eichner

Hello, everyody,

when asking, e.g., Effect() to compute the effects of a fitted,
e.g., linear model after having deleted the data frame from the
workspace for which the model was obtained an error is reported:

> myair <- airquality
> fm <- lm(Ozone ~ Temp, data = myair)
> rm(myair)
> Effect("Temp", fm)
Error in eval(model$call$data, envir) : object 'myair' not found

Has anybody a better "workaround" for this than, e.g., explicitly
saving the fitted model object fm together with its original
environment or just the data needed frame (maybe in a list like
fm.plus.origdata <- list(fm, myair = myair)) to be able to restore
the original environemt (or at least the needed opriginal data
frame) of the time when fm was created?

Thx for any hint!

 Regards  --  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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner

__
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] barplot_add=TRUE

2018-01-09 Thread Gerrit Eichner

Dear Sibylle!

Am 09.01.2018 um 10:24 schrieb Sibylle Stöckli:

Dear Gerrit

Thanks a lot. "rbind" seems to be the right function. Unfortunately 
there is a shift in the x-axis (see pdf). There are 52 trapcatch values 
each, m and w, but m$trapcatch and w$trapcatch are shifted up to x-value 
60.

The follow-up lines for temp and humidity are fine.


Hm, I'm not quite sure if you are asking another question here ... ;-)
But I assume you do.

However, without knowledge about the structure of Hecke or m,
respectively, in particular about their row numbers, it is impossible
to spot the cause of your "problem". I suggest you check the structure
of m:

str(m)

I suspect you'll see that the assumption of 52 trapcatch values is
somehow wrong.

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-


Thanks
Sibylle







setwd("~/Desktop/DatenLogger2017") #  am Mac sks
trap= read.delim("SWD_Trap_week-new.txt", na.strings="*", header=TRUE)
climate= read.delim("Agrometeo_week-2017.txt", na.strings="*", header=TRUE)
names(trap)
names(climate)


Hecke<-trap[trap$station=="FiBL_Hecke",]
m<-Hecke[Hecke$m_w=="m",]
w<-Hecke[Hecke$m_w=="w",]
par(mar=c(5,4,4,10))
barplot(rbind(m$trapcatch, w$trapcatch), ylim=c(0,350))
axis(1, 1:52)

par(new=T)
plot(climate$Week,climate$Frick_Temp.mittel, type="n", axes=F, 
ylim=c(0,25), ylab="", xlab="", xaxt="n")

lines(climate$Week, climate$Frick_Temp.mittel, lty=2, lwd=2, col="blue")
axis(4,las=1, cex.axis=0.8, col="blue")
mtext(side=4, line=2.5, "Mittlere Temperatur (°C)", cex=0.8, col="blue")

par(new=T)
plot(climate$Week,climate$Frick_Feuchte.mittel, type="n", axes=F, 
ylim=c(0,100), ylab="", xlab="", xaxt="n")
lines(climate$Week, climate$Frick_Feuchte.mittel, lty=2, lwd=2, 
col="darkgreen")

axis(4,las=1, line=5.5, cex.axis=0.8, col="darkgreen")
mtext(side=4, line=7.5, "Mittlere Feuchte (%)", cex=0.8, col="dark green")




Am 09.01.2018 um 09:30 schrieb Gerrit Eichner:


Hi, Sibylle,

since you write '"mathematically" add', does

barplot(rbind(m$trapcatch, w$trapcatch))

do what you want (modulo layout details)?

Hth  --  Gerrit

-
Dr. Gerrit Eichner   Mathematical Institute, Room 212
gerrit.eich...@math.uni-giessen.de 
<mailto:gerrit.eich...@math.uni-giessen.de>   Justus-Liebig-University 
Giessen

Tel: +49-(0)641-99-32104  Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/eichner
-

Am 09.01.2018 um 09:19 schrieb Sibylle Stöckli:

Dear R users
aim
Barplot of insect trap catches (y variable trapcatch) at one specific 
station (variable FiBL_Hecke) from week 1-52 ( x variable week).
It works well using the function tapply (sum trapcatch per week, 
males and females not separated), however, I intend to separate the y 
variable trapcatch in males and females (variable m_w: m and w)

problem
I used the function "add" to merge two bar plots (males and females). 
Unfortunately the second barplot masks the first barplot.

question
Is there a function to "mathematically" add the values from both 
barplots with the aim the barplot presenting the total trap (males 
and females) catches per week?

Hecke<-trap[trap$station=="FiBL_Hecke",] # station = Hecke
m<-Hecke[Hecke$m_w=="m",] # male trap catches
w<-Hecke[Hecke$m_w=="w",] # female trap catches
barplot(m$trapcatch, ylab="Y", space=0.5, col=c("grey0"), 
ylim=c(0,450), las=2, cex.lab=0.9, cex.axis=0.9, cex.names=0.9)
barplot(w$trapcatch,space=0.5, add=TRUE, beside=FALSE, 
col=c("grey50"), xaxt="n", yaxt="n")

Thanks a lot
Sibylle
[[alternative HTML version deleted]]
__
R-help@r-project.org <mailto: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.



__
R-help@r-project.org <mailto:R-help@r-project.org> mailing list -- To 
UNSUBSCRIBE and more, see

https:/

Re: [R] barplot_add=TRUE

2018-01-09 Thread Gerrit Eichner

Hi, Sibylle,

since you write '"mathematically" add', does

barplot(rbind(m$trapcatch, w$trapcatch))

do what you want (modulo layout details)?

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 09.01.2018 um 09:19 schrieb Sibylle Stöckli:

Dear R users

aim
Barplot of insect trap catches (y variable trapcatch) at one specific station 
(variable FiBL_Hecke) from week 1-52 ( x variable week).
It works well using the function tapply (sum trapcatch per week, males and 
females not separated), however, I intend to separate the y variable trapcatch 
in males and females (variable m_w: m and w)

problem
I used the function "add" to merge two bar plots (males and females). 
Unfortunately the second barplot masks the first barplot.

question
Is there a function to "mathematically" add the values from both barplots with 
the aim the barplot presenting the total trap (males and females) catches per week?



Hecke<-trap[trap$station=="FiBL_Hecke",] # station = Hecke
m<-Hecke[Hecke$m_w=="m",] # male trap catches
w<-Hecke[Hecke$m_w=="w",] # female trap catches

barplot(m$trapcatch, ylab="Y", space=0.5, col=c("grey0"), ylim=c(0,450), las=2, 
cex.lab=0.9, cex.axis=0.9, cex.names=0.9)
barplot(w$trapcatch,space=0.5, add=TRUE, beside=FALSE, col=c("grey50"), xaxt="n", 
yaxt="n")

Thanks a lot
Sibylle
[[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.



__
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] Help avoiding setting column type two times

2017-11-30 Thread Gerrit Eichner

See below.

Am 30.11.2017 um 15:27 schrieb Martin Møller Skarbiniks Pedersen:

Hi,
   I think and hope this a good place to ask for code review for a R
beginners?

   I have made a R script which generates a dataset based on 2009 danish
referendum and it does work.

   But I think the code could be better and I would any comments how the
code can be improved.
   At least I would like to know how I avoid converting several of the
columns to factors in the end of the code?

Description of the code:

   It reads a lot of xml-files from ../raw/ and saves a data.frame with
information
from these xml-files.

   In the ../raw/ directiory I have placed the xml-files which I got from
"Statistics Denmark"
   I have also put these xml-files on my website and they can be download
freely from http://20dage.dk/R/referendum-2009/raw.tar.gz

   The code is below but I have also put the code at this place:
http://20dage.dk/R/referendum-2009/convert_from_xml.R

Best Regards
Martin M. S. Pedersen

---
library(xml2)

convert_one_file <- function(url) {
 x <- read_xml(url)

 Sted <- xml_find_first(x, ".//Sted")
 StedType <- xml_attr(Sted, "Type")
 StedTekst <- xml_text(Sted)

 Parti <- xml_find_all(x, ".//Parti")
 PartiId <- xml_attr(Parti, "Id")
 PartiBogstav <- xml_attr(Parti, "Bogstav")
 PartiNavn <- xml_attr(Parti, "Navn")


 StemmerAntal <- xml_attr(Parti, "StemmerAntal")
 Stemmeberettigede <- xml_integer(xml_find_first(x,
".//Stemmeberettigede"))
 DeltagelsePct <- xml_double(xml_find_first(x, ".//DeltagelsePct"))
 IAltGyldigeStemmer <- xml_integer(xml_find_first(x,
".//IAltGyldigeStemmer"))
 BlankeStemmer <- xml_integer(xml_find_first(x, ".//BlankeStemmer"))
 AndreUgyldigeStemmer <- xml_integer(xml_find_first(x,
".//AndreUgyldigeStemmer"))

 data.frame(cbind(StedType, StedTekst, PartiId, PartiBogstav, PartiNavn,
  StemmerAntal, Stemmeberettigede, DeltagelsePct,
IAltGyldigeStemmer,
BlankeStemmer, AndreUgyldigeStemmer), stringsAsFactors = FALSE)
}

raw_path <- "../raw"
filenames <- dir(path = raw_path, pattern = "fintal_.*", full.names = T)

result <- data.frame(StedType = factor(),
  StedTekst = character(),
  PartiId   = factor(),
  PartiBogstav = factor(),
  PartiNavn= factor(),
  StemmerAntal = integer(),
  Stemmeberettigede = integer(),
  DeltagelsePct = numeric(),
  IAltGyldigeStemmer = integer(),
  BlankeStemmer = integer(),
  AndreUgyldigeStemmer = integer(),
  stringsAsFactors = FALSE)

for (i in 1:length(filenames)) {
 #cat(paste0(filenames[i],"\n"))
 returnCode <-  tryCatch({
result <- rbind(result, convert_one_file(filenames[i]))
 }, error = function(e) {
cat(paste0(filenames[i]," failed:\n",e,"\n"))
 })
}

result$StedType <- as.factor(result$StedType)
result$PartiId <- as.factor(result$PartiId)
result$PartiBogstav <- as.factor(result$PartiBogstav)
result$PartiNavn <- as.factor(result$PartiNavn)
result$StemmerAntal <- as.integer(result$StemmerAntal)
result$Stemmeberettigede <- as.integer(result$Stemmeberettigede)
result$DeltagelsePct <- as.numeric(result$DeltagelsePct)
result$IAltGyldigeStemmer <- as.integer(result$IAltGyldigeStemmer)
result$BlankeStemmer <- as.integer(result$BlankeStemmer)
result$AndreUgyldigeStemmer <- as.integer(result$AndreUgyldigeStemmer)
str(result)
save(result, file = "folkeafstemning2009.Rdata")


Maybe two loops simplify this a little bit for you (not tested):

for(v in c("StedType", ))
 result[[v]] <- factor(result[[v]])

for(v in c("StemmerAntal", ))
 result[[v]] <- as.integer(result[[v]])

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-



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



__
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] adding predictor to linear model without changingexistingcoefficients

2017-05-17 Thread Gerrit Eichner

Hello, Urs,

you may have seen Wolfgang Viechtbauer's answer already which offers
an R-technical solution, but this may leave the mathematical grounds
of linear models. See inline below for my concern and a hint.

Am 17.05.2017 um 09:12 schrieb Urs Kleinholdermann:

Dear list members,

I want to add a predictor to a linear model without changing the
coefficients of the existing model. How is that done with R?

So if I have a response y and predictors x1, x2, x3 I want to make a model lm1 
like

lm1 = lm(y~x1+x2)

After this model is computed I want to add x3 like

lm2 = lm(y~x1+x2+x3)

However, unlike it is done by the notation above or by update or add1
(as far as I understand) I don't want a new model with all predictors
estimated anew but I want a model lm2 where the coefficients for x1 and
x2 stay exactly as in lm1 and the coefficent for x3 is estimated
additionally. The reasons for this are theoretical.


And the reasons why this is usually impossible (for a valid linear
model as a projection of the response vector onto a linear subspace
spanned by the columns of the design matrix) are also theoretical:
It is not an R problem, but a mathematical fact that unless the vector
of values of a new model term is orthogonal to the vectors of all model
terms already included in the model (i.e., to all columns of its design
matrix) the estimated coefficients of the "old" model are correlated
with the estimated coefficient of the "new" one, and hence the already
existing ones change. So, if you manage to obtain orthogonality you can
achieve what you desire. (You may want to consult with a (theoretical)
book on linear models ... or a local statistician.)

Hth  --  Gerrit



I guess what I want is similar to calculating a new regression on
the residuals of lm1.

lm2 = lm(residuals(lm1)~x3)

however, I would prefer to to that in the common framework of the lm
command in order to calculate statistics, perform anova on the models
and so on.

thanks for your help!
Urs

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



__
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] Paired sample t-test with mi.t.test

2017-04-07 Thread Gerrit Eichner

Hi, Joel,

I think, according to the help page of mi.t.test,

mi.t.test(implist, x = "pre_test", y = "post_test",
  alternative = "greater", paired = TRUE, var.equal = TRUE,
  conf.level = 0.95)

should do it (untested).

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 06.04.2017 um 18:32 schrieb Joel Gagnon:

Dear all,

It is my first time posting on this list so forgive me for any rookie
mistakes I could make.

I want to conduct t-tests on a dataset that has been imputed using the mice
package:
imput_pps <- mice(pps, m=20, maxit=20, meth='pmm') # pps is my dataset. It
contains items from an 11-item questionnaire gather at pre and post test.
So the data set has 22 columns.

I then proceed to compute the total scores for the pre and post test on my
imputed datasets:

long_pps <- complete(imput_pps, action ="long", include = TRUE)
long_pps$pre_test <- rowSums(long_pps[ ,c(3:13)])
long_pps$post_test <- rowSums(long_pps[ , c(14:24)])

I then used as.mids to convert back to mids object:
mids_pps <- as.mids(long_pps)

Next, I created an imputation list object using mitools:
implist <- lapply(seq(mids_pps$m), function(im) complete(mids_pps, im))
implist <- imputationList(implist)

Now, I want to conduct t-tests using the mi.t.test package. I tried the
following code:
mi.t.test(implist, implist$pre_test, implist$post_test, alternative =
"greater", paired = TRUE, var.equal = TRUE, conf.level = 0.95)

When I run this code, R tells me that Y is missing. I know this may sound
stupid, but I thought that I specified Y with this line: implist$pre_test,
implist$post_test - with implist$pre_test being X and implist$post_test
being Y - like I usually do for a normal t-test using the t.test function.

It seems I don't quite understand what the Y variable is supposed to
represent. Could someone help me figure out what I am doing wrong? You
help would be very much appreciated.

Best regards,

Joel Gagnon, Ph.D(c),
Department of Psychology,
Université du Québec à Trois-Rivières
Québec, Canada

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



__
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 empty when drawing from custom function

2017-03-28 Thread Gerrit Eichner

Hi, Luigi,

you are probably missing a call to print() around the call to
the latticeExtra plotting function useOuterStrips() you use
inside your function printer().

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 28.03.2017 um 10:19 schrieb Luigi Marongiu:

Dear all,
I have set a function to draw some data using lattice; the drawing
works when I use lattice on its own, but if I put it into my custom
function, the final plot is empty, yet the terminal reports RStudioGD
1
as normal.
What am I missing?
regards,
Luigi




cluster <- c(rep("A", 90), rep("B", 100))
sample <- c(
  rep(c("cow-01", "cow-02", "cow-03", "cow-04", "cow-05", "cow-06",
"cow-07", "cow-08", "cow-09", "cow-10", "cow-11",
"cow-12", "cow-13", "cow-14", "cow-15", "cow-16", "cow-17",
"blank"), 5),
  rep(c("cow-26", "cow-35", "cow-36", "cow-37", "cow-38", "cow-39",
"cow-40", "cow-41", "cow-42", "cow-43", "cow-44", "cow-45",
"cow-46", "cow-47", "cow-48", "cow-49", "cow-50", "cow-51",
"cow-59", "blank"), 5)
)
type <- c(
  rep(c("negative", "negative", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "blank"), 5),
  rep(c("negative", "positive", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "positive", "positive", "blank"), 5)
)
target <- c(
c(rep("a", 18), rep("b", 18), rep("c", 18), rep("d", 18), rep("e", 18)),
c(rep("a", 20), rep("b", 20), rep("c", 20), rep("d", 20), rep("e", 20))
)
average <- c(88.5, 49, 41, 33, 35, 45, 95, 30, 41, 64, 22, 29, 59, 71,
128, 39, 42, 47, 86, 100,
 69, 44, 53, 66, 66, 71, 161, 69, 22.5, 30, 67, 99, 129,
94, 49, 33, 28, 31, 26, 23,
 30, 41, 35, 23, 38, 43, 15, 21, 45, 51.5, 34, 26, 43,
32.5, 59, 58.5, 61, 62.5, 58,
 59.5, 60.5, 60, 64, 110, 55, 66, 197, 83.5, 155, 76, 125,
90, 73, 84, 95.5, 62, 82, 138,
 103.5, 57, 138, 149.5, 57, 54, 245.5, 191, 131, 96, 176,
45, 76, 33, 37, 51, 44, 50, 54,
 66, 49, 90, 66.5, 42.5, 67, 56, 54, 50, 45, 99, 50, 51.5,
212, 40, 68, 121, 80, 57,
 81.5, 128, 77, 119.5, 126, 184, 101, 103, 88, 100, 140,
186, 297, 32, 184, 36, 45, 45, 44,
 86, 65, 61, 76, 62, 136, 84, 80, 56, 109, 116, 54, 59,
79, 34, 74.5, 54, 49, 55, 56,
 59, 56, 56, 57, 67, 65, 63, 52, 58, 59, 56, 54, 66, 92,
87, 59, 33, 58, 51, 54,
 52, 47, 45, 42, 52, 57, 79, 42, 45.5, 47, 47, 36, 50, 53, 49 )
stdev <- c(17.85, 6.31, 3.42, 1.04, 0.51, 6.04, 38.43, 2.78, 5.55,
26.72, 1.83, 9.92, 4.59, 19, 7.96,
   7.5, 1.06, 9.66, 75.94, 36.79, 50.45, 9.79, 1.55,
11.42, 64.12, 0.79, 15.14, 16.15, 8.12, 4.04, 92.57, 35.35,
   42.28, 52.96, 7.06, 4.97, 1.15, 4.77, 6.59, 7.27, 0.75,
4.25, 9, 0.1, 1.14, 4.17, 6.73, 3.81, 3.27,
   97.44, 9.74, 0.45, 8.14, 5.91, 13.1, 98.22, 8.92,
72.62, 70.26, 59.46, 29.89, 56.35, 91.25, 49.94, 20.65, 62.04,
   95.13, 35.89, 99.64, 29.44, 33.12, 45.91, 96.69, 9.05,
38.56, 3.09, 0.6, 8.69, 16.95, 74.03, 84.05, 39.87, 15.52,
   27.92, 35.72, 80.26, 71.93, 66.73, 87.8, 5.43, 98.3,
7.41, 9.86, 63.64, 0.36, 5.84, 1.58, 20.1, 4.21, 82.12,
   19.29, 9.02, 22.12, 54.08, 74.95, 3.24, 9.67, 67.98,
9.92, 40.69, 6.24, 8.76, 74.25, 46.34, 25.69, 90.63, 83.71,
   73.53, 57.88, 15.84, 82.07, 67.45, 47.39, 98.77, 75.1,
64.9, 3.71, 87.44, 61.06, 4.77, 57.54, 7.68, 4.54, 6.15,
   3.32, 60.39, 33.78, 66.22, 18.67, 76.53, 63.54, 47.06,
38.47

Re: [R] Arguments imply differing number of rows: 1, 0

2017-03-28 Thread Gerrit Eichner

Hi, John,

see inline.

Am 27.03.2017 um 20:47 schrieb John Murtagh:

Hi All,

I am trying to generate a cdf plot by using ggplot and have looked at some
examples online. However when I try to replicate it I get the following
error:

"arguments imply differing number of rows: 1, 0"

I made a search and it seems from what I gather the nrows!=ncol and that
doesn't work for a data.frame. I am confused a bit as my MCtab dataframe is
similar.

If someone can explain what is going wrong or what i am
misunderstanding/doing wrong would be great? Code is below to replicate.
Thanks

library (triangle)
library(ggplot2)

n = 1000
W1 = rtriangle(n,330,400)
W2 = rtriangle(n,300,420)
SO = rtriangle(n,0.2,0.3)

MCtab <- data.frame(W1,W2,SO)

set.seed(1)
for (n in 1:n) {
  N0 <- (W1 + W2 + SO )}

set.seed(1)
for (n in 1:n) {
  N1 <- ((0.99*W1 + 0.99*W2 + 0.99*SO ))}

set.seed(1)
for (n in 1:n) {
  N2 <- ((0.98*W1 + 0.98*W2 + 0.98*SO))}

ggdata <- data.frame(N0,N1,N2)


ggdata <- ddply(ggdata, .(N0,N1,N2), transform, ecd=ecdf)


I'm not familiar with ggplot, but I do not think that splitting your
ggdata by your numerical variables N1, N2 and N3 makes any sense ...

PS: I also think that your loops to create N1, N2 and N3 are pretty
nonsensical.



cdf <- ggplot(ggdata, aes(x=value)) +
stat_ecdf(aes(colour="blue","red","green"))
cdf

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



--

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner

__
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] Why is options(digits = 1) displays two digits?

2017-03-21 Thread Gerrit Eichner

Hi, Tal,

in print.default it says:

digits:

a non-null value for digits specifies the __minimum__
number of __significant__ digits to be printed in values.

Maybe this clarifies your observation.

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 21.03.2017 um 10:30 schrieb Tal Galili:

This may have been asked before, but I don't understand the behavior
of options(digits = 1) for vectors containing values such as 0.01

For example, why is this happening:
options(digits = 1)

0.01

[1] 0.01


More examples:

options(digits = 7)
0.1

[1] 0.1

0.01

[1] 0.01

0.11

[1] 0.11

c(0.1,0.01)

[1] 0.10 0.01

options(digits = 1)
0.1

[1] 0.1

0.01

[1] 0.01

0.11

[1] 0.1

c(0.1,0.01)

[1] 0.10 0.01




The help file in ?options says:
digits:
controls the number of digits to print when printing numeric values. It is
a suggestion only.


Is this what is mean by "It is a suggestion only." ?

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



__
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] How to stop as.integer removing dimenions

2017-02-23 Thread Gerrit Eichner

... or:

net1 <- array(0L, dim=c(5,5))

Note the difference between 0 and 0L.


 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 23.02.2017 um 12:49 schrieb Thomas Chesney:

I have:

net1 <- array(0, dim=c(5,5))

str(net1)
 num [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ...

and what I want is:

str(net1)
 int [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ...

Neither of the following work:

net1 <- as.integer(net1, drop=FALSE)

net1 <- as.integer(net1, dim=c(5,5))

Can someone please help?

Thank you,

Thomas




This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it.

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

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



__
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] How to stop as.integer removing dimenions

2017-02-23 Thread Gerrit Eichner

Hi, Thomas,

maybe

mode(net1) <- "integer"

does what you want?

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 23.02.2017 um 12:49 schrieb Thomas Chesney:

I have:

net1 <- array(0, dim=c(5,5))

str(net1)
 num [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ...

and what I want is:

str(net1)
 int [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ...

Neither of the following work:

net1 <- as.integer(net1, drop=FALSE)

net1 <- as.integer(net1, dim=c(5,5))

Can someone please help?

Thank you,

Thomas




This message and any attachment are intended solely for the addressee
and may contain confidential information. If you have received this
message in error, please send it back to me, and immediately delete it.

Please do not use, copy or disclose the information contained in this
message or in any attachment.  Any views or opinions expressed by the
author of this email do not necessarily reflect the views of the
University of Nottingham.

This message has been checked for viruses but the contents of an
attachment may still contain software viruses which could damage your
computer system, you are advised to perform your own checks. Email
communications with the University of Nottingham may be monitored as
permitted by UK legislation.

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



__
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] Power of t test for unequal variances?

2016-12-19 Thread Gerrit Eichner

Hello, Mauricio,

maybe pwr.t2n.test() in package pwr or/and n.ttest() in package
samplesize do what you need/want.

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 20.12.2016 um 00:31 schrieb David Winsemius:



On Dec 19, 2016, at 1:47 PM, Mauricio Cornejo via R-help  
wrote:

Is there a function similar to stats::power.t.test that can handle unequal 
variances from two samples?
I noticed that stats::t.test has an argument for indicating whether or not to 
treat the two sample variances as equal.  Wondering why stats::power.t.test 
doesn’t have that option.
Thanks,Mauricio
[[alternative HTML version deleted]]


Because R was developed by statisticians for statisticians and they assumed 
those other statisticians would know how to extend its functions when needed. 
But R-help is not advertised as the place to ask such questions when you don't 
have the statistical skills. (You might want to look at the code of `t.test` to 
see how you might construct appropriate arguments for `power.t.test` in the 
situation you imagine. Seems to me it should be fairly straightforward. 
`power.t.test` is built around the non-central t-distribution and solves a 
uniroot problem for the missing parameter among  n, delta, power, sd, and 
sig.level, given the other 4 parameters.)




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

[R] update of formula with conditional rhs introduces unwantedparentheses

2016-07-19 Thread Gerrit Eichner

Dear list members,

is anyone aware of a (simple) strategy to prevent update() from
introducing parentheses around a conditional rhs of a formula
when updating, e.g., only its lhs? Simple example:

update( y ~ a|b, log(.) ~ .)

gives log(y) ~ (a | b), but I want/need log(y) ~ a | b


I do know how to extract various components of a formula and how to
"re-build" formulae from such single components, but I would like to
avoid that.

 Thx for any hint  --  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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner

__
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] make a right subset!

2016-07-07 Thread Gerrit Eichner

Hello, Elahe,

look at

?match

and check if

df2$Count[ match( Matched, df2$Serial)]

does what you want/need.

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-

Am 07.07.2016 um 13:34 schrieb ch.elahe via R-help:

Hi all,
I have 2 data frames like the following:
the first one df1:

'data.frame':  141obs. of 1 variable:
$SerialNum: int 41006 41013 41044 41046 41067 41166 41202 41262 41274 41290
and the second one df2:

'data.frame':  194 obs. of 2 variables:
$Serial: int   41006 41013 41018 41044 41046 41067 4 41200 41262 41331
$Count : int   1 10 103 11 12 13 138 14 15 16 169 18 182 2 20 21  224 226
then I find the intersect of two data frames in serials which is:

Matched=intersect(df1$SerialNum,df2$Serial)
which gives me matched serials in both data frames. Next I want to get Count of 
these matched serials from df2 but I don't know how to make the right subset 
for this! Does anyone know how should I do that?
Thanks for any help,
Elahe

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



__
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] Where to get quantiles (1st parameter q) for pnorm?(Normalapproximation to binomial distribution)

2016-01-20 Thread Gerrit Eichner

Hi, Matti,

use

?pnorm

and read about qnorm.

 Hth  --  Gerrit


On Wed, 20 Jan 2016, mviljamaa wrote:


I'm doing Normal approximation to binomial distribution.

My variables are generated by rbinom.

Here: 
http://msemac.redwoods.edu/~darnold/math15/spring2013/R/Activities/ApproxBinomWithNorm.html


it's claimed that normal approximation is done using the command pnorm.

Question:

Where to get quantiles (1st parameter q) for pnorm?

-Matti

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


__
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] Scaling rows of a large Matrix::sparseMatrix()

2016-01-13 Thread Gerrit Eichner

Hello, Dirk,

maybe I'm missing something, but to avoid your for-loop-approach doesn't

M <- M/Matrix::rowSums(M)

do what you want?

 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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/eichner
-


Hello R-Users,

I'm looking for a way to scale the rows of a sparse matrix M with about
57,000 rows, 14,000 columns, and 238,000 non-zero matrix elements; see
example code below.

Usually I'd use the base::scale() function (see sample code), but it
freezes my computer. The same happens when I try to run a for loop over
the matrix rows.

The conversion with as.matrix() yields a 5.8 Gb large object, which
appears too large for scale().


So my question is: How can the rows of a large sparse matrix be
efficiently scaled?

Thanks and regards,

Dirk


### Hardware/Session Info
Intel Core i7 w/ 12 Gb RAM
R version 3.2.1 (2015-06-18)
Platform: x86_64-unknown-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS

### Example Code
library(Matrix)
set.seed(42)

## These are exemplary values for my real "problem matrix"
N_ROW <- 56743
N_COL <- 13648
SIZE  <- 238283
PROB <- c(0.050, 0.050, 0.099, 0.149, 0.198, 0.178, 0.119,
 0.079, 0.0297, 0.0198, 0.001, 0.001, 0.001)

## get some random values to populate the sparse matrix
x <- do.call(
 what = rbind,
 args = lapply(X = 1:N_ROW,
   FUN = function(i)
 expand.grid(i,
   sample(x = 1:N_COL,
 size = sample(1:15, 1),
 replace = TRUE)
 )
)
)
x[,3] <- sample(x = 1:13, size = nrow(x),
  replace = TRUE, prob = PROB)

## build the sparse matrix
M <- Matrix::sparseMatrix(
  dims = c(N_ROW, N_COL),
  i = x[,1],
  j = x[,2],
  x = x[,3]
)
print(format(object.size(M), units = "auto"))

## ***
## Scaling the rows of M

## scale() lets my computer freeze
# M <- scale(t(M), center = FALSE, scale(Matrix::rowSums(M)))

## this appears to be not elegant at all and takes forever
# rwsms <- Matrix::rowSums(M)
# for (i in 1:nrow(M)) M[i,] <- M[i,]/rwsms[[i]]

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


__
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 several lines programmaticaly

2015-12-15 Thread Gerrit Eichner

Hi, Petr,

from your example it's not doubtlessly clear to me sure how the sequence 
of ifs should really be continued, but couldn't a nested loop help? 
Something like:


for (i in 1:npks) {
 plot(res[[i]]$x, res[[i]]$y, pch=20)

 for (j in 1:i) {
  lines(res[[i]]$x, res[[i]]$fitpk[j,], col=j, lwd=3)}
  }
 }

(However, this seems too simple ...)

 Hth  --  Gerrit


On Tue, 15 Dec 2015, PIKAL Petr wrote:


Dear all

I am stuck with output of some result. Sorry for not providing working 
example but res is quite a big list and I believe you are able to 
understand my problem.


I have npks variable, which can be anything from 1 to let say 5.

I get result called here res as a nested list with several components 
and I want to plot these components based on npks value. I got this far


par(mfrow=c(npks,1)) # slit the device
for (i in 1:npks) {
plot(res[[i]]$x, res[[i]]$y, pch=20)

if (i ==1) { #lines in case npks==1
lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)}

if(i==2) { # lines in case npks ==2
lines(res[[i]]$x, res[[i]]$fitpk[1,], col=1, lwd=3)
lines(res[[i]]$x, res[[i]]$fitpk[i,], col=i, lwd=3)
}

I can follow this further and expand lines plotting with ifs but it 
seems to me that there must be better solution I overlooked.


Here is a structure of res


str(res)

List of 2
$ :List of 15
 ..$ intnr  : int 1
 ..$ x  : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ...
 .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ...
 ..$ y  : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ...
 ..$ fit: num [1:153] 15.2 15.3 15.4 15.5 15.7 ...
 ..$ fitpk  : num [1, 1:153] 2.35 2.49 2.65 2.81 2.99 ...
 ..$ basl   : num [1:153] 258 258 258 258 258 ...
 ..$ baslchg: num [1:153] 12.8 12.8 12.7 12.7 12.7 ...
 ..$ rss: num 1354
 ..$ num.ker: int 1
 ..$ par: num [1:6] 12.8649 -0.0409 4549.1417 1.9927 66.939 ...
 ..$ parbl  : Named num [1:2] 12.86 -4.09
 .. ..- attr(*, "names")= chr [1:2] "" "2485"
 ..$ parpks : num [1, 1:5] 35.494 4549.142 715.324 0.129 1.993
 .. ..- attr(*, "dimnames")=List of 2
 .. .. ..$ : NULL
 .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ...
 ..$ accept : logi FALSE
 ..$ alpha  : num 0.1
 ..$ thresh : Named num 3.81
 .. ..- attr(*, "names")= chr "90%"
$ :List of 15
 ..$ intnr  : int 1
 ..$ x  : Named num [1:153] 34.8 34.8 34.9 34.9 34.9 ...
 .. ..- attr(*, "names")= chr [1:153] "2484" "2485" "2486" "2487" ...
 ..$ y  : num [1:153] 3.08 -2.91 5.1 12.1 42.11 ...
 ..$ fit: num [1:153] 15 15 15.1 15.1 15.2 ...
 ..$ fitpk  : num [1:2, 1:153] 2.1329 0.0859 2.2666 0.0876 2.4109 ...
 ..$ basl   : num [1:153] 258 258 258 258 258 ...
 ..$ baslchg: num [1:153] 12.8 12.7 12.6 12.5 12.4 ...
 ..$ rss: num 1325
 ..$ num.ker: num 2
 ..$ par: num [1:10] 12.8649 -0.0942 4540.4742 2.0373 66.9394 ...
 ..$ parbl  : Named num [1:2] 12.86 -9.42
 .. ..- attr(*, "names")= chr [1:2] "" "2485"
 ..$ parpks : num [1:2, 1:5] 35.5 35.9 4540.5 39.4 715.3 ...
 .. ..- attr(*, "dimnames")=List of 2
 .. .. ..$ : NULL
 .. .. ..$ : chr [1:5] "loc" "height" "intens" "FWHM" ...
 ..$ accept : logi FALSE
 ..$ alpha  : num 0.1
 ..$ thresh : Named num 3.81
 .. ..- attr(*, "names")= chr "90%"




Best Regards
Petr


__
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] vector of constant values

2015-10-29 Thread Gerrit Eichner

Hi, Thanoon!


I want to simulate a vector of constants values with dimention = 200x2 and
all values of this vector are 1.


You mean "I want to _construct_ a _matrix_ of dimension 200 x 2 with all 
entries equal to 1", don't you?


Homework? Take a look at


?matrix


 Hth  --  Gerrit


Any help please.


Regards

--
Thanoon Y. Thanoon
PhD Candidate
Department of Mathematical Sciences
Faculty of Science
University Technology Malaysia, UTM
E.Mail: thanoon.youni...@gmail.com
E.Mail: dawn_praye...@yahoo.com
Facebook:Thanoon Younis AL-Shakerchy
Twitter: Thanoon Alshakerchy
H.P:00601127550205

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


__
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] rbind - names in dataframe. Beginner Question

2015-10-29 Thread Gerrit Eichner

Hello, Sarah,

take a look at the online help page of the function cut() (and apply the 
function to the Hunger-column).


 Hth  --  Gerrit

On Thu, 29 Oct 2015, Dagmar wrote:


Dear Sarah, (dear All),
Thank you for trying to help! You are right, that I want to add a column to 
my dataframe with a corresponding value to the Hunger column.
Your solution is basically correct in the result but my data are a little 
more complicated. Maybe that example describes it better:


myframe <- data.frame (ID=c("Ernie", "Ernie", "Ernie", "Bert",
"Bert","Bert", "Duck"), Hunger=c(1.2,1.3,1.1,2.1,2.2,1.4,3.3) )
myframe

# Now I want to add a column which says "hunger" for values between 1.0 - 2;
#"big Hunger" for >2 $ <=3, "very big Hunger" for >3
# so that the result looks somewhat like that:
myframeresult <- data.frame (ID=c("Ernie", "Ernie", "Ernie", "Bert",
"Bert","Bert", "Duck"), Hunger=c(1.2,1.3,1.1,2.1,2.2,1.4,3.3),Hungertype 
=c("Hunger", "Hunger", "Hunger", "bigHunger", "bigHunger", 
"Hunger","verybigHunger" ) )

myframeresult

Does anyone know the solution?
Thanks in advance for trying,
Dagmar


Am 28.10.2015 um 20:54 schrieb Sarah Goslee:

If I'm reading this correctly, you want to add a column to your
dataframe with a name corresponding to the value in the Hunger column.

myframe <- data.frame (ID=c("Ernie", "Ernie", "Ernie", "Bert",
"Bert","Bert", "Duck"), Hunger=c(1,1,1,2,2,1,3) )

myframe$Hungertype <- c("none", "bighunger", 
"verybighunger")[myframe$Hunger]


  ID HungerHungertype
1 Ernie  1  none
2 Ernie  1  none
3 Ernie  1  none
4  Bert  2 bighunger
5  Bert  2 bighunger
6  Bert  1  none
7  Duck  3 verybighunger

Then you can subset it to remove low values, sort it, etc.

On Wed, Oct 28, 2015 at 8:20 AM, Dagmar Cimiotti  
wrote:

Hello,
It must be very easy.

I have data like this:
myframe <- data.frame (ID=c("Ernie", "Ernie", "Ernie", "Bert",
"Bert","Bert", "Duck"), Hunger=c(1,1,1,2,2,1,3) )
myframe
bighunger <- subset (myframe, myframe$Hunger>=2 &myframe$Hunger <3 )
bighunger
verybighunger <- subset(myframe,myframe$Hunger>=3)
verybighunger
hungry <- rbind (bighunger=bighunger,very=verybighunger)
hungry

BUT I want a result like this:
myframesresult <- data.frame(Hunger=c("bighunger","bighunger","very"),
ID=c("Bert", "Bert", "duck"), Hunger=c(2,2,3))
myframesresult

Where is my mistake?
Very many thanks in advance!!
Dagmar


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


__
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] extract all dataframes from list

2015-10-06 Thread Gerrit Eichner

Hello, Maicel,

if you only want to extract info from those data frames, maybe it is 
enough to attach the list to the search path using attach (and afterwards 
detach()); see ?attach. Otherwise the online help page of assign() might 
be a starting point for you.


 Hth  --  Gerrit


Hi

Or basically you can use for cycle. This can be as effective as lapply 
and if you plan to do some operations on your data frames maybe more 
manageable.


Cheers
Petr


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of maicel
Sent: Tuesday, October 06, 2015 12:50 PM
To: r-help@r-project.org
Subject: [R] extract all dataframes from list

Hello List, I have list of named dataframe. How can I extract all
dataframes from this list? The dataframe names should be the same of
the original list.
May I use the lapply function?

Thanks for your help. Best regards,
Maicel Monzon, MD
National Center of Clinical Trials
Havana, Cuba



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


__
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] Fisher's Test 5x4 table

2015-08-31 Thread Gerrit Eichner

Paul,

in addition to Peter's suggestion about the missing of theory you are also 
completely missing to explain what you mean by "[it] is not giving me the 
results for the calculations" or "[how] to get the results of the fisher 
test". They are there in the output of R's fisher.test() (if you have an 
idea about the theory).


And again:


fisher.test( Trapz, simulate.p.value = TRUE, B = 1e5)


specifies enough arguments in the case of simulating to approximate the 
p-value since workspace (quoting from the help page) is "Only used for 
***non-simulated*** p-values [of] larger than 2 by 2 tables." (Similarly, 
control and hybrid are not needed either here.)


 Regards  --  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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-


On Sun, 30 Aug 2015, paul brett wrote:


Hi Gerrit,
I tried both of your suggestions and got the exact same thing.
Fisher's Exact Test for Count Data with simulated p-value (based on 1e+05
replicates)

data:  Trapz
p-value = 1e-05
alternative hypothesis: two.sided

I put in a few changes myself based on the details section on what should
be used for a larger than 2x2 table, getting the exact same thing as
before. I have removed or = 1, conf.int = TRUE. Added y = NULL, control =
list(30) and changed simulate.p.value = TRUE.

fisher.test( Trapz, y = NULL, workspace = 20, hybrid = TRUE,control =

list(30), simulate.p.value = TRUE, B =1e5)
isher's Exact Test for Count Data with simulated p-value (based on 1e+05
replicates)

data:  Trapz
p-value = 1e-05
alternative hypothesis: two.sided


fisher.test( Trapz, y = NULL, workspace = 20, hybrid = TRUE,control =

list(30), simulate.p.value = TRUE, B =1e7)

Fisher's Exact Test for Count Data with simulated p-value (based on 1e+07
replicates)

data:  Trapz
p-value = 1e-07
alternative hypothesis: two.sided


Dispite these chages, the changes equations is not giving me the results
for the calculations. The changes I have made seem to satisfy what is in
the details section on R, and I don't have the issue of workspace in R.
What I do to get the results of the fisher test?
Is there something simple that I am missing?

Regards,
    Paul

On Fri, Aug 28, 2015 at 3:52 PM, Gerrit Eichner <
gerrit.eich...@math.uni-giessen.de> wrote:


Paul,

as the error messages of your first three attempts (see below) tell you -
in an admittedly rather cryptic way - your table or its sample size,
respectively, are too large, so that either the "largest (hash table) key"
is too large, or your (i.e., R's) workspace is too small, or your
hardware/os cannot allocate enough memory to calculate the p-value of
Fisher Exact Test exactly by means of the implemented algorithm.

One way out of this is to approximate the exact p-value through
simulation, but apparently there occurred a typo in your (last) attempt to
do that (Error: unexpected '>' in ">").


So, for me the following works (and it should also for you) and gives the
shown output (after a very short while):

Trapz <- as.matrix( read.table( "w.txt", head = T, row.names = "Traps"))




set.seed( 20150828)   # For the sake of reproducibility.

fisher.test( Trapz, simulate.p.value = TRUE,


+ B = 1e5)

   Fisher's Exact Test for Count Data with simulated p-value (based on
   1e+05 replicates)

data:  Trapz
p-value = 1e-05
alternative hypothesis: two.sided



Or for a higher value for B if you are patient enough (with a computing
time of several seconds) :

set.seed( 20150828)

fisher.test( Trapz, simulate.p.value=TRUE, B = 1e7)



   Fisher's Exact Test for Count Data with simulated p-value (based on
   1e+07 replicates)

data:  Trapz
p-value = 1e-07
alternative hypothesis: two.sided


 Hth  --  Gerrit

(BTW, you don't have to specify arguments (in function calls) whose
default values you don't want to change.)




On Fri, 28 Aug 2015, paul brett wrote:

Hi Gerrit,

I spotted that, it was a mistake on my own part, it should
read 1.trap.2.barrier. I have corrected it on the file attached.

So I have done these so far:

fisher.test(Trapz, workspace = 20, hybrid = FALSE, control = list(),

or = 1, alternative = "two.sided", conf.int = TRUE, conf.level =
0.95,simulate.p.value = FALSE, B = 2000)
Error in fisher.test(Trapz, workspace = 2e+05, hybrid = FALSE, control =
list(),  :
 FEXACT error 501.
The hash table key cannot be computed because the largest key
is larger than the largest representable int.
The algorithm cannot proceed.
Reduce the

Re: [R] Fisher's Test 5x4 table

2015-08-28 Thread Gerrit Eichner

Paul,

as the error messages of your first three attempts (see below) tell you - 
in an admittedly rather cryptic way - your table or its sample size, 
respectively, are too large, so that either the "largest (hash table) key" 
is too large, or your (i.e., R's) workspace is too small, or your 
hardware/os cannot allocate enough memory to calculate the p-value of 
Fisher Exact Test exactly by means of the implemented algorithm.


One way out of this is to approximate the exact p-value through 
simulation, but apparently there occurred a typo in your (last) attempt to 
do that (Error: unexpected '>' in ">").



So, for me the following works (and it should also for you) and gives the 
shown output (after a very short while):



Trapz <- as.matrix( read.table( "w.txt", head = T, row.names = "Traps"))



set.seed( 20150828)   # For the sake of reproducibility.
fisher.test( Trapz, simulate.p.value = TRUE,

+ B = 1e5)

   Fisher's Exact Test for Count Data with simulated p-value (based on
   1e+05 replicates)

data:  Trapz
p-value = 1e-05
alternative hypothesis: two.sided



Or for a higher value for B if you are patient enough (with a computing 
time of several seconds) :



set.seed( 20150828)
fisher.test( Trapz, simulate.p.value=TRUE, B = 1e7)


   Fisher's Exact Test for Count Data with simulated p-value (based on
   1e+07 replicates)

data:  Trapz
p-value = 1e-07
alternative hypothesis: two.sided


 Hth  --  Gerrit

(BTW, you don't have to specify arguments (in function calls) whose 
default values you don't want to change.)




On Fri, 28 Aug 2015, paul brett wrote:


Hi Gerrit,
I spotted that, it was a mistake on my own part, it should
read 1.trap.2.barrier. I have corrected it on the file attached.

So I have done these so far:
> fisher.test(Trapz, workspace = 20, hybrid = FALSE, control = list(),
or = 1, alternative = "two.sided", conf.int = TRUE, conf.level =
0.95,simulate.p.value = FALSE, B = 2000)
Error in fisher.test(Trapz, workspace = 2e+05, hybrid = FALSE, control =
list(),  :
 FEXACT error 501.
The hash table key cannot be computed because the largest key
is larger than the largest representable int.
The algorithm cannot proceed.
Reduce the workspace size or use another algorithm.


fisher.test(Trapz, workspace = 2000, hybrid = FALSE, control = list(), or

= 1, alternative = "two.sided", conf.int = TRUE, conf.level =
0.95,simulate.p.value = FALSE, B = 2000)
Error in fisher.test(Trapz, workspace = 2000, hybrid = FALSE, control =
list(),  :
 FEXACT error 40.
Out of workspace.

fisher.test(Trapz, workspace = 1e8, hybrid = FALSE, control = list(), or

= 1, alternative = "two.sided", conf.int = TRUE, conf.level =
0.95,simulate.p.value = FALSE, B = 2000)
Error in fisher.test(Trapz, workspace = 1e+08, hybrid = FALSE, control =
list(),  :
 FEXACT error 501.
The hash table key cannot be computed because the largest key
is larger than the largest representable int.
The algorithm cannot proceed.
Reduce the workspace size or use another algorithm.

fisher.test(Trapz, workspace = 20, hybrid = FALSE, control =

list(), or = 1, alternative = "two.sided", conf.int = TRUE, conf.level =
0.95,simulate.p.value = FALSE, B = 2000)
Error: cannot allocate vector of size 7.5 Gb
In addition: Warning messages:
1: In fisher.test(Trapz, workspace = 2e+09, hybrid = FALSE, control =
list(),  :
 Reached total allocation of 6027Mb: see help(memory.size)
2: In fisher.test(Trapz, workspace = 2e+09, hybrid = FALSE, control =
list(),  :
 Reached total allocation of 6027Mb: see help(memory.size)
3: In fisher.test(Trapz, workspace = 2e+09, hybrid = FALSE, control =
list(),  :
 Reached total allocation of 6027Mb: see help(memory.size)
4: In fisher.test(Trapz, workspace = 2e+09, hybrid = FALSE, control =
list(),  :
 Reached total allocation of 6027Mb: see help(memory.size)

fisher.test(Trapz, workspace = 1e8, hybrid = FALSE, control = list(), or =
1, alternative = "two.sided", conf.int = TRUE, conf.level =
0.95,simulate.p.value = TRUE, B = 1e5)
Error: unexpected '>' in ">"

So the issue could be perhaps that R cannot compute my sample as the
workspace needed is too big? Is there a way around this? I think I have
everything set out correctly.
Is my only other alternative is to do a 2x2 fisher test for each of the
variables?

I attach on the pdf the Minitab result for the Chi squared test as proof (I
know that getting very low p values are highly unlikely but sometimes it
happens). Seeing is believing i suppose!

Regards,
Paul



On Fri, Aug 28, 2015 at 8:56 AM, Gerrit Eichner <
gerrit.eich...@math.uni-giessen.de> wrote:


Dear Paul,

quoting the email-footer: "PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html and provide commented,
minimal, self-contained, reproducible code."

So, what 

Re: [R] Fisher's Test 5x4 table

2015-08-28 Thread Gerrit Eichner

Dear Paul,

quoting the email-footer: "PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html and provide commented, 
minimal, self-contained, reproducible code."


So, what exactly did you try and what was the actual problem/error 
message?


Besides that, have you noted that two of you data rows have the same name?


Have you read the online help page of fisher.test():

 ?fisher.test


Have you tried anything like the following?

W <- as.matrix( read.table( "w.txt", head = T)[-1])

fisher.test( W, workspace = 1e8)
   # For workspace look at the help page, but it presumably
   # won't work because of your sample size.


set.seed( 20150828) # for reproducibility
fisher.test( W, simulate.p.value = TRUE, B = 1e5)
   # For B look at the help page.


Finally: Did Minitab really report "p > 0.001"? ;-)

 Hth  --  Gerrit


Dear all,
   I am trying to do a fishers test on a 5x4 table on R
statistics. I have already done a chi squared test using Minitab on this
data set, getting a result of (1, N = 165.953, DF 12, p>0.001), yet using
these results (even though they are excellent) may not be suitable for
publication. I have tried numerous other statistical packages in the hope
of doing this test, yet each one has just the 2x2 table.
   I am struggling to edit the template fishers test on R to fit
my table (as according to the R book it is possible, yet i cannot get it to
work). The template given on the R documentation and R book is for a 2x2
fisher test. What do i need to change to get this to work? I have attached
the data with the email so one can see what i am on about. Or do i have to
write my own new code to compute this.

Yours Sincerely,
Paul Brett



__
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] replacing then summing by values from another dataframe

2015-08-11 Thread Gerrit Eichner

Hello, Xianming,

I have changed your (particular) data structure: use matrices because you 
have only numeric scores and effects, use NA instead of -1 as missing 
value (as usual), don't use columns for ids or row/column names (except 
for the easy of reading the data structures), increase your score values 
in dat1 by 1 to obtain valid column indices for dat2. Finally, loop (!) 
rowwise through your matrix dat1 and construct an index-matrix (!) to 
index dat2 (and sum up the indexed elements). Hope this does what you 
want. (See below.)


The same remark regarding elegancy/efficiency applies as in Petr's 
solution (but w/o an additional package ;-)).



dat1 <- cbind( c(2, 2, 1, NA, 0),
   c(1, 0, 1, NA, 1),
   c(0, 1, 1, NA, 0))
# dimnames( dat1) <- list( paste0( 'C', 1:5), paste0( "m", 1:3))

dat2 <- cbind( c(-19.5482, -.512, -.492),
   c(.007, 3.241, -2.256),
   c(1.223, -4.490, 1.779))
# rownames( dat2) <- paste0 ('m', 1:3)

apply( dat1 + 1, 1,
   function( idx, d2)
sum( d2[ cbind( seq( nrow( d2)), idx)]),
   d2 = dat2
  )


 Hth  --  Gerrit



On Tue, 11 Aug 2015, Xianming Wei wrote:


[I might have sent  the following request to a wrong email address - 
'r-help-requ...@r-project.org']

Hi,



I have two data frame dat1 and dat2.



dat1 <- data.frame(pid = paste('C', 1:5, sep = ''),

   m1 = c(2, 2, 1, -1, 0),

m2 = c(1, 0, 1, -1, 1),

m3 = c(0, 1, 1, -1, 0))

dat2 <- data.frame(mid = paste('m', 1:3, sep = ''),

   '0' = c(-19.5482, -.512, -.492),

'1' = c(.007, 3.241, -2.256),

'2' =c(1.223, -4.490, 1.779)) names(dat2)[-1] 
<- c('0', '1', '2')



dat1 contains individuals with scores of three measurements (-1 represents 
missing) and dat2 with the effect of the different levels of the three 
measurements. What I'd like to do is to summise the effects of three 
measurements based on the level effects. So C1 I want to get the values of dat2 
for m1 at level 2 = 1.223, m2 at level 1 = 3.241 and m3 at level 0 = -0.4920 
and sum them up as 3.972.



I can only think of a loop to do that at the moment. Because of much higher 
dimensions of actual two datasets, I need help to come up with an efficient / 
elegant approach.



Any help is much appreciated.





Regards,
Xianming


 Internet e-Mail Disclaimer 

PRIVILEGED - PRIVATE AND CONFIDENTIAL: This email and any files transmitted 
with it are intended solely for the use of the addressee(s) and may contain 
information, which is confidential or privileged. If you are not the intended 
recipient, be aware that any disclosure, copying, distribution, or use of the 
contents of this information is prohibited. In such case, you should destroy 
this message and kindly notify the sender by reply e-mail. The views and 
opinions expressed in this e-mail are those of the sender and do not 
necessarily reflect the views of the company.

VIRUSES:  Email transmission cannot be guaranteed to be secure or error free, 
as information may be intercepted, corrupted, lost, destroyed, arrive late or 
incomplete or contain viruses. This email and any files attached to it have 
been checked with virus detection software before transmission. You should 
nonetheless carry out your own virus check before opening any attachment. Sugar 
Research Australia Limited does not represent or warrant that files attached to 
this email are free from computer viruses or other defects and accepts no 
liability for any loss or damage that may be caused by software viruses

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


__
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] Recursive looping of a list in R

2015-08-09 Thread Gerrit Eichner

Hi Evans,

not many people (incl. me) are going to guess the building law for your 
recursive structure from the -- in fact at first sight not so clear -- 
picture, but I have some comments inline below.


 Hth  --  Gerrit

I am trying to creat a list from a loop such that once you loop the 
value obtained is appended onto the list, then you loop through that 
value to give the next elemet of the list and the system continues 
recusively. To be clear I am creating a list to contain elements of the 
following tree probabilities; 
 .
The elements of the diagram should be presented in a list such that each 
level of the tree represents elements in the list (only the coefficients 
are of interest). I have this code to start with



If you use a while-loop without a termination criterion and, e.g., a call 
to break, in its body it would run forever (if the code in its body were 
correct). Start coding with a (finite) for-loop. (Or even better start 
setting j and i "by hand" and let your code be evaluated step by step.)



j <- 0

while(j >= 0){

 j <- j+1



Here you create in each loop the same starting list (which I guess is not 
what you want/should):



 occlist <- list(1)



So, as a consequence an error occurs for j >= 2 in the following for-loop, 
because occlist has always only 1 component:



 for(i in occlist[[j]]){

   occ_cell <- seq(i, i+1, by = 1)



The following two lines of code compensate each other, so seem to be 
superfluous:



   occllist <- list(occ_cell)

   occunlist <- as.vector(unlist(occllist, recursive = TRUE))





   occlist[[j]] <- occunlist

   print(occlist)

 }
}

Any assistance will be highly appreciated. Thanks.



--
View this message in context: 
http://r.789695.n4.nabble.com/Recursive-looping-of-a-list-in-R-tp4710898.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.


__
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] numeric of length 1

2015-06-23 Thread Gerrit Eichner

Hi, Ragia,

use


names( pr_sub$vector[ 1])


 Regards  --  Gerrit


On Tue, 23 Jun 2015, Ragia Ibrahim wrote:


Dear group,
I have the following object


pr_sub$vector[1]

   14
0.07782809


class( pr_sub$vector[1])

[1] "numeric"

> length( pr_sub$vector[1])
[1] 1
how can I separate  pr_sub$vector[1]

and get 14 only

thanks in advance
Ragia

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


__
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] [FORGED] Re: Dunnett Test in 'multicomp' package

2015-06-05 Thread Gerrit Eichner

Hello, everyone,

aside from Rolf's hint (and Richard's warning!) you could also consider 
relevel():


viagraData$dose <- relevel( viagraData$dose, ref = "placebo")

 Hth  --  Gerrit

On Fri, 5 Jun 2015, Rolf Turner wrote:


On 05/06/15 11:08, Jim Lemon wrote:

Hi James,
You can change the order of levels like this:

levels(viagraData$dose)<-c("placebo","low dose","high dose")




As Richard Heiberger has pointed out, this is wrong.

What *does* work is:

viagraData$dose)<-factor(viagraData$dose,
   levels=c("placebo","low dose","high dose")

This is a trap into which many a Young Player (including my very good self) 
has fallen.


cheers,

Rolf Turner



--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

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


__
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] generate a list as follows: 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, . . . . ., n, n, n, n

2015-04-20 Thread Gerrit Eichner

Hi, John,

doesn't

n <- 
lapply( 1:n, rep, each = 4)

do what you need?

 Hth  --  Gerrit


On Sat, 18 Apr 2015, John Sorkin wrote:


Windows 7 64-bit
R 3.1.3
RStudio 0.98.1103



I am trying to generate a list of  length 4n which consists of the integers 1 
to n repeated in groups of four, i.e.


1,1,1,1,  2,2,2,2,  3,3,3,3, . . . . , n,n,n,n


(The spaces in the list are added only for clarity.)


I can generate the list as follows, but the code must be modified for any value 
n, and the code is UGLY!


c(rep(1,4), rep(2,4), rep(3,4), . . . ,c(n,4))


Can anyone help me?


Thank you,
John

John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric 
Medicine
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)


Confidentiality Statement:
This email message, including any attachments, is for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
Any unauthorized use, disclosure or distribution is prohibited. If you are not 
the intended recipient, please contact the sender by reply email and destroy 
all copies of the original message.
__
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.


__
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] check a list that a sublist exists

2015-03-03 Thread Gerrit Eichner

Hello, Alaios,

try

is.null( Mylist[[i]]$parameters)

It returns TRUE if your list doesn't have a component named "parameters" 
or if that component contains NULL.


 HtH  --  Gerrit


On Tue, 3 Mar 2015, Alaios via R-help wrote:


Hi all,I have a list that has the following fields.
$`80`
[1] "Error in if (fitcass1[[2]] == \"Error\") { : \n  Fehlender Wert, wo TRUE/FALSE 
nötig ist\n"
attr(,"class")
[1] "try-error"
attr(,"condition")



$`81`
[1] 0

$`9`
[1] 0

$`79`
$parameters
    pi   mu    sigma
1 0.9996796725 1.654832 127.6542
2 0.0003203275 17183.001125 302.8063

$se
 pi.se  mu.se sigma.se
1 2.113882e-05  0.1439152 14.22274
2 2.113882e-05 38.3582148  NaN

$distribution
[1] "gamma"



and so one. The content of each first level sublist are never the same. I want 
for each first-level sublist my list has to check fast that the current element 
, lets say the 79th has the $parameters.then I would keep only the numbers from 
the sublists that have this $parameters inside them and skip all the rest.
I tried something like exists(Mylist[[i]]$parameters) but it does not workI 
also tried the is.numeric(Mylist[[i]]$parameters)) but this line fails when the 
current sublist does not contain the $parameters field.
Can you please help me sort this out?
RegardsAlex


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

__
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] from expand.grid to a list (lapply)

2015-02-25 Thread Gerrit Eichner

Hie Alaiso,

try to simply apply lapply() to your data frame. It should work w/o any 
further operation since data frames are lists (check with is.list()).


 Hth  --  Gerrit

On Wed, 25 Feb 2015, Alaios via R-help wrote:

Hi all,I would like to use an expand.grid functionality that would give 
me at the end a listso far my code looks like:

 sigma_max_On_seq<-seq(0.05,100,length.out=1)
mean_max_On_seq<-seq(2,1),length.out=1)
expandMeanSigmaOn<-expand.grid(mean_max_On_seq,mean_max_On_seq,sigma_max_On_seq,sigma_max_On_seq)
that gives me at the end all the possible combinations as a data 
frame.

Browse[1]> str((expandMeanSigmaOn))
'data.frame':   XXX obs. of  4 variables:
 $ Var1: num  1 11432 22864 34295 45727 ...
 $ Var2: num  1 1 1 1 1 1 1 1 1 1 ...
 $ Var3: num  0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 ...
 $ Var4: num  0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 0.05 ...
 - attr(*, "out.attrs")=List of 2
  ..$ dim : int  10 10 10 10
  ..$ dimnames:List of 4
  .. ..$ Var1: chr  "Var1= 1.00" "Var1= 11432.44" "Var1= 22863.89" "Var1= 
34295.33" ...
  .. ..$ Var2: chr  "Var2= 1.00" "Var2= 11432.44" "Var2= 22863.89" "Var2= 
34295.33" ...
  .. ..$ Var3: chr  "Var3=  0.05000" "Var3= 31.48065" "Var3= 62.91131" "Var3= 
94.34196" ...
  .. ..$ Var4: chr  "Var4=  0.05000" "Var4= 31.48065" "Var4= 62.91131" "Var4= 
94.34196" ...

 but I want to have a list that I would be able to use it as input into 
a lapply function. The lapply should use then each list entry 
independently giving as input variables only the current 
$Var1,$Var2,$Var3,$Var4


How I can convert in R the data.frame into a list?
I would like to thank you in advance for your replyRegardsAlex

__
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] i need help for var.test()

2015-01-08 Thread Gerrit Eichner

Hello, Sait,

take, for example, a look at bartlett.test(), but keep in mind that 
Bartlett's test is quite sensitive to deviations from normality. Levene's 
test (e.g., in leveneTest() in package car) is said to be more robust.


 Hth  --  Gerrit

On Thu, 8 Jan 2015, sait k wrote:


Dear Sir or Madam,
i want to use the var.test() (f.test()) for n samples.
But in R the var.test() can only used for variances of two samples. In the 
intruductions stands:  Performs an F test to compare the variances of two 
samples from normal populations.
I need a variance test for n samples. It will be great, if you tell me the 
which test i can use in R for this problem.
Thank you for the help.
Yours sincerely,
Sait Polat
[[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.


__
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] factor levels > numeric values

2014-11-12 Thread Gerrit Eichner

Hello, David,

take a look at the beginning of the "Warning" section of ?factor.

 Hth  --  Gerrit


Hi everybody,

I have another question (to which I could not find an answer in my r-books.
I am sure, it's not a great issue, but I simply lack of a good idea how to
solve this:

One of my variables gets imported as a factor instead of a numeric variable.
Now I have a...
Factor w/ 63 levels "0","0.02","0.03",..: 1 NA NA 1 NA NA 1 1 53 10 ...

How can I transform these factor levels into actual values?

Thank you very much for any help!
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.


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


Re: [R] qq-plot in R

2014-11-11 Thread Gerrit Eichner

Hello, ron,

have you looked at the help page of qqplot and consequently tried, e.g., 
the following?


xy <- qqplot( rt(300, df = 5), rt(300, df = 5),
  xlim = c(-10, 10), ylim = c(0, 10))
str( xy)



Hth  --  Gerrit


On Tue, 11 Nov 2014, Ron Michael wrote:


Hi,

I am some questions on qq-plot offered by R. Let say I have following qq-plot:

 qqplot(rt(300, df = 5), rt(300, df = 5))
However I want to get more controls to define the range of x-axis as well as 
y-axis. For example I want to define that, x-axis range will be -10 to 10 and 
y-axis range will be 0-10 (just an example on what I am looking for). 
Additionally I want to get the entire list of (x,y) coordinates for all plotted 
points.
Basically one my goals is to draw multiple different qq-plots onto same 
plot-window, with my optimally chosen range of x & y axes.
Can somebody here guide me how to achieve that?
Appreciate your pointers and 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.__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] [survMisc]: error message in examples of comp()

2014-10-17 Thread Gerrit Eichner

Hello, list members,

I have tried to contact the maintainer of the survMisc package, but my 
message could not be delivered. I can't get survMisc package to work as 
expected or documented, respectively. Maybe one of you has an idea 
regarding the following problem:


When, e.g., trying to executed the first few lines of code in the examples 
section of comp() (one of the package functions), i.e.,



data(kidney,package="KMsurv")
s1 <- survfit(Surv(time=time, event=delta) ~ type, data=kidney)
comp(s1)



I receive the following error message:

Error in parse(text = t2) : :1:8: unexpected input
1: paste( ``
^


Could this be an encoding-related issue inside the code? Does somebody 
have an idea where to look for a solution for this problem?


Below you'll find my survMisc version and R session info. Thanks for any 
support!


 Kind regards  --  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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-



citation( "survMisc")


To cite package .survMisc. in publications use:

  Chris Dardis (2014). survMisc: Miscellaneous functions for survival
  data.. R package version 0.4.2.
  http://CRAN.R-project.org/package=survMisc



sessionInfo()

R version 3.1.1 (2014-07-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] survMisc_0.4.2   rpart_4.1-8  data.table_1.9.2 ggplot2_1.0.0
[5] survival_2.37-7  fortunes_1.5-2

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4 digest_0.6.4 gam_1.09.1   grid_3.1.1
 [5] gtable_0.1.2 km.ci_0.5-2  KMsurv_0.1-5 MASS_7.3-33
 [9] munsell_0.4.2plyr_1.8.1   proto_0.3-10 Rcpp_0.11.2
[13] reshape2_1.4 scales_0.2.4 stringr_0.6.2tools_3.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.


Re: [R] Compare data in two rows and replace objects in data frame

2014-08-04 Thread Gerrit Eichner

Hello, Raz,

if X is the data frame that contains your data, then using sort of an 
"indexing trick" to circumvent your numerous if-statements as in


aggregate( X[ c( "genotype 2001", "genotype 2002", "genotype 2003")],
   X[ "CloneID"],
   FUN = function( x)
  c( "11" = "HT",
 "10" = "A",
 "01" = "B",
 "1-" = "Aht",
 "-1" = "Bht")[ paste( x, collapse = "")])

presumably does what you want (and can certainly be improved).

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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-

On Mon, 4 Aug 2014, raz wrote:


Dear all,

I have a data frame 144 x 2 values.
I need to take every value in the first row and compare to the second row,
and the same for rows 3-4 and 5-6 and so on.
the output should be one line for each of the two row comparison.
the comparison is:
if row1==1 and row2==1 <-'HT'
if row1==1 and row2==0 <-'A'
if row1==0 and row2==1 <-'B'
if row1==1 and row2=='-' <-'Aht'
if row1=='-' and row2==1 <-'Bht'

for example:
if the data is:
CloneIDgenotype 2001genotype 2002genotype 2003
2471250111
2471250000
2433062000
2433062111
100021605110
100021605101
15599110
15599111
12798110
12798111

then the output should be:
CloneIDgenotype 2001genotype 2002genotype 2003
2471250AAA
2433062BBB
100021605HTAB
15599HTHTB
12798HTHTB

I tried this for the whole data, but its so slow:

AX <- data.frame(lapply(AX, as.character), stringsAsFactors=FALSE)


for (i in seq(1,nrow(AX),by=2)){
for (j in 6:144){
if (AX[i,j]==1 & AX[i+1,j]==0){
AX[i,j]<-'A'
}
if (AX[i,j]==0 & AX[i+1,j]==1){
AX[i,j]<-'B'
}
if (AX[i,j]==1 & AX[i+1,j]==1){
AX[i,j]<-'HT'
}
if (AX[i,j]==1 & AX[i+1,j]=="-"){
AX[i,j]<-'Aht'
}
if (AX[i,j]=="-" & AX[i+1,j]==1){
AX[i,j]<-'Bht'
}
}
}

AX1<-AX[!duplicated(AX[,3]),]
AX2<-AX[duplicated(AX[,3]),]

Thanks for any help,

Raz



--
\m/

[[alternative HTML version deleted]]

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


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


Re: [R] Filling in missing values in a column based on previousandfollowingvalues

2014-08-04 Thread Gerrit Eichner

On Mon, 4 Aug 2014, Florian Denzinger wrote:


this is great, thanks!

one problem I noticed though is that it fills all NA values in every 
column, is it possible to specify only one column, e.g. only ID (I have 
NA values in another column I want to keep)


Yes, of course. Just access only one column, not all: Something like

yourdataframe$ID <- na.locf( yourdataframe$ID)

should replace the ID-column with the modified version you want.

Regards  --  Gerrit



Kind regards,
Florian



Am 04.08.2014 um 11:31 schrieb Gerrit Eichner 
:


Hello, Florian,

function na.locf() from package zoo mightdo what you want.

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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-

On Mon, 4 Aug 2014, fd wrote:


I have the following .csv file containing about 4 values (here only an
extract and simplified version):

NAME  ; YEAR; ID;   VALUE; CUMMB
Sample1;1998;354;   45;45
Sample1;1999;354;   23;68
Sample1;2000;NA;66;134
Sample1;2001;NA;98;232
Sample1;2002;NA;36;268
Sample1;2003;NA;59;327
Sample1;2004;NA;64;391
Sample1;2005;354;   23;414
Sample1;2006;354;   69;483
Sample1;2007;354;   94;577
Sample1;2008;354;   24;601
Sample2;1964;   1342;   7;7
Sample2;1965;   1342;   24;  31
Sample3;2002;859;   90;  90
Sample3;2003; NA;   93; 183
Sample3;2004; NA;   53; 236
Sample3;2005;859;   98; 334

What I would like to do is to replace the NA values in ID with the values
from the ID. E.g. all values in ID from Sample 1 should have the value 354;
all values in ID from Sample 3 should have the value 859 etc.

Is there a simple way to do this?

Thanks for your help.



--
View this message in context: 
http://r.789695.n4.nabble.com/Filling-in-missing-values-in-a-column-based-on-previous-and-following-values-tp4694993.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] Filling in missing values in a column based on previousandfollowing values

2014-08-04 Thread Gerrit Eichner

Hello, Florian,

function na.locf() from package zoo mightdo what you want.

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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner
-

On Mon, 4 Aug 2014, fd wrote:


I have the following .csv file containing about 4 values (here only an
extract and simplified version):

NAME  ; YEAR; ID;   VALUE; CUMMB
Sample1;1998;354;   45;45
Sample1;1999;354;   23;68
Sample1;2000;NA;66;134
Sample1;2001;NA;98;232
Sample1;2002;NA;36;268
Sample1;2003;NA;59;327
Sample1;2004;NA;64;391
Sample1;2005;354;   23;414
Sample1;2006;354;   69;483
Sample1;2007;354;   94;577
Sample1;2008;354;   24;601
Sample2;1964;   1342;   7;7
Sample2;1965;   1342;   24;  31
Sample3;2002;859;   90;  90
Sample3;2003; NA;   93; 183
Sample3;2004; NA;   53; 236
Sample3;2005;859;   98; 334

What I would like to do is to replace the NA values in ID with the values
from the ID. E.g. all values in ID from Sample 1 should have the value 354;
all values in ID from Sample 3 should have the value 859 etc.

Is there a simple way to do this?

Thanks for your help.



--
View this message in context: 
http://r.789695.n4.nabble.com/Filling-in-missing-values-in-a-column-based-on-previous-and-following-values-tp4694993.html
Sent from the R help mailing list archive at Nabble.com.

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] format of output of residual standard errors of manova()

2014-03-18 Thread Gerrit Eichner

Dear all,

I wasn't successful in finding any related "bug" or "wish" report on 
bugs.r-project.org, svn.R-project.org/R/trunk/doc/NEWS.Rd, or RSeek 
regarding the following:


The code of stats:::print.aov contains the two commands

cat("Residual standard error: ", sapply(sqrt(ss/rdf), format), "\n", sep = 
"")


and

cat("Residual standard error: ", sapply(rs, format), "\n", sep = "")

which provide the output of the RSEs. However, the RSE-values are glued 
together because of sep = "" in the call to cat(), which makes them hard 
or even impossible to read off free of doubt. (See the respective output 
of npk.aov2 in example( manova) or of fit in example( summary.manova).)


Is it intended to change those lines of code into something like

cat("Residual standard error: ", paste( sapply(sqrt(ss/rdf), format), 
collapse = "; "), "\n", sep = "")


and

cat("Residual standard error: ", paste( sapply(rs, format), collapse = "; 
"), "\n", sep = "")


respectively? (Of course, any other sep-value would be "accepted". :))

If not, I would suggest this modification as a "wish" (and was wondering 
if my next step should indeed be submitting a wish report on 
bugs.r-project.org ...)



 Best regards  --  Gerrit

PS:


sessionInfo()

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] fortunes_1.5-2

loaded via a namespace (and not attached):
[1] tools_3.0.2


-
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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

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


Re: [R] Sweave: cat() in a chunk with option results=texdoesn'tproducelinebreaksatthe end of a character string anymore

2014-03-05 Thread Gerrit Eichner

Thanks, Duncan,

I got it! I missread/-understood strip.white's meaning and thought it 
would refer only to blank lines within "real" code chunks (i.e., to those 
between \begin{Schunk} and \end{Schunk}), but not to the (TeX-)output 
which was generated by code chunks with results=tex.


My goal: I don't want blank lines at the beginning or end of "real" R 
output between \begin{Schunk} and \end{Schunk}), but want to be able to 
create linebreaks using cat( "\n") explicitly in chunks with results=tex


The solution appears to be: use strip.white=false "locally" in case of 
need, i.e., as the option for the respective code chunks (which also have 
results=tex, and from which I want "only" linebreaks in the TeX-output).


Actually, embarrassingly simple.

 Thanks again -- Gerrit


On Wed, 5 Mar 2014, Duncan Murdoch wrote:


On 05/03/2014 9:29 AM, Gerrit Eichner wrote:

Thanks, Duncan,

but, sorry, including

\SweaveOpts{strip.white=true}

doesn't help. Have tried that before and forgot to mention; sorry!


true is the default.  You want false.

Duncan Murdoch



BTW: using \SweaveOpts{strip.white="true"}, i.e., with quotation marks as
requested in RweaveLatex()'s help file, throws out

Error in match.arg(options$strip.white, c("true", "false", "all")) :
'arg' should be one of "true", "false", "all"

which used to happen before (on my system) so that I used to use it w/o
quotes successfully. (!?)


Still big question marks ... Any further ideas?

   Regards -- Gerrit


On Wed, 5 Mar 2014, Duncan Murdoch wrote:

> On 05/03/2014 7:32 AM, Gerrit Eichner wrote:
>> Hello, everyone,
>>
>> I am struggling with an Sweave-problem that didn't occur sofar (and I 
have
>> no clue what I might have changed in my system; see below). The 
following

>> example *.Rnw file's only task is (for simplicity) to output text with a
>> little bit of TeX-code with linebreaks (e. g., to be better readable):
>>
>>
>> \documentclass{article}
>> \begin{document}
>> Text 1 (not through cat()) followed by a double-backslash and
>> a blank line, i.e., a linebreak.\\
>>
>> <>=
>> cat( "Text 2 (through cat()) with a respected newline here\n",
>>"and likewise two tabs here\t\t followed by two 
double-backslashes

>> ",
>>"and IGNORED newline escape characters at the end. \n \n",
>>sep = "")
>>
>> cat( "Text 3 (through cat()) just to finish this example and ",
>>"with also IGNORED newline escapes at its end. \n \n", sep = "")
>> @
>> \end{document}
>>
>>
>>
>> When processed by Sweave I obtain the following TeX file:
>>
>>
>> \documentclass{article}
>> \usepackage{Sweave}
>> \begin{document}
>> Text 1 (not through cat()) followed by a double-backslash and
>> a blank line, i.e., a linebreak.\\
>>
>> Text 2 (through cat()) with a respected newline here
>> and likewise two tabs here  followed by two
>> double-backslashes and IGNORED newline escape characters at the end.\\
>> Text 3 (through cat()) to finish this example and with also IGNORED
>> newline escapes at its end. \end{document}
>>
>>
>> the point being that the linebreaks (\n) at the ends of the output
>> character strings have been completely ignored.
>
> See the "strip.white" option in ?RweaveLatex.
>
> Duncan Murdoch
>
>>
>> I wasn't successful in searching the archive, RSeek, SE and the like. 
Any

>> idea where and how to continue to search, or what to do to get back
>> Sweave's "old" behavior (except for reinstalling R ... which of course 
is

>> still an option)? Thanks for any hint!
>>
>>Best regards  --  Gerrit
>>
>> PS:
>> > sessionInfo()
>> R version 3.0.2 (2013-09-25)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>>
>> locale:
>> [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
>> [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
>> [5] LC_TIME=German_Germany.1252
>>
>> attached base packages:
>> [1] graphics  grDevices utils datasets  stats methods   base
>>
>> other attached packages:
>> [1] fortunes_1.5-2
>>
>> loaded via a namespace (and not attached):
>> [1] grid_3.0.2  lattice_0.20-27 tools_3.0.2
>>
>>
>>
>> -
>> Dr. Gerrit Eichner   Mathematical Institute, Room 212
>>

Re: [R] Sweave: cat() in a chunk with option results=texdoesn'tproducelinebreaks at the end of a character string anymore

2014-03-05 Thread Gerrit Eichner

Thanks, Duncan,

but, sorry, including

\SweaveOpts{strip.white=true}

doesn't help. Have tried that before and forgot to mention; sorry!

BTW: using \SweaveOpts{strip.white="true"}, i.e., with quotation marks as 
requested in RweaveLatex()'s help file, throws out


Error in match.arg(options$strip.white, c("true", "false", "all")) :
  'arg' should be one of "true", "false", "all"

which used to happen before (on my system) so that I used to use it w/o 
quotes successfully. (!?)



Still big question marks ... Any further ideas?

 Regards -- Gerrit


On Wed, 5 Mar 2014, Duncan Murdoch wrote:


On 05/03/2014 7:32 AM, Gerrit Eichner wrote:

Hello, everyone,

I am struggling with an Sweave-problem that didn't occur sofar (and I have
no clue what I might have changed in my system; see below). The following
example *.Rnw file's only task is (for simplicity) to output text with a
little bit of TeX-code with linebreaks (e. g., to be better readable):


\documentclass{article}
\begin{document}
Text 1 (not through cat()) followed by a double-backslash and
a blank line, i.e., a linebreak.\\

<>=
cat( "Text 2 (through cat()) with a respected newline here\n",
   "and likewise two tabs here\t\t followed by two double-backslashes 
",

   "and IGNORED newline escape characters at the end. \n \n",
   sep = "")

cat( "Text 3 (through cat()) just to finish this example and ",
   "with also IGNORED newline escapes at its end. \n \n", sep = "")
@
\end{document}



When processed by Sweave I obtain the following TeX file:


\documentclass{article}
\usepackage{Sweave}
\begin{document}
Text 1 (not through cat()) followed by a double-backslash and
a blank line, i.e., a linebreak.\\

Text 2 (through cat()) with a respected newline here
and likewise two tabs here   followed by two
double-backslashes and IGNORED newline escape characters at the end.\\
Text 3 (through cat()) to finish this example and with also IGNORED
newline escapes at its end. \end{document}


the point being that the linebreaks (\n) at the ends of the output
character strings have been completely ignored.


See the "strip.white" option in ?RweaveLatex.

Duncan Murdoch



I wasn't successful in searching the archive, RSeek, SE and the like. Any
idea where and how to continue to search, or what to do to get back
Sweave's "old" behavior (except for reinstalling R ... which of course is
still an option)? Thanks for any hint!

   Best regards  --  Gerrit

PS:
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] fortunes_1.5-2

loaded via a namespace (and not attached):
[1] grid_3.0.2  lattice_0.20-27 tools_3.0.2



-
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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

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

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


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


[R] Sweave: cat() in a chunk with option results=tex doesn't producelinebreaks at the end of a character string anymore

2014-03-05 Thread Gerrit Eichner

Hello, everyone,

I am struggling with an Sweave-problem that didn't occur sofar (and I have 
no clue what I might have changed in my system; see below). The following 
example *.Rnw file's only task is (for simplicity) to output text with a 
little bit of TeX-code with linebreaks (e. g., to be better readable):



\documentclass{article}
\begin{document}
Text 1 (not through cat()) followed by a double-backslash and
a blank line, i.e., a linebreak.\\

<>=
cat( "Text 2 (through cat()) with a respected newline here\n",
 "and likewise two tabs here\t\t followed by two double-backslashes ",
 "and IGNORED newline escape characters at the end. \n \n",
 sep = "")

cat( "Text 3 (through cat()) just to finish this example and ",
 "with also IGNORED newline escapes at its end. \n \n", sep = "")
@
\end{document}



When processed by Sweave I obtain the following TeX file:


\documentclass{article}
\usepackage{Sweave}
\begin{document}
Text 1 (not through cat()) followed by a double-backslash and
a blank line, i.e., a linebreak.\\

Text 2 (through cat()) with a respected newline here
and likewise two tabs here		 followed by two 
double-backslashes and IGNORED newline escape characters at the end.\\ 
Text 3 (through cat()) to finish this example and with also IGNORED 
newline escapes at its end. \end{document}



the point being that the linebreaks (\n) at the ends of the output 
character strings have been completely ignored.


I wasn't successful in searching the archive, RSeek, SE and the like. Any 
idea where and how to continue to search, or what to do to get back 
Sweave's "old" behavior (except for reinstalling R ... which of course is 
still an option)? Thanks for any hint!


 Best regards  --  Gerrit

PS:

sessionInfo()

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] fortunes_1.5-2

loaded via a namespace (and not attached):
[1] grid_3.0.2  lattice_0.20-27 tools_3.0.2



-
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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 an value in dependence of another column

2014-01-17 Thread Gerrit Eichner

Hi, Mat,

e. g., try something like

ORDER$VALUE * c( NY = 3, BER = 2, FRA = 1, WAS = 4)[ ORDER$DESTINY]

 Hth  --  Gerrit

On Fri, 17 Jan 2014, Mat wrote:


Hello together,

i have a little problem, to create a new column, in a data.frame.
I know i can calculate one column with as a example 2 like this:
ORDER$WEIGHT <- ORDER$VALUE * 2

But how can i create the ORDER$WEIGHT with different numbers, like this one.

I have a data.frame like this one:

ORDER   DESTINYVALUE
A NY  100
B BER  10
C FRA 100
D WAS 50

I want now the column ORDER$WEIGHT in dependence of "DESTINY". NY should be
*3, BER *2, FRA*1 and WAS * 4.

The solution look like this one:

ORDER   DESTINYVALUE   WEIGHT
A NY  100  300
B BER  10 20
C FRA 100100
D WAS 50 200

Maybe anyone can help me, how i can do this?

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.


Re: [R] How to verify char variables contain at least one value

2014-01-02 Thread Gerrit Eichner
O-ha, sorry, Luca, I mixed up arguments: it shouldn't be "subset" but 
"select".


apply( subset( d2, select = V13:V239), 1, function( x) any( x != ""))

should work.

"Auf Wiederhören!" ;-)

 Regards  --  Gerrit


On Thu, 2 Jan 2014, Luca Meyer wrote:


Hi Gerrit,

Thank you for the suggestion. Unfortunatedly the line of code you suggest -
i.e.

apply( subset( d2, subset = V13:V239), 1, function( x) any( x != ""))

returns the same error. Any other suggestion?

Danke schôn und auf wiederhoren

Luca





2014/1/2 Gerrit Eichner 


Hello, Luca,

also a happy new year!

It's not quite clear to me what you want to do, but note first that the
":"-operator is a short-cut for seq() with by = 1 (look at ?seq), and that
it usually (!) does not work on columns of data frames. Exception: when
used for the argument subset of function subset().

Second, you seem to want to check in each row of d2 if there is any entry
different from "", right?

So, does

 apply( subset( d2, subset = V13:V239), 1, function( x) any( x != ""))




what you want?

 Hth  --  Gerrit

On Thu, 2 Jan 2014, Luca Meyer wrote:

 Happy new year fellows,


I am trying to do something I believe should be fairly straightforward but
I cannot find my way out.

My dataset d2 is 26 rows by 245 columns, exclusively char variables. I
would like to check whether at least one column from V13 till V239 (they
are in numerical sequence) has been filled in, so I try

d2$check <- c(d2$V13:d2$V239)

and/or

d2$check <- paste(d2$V13:d2$V239,sep="")

but I get (translated from Italian):

Error in d2$V13:d2$V239 : argument NA/NaN

I have tried nchar but the same error occurs. I have also tried to run the
above functions on a smaller variable subset (V13, V14, V15, see below for
details) just to double check in case some variable would erroneously be
in
another format, but the same occur.

 d2$V13



[1] """"""
"""""""da -5.1% a -10%"
""
[9] """"""
""""""""
""
[17] """"""
""""""""
""
[25] """"


d2$V14


[1] "" "" ""
"" "" "" "da -10.1% a
-15%"
""
[9] "" "" ""
"" "" "" ""
""
[17] "" "" ""
"" "" "" ""
""
[25] "" ""


d2$V15


[1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" ""

Can anyone suggest an alternative function for me to create a variable
that
checks whether there is at least one value for each of the 26 records I
need to analyze?

Thank you in advance,

Luca

[[alternative HTML version deleted]]

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


Re: [R] How to verify char variables contain at least one value

2014-01-01 Thread Gerrit Eichner

Hello, Luca,

also a happy new year!

It's not quite clear to me what you want to do, but note first that the 
":"-operator is a short-cut for seq() with by = 1 (look at ?seq), and that 
it usually (!) does not work on columns of data frames. Exception: when 
used for the argument subset of function subset().


Second, you seem to want to check in each row of d2 if there is any entry 
different from "", right?


So, does


apply( subset( d2, subset = V13:V239), 1, function( x) any( x != ""))


what you want?

 Hth  --  Gerrit

On Thu, 2 Jan 2014, Luca Meyer wrote:


Happy new year fellows,

I am trying to do something I believe should be fairly straightforward but
I cannot find my way out.

My dataset d2 is 26 rows by 245 columns, exclusively char variables. I
would like to check whether at least one column from V13 till V239 (they
are in numerical sequence) has been filled in, so I try

d2$check <- c(d2$V13:d2$V239)

and/or

d2$check <- paste(d2$V13:d2$V239,sep="")

but I get (translated from Italian):

Error in d2$V13:d2$V239 : argument NA/NaN

I have tried nchar but the same error occurs. I have also tried to run the
above functions on a smaller variable subset (V13, V14, V15, see below for
details) just to double check in case some variable would erroneously be in
another format, but the same occur.


d2$V13

[1] """"""
"""""""da -5.1% a -10%"
""
[9] """"""
""""""""
""
[17] """"""
""""""""
""
[25] """"

d2$V14

[1] "" "" ""
"" "" "" "da -10.1% a -15%"
""
[9] "" "" ""
"" "" "" ""
""
[17] "" "" ""
"" "" "" ""
""
[25] "" ""

d2$V15

[1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
"" "" ""

Can anyone suggest an alternative function for me to create a variable that
checks whether there is at least one value for each of the 26 records I
need to analyze?

Thank you in advance,

Luca

[[alternative HTML version deleted]]

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


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


Re: [R] filter a data.frame

2013-12-13 Thread Gerrit Eichner

Hello, Mat,

see below.

hello together, i want to filter a data.frame. My problem is, that i 
want to filter 2 numbers.


My data.frame look like this one.

No.   text
1  abc
2  def
3  ee
4  ff
5  gg

I want now to filter No. 2 and 3, so my solution should be look like this
one.

No.   text
2 def
3 ee

i tried it like this one:
out1<-out[(out$No==no.ind),]

in no.ind i have the 2 numbers: c("2","3")

but this doesn't work.


You should not expect a vector (of two elements), here no.ind, equal 
elementwise any of the elements of another (longer) vector, here out$No. 
You probably actually want to check for each element of out$No if it is 
contained in the set of elements in no.ind. So, use, e.g.,



out1 <- out[(out$No %in% no.ind),]


See ?is.element.


 Hth  --  Gerrit

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 write the function into a file c:/mytest.R withcatfunction?

2013-12-13 Thread Gerrit Eichner

Hello, Ë®¾²Á÷Éî!


mytest<-function(x,f){
   sum(x*f)/sum(f)
   }
   cat(mytest,file="c:/mytest.R")
   Error in cat(list(...), file, sep, fill, labels, append) :
   argument 1 (type 'closure') cannot be handled by 'cat'

how can i write the mytest function into a file c:/mytest.R with cat function?


Maybe by replacing cat(), e.g., by the use of sink():

sink( "c:/mytest.R")
mytest
sink()


You may want to look at ?dput and ?dget.


However, I doubt that that produces what you really want because only the 
body of your function mytest() will be stored in the file, but not the 
assignment that created it. Maybe you should store your R-code, i.e., the 
assignment in a text file (e.g., using R's editor) to -- later again -- 
use source() to read that file in and have it executed? See ?source.


 Hth  --  Gerrit__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 vector

2013-12-11 Thread Gerrit Eichner

Hello, Long Vo,

take a look at the help page of split or directly at

str(Y)

They tell you that Y is a list, and list components are indexed using 
"[[":


mean(Y[[4]])

should do what you want.

  Regards  --  Gerrit



This does what I needed. However, as the output is a list object, is there
any way to apply a function to such object? For example if I want to compute
the mean for the 4th subvectors, I can't simply use:
#
Y=split(X,as.numeric(gl(length(X),3,length(X
mean(Y[4])
#
as the error message shows "argument is not numeric or logical"



--
View this message in context: 
http://r.789695.n4.nabble.com/Splitting-a-vector-tp4681930p4681987.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] If-statement in for-loop

2013-12-11 Thread Gerrit Eichner

Hello, "gncl dzgn",

your problem has a flavor of homework which is usually not delt with on 
this list. However, a few comments:


0. The description of your problem is rather vague, in particular, the 
meaning of "input" in the description of your "conditions" is unclear! (By 
the way, your main problem is probably not the inclusion of the 
conditions; see 2.)


Note: "PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html and provide commented, 
minimal, self-contained, reproducible code."

^^^

1. Do not use variable names like t, T, c, s because they already exist as 
R-objects.


2. Have you noticed the warnings "In s >= d : longer object length is not 
a multiple of shorter object length" and "In s + b * (0:T) : longer object 
length is not a multiple of shorter object length"? Apparently the 
involved objects (s, d, b and T) do not "fit together". Hint: Compare the 
lenght of s with the lengths of d and 0:T!


3. Do not run the code all at once, but either without the for-loops line 
by line with j and i set to approriate values (like i = 1 and j = 2), or 
with the for-loops, but with N and T very small, e. g. N = 1 and T = 2 to 
start with. Alternatively, you could also take a look at the function 
browser() (and include it in the bodies of your for-loops).


4. Another hint: Your if-else-statement

  if(x < minx) {
s[i] <- minx
   } else {
if(x > maxx) {
  s[i] <- maxx
 } else s[i] <- x
   }

appears be simplifiable to

  s[i] <- min( max( x, minx), maxx)


 Hth  --  Gerrit



Hi everyone,

you might find my question elementary but I am a beginner and 
unfortunately I can't fix the problem.


So, I simulate this following algorithm and some values of c are NA. 
Therefore, I should add these following two if-statements but I don't 
know how I should do it in a for-loop.


Thank in advance if someone helps me!

The conditions:

If there is no input greater or equal to d, then ALG = b*T
If  max(s +  b*(0:T)) < b*T , then OPT = b*T


The algorithm:

a <- 0.0008
b <- 0.0001
T <- 100
t <- 0:T
alpha <- 1

d<- sqrt(a * b) * T - b * t

N <- 100
c <- rep(0, N)
for (j in 1:N) {

e <- rnorm(T, mean = 0, sd = 0.001)
s<- c( runif(1,0, a*T), rep(0, T-1) )
minx <- 0
for(i in 2:T) {
   x <- alpha * s[i-1] + e[i]
maxx <- a*(T-i)
if(x < minx) {
s[i] <- minx
} else {
if(x > maxx) {
s[i] <- maxx
} else s[i] <- x
}
}

p<- which(s >= d)[1]
ALG<- s[p] + b*(p-1)
OPT <- max(s +  b*(0:T))

c[j] <-  OPT / ALG

}

head(c)
mean(c)
plot(c)



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


Re: [R] lattice: superposed boxplots with same colors forrectanglesandumbrellas and filled boxes

2013-12-10 Thread Gerrit Eichner
Thank you very much, Rich, for the fast and very helpful reply! It helped 
me to reach my goal.


 Regards -- Gerrit

PS: I extended your solution to a version that allows slightly finer 
control over the components of the boxplots, in particular if one wants to 
combine it with, e.g., panel.stripplot() or panel.average(). It was also 
possible to simplify my call of bwplot() a bit. The code is certainly not 
perfect and fully tested, but does work (for me ;-)), and follows as a 
little 'thank you':



panel.bwplot.constantColor <- function( ..., col, fill, cex, pch,
dot.pch, umbrella.lty, box.alpha) {
 ## Date: Mon, 9 Dec 2013 17:52:38 -0500
 ## From: Richard M. Heiberger 
 ## Subject: Re: [R] lattice: superposed boxplots with same colors
 ##  for rectangles and umbrellas and filled boxes

 ## to be included in next version of the HH package
 box.save <- list( box.dot = trellis.par.get( "box.dot"),
   box.rectangle = trellis.par.get( "box.rectangle"),
   box.umbrella = trellis.par.get( "box.umbrella"),
   plot.symbol = trellis.par.get( "plot.symbol"))
 trellis.par.set( box.dot = list( col = col),
  box.rectangle = list( col = col, alpha = box.alpha),
  box.umbrella = list( col = col, lty = umbrella.lty,
   alpha = box.alpha),
  plot.symbol = list( col = col))
 panel.bwplot( ..., fill = col, cex = cex, pch = dot.pch)
 trellis.par.set( box.save)
 }


bwplot( Y ~ F1, groups = F2, data = Data, jitter.data = TRUE,
col = c( "red", "blue"), box.alpha = 1/4,
dot.pch = 17, umbrella.lty = 1, do.out = FALSE,
panel = panel.superpose,
panel.groups = panel.bwplot.constantColor)




Thank you for the opportunity to illustrate this.  I solved this problem 
last week and it will be included in the next version of the HH package 
(about a month away).


panel.bwplot.constantColor <- function(..., col, fill, cex, pch) {
 ## to be included in next version of the HH package
 box.save <- list(box.dot=trellis.par.get("box.dot"),
  box.rectangle=trellis.par.get("box.rectangle"),
  box.umbrella=trellis.par.get("box.umbrella"),
  plot.symbol=trellis.par.get("plot.symbol"))
 trellis.par.set(box.dot=list(col=col),
 box.rectangle=list(col=col),
 box.umbrella=list(col=col),
 plot.symbol=list(col=col))
 panel.bwplot(..., fill=col, cex=cex, pch=pch)
 trellis.par.set(box.save)
}

bwplot( Y ~ F1, groups = F2, data = Data,
   col = mycolors, fill = mycolors, jitter.data = TRUE, pch=19,
   panel = panel.superpose,
   panel.groups = function(..., pch, col, alpha){
   panel.stripplot(...)
   panel.bwplot.constantColor(..., pch=pch, col=col,
alpha=alpha, do.out = FALSE)
   },
   par.settings = list( box.dot = list( alpha = myalpha),
box.rectangle = list( col = mycolors,
  alpha = myalpha),
box.umbrella = list( col = mycolors,
     alpha = myalpha))
   )


Rich

On Mon, Dec 9, 2013 at 5:17 PM, Gerrit Eichner
 wrote:

Dear R-list,

I've been trying to produce a sort of an interaction plot wherein colored
stripplots and boxplots are superposed. In particular, I want the colors of
the (transparently) filled boxes to be the same as the colors of the box
borders (rectangle) and their whiskers (umbrella). Below I'm going to create
an artificial data set and provide the code with which I've come up so far,
and which is a fusion and adaptation of a few pieces of code I've found in
the help pages and the mail archives. It does almost what I want, but still
colors the rectangles and the umbrellas in black (of course, because it is
the setting in the example presented below). However, the latter is what I
want to change.

x <- c( rep( 1:4, each = 10), rep( -2, 40))
Data <- data.frame( F1 = gl( 4, 10, length = 80, labels = LETTERS[ 1:4]),
F2 = gl( 2, 40), Y = x + rnorm( length( x)))

mycolors <- c( "red", "blue")
myalpha <- 0.33
bwplot( Y ~ F1, groups = F2, data = Data,
col = mycolors, fill = mycolors, jitter.data = TRUE,
panel = panel.superpose,
panel.groups = function(..., pch, col, alpha){
panel.stripplot(...)
panel.bwplot(..., do.out = FALSE)
},
par.settings = list( box.dot = list( alpha = myalpha),
 box.rectangle = list( col = "black",
   alpha = myalpha),
 box.umbrella = list( col = "black&qu

[R] lattice: superposed boxplots with same colors for rectanglesand umbrellas and filled boxes

2013-12-09 Thread Gerrit Eichner

Dear R-list,

I've been trying to produce a sort of an interaction plot wherein colored 
stripplots and boxplots are superposed. In particular, I want the colors 
of the (transparently) filled boxes to be the same as the colors of the 
box borders (rectangle) and their whiskers (umbrella). Below I'm going to 
create an artificial data set and provide the code with which I've come up 
so far, and which is a fusion and adaptation of a few pieces of code I've 
found in the help pages and the mail archives. It does almost what I want, 
but still colors the rectangles and the umbrellas in black (of course, 
because it is the setting in the example presented below). However, the 
latter is what I want to change.


x <- c( rep( 1:4, each = 10), rep( -2, 40))
Data <- data.frame( F1 = gl( 4, 10, length = 80, labels = LETTERS[ 1:4]),
F2 = gl( 2, 40), Y = x + rnorm( length( x)))

mycolors <- c( "red", "blue")
myalpha <- 0.33
bwplot( Y ~ F1, groups = F2, data = Data,
col = mycolors, fill = mycolors, jitter.data = TRUE,
panel = panel.superpose,
panel.groups = function(..., pch, col, alpha){
panel.stripplot(...)
panel.bwplot(..., do.out = FALSE)
},
par.settings = list( box.dot = list( alpha = myalpha),
 box.rectangle = list( col = "black",
   alpha = myalpha),
 box.umbrella = list( col = "black",
  alpha = myalpha))
)


If I'd provide mycolors instead of "black" to the col-component of the 
(sub-)lists given to par.settings, the coloring of the respective 
components of the boxplots would not be what I want. Having studied the 
code of panel.superpose() and panel.bwplot() it appears to me that 
panel.bwplot() cannot access the settings created by panel.supperpose when 
it comes to drawing the rectangle and umbrella of a boxplot. It only 
accesses box.[dot, rectangle, umbrella], which does not give what I need.


I may have overlooked the obvious and would be quite grateful if somebody 
could give me a hint where to look further. Or is a workaround necessary 
(and available)?


Thanks a lot in advance!

 Best Regards  --  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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

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


Re: [R] interaction plot with SE bar

2013-12-04 Thread Gerrit Eichner

Hi, Kristi,

I have adapted the interaction plot example of function panel.average() of 
the lattice package and modified the code of panel.average() to a new 
function panel.loc_and_scale(). See below. (There might be a much simpler 
solution, though.)


Remark on the side: I can't resist to point you to Tatsuki Koyama's very 
instructive explanation on why plots of SE bars are not quite 
recommendable: 
http://biostat.mc.vanderbilt.edu/wiki/pub/Main/TatsukiRcode/Poster3.pdf



Nevertheless, here's the code (note that it also allows to graph other 
location +/- scale bars if you provide fun1 and fun2 with respective 
functions):


 Regards  --  Gerrit


panel.loc_and_scale <- function(x, y, fun1 = mean, fun2 = sd,
 horizontal = TRUE,
 lwd = add.line$lwd, lty = add.line$lty,
 col, col.line = add.line$col, ...) {
x <- as.numeric(x)
y <- as.numeric(y)
add.line <- trellis.par.get( "add.line")
if (!missing(col)) {
if (missing(col.line))
col.line <- col
}
if (horizontal) {
vals <- unique(sort(y))
yy <- seq_along(vals)
xx1 <- xx2 <- numeric(length(yy))
for (i in yy) {
 xx1[i] <- fun1(x[y == vals[i]])
 xx2[i] <- fun2(x[y == vals[i]])
 }
panel.arrows( x0 = xx1 - xx2, y0 = vals[yy],
  x1 = xx1 + xx2, y1 = vals[yy],
  code = 3, angle = 90, length = 0.1,
  col = col.line, lty = lty, lwd = lwd)
panel.points( x = xx1, y = vals[yy], col = col, pch = 18)

}
else {
vals <- unique(sort(x))
xx <- seq_along(vals)
yy1 <- yy2 <- numeric(length(xx))
for (i in xx) {
 yy1[i] <- fun1(y[x == vals[i]])
 yy2[i] <- fun2(y[x == vals[i]])
 }
panel.arrows( x0 = vals[xx], y0 = yy1 - yy2,
  x1 = vals[xx], y1 = yy1 + yy2,
  code = 3, angle = 90, length = 0.1,
  col = col.line, lty = lty, lwd = lwd)
panel.points( x = vals[xx], y = yy1, col = col, pch = 18)
}
}


stripplot(yield ~ site, barley, groups = year,  # fun1 = median, fun2 = IQR,
   panel = function(x, y, groups, subscripts, ...) {
   panel.grid(h = -1, v = 0)
   panel.stripplot(x, y, ..., jitter.data = TRUE,
   groups = groups, subscripts = subscripts)
   panel.superpose(x, y, ..., panel.groups = panel.loc_and_scale,
   groups = groups, subscripts = subscripts)
   panel.superpose(x, y, ..., panel.groups = panel.average,
   groups = groups, subscripts = subscripts)
   },
   auto.key = list(points = FALSE, lines = TRUE, columns = 2))




Hi R user,
I am just wondering how I can add Standard error bar in the interaction 
plot. I used the following code but I don't know how i can edit this to 
put a started error's bar on the mean.
Would you give me some hints? or do other packages provide the 
information about plotting the SE bar for interaction.plot?


require(graphics)
with(OrchardSprays, {
 interaction.plot(treatment, rowpos, decrease)
 interaction.plot(rowpos, treatment, decrease, cex.axis = 0.8)
 ## order the rows by their mean effect
 rowpos <- factor(rowpos,
  levels = sort.list(tapply(decrease, rowpos, mean)))
 interaction.plot(rowpos, treatment, decrease, col = 2:9, lty = 1)
})

thanks


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


Re: [R] remap values from one vector to the other

2013-10-31 Thread Gerrit Eichner

Alex,

it is a bit unclear what you mean by "remap" etc., but maybe

y0 <- 880e6;   y1 <- 1020e6
x0 <- 1;   x1 <- ncol(x)

y0 + (x0-1):x1 * (y1 - y0)/(x1 - (x0-1))

gives what you want.

 Hth  --  Gerrit


On Thu, 31 Oct 2013, Alaios wrote:


Hi everyone,
I am plotting some legend and I am using the axis(at=..) to specify the place 
to plot the marks I want.

My plotted data have ncol(x) so the at places have values that span from 1 to 
ncol(x)

there I would like to be able to map values that go from 880e6 to 1020e6.
so
880e6 remaps to 1


1020e6 repams to ncol(x)

what I do not know how to do is to remap the values that are between 880e6 and 
1020e6 between then 1 and ncol(x).

Can someone help me find an appropriate function for that?

I would like to thank you in advance for your help

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.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 integer(0) rows from data frame

2013-10-30 Thread Gerrit Eichner

Hi, Jack,

well, I disagree: What do you expect to grab out of a bucket (= data 
frame) if you do not at all grab into it (indexing with an _empty_ index, 
i.e. with nothing)? And changing the sign of nothing is still nothing ...


 Hth --  Gerrit

On Wed, 30 Oct 2013, Jack Tanner wrote:


I'm not sure if this is correct behavior or not, but it seems counterintuitive
to me:

dat <- data.frame(id=1:5, let=letters[1:5])
# A. omits the first row
dat[- 1, ]

# B. unexpectedly omits ALL rows
dat[- integer(0), ]

It would be less surprising if there were no rows omitted in the (B) case.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Select fixed number of elements

2013-10-30 Thread Gerrit Eichner

Hello, Alaois,

if x is your vector maybe

n <- length( x)
positions <- trunc( quantile( seq( n), prob = 0:5/5))
x[ positions]

comes close to what you want.

 Hth  --  Gerrit

Hi all, I have in my code some vectors that are not of equal size. I 
would like to be able for each of these vectors select 6 elements that 
are (almost) equally spaced. So the first one would be at (or close) to 
the beginning the last one at (or close) to the end and the other 4 
equally spaced between first and last element.


How can I do something like that on a vector of not known size?

I would like to thank you in advance for your help

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.


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


Re: [R] Nonparametric k-way ANOVA

2013-10-25 Thread Gerrit Eichner

Hello, Vincent,

you may want to take a look at "Nonparametric methods in factorial 
designs" by Edgar Brunner and Madan L. Puri in Statistical Papers 42, 1-52 
(2001).


There is the R-package nparcomp for one-way layouts, but the paper goes 
further (and mentions another software) and is maybe a starting point for 
you.


 Hth -- Gerrit

On Thu, 24 Oct 2013, Vicent Giner-Bosch wrote:


Sorry if this subject has been already dealt here.

Which are some common tests for nonparametric k-way ANOVA?

I have read about Kruskal-Wallis test as a kind of nonparametric one-way
ANOVA, but I have not found anything about a general-setting (I mean k-way)
nonparametric ANOVA.

Can you recommend me a good R package (or other reliable software) for that?

Looking forward to your answers,


--
vicent
@vginer_upv
about.me/vginer_upv

[[alternative HTML version deleted]]

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


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


Re: [R] Where is element 30?

2013-10-22 Thread Gerrit Eichner

Hi, Alaios,

check out

?which

and in particular its "Examples" and "See Also" section.

 Hth -- Gerrit

On Tue, 22 Oct 2013, Alaios wrote:


Hi I have a vector like that

readCsvFile$V1
 [1]  30  31  32  33  34  35  36  37  38  39 310 311 312 313 314 315 316 317 318
[20] 319 320 321  20  21  22  23  24  25  26  27  28  29 210 211 212 213 214 215
[39] 216 217 218 219 220 221 222 223  40  41  42  43  44  45  46  47  48  49 410
[58] 411 412 413 414 415 416 417 418 419 420 421


and I am looking to find where the number 31 is located. So I need one function 
to return me the index of where the number 31 is.
Is there a function for that in R?

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


Re: [R] bug(?) in str() with strict.width = "cut" when appliedtodataframe with numeric component AND factor or character component withlongerlevels/strings

2013-10-16 Thread Gerrit Eichner

Dear Duncan,

unfortunately, I have to correct myself in that I _can_ reproduce the 
problem after changing the global width-option to 70, say: Using the data 
frame X from before with the 'factory-fresh' setting for width and 
executing




str( X, strict.width = "cut")

'data.frame':   11 obs. of  2 variables:
 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+05 ...
 $ B: Factor w/ 1 level "zjtvorkmoydsepnxkabmeondrjaanutjmfxlgzmrbjp": 1 1 1 1..


produces the correct output. But



oo <- options( width = 70)
str( X, strict.width = "cut")

'data.frame':   11 obs. of  2 variables:
 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..
 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..


is obviously the wrong output I reported previously. Restoring the old 
options "solves" the problem:




options( oo)
str( X, strict.width = "cut")

'data.frame':   11 obs. of  2 variables:
 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+05 ...
 $ B: Factor w/ 1 level "zjtvorkmoydsepnxkabmeondrjaanutjmfxlgzmrbjp": 1 1 1 1..


Is that reproducible for you?

  Regards  --  Gerrit


PS: "New" session info:


sessionInfo()

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] fortunes_1.5-0

loaded via a namespace (and not attached):
[1] tools_3.0.2





On Wed, 16 Oct 2013, Gerrit Eichner wrote:


Thanks, Duncan,

for the good (indirect) hint: after a restart of R the problem is -- 
fortunately :-) -- not reproducible anymore for me either. The R session had 
been running for a longer time and I recall doing some (system-related) 
things outside of R that may have interfered with it; I just forgot to take 
that possibility into consideration. :(


Regards  --  Gerrit

On Tue, 15 Oct 2013, Duncan Murdoch wrote:


On 15/10/2013 7:53 AM, Gerrit Eichner wrote:

Dear list subscribers,

here is a small artificial example to demonstrate the problem that I
encountered when looking at the structure of a (larger) data frame that
comprised (among other components)

a numeric component of elements of the order of > 1, and

a factor or character component with longer levels/strings:


k <- 43  # length of levels or character strings
n <- 11  # number of rows of data frame
M <- 1   # order of magnitude of numerical values

set.seed( 47) # to reproduce the following artificial character string
longer.char.string <- paste( sample( letters, k, replace = TRUE),
   collapse = "")

X <- data.frame( A = 1:n * M,
   B = rep( longer.char.string, n))


The following call to str() gives apparently a wrong result

str( X, strict.width = "cut")

'data.frame':   11 obs. of  2 variables:
   $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..
   $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..


whereas the correct result appears for str( X) or if you decrease k to 42
(isn't that "the answer"? ;-) ) or n to 10 or M to 1000 (or smaller,
respectively).


I tried to dig into the entrails of str.default(), where the cause may
lie, but got lost pretty soon. So, I am hoping that someone may already
have a work-around or patch (or dares to dig further)? Thank you for any
feedback!


I can't reproduce this.  I don't have a 64 bit copy of 3.0.2 handy, but I 
don't see it in 64 bit 3.0.1, or 64 bit 3.0.2-patched, or various 32 bit 
versions.


Is it reproducible for you?  It looks to me as though (if it isn't just 
something weird on your system, e.g. an old copy of str() in your 
workspace), it might be a memory protection problem:  something needed to 
be duplicated but wasn't.  But unless I can see it happen, I can't start to 
fix it.


Duncan Murdoch



   Best regards  --  Gerrit

PS:

> sessionInfo()

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] nparcomp_2.0 multcomp_1.2-21  mvtnorm_0.9-9996
[4] car_2.0-19   Hmisc_3.12-2 Formula_1.1-1
[7] survival_2.37-4  fortunes_1.5-0

loaded via a namespace (and not attached):
[1] cluster_1.14.4  grid_3.0.2  lattice_0.20-23 MASS_7.3-29
[5] nnet_7.3-7  rpart_4.1-3 stats4_3.0.2tools_3.0.2

-

Re: [R] bug(?) in str() with strict.width = "cut" when appliedtodataframe with numeric component AND factor or character component withlongerlevels/strings

2013-10-16 Thread Gerrit Eichner

Thanks, Duncan,

for the good (indirect) hint: after a restart of R the problem is -- 
fortunately :-) -- not reproducible anymore for me either. The R session 
had been running for a longer time and I recall doing some 
(system-related) things outside of R that may have interfered with it; I 
just forgot to take that possibility into consideration. :(


 Regards  --  Gerrit

On Tue, 15 Oct 2013, Duncan Murdoch wrote:


On 15/10/2013 7:53 AM, Gerrit Eichner wrote:

Dear list subscribers,

here is a small artificial example to demonstrate the problem that I
encountered when looking at the structure of a (larger) data frame that
comprised (among other components)

a numeric component of elements of the order of > 1, and

a factor or character component with longer levels/strings:


k <- 43  # length of levels or character strings
n <- 11  # number of rows of data frame
M <- 1   # order of magnitude of numerical values

set.seed( 47) # to reproduce the following artificial character string
longer.char.string <- paste( sample( letters, k, replace = TRUE),
   collapse = "")

X <- data.frame( A = 1:n * M,
   B = rep( longer.char.string, n))


The following call to str() gives apparently a wrong result

str( X, strict.width = "cut")

'data.frame':   11 obs. of  2 variables:
   $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..
   $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..


whereas the correct result appears for str( X) or if you decrease k to 42
(isn't that "the answer"? ;-) ) or n to 10 or M to 1000 (or smaller,
respectively).


I tried to dig into the entrails of str.default(), where the cause may
lie, but got lost pretty soon. So, I am hoping that someone may already
have a work-around or patch (or dares to dig further)? Thank you for any
feedback!


I can't reproduce this.  I don't have a 64 bit copy of 3.0.2 handy, but I 
don't see it in 64 bit 3.0.1, or 64 bit 3.0.2-patched, or various 32 bit 
versions.


Is it reproducible for you?  It looks to me as though (if it isn't just 
something weird on your system, e.g. an old copy of str() in your workspace), 
it might be a memory protection problem:  something needed to be duplicated 
but wasn't.  But unless I can see it happen, I can't start to fix it.


Duncan Murdoch



   Best regards  --  Gerrit

PS:

> sessionInfo()

R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] nparcomp_2.0 multcomp_1.2-21  mvtnorm_0.9-9996
[4] car_2.0-19   Hmisc_3.12-2 Formula_1.1-1
[7] survival_2.37-4  fortunes_1.5-0

loaded via a namespace (and not attached):
[1] cluster_1.14.4  grid_3.0.2  lattice_0.20-23 MASS_7.3-29
[5] nnet_7.3-7  rpart_4.1-3 stats4_3.0.2    tools_3.0.2

-
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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

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

2013-10-15 Thread Gerrit Eichner

Hello, Catalin,

fist: keep the reply on-list so that others can follow.

second: (see below)

On Tue, 15 Oct 2013, catalin roibu wrote:


Hello!
I try that! But I want to use them forward in the equation and I don't want
to write every time when I change the values.


This way to unspecific to give you any hint. So, "PLEASE do read the 
posting guide http://www.R-project.org/posting-guide.html and provide 
commented, minimal, self-contained, reproducible code."


 Regards  --  Gerrit



On 15 October 2013 14:59, Gerrit Eichner 
wrote:



Hello, Catalin,

check out

?coef

 Regards -- Gerrit



On Tue, 15 Oct 2013, catalin roibu wrote:

 Hello all!

I have a problem with R. I want to extract regression coefficients from
summary and use it for compute the theoretical values.

How can I do that in R?

thank you!

best regards,

--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro

[[alternative HTML version deleted]]

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






--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro


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


Re: [R] extract regression coefficients

2013-10-15 Thread Gerrit Eichner

Hello, Catalin,

check out

?coef

 Regards -- Gerrit


On Tue, 15 Oct 2013, catalin roibu wrote:


Hello all!
I have a problem with R. I want to extract regression coefficients from
summary and use it for compute the theoretical values.

How can I do that in R?

thank you!

best regards,

--
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
  +4 0766 71 76 58
FAX:+4 0230 52 16 64
silvic.usv.ro

[[alternative HTML version deleted]]

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


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


[R] bug(?) in str() with strict.width = "cut" when applied to dataframe with numeric component AND factor or character component with longerlevels/strings

2013-10-15 Thread Gerrit Eichner

Dear list subscribers,

here is a small artificial example to demonstrate the problem that I 
encountered when looking at the structure of a (larger) data frame that 
comprised (among other components)


a numeric component of elements of the order of > 1, and

a factor or character component with longer levels/strings:


k <- 43  # length of levels or character strings
n <- 11  # number of rows of data frame
M <- 1   # order of magnitude of numerical values

set.seed( 47) # to reproduce the following artificial character string
longer.char.string <- paste( sample( letters, k, replace = TRUE),
 collapse = "")

X <- data.frame( A = 1:n * M,
 B = rep( longer.char.string, n))


The following call to str() gives apparently a wrong result

str( X, strict.width = "cut")

'data.frame':   11 obs. of  2 variables:
 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..
 $ A: num  1e+04 2e+04 3e+04 4e+04 5e+04 6e+04 7e+04 8e+04 9e+04 1e+..


whereas the correct result appears for str( X) or if you decrease k to 42 
(isn't that "the answer"? ;-) ) or n to 10 or M to 1000 (or smaller, 
respectively).



I tried to dig into the entrails of str.default(), where the cause may 
lie, but got lost pretty soon. So, I am hoping that someone may already 
have a work-around or patch (or dares to dig further)? Thank you for any 
feedback!


 Best regards  --  Gerrit

PS:


sessionInfo()


R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
[1] nparcomp_2.0 multcomp_1.2-21  mvtnorm_0.9-9996
[4] car_2.0-19   Hmisc_3.12-2 Formula_1.1-1
[7] survival_2.37-4  fortunes_1.5-0

loaded via a namespace (and not attached):
[1] cluster_1.14.4  grid_3.0.2  lattice_0.20-23 MASS_7.3-29
[5] nnet_7.3-7  rpart_4.1-3 stats4_3.0.2tools_3.0.2

---------
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
Fax: +49-(0)641-99-32109http://www.uni-giessen.de/cms/eichner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
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 write a wrapper function which can honor defaultvalues, when the target function has ones?

2013-09-13 Thread Gerrit Eichner

Hello, Adam,

I'm rather uncertain about your goal (and consequently even more so about 
how to reach it), but anyway, maybe the function match.call() with its 
argument expand.dots is of some help for you. From its help page:


"match.call is most commonly used in two circumstances:

To record the call for later re-use: for example most model-fitting 
functions record the call as element call of the list they return. Here 
the default expand.dots = TRUE is appropriate.


To pass most of the call to another function, often model.frame. Here 
the common idiom is that expand.dots = FALSE is used, and the ... element 
of the matched call is removed. An alternative is to explicitly select the 
arguments to be passed on, as is done in lm."



 Hth  --  Gerrit

On Fri, 13 Sep 2013, Adam Ryczkowski wrote:



  (This is crosspost from
  [1]http://stackoverflow.com/questions/18670895/how-to-write-a-wrapper-functi
  on-which-can-honour-default-values-when-the-target, posted week ago, where
  although the question did receive some attention, nobody was able to help
  me.)
  I'd like to write a more-or-less generic caller to `targetf` that retains
  its default parameters.
  Suppose we have a provided by some 3rd party library `targetf`:
  targetf<-function(x=1,...){
  print(paste("x =",x))
  }
  How to write `wrapperf`, that will respect `targetf`s default arguments, so
  calling `wrapperf()` would not yield the error massage `Error in paste("x
  =", x) : argument "x" is missing, with no default`?
  The obvious candidate
  wrapperf1<-function(x,y) {
  targetf(x=x)
  }
   doesn't seem to respect targetf's default value for parameter `x`.
  OTH the
  wrapperf2<-function(...) {
  targetf(...)
  }
   behaves correctly, but it doesn't work for me, because I only care to pass
  the `x` argument, (and possibly reserve the `...` to other functions in
  `wrapperf` body).
  Maybe to solve the issue I'd have to play with ellipsis filtering, which is
  a *terra incognita* for me at the moment...
  ***
  One idea on how to solve the problem: maybe I'd need to create a specially
  crafted `...` object from scratch in `wrapperf` to do pseudo code like this:
  wrapperfX<-function(x,y,...)
  {
  ...<-if(missing(x){
  list()
  }else{
  list(x=x)
  }
  targetf(...)
  }
  But I have no idea how to even start doing assignments into ellipsis... is
  it possible at all?
  kind regards,
  Adam Ryczkowski

  [2]www.statystyka.net
  [3]+48505919892
  [4]Skype:sisteczko

References

  1. 
http://stackoverflow.com/questions/18670895/how-to-write-a-wrapper-function-which-can-honour-default-values-when-the-target
  2. http://www.google.com/
  3. callto:+48505919892
  4. skype:sisteczko
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] substituting string variable in expression with its value

2013-09-12 Thread Gerrit Eichner

Hi, Jannis,

maybe

plot( 1, 1, main = bquote( paste( .(a), " [", .(b), "]")))


comes close to what you want, but I think you may even have to use the 
following to get a varying exponent really printed elevated:


a <- "speed"
b <- "m * s"
cc <- -2

plot( 1, 1, main = bquote( paste( .(a), " [", .(b)^{.(cc)}, "]")))



 Hth  --  Gerrit



plot(1,1, main=expression(paste("speed [", m * s^{-1}, "]")))


I would, however, like to be able to supply the value "speed" and m*s^{-a} by 
variables, e.g. do something like:



a = 'speed'
b = 'm*s^{-2}'

plot(1,1, main=expression(paste(a, " [", b, "]")))

This, however, does not work as a and b are not treated as variable names in 
this case. Does anyone have a solution for this?



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


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


Re: [R] Formula in a model

2013-09-12 Thread Gerrit Eichner

Hello, Paulito,

my comments are inline below:

Thanks for the explanation. Let me give a specific example. Assume Temp 
(column 4) is the output and the rest of the columns are input is the 
training features. Note that I only use the air quality data for 
illustration purpose. T input->output mapping may not make sense in the 
real interpretation of this data.


library(e1071)

data(airquality)
mytable=airquality

colnames(mytable)=c('a','b','c','d','e','f')

modelSVM1=svm(mytable[,6] ~ .,data=mytable)
modelSVM2=svm(mytable[,-6],mytable[,6])
modelSVM3=svm(f ~ ., data=mytable)

predSVM1=predict(modelSVM1,newdata=mytable)
predSVM2=predict(modelSVM2,newdata=mytable[,-6])
predSVM3=predict(modelSVM3,newdata=mytable)

Results of predSVM2 is similar with predSVM3  but different from predSVM1.


Well, because already modelSVM1 is different from the other two. This is 
due to how the "." on the rhs of a formula is interpreted. From the help 
page of formula:


"There are two special interpretations of . in a formula. The
usual one is in the context of a data argument of model fitting
functions and means 'all columns not otherwise in the formula':
see terms.formula. In the context of update.formula, only, it
means 'what was previously in this part of the formula'."

The first interpretation applies to your situation. With the formula for 
your modelSVM1 the function model.matrix() (which is called inside the 
formula version of svm()) creates a model matrix after looking for a 
column "mytable[,6]" in the data argument. And since there is no column 
with that name, it takes all columns of mytable (including the 6th, i.e., 
the one named "f"). See what model.matrix() does in that case:



head( model.matrix(mytable[,6] ~ .,data=mytable), 3)

  (Intercept)  a   bc  d e f
1   1 41 190  7.4 67 5 1
2   1 36 118  8.0 72 5 2
3   1 12 149 12.6 74 5 3



In the case of modelSVM3 model.matrix() does find column "f" in the data 
argument, and hence omits this column in forming the terms of the rhs of 
the formula:



head( model.matrix( f ~ .,data=mytable), 3)

  (Intercept)  a   bc  d e
1   1 41 190  7.4 67 5
2   1 36 118  8.0 72 5
3   1 12 149 12.6 74 5



The call to svm() for modelSVM2 is the (non-formula) default version and 
does not need to call model.matrix() because (so to say) it expects that 
the user has done that already by supplying the response to its argument y 
and the adequately formed data matrix to its argument x.




Question: Which is the correct formulation?


The second and the third (for a sensible purpose), unless you want to 
experiment with svm() to see what happens if one does something rather 
nonsensical.




Why R doesn't detect error/discrepancy in formulation?


Because R, or in this case rather the concept of a formula and the 
function model.matrix() are not designed to replace the user who knows 
what s/he is doing after having read the documentation. ;)





If I use the same formulation with rpart using the same data:

library(rpart)

data(airquality)
mytable=airquality

colnames(mytable)=c('a','b','c','d','e','f')

modelRP1=rpart(mytable[,6]~.,data=mytable,method='anova') # this works
modelRP3=rpart(f ~ ., data=mytable,method='anova') # this works

predRP1=predict(modelRP1,newdata=mytable)
predRP3=predict(modelRP3,newdata=mytable)


The results between predRP1 and predRP3 are different while the statements:

predRP2=predict(modelRP2,newdata=mytable[,-6])
modelRP2=rpart(mytable[,-6],mytable[,6],method='anova') 

have errors.


This is presumably due to the same reasons as described above.


Remark: It is generally - for various reasons - recommended to use "<-" as 
the assignment operator, not "=". (And I like to recommend to use use 
blanks to increase readability of code.)


[... snip ...]


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


Re: [R] Formula in a model

2013-09-11 Thread Gerrit Eichner

Hello, Paulito,

first, I think you haven't received an answer yet because you did not 
"provide commented, minimal, self-contained, reproducible code" as the 
posting guide does request it from you.


Second, see inline below.

On Wed, 11 Sep 2013, Paulito Palmes wrote:


Hi,

I have a data.frame with dimension 336x336 called *training*, and 
another one called *observation* which is 336x1. I combined them as one 
table using table=data.frame(training, observation). table now has 
336x337 dimension with the last column as the observation to learn using 
the training data of the rest of the column in the table. For 
prediction, i combined the testing data and observation and pass it like 
predict(model,testingWTesingObservation)



I've used the formula: rpart(table[,337] ~ ., data=table) or 
svm(table[,337] ~ ., data=table).


I am not familiar with rpart() nor with svm() but "table[,337] ~ ., data = 
table" has the consequence that table[,337] is also in the right hand side 
of the formula, so that your "observations" are also in the "training" 
data. That doesn't seem to make sense to me, and is different from the 
call to svm() below.


 Hth  --  Gerrit

I recently discovered that this formulation produces different model 
from the: svm(training, observation) formulation. Which is correct and 
why one of them is not correct? I thought that syntactically, both are 
the same. I hope that R should be able to detect the error in one of the 
formulation to avoid the possibility of using it.


Regards,
Paul
[[alternative HTML version deleted]]

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


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


Re: [R] probability of occurrence of an event and the probabilityof anevent upon the occurrence of another event

2013-09-06 Thread Gerrit Eichner

Hello, Francesco,

these could be considered as two of the central questions in statistics in 
general ... but they do not necessarily have anything to do with R.


 Regards -- Gerrit

On Fri, 6 Sep 2013, Francesco Miranda wrote:

how can i calculate the probability of occurrence of an event and the 
probability of an event upon the occurrence of another event.

 P (A) and P (A | B) ..
[[alternative HTML version deleted]]

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


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


  1   2   >